Browse Source

MIDI-Out is now working for plugin bridges

tags/1.9.6
falkTX 9 years ago
parent
commit
53cc6fac62
2 changed files with 117 additions and 4 deletions
  1. +63
    -3
      source/backend/engine/CarlaEngineBridge.cpp
  2. +54
    -1
      source/backend/plugin/CarlaPluginBridge.cpp

+ 63
- 3
source/backend/engine/CarlaEngineBridge.cpp View File

@@ -1418,11 +1418,71 @@ protected:
plugin->unlock();
}

// clear buffer
CARLA_SAFE_ASSERT_BREAK(pData->events.in != nullptr);
uint8_t* midiData(fShmRtClientControl.data->midiOut);
carla_zeroBytes(midiData, kBridgeRtClientDataMidiOutSize);
std::size_t curMidiDataPos = 0;

if (pData->events.in[0].type != kEngineEventTypeNull)
carla_zeroStruct<EngineEvent>(pData->events.in, kMaxEngineEventInternalCount);
carla_zeroStruct<EngineEvent>(pData->events.in, kMaxEngineEventInternalCount);

if (pData->events.out[0].type != kEngineEventTypeNull)
{
for (ushort i=0; i < kMaxEngineEventInternalCount; ++i)
{
const EngineEvent& event(pData->events.out[i]);

if (event.type == kEngineEventTypeNull)
break;

if (event.type == kEngineEventTypeControl)
{
uint8_t size;
uint8_t data[3];
event.ctrl.convertToMidiData(event.channel, size, data);
CARLA_SAFE_ASSERT_CONTINUE(size > 0 && size <= 3);

if (curMidiDataPos + 1 /* size*/ + 4 /* time */ + size >= kBridgeRtClientDataMidiOutSize)
break;

// set size
*midiData++ = size;

// set time
*(uint32_t*)midiData = event.time;
midiData = midiData + 4;

// set data
for (uint8_t j=0; j<size; ++j)
*midiData++ = data[j];

curMidiDataPos += 1 /* size*/ + 4 /* time */ + size;
}
else if (event.type == kEngineEventTypeMidi)
{
const EngineMidiEvent& _midiEvent(event.midi);

if (curMidiDataPos + 1 /* size*/ + 4 /* time */ + _midiEvent.size >= kBridgeRtClientDataMidiOutSize)
break;

const uint8_t* const _midiData(_midiEvent.dataExt != nullptr ? _midiEvent.dataExt : _midiEvent.data);

// set size
*midiData++ = _midiEvent.size;

// set time
*(uint32_t*)midiData = event.time;
midiData = midiData + 4;

// set data
for (uint8_t j=0; j<_midiEvent.size; ++j)
*midiData++ = _midiData[j];

curMidiDataPos += 1 /* size*/ + 4 /* time */ + _midiEvent.size;
}
}

carla_zeroStruct<EngineEvent>(pData->events.out, kMaxEngineEventInternalCount);
}

} break;



+ 54
- 1
source/backend/plugin/CarlaPluginBridge.cpp View File

@@ -1618,7 +1618,60 @@ public:

} // End of Event Input

processSingle(audioIn, audioOut, cvIn, cvOut, frames);
if (! processSingle(audioIn, audioOut, cvIn, cvOut, frames))
return;

// --------------------------------------------------------------------------------------------------------
// Control and MIDI Output

if (pData->event.portOut != nullptr)
{
float value;

for (uint32_t k=0; k < pData->param.count; ++k)
{
if (pData->param.data[k].type != PARAMETER_OUTPUT)
continue;

if (pData->param.data[k].midiCC > 0)
{
value = pData->param.ranges[k].getNormalizedValue(fParams[k].value);
pData->event.portOut->writeControlEvent(0, pData->param.data[k].midiChannel, kEngineControlEventTypeParameter, static_cast<uint16_t>(pData->param.data[k].midiCC), value);
}
}

uint8_t size;
uint32_t time;
const uint8_t* midiData(fShmRtClientControl.data->midiOut);

for (std::size_t read=0; read<kBridgeRtClientDataMidiOutSize;)
{
size = *midiData;

if (size == 0)
break;

// advance 8 bits (1 byte)
midiData = midiData + 1;

// get time as 32bit
time = *(uint32_t*)midiData;

// advance 32 bits (4 bytes)
midiData = midiData + 4;

// store midi data advancing as needed
uint8_t data[size];

for (uint8_t j=0; j<size; ++j)
data[j] = *midiData++;

pData->event.portOut->writeMidiEvent(time, size, data);

read += 1 /* size*/ + 4 /* time */ + size;
}

} // End of Control and MIDI Output
}

bool processSingle(const float** const audioIn, float** const audioOut, const float** const cvIn, float** const cvOut, const uint32_t frames)


Loading…
Cancel
Save