mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
AudioProcessor: Add VST2/VST3 midi note name support
Co-authored-by: Roland Rabien <roland@rabien.com>
This commit is contained in:
parent
ad3457434e
commit
96e4ba06af
6 changed files with 85 additions and 2 deletions
|
|
@ -918,6 +918,7 @@ public:
|
||||||
case Vst2::effSetProcessPrecision: return handleSetSampleFloatType (args);
|
case Vst2::effSetProcessPrecision: return handleSetSampleFloatType (args);
|
||||||
case Vst2::effGetNumMidiInputChannels: return handleGetNumMidiInputChannels();
|
case Vst2::effGetNumMidiInputChannels: return handleGetNumMidiInputChannels();
|
||||||
case Vst2::effGetNumMidiOutputChannels: return handleGetNumMidiOutputChannels();
|
case Vst2::effGetNumMidiOutputChannels: return handleGetNumMidiOutputChannels();
|
||||||
|
case Vst2::effGetMidiKeyName: return handleGetMidiKeyName (args);
|
||||||
case Vst2::effEditIdle: return handleEditIdle();
|
case Vst2::effEditIdle: return handleEditIdle();
|
||||||
default: return 0;
|
default: return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -2049,6 +2050,22 @@ private:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pointer_sized_int handleGetMidiKeyName (VstOpCodeArguments args)
|
||||||
|
{
|
||||||
|
if (processor != nullptr)
|
||||||
|
{
|
||||||
|
auto keyName = (Vst2::MidiKeyName*) args.ptr;
|
||||||
|
|
||||||
|
if (auto name = processor->getNameForMidiNoteNumber (keyName->thisKeyNumber, args.index))
|
||||||
|
{
|
||||||
|
name->copyToUTF8 (keyName->keyName, Vst2::kVstMaxNameLen);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
pointer_sized_int handleEditIdle()
|
pointer_sized_int handleEditIdle()
|
||||||
{
|
{
|
||||||
#if JUCE_LINUX || JUCE_BSD
|
#if JUCE_LINUX || JUCE_BSD
|
||||||
|
|
|
||||||
|
|
@ -525,9 +525,27 @@ public:
|
||||||
return kResultFalse;
|
return kResultFalse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tresult PLUGIN_API hasProgramPitchNames (Vst::ProgramListID, Steinberg::int32) override
|
||||||
|
{
|
||||||
|
for (int i = 0; i <= 127; ++i)
|
||||||
|
if (audioProcessor->getNameForMidiNoteNumber (i, 1))
|
||||||
|
return kResultTrue;
|
||||||
|
|
||||||
|
return kResultFalse;
|
||||||
|
}
|
||||||
|
|
||||||
|
tresult PLUGIN_API getProgramPitchName (Vst::ProgramListID, Steinberg::int32, Steinberg::int16 midiNote, Vst::String128 nameOut) override
|
||||||
|
{
|
||||||
|
if (auto name = audioProcessor->getNameForMidiNoteNumber (midiNote, 1))
|
||||||
|
{
|
||||||
|
toString128 (nameOut, *name);
|
||||||
|
return kResultTrue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return kResultFalse;
|
||||||
|
}
|
||||||
|
|
||||||
tresult PLUGIN_API getProgramInfo (Vst::ProgramListID, Steinberg::int32, Vst::CString, Vst::String128) override { return kNotImplemented; }
|
tresult PLUGIN_API getProgramInfo (Vst::ProgramListID, Steinberg::int32, Vst::CString, Vst::String128) override { return kNotImplemented; }
|
||||||
tresult PLUGIN_API hasProgramPitchNames (Vst::ProgramListID, Steinberg::int32) override { return kNotImplemented; }
|
|
||||||
tresult PLUGIN_API getProgramPitchName (Vst::ProgramListID, Steinberg::int32, Steinberg::int16, Vst::String128) override { return kNotImplemented; }
|
|
||||||
tresult PLUGIN_API selectUnit (Vst::UnitID) override { return kNotImplemented; }
|
tresult PLUGIN_API selectUnit (Vst::UnitID) override { return kNotImplemented; }
|
||||||
tresult PLUGIN_API setUnitProgramData (Steinberg::int32, Steinberg::int32, IBStream*) override { return kNotImplemented; }
|
tresult PLUGIN_API setUnitProgramData (Steinberg::int32, Steinberg::int32, IBStream*) override { return kNotImplemented; }
|
||||||
Vst::UnitID PLUGIN_API getSelectedUnit() override { return Vst::kRootUnitId; }
|
Vst::UnitID PLUGIN_API getSelectedUnit() override { return Vst::kRootUnitId; }
|
||||||
|
|
|
||||||
|
|
@ -3090,6 +3090,22 @@ public:
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<String> getNameForMidiNoteNumber (int note, int /*midiChannel*/) override
|
||||||
|
{
|
||||||
|
if (unitInfo == nullptr || unitInfo->getProgramListCount() == 0)
|
||||||
|
return std::nullopt;
|
||||||
|
|
||||||
|
Vst::String128 name{};
|
||||||
|
Vst::ProgramListInfo programListInfo{};
|
||||||
|
|
||||||
|
const auto nameOk = unitInfo->getProgramListInfo (0, programListInfo) == kResultOk
|
||||||
|
&& unitInfo->hasProgramPitchNames (programListInfo.id, 0) == kResultTrue
|
||||||
|
&& unitInfo->getProgramPitchName (programListInfo.id, 0, (Steinberg::int16) note, name) == kResultOk;
|
||||||
|
|
||||||
|
return nameOk ? std::make_optional (toString (name))
|
||||||
|
: std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
void updateTrackProperties (const TrackProperties& properties) override
|
void updateTrackProperties (const TrackProperties& properties) override
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1335,6 +1335,18 @@ struct VSTPluginInstance final : public AudioPluginInstance,
|
||||||
|
|
||||||
int pluginCanDo (const char* text) const { return (int) dispatch (Vst2::effCanDo, 0, 0, (void*) text, 0); }
|
int pluginCanDo (const char* text) const { return (int) dispatch (Vst2::effCanDo, 0, 0, (void*) text, 0); }
|
||||||
|
|
||||||
|
std::optional<String> getNameForMidiNoteNumber (int note, int midiChannel) override
|
||||||
|
{
|
||||||
|
Vst2::MidiKeyName keyName{};
|
||||||
|
|
||||||
|
keyName.thisProgramIndex = getCurrentProgram();
|
||||||
|
keyName.thisKeyNumber = note;
|
||||||
|
|
||||||
|
return dispatch (Vst2::effGetMidiKeyName, midiChannel, 0, &keyName, 0.0f) != 0
|
||||||
|
? std::make_optional (String::createStringFromData (keyName.keyName, Vst2::kVstMaxNameLen))
|
||||||
|
: std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
void prepareToPlay (double rate, int samplesPerBlockExpected) override
|
void prepareToPlay (double rate, int samplesPerBlockExpected) override
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -950,6 +950,11 @@ void AudioProcessor::copyXmlToBinary (const XmlElement& xml, juce::MemoryBlock&
|
||||||
= ByteOrder::swapIfBigEndian ((uint32) destData.getSize() - 9);
|
= ByteOrder::swapIfBigEndian ((uint32) destData.getSize() - 9);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<String> AudioProcessor::getNameForMidiNoteNumber (int /*note*/, int /*midiChannel*/)
|
||||||
|
{
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
std::unique_ptr<XmlElement> AudioProcessor::getXmlFromBinary (const void* data, const int sizeInBytes)
|
std::unique_ptr<XmlElement> AudioProcessor::getXmlFromBinary (const void* data, const int sizeInBytes)
|
||||||
{
|
{
|
||||||
if (sizeInBytes > 8 && ByteOrder::littleEndianInt (data) == magicXmlNumber)
|
if (sizeInBytes > 8 && ByteOrder::littleEndianInt (data) == magicXmlNumber)
|
||||||
|
|
|
||||||
|
|
@ -1327,6 +1327,21 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual void updateTrackProperties (const TrackProperties& properties);
|
virtual void updateTrackProperties (const TrackProperties& properties);
|
||||||
|
|
||||||
|
/** Returns a custom name for a MIDI note number.
|
||||||
|
|
||||||
|
This method allows the host to query your plugin for a custom name to display
|
||||||
|
for a given MIDI note number. It's useful for plugins that work with drum kits,
|
||||||
|
microtonal scales, or other mappings.
|
||||||
|
|
||||||
|
@param note The MIDI note number for which the name is being requested.
|
||||||
|
This is an integer in the range [0, 127], representing the
|
||||||
|
full MIDI note range.
|
||||||
|
@param midiChannel The MIDI channel associated with the note. This is a 1-based
|
||||||
|
index (1-16). Use this parameter if your plugin provides
|
||||||
|
channel-specific note mappings.
|
||||||
|
*/
|
||||||
|
virtual std::optional<String> getNameForMidiNoteNumber (int note, int midiChannel);
|
||||||
|
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
/** Helper function that just converts an xml element into a binary blob.
|
/** Helper function that just converts an xml element into a binary blob.
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue