-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added midiUnifyChannel (used as template for midiFromJoystick)
- Loading branch information
Showing
17 changed files
with
1,237 additions
and
85 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#define PIZMIDI 1 | ||
#define PLUG_MIDI_INPUTS 1 //(only 1 or 0!) | ||
#define PLUG_MIDI_OUTPUTS 1 //(only 1 or 0!) | ||
#define PLUG_AUDIO_INPUTS 0 | ||
#define PLUG_AUDIO_OUTPUTS 0 | ||
#define PLUG_FORCE_EFFECT 0 | ||
#define PLUG_FORCE_INST 0 | ||
#define PLUG_NAME "midiFromJoystick" | ||
#define PLUG_IDENT 'mJoy' | ||
#define PLUG_VENDOR "hrgraf" | ||
#define PLUG_VERSION 0x10200 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,208 @@ | ||
/*----------------------------------------------------------------------------- | ||
MidiFromJoystick | ||
original framework by Reuben Vinal | ||
specific implementation by H.R.Graf | ||
-----------------------------------------------------------------------------*/ | ||
#include "../common/PizMidi.h" | ||
|
||
enum | ||
{ | ||
kChannel, | ||
kPower, | ||
|
||
kNumParams, | ||
kNumPrograms = 4 | ||
}; | ||
|
||
//------------------------------------------------------------------------------------------------------- | ||
class MidiFromJoystickProgram { | ||
friend class MidiFromJoystick; | ||
public: | ||
MidiFromJoystickProgram(); | ||
~MidiFromJoystickProgram() {} | ||
private: | ||
float fChannel; | ||
float fPower; | ||
char name[kVstMaxProgNameLen]; | ||
}; | ||
|
||
//------------------------------------------------------------------------------------------------------- | ||
class MidiFromJoystick : public PizMidi | ||
{ | ||
public: | ||
MidiFromJoystick(audioMasterCallback audioMaster); | ||
~MidiFromJoystick(); | ||
|
||
virtual void setProgram(VstInt32 program); | ||
virtual void setProgramName(char *name); | ||
virtual void getProgramName(char *name); | ||
virtual bool getProgramNameIndexed(VstInt32 category, VstInt32 index, char* text); | ||
|
||
virtual void setParameter(VstInt32 index, float value); | ||
virtual float getParameter(VstInt32 index); | ||
virtual void getParameterDisplay(VstInt32 index, char *text); | ||
virtual void getParameterName(VstInt32 index, char *text); | ||
|
||
protected: | ||
float fChannel; | ||
float fPower; | ||
|
||
virtual void processMidiEvents(VstMidiEventVec *inputs, VstMidiEventVec *outputs, VstInt32 sampleFrames); | ||
|
||
MidiFromJoystickProgram *programs; | ||
}; | ||
|
||
|
||
//------------------------------------------------------------------------------------------------------- | ||
AudioEffect* createEffectInstance(audioMasterCallback audioMaster) { | ||
return new MidiFromJoystick(audioMaster); | ||
} | ||
|
||
MidiFromJoystickProgram::MidiFromJoystickProgram() | ||
{ | ||
// default Program Values | ||
fChannel = 0.0f; | ||
fPower = 1.0f; | ||
|
||
// default program name | ||
strcpy(name, "Default"); | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
MidiFromJoystick::MidiFromJoystick(audioMasterCallback audioMaster) | ||
: PizMidi(audioMaster, kNumPrograms, kNumParams), programs(0) | ||
{ | ||
programs = new MidiFromJoystickProgram[numPrograms]; | ||
|
||
if (programs) { | ||
CFxBank* defaultBank = new CFxBank(kNumPrograms, kNumParams); | ||
if (readDefaultBank(PLUG_NAME, defaultBank)) { | ||
if ((VstInt32)defaultBank->GetFxID() == PLUG_IDENT) { | ||
for (int i = 0; i < kNumPrograms; i++) { | ||
programs[i].fChannel = defaultBank->GetProgParm(i, 0); | ||
programs[i].fPower = defaultBank->GetProgParm(i, 1); | ||
strcpy(programs[i].name, defaultBank->GetProgramName(i)); | ||
} | ||
} | ||
} | ||
else { | ||
// built-in programs | ||
for (int i = 0; i < kNumPrograms; i++) { | ||
switch (i) | ||
{ | ||
case 0: | ||
sprintf(programs[i].name, "Output on channel 10"); | ||
programs[i].fChannel = CHANNEL_TO_FLOAT015(9); | ||
break; | ||
default: | ||
sprintf(programs[i].name, "Program %d", i + 1); | ||
break; | ||
} | ||
} | ||
} | ||
setProgram(0); | ||
} | ||
|
||
init(); | ||
} | ||
|
||
|
||
//----------------------------------------------------------------------------------------- | ||
MidiFromJoystick::~MidiFromJoystick() { | ||
if (programs) | ||
delete[] programs; | ||
} | ||
|
||
//------------------------------------------------------------------------ | ||
void MidiFromJoystick::setProgram(VstInt32 program) | ||
{ | ||
MidiFromJoystickProgram* ap = &programs[program]; | ||
|
||
curProgram = program; | ||
setParameter(kChannel, ap->fChannel); | ||
setParameter(kPower, ap->fPower); | ||
} | ||
|
||
//------------------------------------------------------------------------ | ||
void MidiFromJoystick::setProgramName(char *name) | ||
{ | ||
vst_strncpy(programs[curProgram].name, name, kVstMaxProgNameLen); | ||
} | ||
|
||
//------------------------------------------------------------------------ | ||
void MidiFromJoystick::getProgramName(char *name) | ||
{ | ||
strcpy(name, programs[curProgram].name); | ||
} | ||
|
||
//----------------------------------------------------------------------------------------- | ||
bool MidiFromJoystick::getProgramNameIndexed(VstInt32 category, VstInt32 index, char* text) | ||
{ | ||
if (index < kNumPrograms) | ||
{ | ||
strcpy(text, programs[index].name); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
//----------------------------------------------------------------------------------------- | ||
void MidiFromJoystick::setParameter(VstInt32 index, float value) { | ||
|
||
MidiFromJoystickProgram* ap = &programs[curProgram]; | ||
|
||
switch (index) { | ||
case kChannel: fChannel = ap->fChannel = value; break; | ||
case kPower: fPower = ap->fPower = value; break; | ||
} | ||
} | ||
|
||
//----------------------------------------------------------------------------------------- | ||
float MidiFromJoystick::getParameter(VstInt32 index) { | ||
float v = 0; | ||
|
||
switch (index) { | ||
case kChannel: v = fChannel; break; | ||
case kPower: v = fPower; break; | ||
} | ||
return v; | ||
} | ||
|
||
//----------------------------------------------------------------------------------------- | ||
void MidiFromJoystick::getParameterName(VstInt32 index, char *label) { | ||
switch (index) { | ||
case kChannel: strcpy(label, "Channel Out"); break; | ||
case kPower: strcpy(label, "Power"); break; | ||
} | ||
} | ||
|
||
//----------------------------------------------------------------------------------------- | ||
void MidiFromJoystick::getParameterDisplay(VstInt32 index, char *text) { | ||
switch (index) { | ||
case kChannel: sprintf(text, "%d", FLOAT_TO_CHANNEL015(fChannel) + 1); break; | ||
case kPower: strcpy(text, (fPower < 0.5f) ? "off" : "on"); break; | ||
} | ||
} | ||
|
||
void MidiFromJoystick::processMidiEvents(VstMidiEventVec *inputs, VstMidiEventVec *outputs, VstInt32 sampleFrames) | ||
{ | ||
// process incoming events (of first input) | ||
for (unsigned int i = 0; i < inputs[0].size(); i++) | ||
{ | ||
//copying event "i" from input (with all its fields) | ||
VstMidiEvent me = inputs[0][i]; | ||
|
||
short status = me.midiData[0] & 0xf0; // scraping channel | ||
short channel = me.midiData[0] & 0x0f; // isolating channel (0-15) | ||
//short data1 = me.midiData[1] & 0x7f; | ||
//short data2 = me.midiData[2] & 0x7f; | ||
|
||
// modify event | ||
channel = FLOAT_TO_CHANNEL015(fChannel); //outgoing midi channel | ||
me.midiData[0] = status | (channel & 0x0f); | ||
|
||
// output event | ||
if (fPower >= 0.5f) | ||
outputs[0].push_back(me); | ||
} | ||
} |
Oops, something went wrong.