Browse Source

Implement get/setState for midiseq, remove initial test song

tags/1.9.6
falkTX 9 years ago
parent
commit
98dccfe76e
2 changed files with 136 additions and 129 deletions
  1. +132
    -0
      source/native-plugins/midi-base.hpp
  2. +4
    -129
      source/native-plugins/midi-sequencer.cpp

+ 132
- 0
source/native-plugins/midi-base.hpp View File

@@ -286,6 +286,138 @@ public:
}

// -------------------------------------------------------------------
// state

char* getState() const
{
static const std::size_t maxTimeSize = 20; // std::strlen("18446744073709551615");
static const std::size_t maxDataSize = 4 + 4*MAX_EVENT_DATA_SIZE; // std::strlen("0xFF:127:127:127");
static const std::size_t maxMsgSize = maxTimeSize + 3 /* sep + size + sep */ + maxDataSize + 1 /* newline */;

const CarlaMutexLocker sl(fMutex);

if (fData.count() == 0)
return nullptr;

char* const data((char*)std::calloc(1, fData.count()*maxMsgSize));
CARLA_SAFE_ASSERT_RETURN(data != nullptr, nullptr);

char* dataWrtn = data;
int wrtn;

for (LinkedList<const RawMidiEvent*>::Itenerator it = fData.begin(); it.valid(); it.next())
{
const RawMidiEvent* const rawMidiEvent(it.getValue(nullptr));
CARLA_SAFE_ASSERT_CONTINUE(rawMidiEvent != nullptr);

wrtn = std::snprintf(dataWrtn, maxTimeSize+4, P_INT64 ":%i:", rawMidiEvent->time, rawMidiEvent->size);
CARLA_SAFE_ASSERT_BREAK(wrtn > 0);
dataWrtn += wrtn;

wrtn = std::snprintf(dataWrtn, 5, "0x%02X", rawMidiEvent->data[0]);
CARLA_SAFE_ASSERT_BREAK(wrtn > 0);
dataWrtn += wrtn;

for (uint8_t i=1, size=rawMidiEvent->size; i<size; ++i)
{
wrtn = std::snprintf(dataWrtn, 5, ":%03u", rawMidiEvent->data[i]);
CARLA_SAFE_ASSERT_BREAK(wrtn > 0);
dataWrtn += wrtn;
}

*dataWrtn++ = '\n';
}

*dataWrtn = '\0';

return data;
}

void setState(const char* const data)
{
CARLA_SAFE_ASSERT_RETURN(data != nullptr,);

const char* dataRead = data;
const char* needle;
RawMidiEvent midiEvent;
char tmpBuf[24];
ssize_t tmpSize;

clear();

const CarlaMutexLocker sl(fMutex);

for (; *dataRead != '\0';)
{
// get time
needle = std::strchr(dataRead, ':');
CARLA_SAFE_ASSERT_RETURN(needle != nullptr,);

tmpSize = needle - dataRead;
CARLA_SAFE_ASSERT_RETURN(tmpSize > 0 && tmpSize < 24,);

std::strncpy(tmpBuf, dataRead, static_cast<size_t>(tmpSize));
tmpBuf[tmpSize] = '\0';
dataRead += tmpSize+1;

const long long time = std::atoll(tmpBuf);
CARLA_SAFE_ASSERT_RETURN(time >= 0,);

midiEvent.time = static_cast<uint64_t>(time);

// get size
needle = std::strchr(dataRead, ':');
CARLA_SAFE_ASSERT_RETURN(needle != nullptr,);

tmpSize = needle - dataRead;
CARLA_SAFE_ASSERT_RETURN(tmpSize > 0 && tmpSize < 24,);

std::strncpy(tmpBuf, dataRead, static_cast<size_t>(tmpSize));
tmpBuf[tmpSize] = '\0';
dataRead += tmpSize+1;

const int size = std::atoi(tmpBuf);
CARLA_SAFE_ASSERT_RETURN(size > 0 && size <= MAX_EVENT_DATA_SIZE,);

midiEvent.size = static_cast<uint8_t>(size);

// get events
for (int i=0; i<size; ++i)
{
CARLA_SAFE_ASSERT_RETURN(dataRead-data >= 4,);

tmpSize = i==0 ? 4 : 3;

std::strncpy(tmpBuf, dataRead, static_cast<size_t>(tmpSize));
tmpBuf[tmpSize] = '\0';
dataRead += tmpSize+1;

long mdata;

if (i == 0)
{
mdata = std::strtol(tmpBuf, nullptr, 16);
CARLA_SAFE_ASSERT_RETURN(mdata >= 0x80 && mdata <= 0xFF,);
}
else
{
mdata = std::atoi(tmpBuf);
CARLA_SAFE_ASSERT_RETURN(mdata >= 0 && mdata < MAX_MIDI_VALUE,);
}

midiEvent.data[i] = static_cast<uint8_t>(mdata);
}

for (int i=size; i<MAX_EVENT_DATA_SIZE; ++i)
midiEvent.data[i] = 0;

RawMidiEvent* const event(new RawMidiEvent());
carla_copyStruct(*event, midiEvent);
fData.append(event);
}
}

// -------------------------------------------------------------------

private:
AbstractMidiPlayer* const kPlayer;


+ 4
- 129
source/native-plugins/midi-sequencer.cpp View File

@@ -40,124 +40,6 @@ public:
fTimeInfo(),
leakDetector_MidiSequencerPlugin()
{
// TEST SONG

// assuming 4x4
const uint32_t onebeat = 48; // 1 beat = 48 ticks
//const uint32_t onebar = onebeat*4; // 1 bar = 4 beats

// 0 On ch=1 n=64 v=90
// 325 Off ch=1 n=64 v=90
// 384 On ch=1 n=62 v=90
// 709 Off ch=1 n=62 v=90
// 768 On ch=1 n=60 v=90
//1093 Off ch=1 n=60 v=90
uint32_t curTick = 0;

fMidiOut.addNote(curTick, 0, 64, 90, onebeat-1);
curTick += onebeat;
fMidiOut.addNote(curTick, 0, 62, 90, onebeat-1);
curTick += onebeat;
fMidiOut.addNote(curTick, 0, 60, 90, onebeat-1);
curTick += onebeat;

// 1152 On ch=1 n=62 v=90
// 1477 Off ch=1 n=62 v=90
// 1536 On ch=1 n=64 v=90
// 1861 Off ch=1 n=64 v=90
// 1920 On ch=1 n=64 v=90
// 2245 Off ch=1 n=64 v=90
fMidiOut.addNote(curTick, 0, 62, 90, onebeat-1);
curTick += onebeat;
fMidiOut.addNote(curTick, 0, 64, 90, onebeat-1);
curTick += onebeat;
fMidiOut.addNote(curTick, 0, 64, 90, onebeat-1);
curTick += onebeat;

// 2304 On ch=1 n=64 v=90
// 2955 Off ch=1 n=64 v=90

// 3072 On ch=1 n=62 v=90
// 3397 Off ch=1 n=62 v=90
// 3456 On ch=1 n=62 v=90
// 3781 Off ch=1 n=62 v=90
fMidiOut.addNote(curTick, 0, 64, 90, onebeat*2-1);
curTick += onebeat*2;
fMidiOut.addNote(curTick, 0, 62, 90, onebeat-1);
curTick += onebeat;
fMidiOut.addNote(curTick, 0, 62, 90, onebeat-1);
curTick += onebeat;

// 3840 On ch=1 n=62 v=90
// 4491 Off ch=1 n=62 v=90
// 4608 On ch=1 n=64 v=90
// 4933 Off ch=1 n=64 v=90
// 4992 On ch=1 n=67 v=90
// 5317 Off ch=1 n=67 v=90
fMidiOut.addNote(curTick, 0, 62, 90, onebeat*2-1);
curTick += onebeat*2;
fMidiOut.addNote(curTick, 0, 67, 90, onebeat-1);
curTick += onebeat;
fMidiOut.addNote(curTick, 0, 64, 90, onebeat-1);
curTick += onebeat;

// 5376 On ch=1 n=67 v=90
// 6027 Off ch=1 n=67 v=90
// 6144 On ch=1 n=64 v=90
// 6469 Off ch=1 n=64 v=90
// 6528 On ch=1 n=62 v=90
// 6853 Off ch=1 n=62 v=90
fMidiOut.addNote(curTick, 0, 67, 90, onebeat*2-1);
curTick += onebeat*2;
fMidiOut.addNote(curTick, 0, 64, 90, onebeat-1);
curTick += onebeat;
fMidiOut.addNote(curTick, 0, 62, 90, onebeat-1);
curTick += onebeat;

// 6912 On ch=1 n=60 v=90
// 7237 Off ch=1 n=60 v=90
// 7296 On ch=1 n=62 v=90
// 7621 Off ch=1 n=62 v=90
// 7680 On ch=1 n=64 v=90
// 8005 Off ch=1 n=64 v=90
fMidiOut.addNote(curTick, 0, 60, 90, onebeat-1);
curTick += onebeat;
fMidiOut.addNote(curTick, 0, 64, 90, onebeat-1);
curTick += onebeat;
fMidiOut.addNote(curTick, 0, 62, 90, onebeat-1);
curTick += onebeat;

// 8064 On ch=1 n=64 v=90
// 8389 Off ch=1 n=64 v=90
// 8448 On ch=1 n=64 v=90
// 9099 Off ch=1 n=64 v=90
// 9216 On ch=1 n=62 v=90
// 9541 Off ch=1 n=62 v=90
fMidiOut.addNote(curTick, 0, 64, 90, onebeat-1);
curTick += onebeat;
fMidiOut.addNote(curTick, 0, 64, 90, onebeat*2-1);
curTick += onebeat*2;
fMidiOut.addNote(curTick, 0, 62, 90, onebeat-1);
curTick += onebeat;

// 9600 On ch=1 n=62 v=90
// 9925 Off ch=1 n=62 v=90
// 9984 On ch=1 n=64 v=90
// 10309 Off ch=1 n=64 v=90
// 10368 On ch=1 n=62 v=90
// 10693 Off ch=1 n=62 v=90
fMidiOut.addNote(curTick, 0, 62, 90, onebeat-1);
curTick += onebeat;
fMidiOut.addNote(curTick, 0, 64, 90, onebeat-1);
curTick += onebeat;
fMidiOut.addNote(curTick, 0, 62, 90, onebeat-1);
curTick += onebeat;

// 10752 On ch=1 n=60 v=90
// 12056 Off ch=1 n=60 v=90
fMidiOut.addNote(curTick, 0, 60, 90, onebeat*2-1);
curTick += onebeat*2;

carla_zeroStruct(fTimeInfo);
}

@@ -283,22 +165,15 @@ protected:

char* getState() const override
{
// TODO: malloc list of events

return nullptr;
return fMidiOut.getState();
}

void setState(const char* const data) override
{
CARLA_SAFE_ASSERT_RETURN(data != nullptr,);

return;

fMidiOut.clear();
fMidiOut.setState(data);

// TODO: set events according to data

_sendEventsToUI();
if (isPipeRunning())
_sendEventsToUI();
}

// -------------------------------------------------------------------


Loading…
Cancel
Save