Browse Source

internal plugins: Allow to notify UI of MIDI events

Signed-off-by: falkTX <falktx@falktx.com>
tags/v2.3.0-RC1
falkTX 4 years ago
parent
commit
c47340d4b0
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
5 changed files with 65 additions and 7 deletions
  1. +4
    -1
      source/backend/engine/CarlaEngineNative.cpp
  2. +24
    -2
      source/backend/plugin/CarlaPluginNative.cpp
  3. +2
    -1
      source/includes/CarlaNative.h
  4. +14
    -0
      source/includes/CarlaNative.hpp
  5. +21
    -3
      source/includes/CarlaNativeExtUI.hpp

+ 4
- 1
source/backend/engine/CarlaEngineNative.cpp View File

@@ -1661,7 +1661,8 @@ public:
}

static intptr_t _dispatcher(NativePluginHandle handle,
NativePluginDispatcherOpcode opcode, int32_t index, intptr_t value, void* ptr, float opt)
NativePluginDispatcherOpcode opcode,
int32_t index, intptr_t value, void* ptr, float opt)
{
switch(opcode)
{
@@ -1688,6 +1689,8 @@ public:
case NATIVE_PLUGIN_OPCODE_IDLE:
//handlePtr->idle();
return 0;
case NATIVE_PLUGIN_OPCODE_UI_MIDI_EVENT:
return 0;
}

return 0;


+ 24
- 2
source/backend/plugin/CarlaPluginNative.cpp View File

@@ -2645,7 +2645,18 @@ public:
if (! fIsUiVisible)
return;

// TODO
if (fDescriptor->dispatcher != nullptr)
{
uint8_t data[3] = {
uint8_t(MIDI_STATUS_NOTE_ON | (channel & MIDI_CHANNEL_BIT)),
note,
velo
};
fDescriptor->dispatcher(fHandle, NATIVE_PLUGIN_OPCODE_UI_MIDI_EVENT,
3, 0,
data,
0.0f);
}
}

void uiNoteOff(const uint8_t channel, const uint8_t note) noexcept override
@@ -2660,7 +2671,18 @@ public:
if (fDescriptor == nullptr || fHandle == nullptr)
return;

// TODO
if (fDescriptor->dispatcher != nullptr)
{
uint8_t data[3] = {
uint8_t(MIDI_STATUS_NOTE_OFF | (channel & MIDI_CHANNEL_BIT)),
note,
0
};
fDescriptor->dispatcher(fHandle, NATIVE_PLUGIN_OPCODE_UI_MIDI_EVENT,
3, 0,
data,
0.0f);
}
}

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


+ 2
- 1
source/includes/CarlaNative.h View File

@@ -99,7 +99,8 @@ typedef enum {
NATIVE_PLUGIN_OPCODE_OFFLINE_CHANGED = 3, /** uses value (0=off, 1=on) */
NATIVE_PLUGIN_OPCODE_UI_NAME_CHANGED = 4, /** uses ptr */
NATIVE_PLUGIN_OPCODE_GET_INTERNAL_HANDLE = 5, /** nothing */
NATIVE_PLUGIN_OPCODE_IDLE = 6 /** nothing */
NATIVE_PLUGIN_OPCODE_IDLE = 6, /** nothing */
NATIVE_PLUGIN_OPCODE_UI_MIDI_EVENT = 7 /** uses ptr */
} NativePluginDispatcherOpcode;

typedef enum {


+ 14
- 0
source/includes/CarlaNative.hpp View File

@@ -405,6 +405,15 @@ protected:
CARLA_SAFE_ASSERT_RETURN(uiName != nullptr && uiName[0] != '\0',);
}

virtual bool uiMIDIEvent(uint8_t size, const uint8_t data[])
{
return false;

// unused
(void)size;
(void)data;
}

virtual const NativeInlineDisplayImageSurface* renderInlineDisplay(const uint32_t width, const uint32_t height)
{
CARLA_SAFE_ASSERT_RETURN(width > 0 && height > 0, nullptr);
@@ -545,6 +554,11 @@ public:
case NATIVE_PLUGIN_OPCODE_IDLE:
handlePtr->idle();
return 0;
case NATIVE_PLUGIN_OPCODE_UI_MIDI_EVENT:
CARLA_SAFE_ASSERT_RETURN(index >= 0 && index < UINT8_MAX, 0);
CARLA_SAFE_ASSERT_RETURN(ptr != nullptr, 0);
return handlePtr->uiMIDIEvent(static_cast<uint8_t>(index),
static_cast<uint8_t*>(ptr));
}

return 0;


+ 21
- 3
source/includes/CarlaNativeExtUI.hpp View File

@@ -1,6 +1,6 @@
/*
* Carla Native Plugin API (C++)
* Copyright (C) 2012-2016 Filipe Coelho <falktx@falktx.com>
* Copyright (C) 2012-2020 Filipe Coelho <falktx@falktx.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -20,6 +20,7 @@

#include "CarlaNative.hpp"
#include "CarlaExternalUI.hpp"
#include "CarlaMIDI.h"

/*!
* @defgroup CarlaNativeAPI Carla Native API
@@ -136,6 +137,22 @@ protected:
flushMessages();
}

bool uiMIDIEvent(const uint8_t size, const uint8_t data[]) override
{
if (size != 3)
return false;

const uint8_t status = MIDI_GET_STATUS_FROM_DATA(data);

if (! (MIDI_IS_STATUS_NOTE_ON(status) || MIDI_IS_STATUS_NOTE_OFF(status)))
return false;

writeMidiNoteMessage(MIDI_IS_STATUS_NOTE_ON(status),
MIDI_GET_CHANNEL_FROM_DATA(data),
data[1], data[2]);
return true;
}

// -------------------------------------------------------------------
// Pipe Server calls

@@ -161,9 +178,10 @@ protected:

if (std::strcmp(msg, "program") == 0)
{
uint32_t channel, bank, program;
uint8_t channel;
uint32_t bank, program;

CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(channel), true);
CARLA_SAFE_ASSERT_RETURN(readNextLineAsByte(channel), true);
CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(bank), true);
CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(program), true);
CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS, true);


Loading…
Cancel
Save