fixed pitch bend and note off bugs + added vst3 pitch bend and mod wheel
This commit is contained in:
parent
c3d2a73990
commit
5b42fbb0e1
34
examples/common/vst3/common.h
Normal file
34
examples/common/vst3/common.h
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Brickworks
|
||||
*
|
||||
* Copyright (C) 2022 Orastron Srl unipersonale
|
||||
*
|
||||
* Brickworks 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, version 3 of the License.
|
||||
*
|
||||
* Brickworks 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
|
||||
*
|
||||
* File author: Stefano D'Angelo
|
||||
*/
|
||||
|
||||
#ifndef _VST3_COMMON_H
|
||||
#define _VST3_COMMON_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#if defined(P_PITCH_BEND)
|
||||
# define TAG_PITCH_BEND NUM_PARAMETERS
|
||||
# if defined(P_MOD_WHEEL)
|
||||
# define TAG_MOD_WHEEL (NUM_PARAMETERS + 1)
|
||||
# endif
|
||||
#elif defined(P_MOD_WHEEL)
|
||||
# define TAG_MOD_WHEEL NUM_PARAMETERS
|
||||
#endif
|
||||
|
||||
#endif
|
@ -21,6 +21,8 @@
|
||||
|
||||
#include "pluginterfaces/base/conststringtable.h"
|
||||
#include "base/source/fstreamer.h"
|
||||
#include "pluginterfaces/vst/ivstmidicontrollers.h"
|
||||
#include "common.h"
|
||||
|
||||
tresult PLUGIN_API Controller::initialize(FUnknown *context) {
|
||||
tresult r = EditController::initialize(context);
|
||||
@ -41,6 +43,32 @@ tresult PLUGIN_API Controller::initialize(FUnknown *context) {
|
||||
config_parameters[i].shortName ? ConstStringTable::instance()->getString(config_parameters[i].shortName) : nullptr
|
||||
);
|
||||
|
||||
#ifdef P_PITCH_BEND
|
||||
parameters.addParameter(
|
||||
ConstStringTable::instance()->getString("MIDI Pitch Bend"),
|
||||
nullptr,
|
||||
0,
|
||||
0.5f,
|
||||
ParameterInfo::kCanAutomate,
|
||||
TAG_PITCH_BEND,
|
||||
0,
|
||||
nullptr
|
||||
);
|
||||
#endif
|
||||
|
||||
#ifdef P_MOD_WHEEL
|
||||
parameters.addParameter(
|
||||
ConstStringTable::instance()->getString("MIDI Mod Wheel"),
|
||||
nullptr,
|
||||
0,
|
||||
0.5f,
|
||||
ParameterInfo::kCanAutomate,
|
||||
TAG_MOD_WHEEL,
|
||||
0,
|
||||
nullptr
|
||||
);
|
||||
#endif
|
||||
|
||||
return kResultTrue;
|
||||
}
|
||||
|
||||
@ -61,3 +89,26 @@ tresult PLUGIN_API Controller::setComponentState(IBStream *state) {
|
||||
|
||||
return kResultTrue;
|
||||
}
|
||||
|
||||
#if defined(P_PITCH_BEND) || defined(P_MOD_WHEEL)
|
||||
tresult PLUGIN_API Controller::getMidiControllerAssignment(int32 busIndex, int16 channel, CtrlNumber midiControllerNumber, ParamID& id) {
|
||||
if (busIndex != 0)
|
||||
return kResultFalse;
|
||||
|
||||
#ifdef P_PITCH_BEND
|
||||
if (midiControllerNumber == Vst::kPitchBend) {
|
||||
id = TAG_PITCH_BEND;
|
||||
return kResultTrue;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef P_MOD_WHEEL
|
||||
if (midiControllerNumber == Vst::kCtrlModWheel) {
|
||||
id = TAG_MOD_WHEEL;
|
||||
return kResultTrue;
|
||||
}
|
||||
#endif
|
||||
|
||||
return kResultFalse;
|
||||
}
|
||||
#endif
|
||||
|
@ -28,7 +28,11 @@
|
||||
using namespace Steinberg;
|
||||
using namespace Steinberg::Vst;
|
||||
|
||||
#if defined(P_PITCH_BEND) || defined(P_MOD_WHEEL)
|
||||
class Controller : EditController, IMidiMapping {
|
||||
#else
|
||||
class Controller : EditController {
|
||||
#endif
|
||||
public:
|
||||
static FUnknown *createInstance(void *context) {
|
||||
return (IEditController *) new Controller();
|
||||
@ -36,6 +40,15 @@ public:
|
||||
|
||||
tresult PLUGIN_API initialize(FUnknown *context) SMTG_OVERRIDE;
|
||||
tresult PLUGIN_API setComponentState(IBStream *state) SMTG_OVERRIDE;
|
||||
#if defined(P_PITCH_BEND) || defined(P_MOD_WHEEL)
|
||||
tresult PLUGIN_API getMidiControllerAssignment(int32 busIndex, int16 channel, CtrlNumber midiControllerNumber, ParamID& id) SMTG_OVERRIDE;
|
||||
|
||||
OBJ_METHODS (Controller, EditController)
|
||||
DEFINE_INTERFACES
|
||||
DEF_INTERFACE (IMidiMapping)
|
||||
END_DEFINE_INTERFACES (EditController)
|
||||
REFCOUNT_METHODS (EditController)
|
||||
#endif
|
||||
|
||||
private:
|
||||
|
||||
|
@ -46,6 +46,7 @@
|
||||
#include "pluginterfaces/vst/ivstparameterchanges.h"
|
||||
#include "pluginterfaces/vst/ivstevents.h"
|
||||
#include "base/source/fstreamer.h"
|
||||
#include "common.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
@ -230,8 +231,22 @@ tresult PLUGIN_API Plugin::process(ProcessData &data) {
|
||||
int32 o;
|
||||
if (q->getPoint(q->getPointCount() - 1, o, v) == kResultTrue) {
|
||||
int32 pi = q->getParameterId();
|
||||
switch (pi) {
|
||||
#ifdef P_PITCH_BEND
|
||||
case TAG_PITCH_BEND:
|
||||
P_PITCH_BEND(instance, static_cast<int>(16383.f * std::min(std::max(static_cast<float>(v), 0.f), 1.f)));
|
||||
break;
|
||||
#endif
|
||||
#ifdef P_MOD_WHEEL
|
||||
case TAG_MOD_WHEEL:
|
||||
P_MOD_WHEEL(instance, static_cast<char>(127.f * std::min(std::max(static_cast<float>(v), 0.f), 1.f)));
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
parameters[pi] = v;
|
||||
P_SET_PARAMETER(instance, pi, std::min(std::max(static_cast<float>(v), 0.f), 1.f));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -470,7 +470,7 @@ void bw_example_synth_mono_note_off(bw_example_synth_mono instance, char note) {
|
||||
}
|
||||
|
||||
void bw_example_synth_mono_pitch_bend(bw_example_synth_mono instance, int value) {
|
||||
instance->pitch_bend = (value - 0x4000) / (float)0x4000;
|
||||
instance->pitch_bend = (value - 0x2000) / (float)0x4000;
|
||||
}
|
||||
|
||||
void bw_example_synth_mono_mod_wheel(bw_example_synth_mono instance, char value) {
|
||||
|
@ -122,7 +122,7 @@ window.addEventListener("load", async function (e) {
|
||||
Synth.noteOff(e.data[1]);
|
||||
break;
|
||||
case 0xe0:
|
||||
Synth.pitchBend(e.data[2] << 8 | e.data[1]);
|
||||
Synth.pitchBend(e.data[2] << 7 | e.data[1]);
|
||||
break;
|
||||
case 0xb0:
|
||||
if (e.data[1] == 1)
|
||||
|
@ -187,7 +187,7 @@ float bw_example_synth_simple_get_parameter(bw_example_synth_simple instance, in
|
||||
|
||||
void bw_example_synth_simple_note_on(bw_example_synth_simple instance, char note, char velocity) {
|
||||
if (velocity == 0)
|
||||
bw_example_synth_mono_note_off(instance, note);
|
||||
bw_example_synth_simple_note_off(instance, note);
|
||||
else
|
||||
instance->note = note;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user