Skip to content
This repository has been archived by the owner on May 23, 2021. It is now read-only.

Commit

Permalink
Update some parts of DPF
Browse files Browse the repository at this point in the history
  • Loading branch information
pdesaulniers committed Aug 6, 2018
1 parent 4e26104 commit 7cc23df
Show file tree
Hide file tree
Showing 9 changed files with 776 additions and 214 deletions.
106 changes: 102 additions & 4 deletions distrho/DistrhoPlugin.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* DISTRHO Plugin Framework (DPF)
* Copyright (C) 2012-2016 Filipe Coelho <[email protected]>
* Copyright (C) 2012-2018 Filipe Coelho <[email protected]>
*
* Permission to use, copy, modify, and/or distribute this software for any purpose with
* or without fee is hereby granted, provided that the above copyright notice and this
Expand Down Expand Up @@ -89,6 +89,15 @@ static const uint32_t kParameterIsLogarithmic = 0x08;
*/
static const uint32_t kParameterIsOutput = 0x10;

/**
Parameter value is a trigger.@n
This means the value resets back to its default after each process/run call.@n
Cannot be used for output parameters.
@note Only officially supported under LV2. For other formats DPF simulates the behaviour.
*/
static const uint32_t kParameterIsTrigger = 0x20 | kParameterIsBoolean;

/** @} */

/* ------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -274,6 +283,90 @@ struct ParameterRanges {
}
};

/**
Parameter enumeration value.@n
A string representation of a plugin parameter value.@n
Used together can be used to give meaning to parameter values, working as an enumeration.
*/
struct ParameterEnumerationValue {
/**
Parameter value.
*/
float value;

/**
String representation of this value.
*/
String label;

/**
Default constructor, using 0.0 as value and empty label.
*/
ParameterEnumerationValue() noexcept
: value(0.0f),
label() {}

/**
Constructor using custom values.
*/
ParameterEnumerationValue(float v, const char* l) noexcept
: value(v),
label(l) {}
};

/**
Collection of parameter enumeration values.@n
Handy class to handle the lifetime and count of all enumeration values.
*/
struct ParameterEnumerationValues {
/**
Number of elements allocated in @values.
*/
uint8_t count;

/**
Wherever the host is to be restricted to only use enumeration values.
@note This mode is only a hint! Not all hosts and plugin formats support this mode.
*/
bool restrictedMode;

/**
Array of @ParameterEnumerationValue items.@n
This pointer must be null or have been allocated on the heap with `new`.
*/
const ParameterEnumerationValue* values;

/**
Default constructor, for zero enumeration values.
*/
ParameterEnumerationValues() noexcept
: count(0),
restrictedMode(false),
values() {}

/**
Constructor using custom values.@n
The pointer to @values must have been allocated on the heap with `new`.
*/
ParameterEnumerationValues(uint32_t c, bool r, const ParameterEnumerationValue* v) noexcept
: count(c),
restrictedMode(r),
values(v) {}

~ParameterEnumerationValues() noexcept
{
count = 0;
restrictedMode = false;

if (values != nullptr)
{
delete[] values;
values = nullptr;
}
}
};

/**
Parameter.
*/
Expand Down Expand Up @@ -312,6 +405,12 @@ struct Parameter {
*/
ParameterRanges ranges;

/**
Enumeration values.@n
Can be used to give meaning to parameter values, working as an enumeration.
*/
ParameterEnumerationValues enumValues;

/**
Designation for this parameter.
*/
Expand All @@ -334,6 +433,7 @@ struct Parameter {
symbol(),
unit(),
ranges(),
enumValues(),
designation(kParameterDesignationNull),
midiCC(0) {}

Expand All @@ -346,6 +446,7 @@ struct Parameter {
symbol(s),
unit(u),
ranges(def, min, max),
enumValues(),
designation(kParameterDesignationNull),
midiCC(0) {}

Expand Down Expand Up @@ -593,9 +694,6 @@ class Plugin
Write a MIDI output event.@n
This function must only be called during run().@n
Returns false when the host buffer is full, in which case do not call this again until the next run().
@note This function is not implemented yet!@n
It's here so that developers can prepare MIDI plugins in advance.@n
If you plan to use this, please report to DPF authors so it can be implemented.
*/
bool writeMidiEvent(const MidiEvent& midiEvent) noexcept;
#endif
Expand Down
14 changes: 7 additions & 7 deletions distrho/src/DistrhoPlugin.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* DISTRHO Plugin Framework (DPF)
* Copyright (C) 2012-2016 Filipe Coelho <[email protected]>
* Copyright (C) 2012-2018 Filipe Coelho <[email protected]>
*
* Permission to use, copy, modify, and/or distribute this software for any purpose with
* or without fee is hereby granted, provided that the above copyright notice and this
Expand All @@ -27,9 +27,10 @@ double d_lastSampleRate = 0.0;
/* ------------------------------------------------------------------------------------------------------------
* Static fallback data, see DistrhoPluginInternal.hpp */

const String PluginExporter::sFallbackString;
const AudioPort PluginExporter::sFallbackAudioPort;
const ParameterRanges PluginExporter::sFallbackRanges;
const String PluginExporter::sFallbackString;
const AudioPort PluginExporter::sFallbackAudioPort;
const ParameterRanges PluginExporter::sFallbackRanges;
const ParameterEnumerationValues PluginExporter::sFallbackEnumValues;

/* ------------------------------------------------------------------------------------------------------------
* Plugin */
Expand Down Expand Up @@ -102,10 +103,9 @@ void Plugin::setLatency(uint32_t frames) noexcept
#endif

#if DISTRHO_PLUGIN_WANT_MIDI_OUTPUT
bool Plugin::writeMidiEvent(const MidiEvent& /*midiEvent*/) noexcept
bool Plugin::writeMidiEvent(const MidiEvent& midiEvent) noexcept
{
// TODO
return false;
return pData->writeMidiCallback(midiEvent);
}
#endif

Expand Down
61 changes: 55 additions & 6 deletions distrho/src/DistrhoPluginInternal.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* DISTRHO Plugin Framework (DPF)
* Copyright (C) 2012-2016 Filipe Coelho <[email protected]>
* Copyright (C) 2012-2018 Filipe Coelho <[email protected]>
*
* Permission to use, copy, modify, and/or distribute this software for any purpose with
* or without fee is hereby granted, provided that the above copyright notice and this
Expand Down Expand Up @@ -32,6 +32,11 @@ static const uint32_t kMaxMidiEvents = 512;
extern uint32_t d_lastBufferSize;
extern double d_lastSampleRate;

// -----------------------------------------------------------------------
// DSP callbacks

typedef bool (*writeMidiFunc) (void* ptr, const MidiEvent& midiEvent);

// -----------------------------------------------------------------------
// Plugin private data

Expand Down Expand Up @@ -65,6 +70,10 @@ struct Plugin::PrivateData {
TimePosition timePosition;
#endif

// Callbacks
void* callbacksPtr;
writeMidiFunc writeMidiCallbackFunc;

uint32_t bufferSize;
double sampleRate;

Expand All @@ -88,6 +97,8 @@ struct Plugin::PrivateData {
#if DISTRHO_PLUGIN_WANT_LATENCY
latency(0),
#endif
callbacksPtr(nullptr),
writeMidiCallbackFunc(nullptr),
bufferSize(d_lastBufferSize),
sampleRate(d_lastSampleRate)
{
Expand Down Expand Up @@ -149,6 +160,16 @@ struct Plugin::PrivateData {
}
#endif
}

#if DISTRHO_PLUGIN_WANT_MIDI_OUTPUT
bool writeMidiCallback(const MidiEvent& midiEvent)
{
if (writeMidiCallbackFunc != nullptr)
return writeMidiCallbackFunc(callbacksPtr, midiEvent);

return false;
}
#endif
};

// -----------------------------------------------------------------------
Expand All @@ -157,7 +178,7 @@ struct Plugin::PrivateData {
class PluginExporter
{
public:
PluginExporter()
PluginExporter(void* const callbacksPtr, const writeMidiFunc writeMidiCall)
: fPlugin(createPlugin()),
fData((fPlugin != nullptr) ? fPlugin->pData : nullptr),
fIsActive(false)
Expand Down Expand Up @@ -191,6 +212,9 @@ class PluginExporter
for (uint32_t i=0, count=fData->stateCount; i < count; ++i)
fPlugin->initState(i, fData->stateKeys[i], fData->stateDefValues[i]);
#endif

fData->callbacksPtr = callbacksPtr;
fData->writeMidiCallbackFunc = writeMidiCall;
}

~PluginExporter()
Expand Down Expand Up @@ -322,9 +346,26 @@ class PluginExporter
return fData->parameters[index].designation;
}

bool isParameterInput(const uint32_t index) const noexcept
{
return (getParameterHints(index) & kParameterIsOutput) == 0x0;
}

bool isParameterOutput(const uint32_t index) const noexcept
{
return (getParameterHints(index) & kParameterIsOutput);
return (getParameterHints(index) & kParameterIsOutput) != 0x0;
}

bool isParameterOutputOrTrigger(const uint32_t index) const noexcept
{
const uint32_t hints = getParameterHints(index);

if (hints & kParameterIsOutput)
return true;
if ((hints & kParameterIsTrigger) == kParameterIsTrigger)
return true;

return false;
}

const String& getParameterName(const uint32_t index) const noexcept
Expand All @@ -348,6 +389,13 @@ class PluginExporter
return fData->parameters[index].unit;
}

const ParameterEnumerationValues& getParameterEnumValues(const uint32_t index) const noexcept
{
DISTRHO_SAFE_ASSERT_RETURN(fData != nullptr && index < fData->parameterCount, sFallbackEnumValues);

return fData->parameters[index].enumValues;
}

const ParameterRanges& getParameterRanges(const uint32_t index) const noexcept
{
DISTRHO_SAFE_ASSERT_RETURN(fData != nullptr && index < fData->parameterCount, sFallbackRanges);
Expand Down Expand Up @@ -601,9 +649,10 @@ class PluginExporter
// -------------------------------------------------------------------
// Static fallback data, see DistrhoPlugin.cpp

static const String sFallbackString;
static const AudioPort sFallbackAudioPort;
static const ParameterRanges sFallbackRanges;
static const String sFallbackString;
static const AudioPort sFallbackAudioPort;
static const ParameterRanges sFallbackRanges;
static const ParameterEnumerationValues sFallbackEnumValues;

DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(PluginExporter)
DISTRHO_PREVENT_HEAP_ALLOCATION
Expand Down
Loading

0 comments on commit 7cc23df

Please sign in to comment.