summaryrefslogtreecommitdiff
path: root/muse2/synti/organ
diff options
context:
space:
mode:
Diffstat (limited to 'muse2/synti/organ')
-rw-r--r--muse2/synti/organ/common_defs.h8
-rw-r--r--muse2/synti/organ/organ.cpp86
-rw-r--r--muse2/synti/organ/organ.h12
-rw-r--r--muse2/synti/organ/organgui.cpp7
4 files changed, 89 insertions, 24 deletions
diff --git a/muse2/synti/organ/common_defs.h b/muse2/synti/organ/common_defs.h
new file mode 100644
index 00000000..31d09081
--- /dev/null
+++ b/muse2/synti/organ/common_defs.h
@@ -0,0 +1,8 @@
+#ifndef __ORGAN_UNIQUE_ID_H
+#define __ORGAN_UNIQUE_ID_H
+
+// Make sure this number is unique among all the MESS synths.
+#define ORGAN_UNIQUE_ID 1
+
+#endif
+
diff --git a/muse2/synti/organ/organ.cpp b/muse2/synti/organ/organ.cpp
index 56fb4db1..f3bb3b9f 100644
--- a/muse2/synti/organ/organ.cpp
+++ b/muse2/synti/organ/organ.cpp
@@ -17,6 +17,7 @@
//#include "libsynti/mpevent.h"
#include "muse/mpevent.h"
+//#include "common_defs.h"
#include "organ.h"
#include "organgui.h"
@@ -76,7 +77,8 @@ double Organ::cb2amp(int cb)
Organ::Organ(int sr)
: Mess(1)
{
- idata = new int[NUM_CONTROLLER];
+ //idata = new int[NUM_CONTROLLER];
+ idata = new unsigned char[3 + NUM_CONTROLLER * sizeof(int)];
setSampleRate(sr);
gui = 0;
@@ -131,7 +133,8 @@ Organ::~Organ()
{
if (gui)
delete gui;
- delete idata;
+ //delete idata;
+ delete [] idata; // p4.0.27
--useCount;
if (useCount == 0) {
delete[] g_pulse_table;
@@ -170,6 +173,13 @@ bool Organ::init(const char* name)
return false;
}
+int Organ::oldMidiStateHeader(const unsigned char** data) const
+{
+ unsigned char const d[3] = {MUSE_SYNTH_SYSEX_MFG_ID, ORGAN_UNIQUE_ID, INIT_DATA_CMD};
+ *data = &d[0];
+ return 3;
+}
+
//---------------------------------------------------------
// processMessages
// Called from host always, even if output path is unconnected.
@@ -192,7 +202,11 @@ void Organ::processMessages()
sendEvent(ev);
}
else
+ {
+ #ifdef ORGAN_DEBUG
printf("Organ::process(): unknown event\n");
+ #endif
+ }
}
}
@@ -404,7 +418,9 @@ bool Organ::playNote(int channel, int pitch, int velo)
voices[i].harm5_accum = 0;
return false;
}
+ #ifdef ORGAN_DEBUG
printf("organ: voices overflow!\n");
+ #endif
return false;
}
@@ -424,7 +440,11 @@ void Organ::noteoff(int channel, int pitch)
}
}
if (!found)
+ {
+ #ifdef ORGAN_DEBUG
printf("Organ: noteoff %d:%d not found\n", channel, pitch);
+ #endif
+ }
}
//---------------------------------------------------------
@@ -515,7 +535,9 @@ void Organ::setController(int ctrl, int data)
setController(0, synthCtrl[i].num, synthCtrl[i].val);
break;
default:
+ #ifdef ORGAN_DEBUG
fprintf(stderr, "Organ:set unknown Ctrl 0x%x to 0x%x\n", ctrl, data);
+ #endif
return;
}
for (int i = 0; i < NUM_CONTROLLER; ++i) {
@@ -573,37 +595,59 @@ bool Organ::setController(int channel, int ctrl, int data)
//---------------------------------------------------------
bool Organ::sysex(int n, const unsigned char* data)
- {
+{
#ifdef ORGAN_DEBUG
printf("Organ: sysex\n");
#endif
- if (unsigned(n) != (NUM_INIT_CONTROLLER * sizeof(int))) {
- printf("Organ: unknown sysex\n");
- return false;
- }
- int* s = (int*) data;
- for (int i = 0; i < NUM_INIT_CONTROLLER; ++i) {
- int val = *s++;
- #ifdef ORGAN_DEBUG
- printf("Organ: sysex before setController num:%d val:%d\n", synthCtrl[i].num, val);
- #endif
- setController(0, synthCtrl[i].num, val);
+
+ // p4.0.27
+ if(unsigned(n) == (3 + NUM_INIT_CONTROLLER * sizeof(int)))
+ {
+ if (data[0] == MUSE_SYNTH_SYSEX_MFG_ID) // MusE Soft Synth
+ {
+ if (data[1] == ORGAN_UNIQUE_ID) // ORGAN
+ {
+ if (data[2] == INIT_DATA_CMD) // Initialization
+ {
+ int* s = (int*)(data + 3);
+ for (int i = 0; i < NUM_INIT_CONTROLLER; ++i)
+ {
+ int val = *s++;
+ #ifdef ORGAN_DEBUG
+ printf("Organ: sysex before setController num:%d val:%d\n", synthCtrl[i].num, val);
+ #endif
+ setController(0, synthCtrl[i].num, val);
+ }
+ return false;
}
- return false;
+ }
+ }
}
-
+ #ifdef ORGAN_DEBUG
+ printf("Organ: unknown sysex\n");
+ #endif
+ return false;
+}
//---------------------------------------------------------
// getInitData
//---------------------------------------------------------
-void Organ::getInitData(int* n, const unsigned char**p) const
- {
- int* d = idata;
+//void Organ::getInitData(int* n, const unsigned char**p) const
+void Organ::getInitData(int* n, const unsigned char**p)
+{
+ // p4.0.27
+ *n = 3 + NUM_INIT_CONTROLLER * sizeof(int);
+ idata[0] = MUSE_SYNTH_SYSEX_MFG_ID; // MusE Soft Synth
+ idata[1] = ORGAN_UNIQUE_ID; // ORGAN
+ idata[2] = INIT_DATA_CMD; // Initialization
+ int* d = (int*)&idata[3];
+
+ //int* d = idata;
for (int i = 0; i < NUM_INIT_CONTROLLER; ++i)
*d++ = synthCtrl[i].val;
- *n = NUM_INIT_CONTROLLER * sizeof(int); // sizeof(idata);
+ //*n = NUM_INIT_CONTROLLER * sizeof(int); // sizeof(idata);
*p = (unsigned char*)idata;
- }
+}
//---------------------------------------------------------
// MESS
diff --git a/muse2/synti/organ/organ.h b/muse2/synti/organ/organ.h
index 60fee98a..f859ea8c 100644
--- a/muse2/synti/organ/organ.h
+++ b/muse2/synti/organ/organ.h
@@ -15,9 +15,11 @@
#include "muse/midictrl.h"
#include "libsynti/mess.h"
+#include "common_defs.h"
#define RESOLUTION (16384*2)
#define VOICES 128 // max polyphony
+#define INIT_DATA_CMD 1
class OrganGui;
@@ -149,7 +151,8 @@ class Organ : public Mess {
static unsigned freq256[128];
static double cb2amp(int cb);
- int* idata; // buffer for init data
+ //int* idata; // buffer for init data
+ unsigned char* idata; // buffer for init data
bool brass, flute, reed;
int attack0, attack1;
@@ -180,7 +183,10 @@ class Organ : public Mess {
virtual bool setController(int channel, int ctrl, int val);
virtual int getControllerInfo(int, const char**, int*, int*, int*, int*) const;
- virtual void getInitData(int*, const unsigned char**) const;
+ //virtual void getInitData(int*, const unsigned char**) const;
+ virtual void getInitData(int*, const unsigned char**);
+ // This is only a kludge required to support old songs' midistates. Do not use in any new synth.
+ virtual int oldMidiStateHeader(const unsigned char** data) const;
//virtual bool guiVisible() const;
//virtual void showGui(bool);
@@ -193,7 +199,7 @@ class Organ : public Mess {
virtual bool sysex(int, const unsigned char*);
static SynthCtrl synthCtrl[];
Organ(int sampleRate);
- ~Organ();
+ virtual ~Organ();
bool init(const char* name);
};
diff --git a/muse2/synti/organ/organgui.cpp b/muse2/synti/organ/organgui.cpp
index b10ab01d..a25a8de9 100644
--- a/muse2/synti/organ/organgui.cpp
+++ b/muse2/synti/organ/organgui.cpp
@@ -19,6 +19,7 @@
#include <QSocketNotifier>
#include <QSpinBox>
+#include "common_defs.h"
#include "organgui.h"
#include "muse/midi.h"
#include "muse/midictrl.h"
@@ -134,7 +135,9 @@ void OrganGui::setParam(int param, int val)
param &= 0xfff;
if (param >= int(sizeof(dctrl)/sizeof(*dctrl))) {
+ #ifdef ORGANGUI_DEBUG
fprintf(stderr, "OrganGui: set unknown Ctrl 0x%x to 0x%x\n", param, val);
+ #endif
return;
}
SynthGuiCtrl* ctrl = &dctrl[param];
@@ -172,7 +175,11 @@ void OrganGui::processEvent(const MidiPlayEvent& ev)
if (ev.type() == ME_CONTROLLER)
setParam(ev.dataA(), ev.dataB());
else
+ {
+ #ifdef ORGANGUI_DEBUG
printf("OrganGui::illegal event type received\n");
+ #endif
+ }
}
//---------------------------------------------------------