Browse Source

add semitones parameter

tags/v1.9.9
HeyCitizen 8 years ago
parent
commit
054bd2db1f
1 changed files with 56 additions and 29 deletions
  1. +56
    -29
      source/native-plugins/midi-transpose.c

+ 56
- 29
source/native-plugins/midi-transpose.c View File

@@ -25,6 +25,8 @@
typedef struct { typedef struct {
const NativeHostDescriptor* host; const NativeHostDescriptor* host;
int octaves; int octaves;
int semitones;
bool invert;
} MidiTransposeHandle; } MidiTransposeHandle;


// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
@@ -38,6 +40,7 @@ static NativePluginHandle miditranspose_instantiate(const NativeHostDescriptor*


handle->host = host; handle->host = host;
handle->octaves = 0; handle->octaves = 0;
handle->semitones = 0;
return handle; return handle;
} }


@@ -50,7 +53,7 @@ static void miditranspose_cleanup(NativePluginHandle handle)


static uint32_t miditranspose_get_parameter_count(NativePluginHandle handle) static uint32_t miditranspose_get_parameter_count(NativePluginHandle handle)
{ {
return 1;
return 2;


// unused // unused
(void)handle; (void)handle;
@@ -58,50 +61,74 @@ static uint32_t miditranspose_get_parameter_count(NativePluginHandle handle)


static const NativeParameter* miditranspose_get_parameter_info(NativePluginHandle handle, uint32_t index) static const NativeParameter* miditranspose_get_parameter_info(NativePluginHandle handle, uint32_t index)
{ {
if (index != 0)
if (index >= miditranspose_get_parameter_count(handle))
return NULL; return NULL;


static NativeParameter param;

param.name = "Octaves";
param.unit = NULL;
param.hints = NATIVE_PARAMETER_IS_ENABLED|NATIVE_PARAMETER_IS_AUTOMABLE|NATIVE_PARAMETER_IS_INTEGER;
param.ranges.def = 0.0f;
param.ranges.min = -8.0f;
param.ranges.max = 8.0f;
param.ranges.step = 1.0f;
param.ranges.stepSmall = 1.0f;
param.ranges.stepLarge = 1.0f;
param.scalePointCount = 0;
param.scalePoints = NULL;

return &param;

// unused
(void)handle;
static NativeParameter param[] =
{
{
.name = "Octaves",
.unit = NULL,
.hints = NATIVE_PARAMETER_IS_ENABLED|NATIVE_PARAMETER_IS_AUTOMABLE|NATIVE_PARAMETER_IS_INTEGER,
.ranges.def = 0.0f,
.ranges.min = -8.0f,
.ranges.max = 8.0f,
.ranges.step = 1.0f,
.ranges.stepSmall = 1.0f,
.ranges.stepLarge = 1.0f,
.scalePointCount = 0,
.scalePoints = NULL,
},
{
.name = "Semitones",
.unit = NULL,
.hints = NATIVE_PARAMETER_IS_ENABLED|NATIVE_PARAMETER_IS_AUTOMABLE|NATIVE_PARAMETER_IS_INTEGER,
.ranges.def = 0.0f,
.ranges.min = -12.0f,
.ranges.max = 12.0f,
.ranges.step = 1.0f,
.ranges.stepSmall = 1.0f,
.ranges.stepLarge = 1.0f,
.scalePointCount = 0,
.scalePoints = NULL,
},
};
return &param[index];
} }


static float miditranspose_get_parameter_value(NativePluginHandle handle, uint32_t index) static float miditranspose_get_parameter_value(NativePluginHandle handle, uint32_t index)
{ {
if (index != 0)
switch (index)
{
case 0:
return (float)handlePtr->octaves;
case 1:
return (float)handlePtr->semitones;
default:
return 0.0f; return 0.0f;

return (float)handlePtr->octaves;
}
} }


static void miditranspose_set_parameter_value(NativePluginHandle handle, uint32_t index, float value) static void miditranspose_set_parameter_value(NativePluginHandle handle, uint32_t index, float value)
{ {
if (index != 0)
return;
switch (index)
{
case 0:
handlePtr->octaves = (int)value;
case 1:
handlePtr->semitones = (int)value;
default:
return;
}


handlePtr->octaves = (int)value;
} }


static void miditranspose_process(NativePluginHandle handle, float** inBuffer, float** outBuffer, uint32_t frames, const NativeMidiEvent* midiEvents, uint32_t midiEventCount) static void miditranspose_process(NativePluginHandle handle, float** inBuffer, float** outBuffer, uint32_t frames, const NativeMidiEvent* midiEvents, uint32_t midiEventCount)
{ {
const NativeHostDescriptor* const host = handlePtr->host; const NativeHostDescriptor* const host = handlePtr->host;
const int octaves = handlePtr->octaves; const int octaves = handlePtr->octaves;
NativeMidiEvent tmpEvent;
const int semitones = handlePtr->semitones;
NativeMidiEvent tmpEvent;


for (uint32_t i=0; i < midiEventCount; ++i) for (uint32_t i=0; i < midiEventCount; ++i)
{ {
@@ -112,7 +139,7 @@ static void miditranspose_process(NativePluginHandle handle, float** inBuffer, f
if (status == MIDI_STATUS_NOTE_OFF || status == MIDI_STATUS_NOTE_ON) if (status == MIDI_STATUS_NOTE_OFF || status == MIDI_STATUS_NOTE_ON)
{ {
int oldnote = midiEvent->data[1]; int oldnote = midiEvent->data[1];
int newnote = oldnote + octaves*12;
int newnote = oldnote + octaves*12 + semitones;


if (newnote < 0 || newnote >= MAX_MIDI_NOTE) if (newnote < 0 || newnote >= MAX_MIDI_NOTE)
continue; continue;
@@ -151,7 +178,7 @@ static const NativePluginDescriptor miditransposeDesc = {
.audioOuts = 0, .audioOuts = 0,
.midiIns = 1, .midiIns = 1,
.midiOuts = 1, .midiOuts = 1,
.paramIns = 1,
.paramIns = 2,
.paramOuts = 0, .paramOuts = 0,
.name = "MIDI Transpose", .name = "MIDI Transpose",
.label = "miditranspose", .label = "miditranspose",


Loading…
Cancel
Save