1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
|
/*
==============================================================================
This file is part of the IEM plug-in suite.
Author: Daniel Rudrich
Copyright (c) 2019 - Institute of Electronic Music and Acoustics (IEM)
https://iem.at
The IEM plug-in suite is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
The IEM plug-in suite is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this software. If not, see <https://www.gnu.org/licenses/>.
==============================================================================
*/
#pragma once
#include <JuceHeader.h>
#include "IOHelper.h"
#include "OSC/OSCInputStream.h"
#include "OSC/OSCParameterInterface.h"
typedef std::vector<std::unique_ptr<juce::RangedAudioParameter>> ParameterList;
template <class inputType, class outputType, bool combined = false>
class AudioProcessorBase : public juce::AudioProcessor,
public OSCMessageInterceptor,
public juce::VST2ClientExtensions,
public IOHelper<inputType, outputType, combined>,
public juce::AudioProcessorValueTreeState::Listener
{
public:
AudioProcessorBase() :
AudioProcessor(),
oscParameterInterface (*this, parameters),
parameters (*this, nullptr, juce::String (JucePlugin_Name), {})
{
}
AudioProcessorBase (ParameterList parameterLayout) :
AudioProcessor(),
parameters (*this,
nullptr,
juce::String (JucePlugin_Name),
{ parameterLayout.begin(), parameterLayout.end() }),
oscParameterInterface (*this, parameters)
{
}
AudioProcessorBase (const BusesProperties& ioLayouts, ParameterList parameterLayout) :
AudioProcessor (ioLayouts),
parameters (*this,
nullptr,
juce::String (JucePlugin_Name),
{ parameterLayout.begin(), parameterLayout.end() }),
oscParameterInterface (*this, parameters)
{
}
~AudioProcessorBase() override {}
VST2ClientExtensions* getVST2ClientExtensions() override { return this; }
//======== AudioProcessor stuff =======================================================
#ifndef JucePlugin_PreferredChannelConfigurations
bool isBusesLayoutSupported (const BusesLayout& layouts) const override
{
ignoreUnused (layouts);
return true;
}
#endif
const juce::String getName() const override { return JucePlugin_Name; }
bool acceptsMidi() const override
{
#if JucePlugin_WantsMidiInput
return true;
#else
return false;
#endif
}
bool producesMidi() const override
{
#if JucePlugin_ProducesMidiOutput
return true;
#else
return false;
#endif
}
double getTailLengthSeconds() const override { return 0.0; }
//======== VSTCallbackHandler =======================================================
juce::pointer_sized_int handleVstManufacturerSpecific (juce::int32 index,
juce::pointer_sized_int value,
void* ptr,
float opt) override
{
juce::ignoreUnused (opt);
//0x69656D is hex code for `iem` in ASCII
if (index == 0x0069656D) // prefix 00 chooses OSC message
{
try
{
size_t size = static_cast<size_t> (value); // let's make this the data size
MyOSCInputStream inputStream (ptr, size);
auto inMessage = inputStream.readMessage();
oscParameterInterface.oscMessageReceived (inMessage);
return 1;
}
catch (const juce::OSCFormatError&)
{
return -1;
}
}
return 0;
}
juce::pointer_sized_int handleVstPluginCanDo (juce::int32 index,
juce::pointer_sized_int value,
void* ptr,
float opt) override
{
juce::ignoreUnused (index, value, opt);
auto text = (const char*) ptr;
auto matches = [=] (const char* s) { return strcmp (text, s) == 0; };
if (matches ("wantsChannelCountNotifications"))
return 1;
if (matches ("hasIEMExtensions"))
return 1;
return 0;
}
//==============================================================================
OSCParameterInterface& getOSCParameterInterface() { return oscParameterInterface; }
//==============================================================================
juce::AudioProcessorValueTreeState parameters;
OSCParameterInterface oscParameterInterface;
private:
bool shouldOpenNewPort = false;
int newPortNumber = -1;
};
|