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 "pluginterfaces/base/conststringtable.h"
|
||||||
#include "base/source/fstreamer.h"
|
#include "base/source/fstreamer.h"
|
||||||
|
#include "pluginterfaces/vst/ivstmidicontrollers.h"
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
tresult PLUGIN_API Controller::initialize(FUnknown *context) {
|
tresult PLUGIN_API Controller::initialize(FUnknown *context) {
|
||||||
tresult r = EditController::initialize(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
|
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;
|
return kResultTrue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,3 +89,26 @@ tresult PLUGIN_API Controller::setComponentState(IBStream *state) {
|
|||||||
|
|
||||||
return kResultTrue;
|
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;
|
||||||
using namespace Steinberg::Vst;
|
using namespace Steinberg::Vst;
|
||||||
|
|
||||||
|
#if defined(P_PITCH_BEND) || defined(P_MOD_WHEEL)
|
||||||
|
class Controller : EditController, IMidiMapping {
|
||||||
|
#else
|
||||||
class Controller : EditController {
|
class Controller : EditController {
|
||||||
|
#endif
|
||||||
public:
|
public:
|
||||||
static FUnknown *createInstance(void *context) {
|
static FUnknown *createInstance(void *context) {
|
||||||
return (IEditController *) new Controller();
|
return (IEditController *) new Controller();
|
||||||
@ -36,6 +40,15 @@ public:
|
|||||||
|
|
||||||
tresult PLUGIN_API initialize(FUnknown *context) SMTG_OVERRIDE;
|
tresult PLUGIN_API initialize(FUnknown *context) SMTG_OVERRIDE;
|
||||||
tresult PLUGIN_API setComponentState(IBStream *state) 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:
|
private:
|
||||||
|
|
||||||
|
@ -46,6 +46,7 @@
|
|||||||
#include "pluginterfaces/vst/ivstparameterchanges.h"
|
#include "pluginterfaces/vst/ivstparameterchanges.h"
|
||||||
#include "pluginterfaces/vst/ivstevents.h"
|
#include "pluginterfaces/vst/ivstevents.h"
|
||||||
#include "base/source/fstreamer.h"
|
#include "base/source/fstreamer.h"
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
@ -230,8 +231,22 @@ tresult PLUGIN_API Plugin::process(ProcessData &data) {
|
|||||||
int32 o;
|
int32 o;
|
||||||
if (q->getPoint(q->getPointCount() - 1, o, v) == kResultTrue) {
|
if (q->getPoint(q->getPointCount() - 1, o, v) == kResultTrue) {
|
||||||
int32 pi = q->getParameterId();
|
int32 pi = q->getParameterId();
|
||||||
parameters[pi] = v;
|
switch (pi) {
|
||||||
P_SET_PARAMETER(instance, pi, std::min(std::max(static_cast<float>(v), 0.f), 1.f));
|
#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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -356,17 +356,17 @@ void bw_example_synth_mono_process(bw_example_synth_mono instance, const float**
|
|||||||
// otherwise no kbd control
|
// otherwise no kbd control
|
||||||
bw_svf_set_cutoff(&instance->vcf_coeffs, bw_clipf(cutoff, 20.f, 20e3f));
|
bw_svf_set_cutoff(&instance->vcf_coeffs, bw_clipf(cutoff, 20.f, 20e3f));
|
||||||
bw_svf_process(&instance->vcf_coeffs, &instance->vcf_state, out, out, NULL, NULL, n);
|
bw_svf_process(&instance->vcf_coeffs, &instance->vcf_state, out, out, NULL, NULL, n);
|
||||||
|
|
||||||
bw_env_gen_process(&instance->vca_env_gen_coeffs, &instance->vca_env_gen_state, instance->buf[0], n);
|
bw_env_gen_process(&instance->vca_env_gen_coeffs, &instance->vca_env_gen_state, instance->buf[0], n);
|
||||||
for (int j = 0; j < n; j++)
|
for (int j = 0; j < n; j++)
|
||||||
out[j] *= instance->buf[0][j];
|
out[j] *= instance->buf[0][j];
|
||||||
|
|
||||||
bw_phase_gen_process(&instance->a440_phase_gen_coeffs, &instance->a440_phase_gen_state, NULL, instance->buf[0], NULL, n);
|
bw_phase_gen_process(&instance->a440_phase_gen_coeffs, &instance->a440_phase_gen_state, NULL, instance->buf[0], NULL, n);
|
||||||
bw_osc_sin_process(instance->buf[0], instance->buf[0], n);
|
bw_osc_sin_process(instance->buf[0], instance->buf[0], n);
|
||||||
if (instance->params[p_a440] >= 0.5f)
|
if (instance->params[p_a440] >= 0.5f)
|
||||||
for (int j = 0; j < n; j++)
|
for (int j = 0; j < n; j++)
|
||||||
out[j] += instance->buf[0][j];
|
out[j] += instance->buf[0][j];
|
||||||
|
|
||||||
bw_vol_process(&instance->vol_coeffs, out, out, n);
|
bw_vol_process(&instance->vol_coeffs, out, out, n);
|
||||||
bw_env_follow_process(&instance->env_follow_coeffs, &instance->env_follow_state, out, NULL, n);
|
bw_env_follow_process(&instance->env_follow_coeffs, &instance->env_follow_state, out, NULL, n);
|
||||||
}
|
}
|
||||||
@ -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) {
|
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) {
|
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]);
|
Synth.noteOff(e.data[1]);
|
||||||
break;
|
break;
|
||||||
case 0xe0:
|
case 0xe0:
|
||||||
Synth.pitchBend(e.data[2] << 8 | e.data[1]);
|
Synth.pitchBend(e.data[2] << 7 | e.data[1]);
|
||||||
break;
|
break;
|
||||||
case 0xb0:
|
case 0xb0:
|
||||||
if (e.data[1] == 1)
|
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) {
|
void bw_example_synth_simple_note_on(bw_example_synth_simple instance, char note, char velocity) {
|
||||||
if (velocity == 0)
|
if (velocity == 0)
|
||||||
bw_example_synth_mono_note_off(instance, note);
|
bw_example_synth_simple_note_off(instance, note);
|
||||||
else
|
else
|
||||||
instance->note = note;
|
instance->note = note;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user