Browse Source

Wait until plugin-server clears the ringbuffer before sending more data

tags/1.9.6
falkTX 10 years ago
parent
commit
4298ddeaf6
3 changed files with 58 additions and 13 deletions
  1. +36
    -11
      source/backend/engine/CarlaEngineBridge.cpp
  2. +13
    -2
      source/backend/plugin/CarlaPluginBridge.cpp
  3. +9
    -0
      source/utils/CarlaRingBuffer.hpp

+ 36
- 11
source/backend/engine/CarlaEngineBridge.cpp View File

@@ -336,6 +336,19 @@ struct BridgeNonRtServerControl : public CarlaRingBufferControl<HugeStackBuffer>
writeUInt(static_cast<uint32_t>(opcode));
}

void waitIfDataIsReachingLimit() const noexcept
{
if (getAvailableDataSize() < HugeStackBuffer::size/4)
return;

for (int i=50; --i >= 0;)
{
if (getAvailableDataSize() >= HugeStackBuffer::size*3/4)
break;
carla_msleep(20);
}
}

CARLA_DECLARE_NON_COPY_STRUCT(BridgeNonRtServerControl)
};

@@ -586,6 +599,8 @@ public:
fShmNonRtServerControl.commitWrite();
}

fShmNonRtServerControl.waitIfDataIsReachingLimit();

// kPluginBridgeNonRtServerParameter*
if (const uint32_t count = plugin->getParameterCount())
{
@@ -659,6 +674,8 @@ public:
fShmNonRtServerControl.writeFloat(plugin->getParameterValue(i));
fShmNonRtServerControl.commitWrite();
}

fShmNonRtServerControl.waitIfDataIsReachingLimit();
}
}

@@ -683,6 +700,7 @@ public:
fShmNonRtServerControl.writeCustomData(bufStr, bufStrSize);

fShmNonRtServerControl.commitWrite();
fShmNonRtServerControl.waitIfDataIsReachingLimit();
}
}

@@ -710,6 +728,7 @@ public:
fShmNonRtServerControl.writeCustomData(mpData.name, bufStrSize);

fShmNonRtServerControl.commitWrite();
fShmNonRtServerControl.waitIfDataIsReachingLimit();
}
}

@@ -720,6 +739,8 @@ public:
carla_stdout("Carla Client Ready!");
}

fShmNonRtServerControl.waitIfDataIsReachingLimit();

if (const uint32_t count = plugin->getParameterCount())
{
const CarlaMutexLocker _cml(fShmNonRtServerControl.mutex);
@@ -732,9 +753,8 @@ public:
fShmNonRtServerControl.writeOpcode(kPluginBridgeNonRtServerParameterValue2);
fShmNonRtServerControl.writeUInt(i);
fShmNonRtServerControl.writeFloat(plugin->getParameterValue(i));

if (! fShmNonRtServerControl.commitWrite())
break;
fShmNonRtServerControl.commitWrite();
fShmNonRtServerControl.waitIfDataIsReachingLimit();
}
}

@@ -761,42 +781,47 @@ public:
switch (action)
{
// uint/index float/value
case ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED:
case ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED: {
CARLA_SAFE_ASSERT_BREAK(value1 >= 0);
const CarlaMutexLocker _cml(fShmNonRtServerControl.mutex);
fShmNonRtServerControl.writeOpcode(kPluginBridgeNonRtServerParameterValue);
fShmNonRtServerControl.writeUInt(static_cast<uint>(value1));
fShmNonRtServerControl.writeFloat(value3);
fShmNonRtServerControl.commitWrite();
break;
} break;

// uint/index float/value
case ENGINE_CALLBACK_PARAMETER_DEFAULT_CHANGED:
case ENGINE_CALLBACK_PARAMETER_DEFAULT_CHANGED: {
CARLA_SAFE_ASSERT_BREAK(value1 >= 0);
const CarlaMutexLocker _cml(fShmNonRtServerControl.mutex);
fShmNonRtServerControl.writeOpcode(kPluginBridgeNonRtServerDefaultValue);
fShmNonRtServerControl.writeUInt(static_cast<uint>(value1));
fShmNonRtServerControl.writeFloat(value3);
fShmNonRtServerControl.commitWrite();
break;
} break;

// int/index
case ENGINE_CALLBACK_PROGRAM_CHANGED:
case ENGINE_CALLBACK_PROGRAM_CHANGED: {
CARLA_SAFE_ASSERT_BREAK(value1 >= -1);
const CarlaMutexLocker _cml(fShmNonRtServerControl.mutex);
fShmNonRtServerControl.writeOpcode(kPluginBridgeNonRtServerCurrentProgram);
fShmNonRtServerControl.writeInt(value1);
fShmNonRtServerControl.commitWrite();
break;
} break;

// int/index
case ENGINE_CALLBACK_MIDI_PROGRAM_CHANGED:
case ENGINE_CALLBACK_MIDI_PROGRAM_CHANGED: {
CARLA_SAFE_ASSERT_BREAK(value1 >= -1);
const CarlaMutexLocker _cml(fShmNonRtServerControl.mutex);
fShmNonRtServerControl.writeOpcode(kPluginBridgeNonRtServerCurrentMidiProgram);
fShmNonRtServerControl.writeInt(value1);
fShmNonRtServerControl.commitWrite();
break;
} break;

case ENGINE_CALLBACK_UI_STATE_CHANGED:
if (value1 != 1)
{
const CarlaMutexLocker _cml(fShmNonRtServerControl.mutex);
fShmNonRtServerControl.writeOpcode(kPluginBridgeNonRtServerUiClosed);
fShmNonRtServerControl.commitWrite();
}


+ 13
- 2
source/backend/plugin/CarlaPluginBridge.cpp View File

@@ -1854,9 +1854,9 @@ public:
for (; fShmNonRtServerControl.isDataAvailableForReading();)
{
const PluginBridgeNonRtServerOpcode opcode(fShmNonRtServerControl.readOpcode());
#if 1//def DEBUG
#ifdef DEBUG
if (opcode != kPluginBridgeNonRtServerPong) {
carla_stdout("CarlaPluginBridge::handleNonRtData() - got opcode: %s", PluginBridgeNonRtServerOpcode2str(opcode));
carla_debug("CarlaPluginBridge::handleNonRtData() - got opcode: %s", PluginBridgeNonRtServerOpcode2str(opcode));
}
#endif
switch (opcode)
@@ -1960,6 +1960,17 @@ public:

pData->param.createNew(count, false);
fParams = new BridgeParamInfo[count];

// we might not receive all parameter data, so ensure range max is not 0
for (uint32_t i=0; i<maxParams; ++i)
{
pData->param.ranges[i].def = 0.0f;
pData->param.ranges[i].min = 0.0f;
pData->param.ranges[i].max = 1.0f;
pData->param.ranges[i].step = 0.001f;
pData->param.ranges[i].stepSmall = 0.0001f;
pData->param.ranges[i].stepLarge = 0.1f;
}
}
} break;



+ 9
- 0
source/utils/CarlaRingBuffer.hpp View File

@@ -149,6 +149,15 @@ public:
return (fBuffer->buf == nullptr || fBuffer->head == fBuffer->tail);
}

uint32_t getAvailableDataSize() const noexcept
{
CARLA_SAFE_ASSERT_RETURN(fBuffer != nullptr, 0);

const uint32_t wrap((fBuffer->tail > fBuffer->wrtn) ? 0 : fBuffer->size);

return wrap + fBuffer->tail - fBuffer->wrtn;
}

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

bool readBool() noexcept


Loading…
Cancel
Save