Browse Source

Fix midiseq plugin event ordering

tags/1.9.4
falkTX 11 years ago
parent
commit
5406145ec8
1 changed files with 14 additions and 33 deletions
  1. +14
    -33
      source/backend/native/midi-sequencer.cpp

+ 14
- 33
source/backend/native/midi-sequencer.cpp View File

@@ -136,13 +136,6 @@ public:
addNote(2304*m, 0, 64, 90, 650*m); addNote(2304*m, 0, 64, 90, 650*m);
addNote(3072*m, 0, 62, 90, 325*m); addNote(3072*m, 0, 62, 90, 325*m);
addNote(3456*m, 0, 62, 90, 325*m); addNote(3456*m, 0, 62, 90, 325*m);

for (auto it = fData.begin(); it.valid(); it.next())
{
const RawMidiEvent* const rawMidiEvent(*it);

carla_stdout("Got event %02X @%i", rawMidiEvent->data[0], rawMidiEvent->time);
}
} }


~MidiPattern() ~MidiPattern()
@@ -159,7 +152,7 @@ public:
ctrlEvent->size = 3; ctrlEvent->size = 3;
ctrlEvent->time = time; ctrlEvent->time = time;


appendAt(ctrlEvent, time);
append(ctrlEvent);
} }


void addProgram(const uint32_t time, const uint8_t channel, const uint8_t bank, const uint8_t program) void addProgram(const uint32_t time, const uint8_t channel, const uint8_t bank, const uint8_t program)
@@ -177,8 +170,8 @@ public:
programEvent->size = 2; programEvent->size = 2;
programEvent->time = time; programEvent->time = time;


appendAt(bankEvent, time);
appendAt(programEvent, time);
append(bankEvent);
append(programEvent);
} }


void addNote(const uint32_t time, const uint8_t channel, const uint8_t pitch, const uint8_t velocity, const uint32_t duration) void addNote(const uint32_t time, const uint8_t channel, const uint8_t pitch, const uint8_t velocity, const uint32_t duration)
@@ -197,8 +190,8 @@ public:
noteOffEvent->size = 3; noteOffEvent->size = 3;
noteOffEvent->time = time+duration; noteOffEvent->time = time+duration;


appendAt(noteOnEvent, time);
appendAt(noteOffEvent, time+duration);
append(noteOnEvent);
append(noteOffEvent);
} }


void play(uint32_t timePosFrame, uint32_t frames) void play(uint32_t timePosFrame, uint32_t frames)
@@ -238,41 +231,29 @@ private:
CarlaMutex fMutex; CarlaMutex fMutex;
NonRtList<const RawMidiEvent*> fData; NonRtList<const RawMidiEvent*> fData;


void appendAt(const RawMidiEvent* const event, const uint32_t time)
void append(const RawMidiEvent* const event)
{ {
if (fData.isEmpty()) if (fData.isEmpty())
{ {
fMutex.lock();
const CarlaMutex::ScopedLocker sl(&fMutex);
fData.append(event); fData.append(event);
fMutex.unlock();
return; return;
} }


uint32_t lastTime = 0;

for (auto it = fData.begin(); it.valid(); it.next()) for (auto it = fData.begin(); it.valid(); it.next())
{ {
const RawMidiEvent* const oldEvent(*it); const RawMidiEvent* const oldEvent(*it);


if (lastTime > time)
{
fMutex.lock();
fData.insertAt(event, it);
fMutex.unlock();
return;
}
if (event->time >= oldEvent->time)
continue;


lastTime = oldEvent->time;
const CarlaMutex::ScopedLocker sl(&fMutex);
fData.insertAt(event, it);
return;
} }


if (time >= lastTime)
{
fMutex.lock();
fData.append(event);
fMutex.unlock();
}
else
carla_stderr2("MidiPattern::appendAt() failed for time %i", time);
const CarlaMutex::ScopedLocker sl(&fMutex);
fData.append(event);
} }


void writeMidiEvent(const MidiEvent* const event) void writeMidiEvent(const MidiEvent* const event)


Loading…
Cancel
Save