Signed-off-by: falkTX <falktx@falktx.com>tags/v2.3.0-RC1
@@ -59,18 +59,9 @@ public: | |||
fStartTime(0), | |||
fReadMutex(), | |||
fWriteMutex(), | |||
fData(), | |||
fTemporary() | |||
fData() | |||
{ | |||
CARLA_SAFE_ASSERT(kPlayer != nullptr); | |||
carla_zeroStructs(fTemporary, 2); | |||
fTemporary[0].data[0] = MIDI_STATUS_NOTE_OFF; | |||
fTemporary[1].data[0] = MIDI_STATUS_NOTE_ON; | |||
fTemporary[1].data[2] = 100; | |||
fTemporary[0].size = fTemporary[1].size = 3; | |||
} | |||
~MidiPattern() noexcept | |||
@@ -192,12 +183,6 @@ public: | |||
appendSorted(rawEvent); | |||
} | |||
void flagTemporaryNote(const uint8_t note, const bool on) | |||
{ | |||
fTemporary[on ? 1 : 0].time = 1; | |||
fTemporary[on ? 1 : 0].data[1] = note; | |||
} | |||
// ------------------------------------------------------------------- | |||
// remove data | |||
@@ -255,8 +240,6 @@ public: | |||
{ | |||
long double ldtime; | |||
playTemporary(); | |||
const CarlaMutexTryLocker cmtl(fReadMutex); | |||
if (cmtl.wasNotLocked()) | |||
@@ -290,21 +273,6 @@ public: | |||
return true; | |||
} | |||
void playTemporary() | |||
{ | |||
if (fTemporary[0].time != 0) | |||
{ | |||
fTemporary[0].time = 0; | |||
kPlayer->writeMidiEvent(fMidiPort, 0.0, &fTemporary[0]); | |||
} | |||
if (fTemporary[1].time != 0) | |||
{ | |||
fTemporary[1].time = 0; | |||
kPlayer->writeMidiEvent(fMidiPort, 0.0, &fTemporary[1]); | |||
} | |||
} | |||
// ------------------------------------------------------------------- | |||
// configure | |||
@@ -495,8 +463,6 @@ private: | |||
CarlaMutex fWriteMutex; | |||
LinkedList<const RawMidiEvent*> fData; | |||
RawMidiEvent fTemporary[2]; | |||
void appendSorted(const RawMidiEvent* const event) | |||
{ | |||
const CarlaMutexLocker cmlw(fWriteMutex); | |||
@@ -19,6 +19,7 @@ | |||
#include "RtLinkedList.hpp" | |||
#include "midi-base.hpp" | |||
#include "midi-queue.hpp" | |||
// matches UI side | |||
#define TICKS_PER_BEAT 48 | |||
@@ -47,7 +48,9 @@ public: | |||
fTicksPerFrame(0.0), | |||
fMaxTicks(0.0), | |||
fMidiOut(this), | |||
fTimeInfo() | |||
fTimeInfo(), | |||
fMidiQueue(), | |||
fMidiQueueRT() | |||
{ | |||
carla_zeroStruct(fTimeInfo); | |||
@@ -237,6 +240,20 @@ protected: | |||
fNeedsAllNotesOff = false; | |||
} | |||
if (fMidiQueue.isNotEmpty() && fMidiQueueRT.tryToCopyDataFrom(fMidiQueue)) | |||
{ | |||
uint8_t d1, d2, d3; | |||
NativeMidiEvent ev = { 0, 0, 3, { 0, 0, 0, 0 } }; | |||
while (fMidiQueueRT.get(d1, d2, d3)) | |||
{ | |||
ev.data[0] = d1; | |||
ev.data[1] = d2; | |||
ev.data[2] = d3; | |||
NativePluginAndUiClass::writeMidiEvent(&ev); | |||
} | |||
} | |||
if (fTimeInfo.playing) | |||
{ | |||
if (! fTimeInfo.bbt.valid) | |||
@@ -281,10 +298,6 @@ protected: | |||
fLastFrame = fTimeInfo.frame; | |||
fLastPosition = static_cast<float>(playPos); | |||
} | |||
else | |||
{ | |||
fMidiOut.playTemporary(); | |||
} | |||
} | |||
// ------------------------------------------------------------------- | |||
@@ -400,7 +413,12 @@ protected: | |||
CARLA_SAFE_ASSERT_RETURN(readNextLineAsByte(note), true); | |||
CARLA_SAFE_ASSERT_RETURN(readNextLineAsBool(on), true); | |||
fMidiOut.flagTemporaryNote(note, on); | |||
const uint8_t status = on ? MIDI_STATUS_NOTE_ON : MIDI_STATUS_NOTE_OFF; | |||
const uint8_t velocity = on ? 100 : 0; | |||
const CarlaMutexLocker cml(fMidiQueue.getMutex()); | |||
fMidiQueue.put(status, note, velocity); | |||
return true; | |||
} | |||
@@ -465,6 +483,8 @@ private: | |||
MidiPattern fMidiOut; | |||
NativeTimeInfo fTimeInfo; | |||
MIDIEventQueue<32> fMidiQueue, fMidiQueueRT; | |||
float fParameters[kParameterCount]; | |||
void _sendEventsToUI() const noexcept | |||