diff options
40 files changed, 738 insertions, 303 deletions
| diff --git a/muse/ChangeLog b/muse/ChangeLog index 65091471..721d3581 100644 --- a/muse/ChangeLog +++ b/muse/ChangeLog @@ -1,3 +1,14 @@ +31.10 (ws) +      - MESS: +        - remove useless QWidget parameter in instantiate() +        - getInitData() and getControllerInfo() +          are no longer const; +        - Added getBankName() to interface to allow for simple structuring +          of patches. +      - queue midi events which cannot be send to busy(locked) software  +        synthesizer +      - zynaddsubfx: implement locking, showGui(), and getControllerInfo(); +        cache patch names  29.10 (ws)        - fixed crash after some time of midi recording: made midi           input queue thread safe. @@ -2,16 +2,10 @@  (29.10.2006)  ---------------------------------------------------------------------------- -      - Handle software synthesizer like an MidiOutPort. This eliminates -        the extra routing from MidiOutPort to the synti and removes the -        extra MidiOutPort. Synthesizer then have channels and MidiTrack's -        can directly routed to synthesizer channels.        - change default: show MidiChannel in mixer, dont show MidiTrack        - Add "monitor" button to midi channel strip in mixer.        - add midi fifo for MESS synthesizer and repeat sending an event          in case the synthesizer is busy -      - replace posix semaphores with simple "busy" flag in -        zynaddsubfx        - change default: do not default to "automation read" when          creating new strips        - change default: when creating midi input strips, route input diff --git a/muse/doc/dimpl/dimpl.tex b/muse/doc/dimpl/dimpl.tex index 524d2222..31b28470 100644 --- a/muse/doc/dimpl/dimpl.tex +++ b/muse/doc/dimpl/dimpl.tex @@ -764,7 +764,7 @@ struct MidiPatch {        for your MESS. They look something like this: (example taken from SimpleSynth/SimpleDrums)  \starttyping -static Mess* instantiate(int sr, QWidget*, const char* name) +static Mess* instantiate(int sr, const char* name)   {    printf("SimpleSynth sampleRate %d\n", sr);    SimpleSynth* synth = new SimpleSynth(sr); diff --git a/muse/muse/globaldefs.h b/muse/muse/globaldefs.h index 0215859a..72f1f948 100644 --- a/muse/muse/globaldefs.h +++ b/muse/muse/globaldefs.h @@ -22,9 +22,7 @@  #define __GLOBALDEFS_H__  const int MAX_CHANNELS = 2;   // max audio channels -const int MAX_PLUGINS  = 4;   // plugins in mixer rack - -const int MIDI_PORTS   = 16;  // max Number of Midi Ports +// const int MIDI_PORTS   = 16;  // max Number of Midi Ports  #ifndef MIDI_CHANNELS  #define MIDI_CHANNELS 16       // Channels per Port diff --git a/muse/muse/midiedit/miditracker.cpp b/muse/muse/midiedit/miditracker.cpp index b23562f7..92e72e0c 100644 --- a/muse/muse/midiedit/miditracker.cpp +++ b/muse/muse/midiedit/miditracker.cpp @@ -15,7 +15,7 @@  //   MidiTrackerEditor  //--------------------------------------------------------- -MidiTrackerEditor::MidiTrackerEditor(PartList* pl, bool init) +MidiTrackerEditor::MidiTrackerEditor(PartList* pl, bool /*init*/)    : MidiEditor(pl) {    //---------menuView--------------------------------- @@ -215,7 +215,7 @@ void MidiTrackerEditor::setFollow(bool f) {  //    pulldown menu commands  //--------------------------------------------------------- -void MidiTrackerEditor::cmd(QAction* a) { +void MidiTrackerEditor::cmd(QAction* /*a*/) {    //int cmd = a->data().toInt();    //canvas()->cmd(cmd, _quantStrength, _quantLimit, _quantLen);  } diff --git a/muse/muse/midififo.cpp b/muse/muse/midififo.cpp index 833b1e80..6264fdca 100644 --- a/muse/muse/midififo.cpp +++ b/muse/muse/midififo.cpp @@ -26,9 +26,7 @@  MidiFifo::MidiFifo()        { -      size   = 0; -      wIndex = 0; -      rIndex = 0; +      clear();        }  //--------------------------------------------------------- diff --git a/muse/muse/midififo.h b/muse/muse/midififo.h index 282e0e7d..bd12ad39 100644 --- a/muse/muse/midififo.h +++ b/muse/muse/midififo.h @@ -40,7 +40,7 @@ class MidiFifo {        bool put(const MidiEvent& event);   // returns true on fifo overflow        MidiEvent get();        bool isEmpty() const { return size == 0; } -      void clear()         { size = 0; } +      void clear()         { size = 0, wIndex = 0, rIndex = 0; }        };  #endif diff --git a/muse/muse/midifile.cpp b/muse/muse/midifile.cpp index 81c48a3f..bfe444c0 100644 --- a/muse/muse/midifile.cpp +++ b/muse/muse/midifile.cpp @@ -241,13 +241,8 @@ bool MidiFile::readTrack(MidiFileTrack* t)              lastchannel = -1;              int rv = readEvent(&event, t); -            if (lastport != -1) { +            if (lastport != -1)                    port = lastport; -                  if (port >= MIDI_PORTS) { -                        printf("port %d >= %d, reset to 0\n", port, MIDI_PORTS); -                        port = 0; -                        } -                  }              if (lastchannel != -1) {                    channel = lastchannel;                    if (channel >= MIDI_CHANNELS) { diff --git a/muse/muse/synth.cpp b/muse/muse/synth.cpp index 732fdaf7..a58a7736 100644 --- a/muse/muse/synth.cpp +++ b/muse/muse/synth.cpp @@ -172,7 +172,7 @@ void* MessSynth::instantiate(const QString& instanceName)              fprintf(stderr, "Synth::instantiate: no MESS descr found\n");              return 0;              } -      Mess* mess = descr->instantiate(AL::sampleRate, muse, instanceName.toLatin1().data()); +      Mess* mess = descr->instantiate(AL::sampleRate, instanceName.toLatin1().data());        return mess;        } @@ -282,20 +282,8 @@ bool SynthI::initInstance(Synth* s)              for (iEvent i = iel->begin(); i != iel->end(); ++i) {                    Event ev = i->second;                    MidiEvent pev(0, 0, ev); -                  static const int TIMEOUT = 1; -                  // -                  // retry until timeout -                  int to; -                  for (to = 0; to < TIMEOUT; ++to) { -                        if (!_sif->putEvent(pev)) -                              break; -                        sleep(1); -                        } -                  if (to == TIMEOUT) { -                        printf("cannot initialize software synthesizer <%s>: busy\n", -                           name().toLatin1().data()); -                        break; -                        } +                  if (_sif->putEvent(pev)) +                        putFifo.put(pev);       // save for later retry                    }              iel->clear();              } @@ -544,6 +532,9 @@ void MessSynthIF::getData(MPEventList* el, unsigned pos, int ports, unsigned n,        int curPos = pos;        int endPos = pos + n; +      while (!synti->putFifo.isEmpty()) +            putEvent(synti->putFifo.get()); +        if (ports >= channels()) {              iMPEvent i = el->begin();              for (; i != el->end(); ++i) { @@ -555,11 +546,11 @@ void MessSynthIF::getData(MPEventList* el, unsigned pos, int ports, unsigned n,                          _mess->process(buffer, curPos-pos, frame - curPos);                          curPos = frame; // don't process this piece again                          } -                  putEvent(*i); +                  if (putEvent(*i)) +                        synti->putFifo.put(*i);                    } -            if (endPos - curPos > 0) { +            if (endPos - curPos > 0)                    _mess->process(buffer, curPos-pos, endPos - curPos); -                  }              el->erase(el->begin(), i);              }        else { @@ -573,18 +564,21 @@ void MessSynthIF::getData(MPEventList* el, unsigned pos, int ports, unsigned n,  //---------------------------------------------------------  //   putEvent -//    return true on error (busy) +//    return true on error (busy), event will later be +//    resend  //---------------------------------------------------------  bool MessSynthIF::putEvent(const MidiEvent& ev)        { -      if (midiOutputTrace) { -            printf("<%s>", synti->name().toLatin1().data()); -            ev.dump(); +      bool rv = true; +      if (_mess) { +            rv = _mess->processEvent(ev); +            if (midiOutputTrace && !rv) { +                  printf("<%s>", synti->name().toLatin1().data()); +                  ev.dump(); +                  }              } -      if (_mess) -            return _mess->processEvent(ev); -      return true; +      return rv;        }  //--------------------------------------------------------- diff --git a/muse/muse/synth.h b/muse/muse/synth.h index dfbbabc4..f657ea41 100644 --- a/muse/muse/synth.h +++ b/muse/muse/synth.h @@ -25,6 +25,7 @@  #include "instruments/minstrument.h"  #include "audiotrack.h"  #include "midiout.h" +#include "midififo.h"  class Mess;  struct MESS; @@ -124,6 +125,7 @@ class SynthI : public AudioTrack, public MidiOut, public MidiInstrument     protected:        Synth* synthesizer;        std::vector<float> initParams; +      MidiFifo putFifo;        bool putMidiEvent(const MidiEvent& ev) {              return _sif->putEvent(ev); @@ -134,6 +136,9 @@ class SynthI : public AudioTrack, public MidiOut, public MidiInstrument        virtual void collectInputData();     public: +      friend class SynthIF; +      friend class MessSynthIF; +        SynthI();        virtual ~SynthI();        virtual TrackType type() const { return AUDIO_SOFTSYNTH; } @@ -181,6 +186,8 @@ class SynthI : public AudioTrack, public MidiOut, public MidiInstrument  //    mess synthesizer instance  //--------------------------------------------------------- +static const int PUT_FIFO_SIZE = 64; +  class MessSynthIF : public SynthIF {        Mess* _mess; diff --git a/muse/synti/deicsonze/deicsonze.cpp b/muse/synti/deicsonze/deicsonze.cpp index c7c4d9c5..900bb32b 100644 --- a/muse/synti/deicsonze/deicsonze.cpp +++ b/muse/synti/deicsonze/deicsonze.cpp @@ -2067,7 +2067,7 @@ void DeicsOnze::writeConfiguration(AL::Xml* xml) {  //---------------------------------------------------------  // getInitData  //--------------------------------------------------------- -void DeicsOnze::getInitData(int* length, const unsigned char** data) const { +void DeicsOnze::getInitData(int* length, const unsigned char** data) {    FILE* tmp;    char* comptmp;    QString cmd="bzip2 > "; @@ -3183,7 +3183,7 @@ const MidiPatch* DeicsOnze::getPatchInfo(int /*ch*/, const MidiPatch* /*p*/) con  */  //---------------------------------------------------------  int DeicsOnze::getControllerInfo(int index, const char** name, -				 int* controller, int* min, int* max) const +				 int* controller, int* min, int* max)  {      if (index >= nbrCtrl) {  	return 0; @@ -3767,7 +3767,7 @@ void DeicsOnze::process(float** buffer, int offset, int n) {  class QWidget; -static Mess* instantiate(int sr, QWidget*, const char*) +static Mess* instantiate(int sr, const char*)  {      DeicsOnze* deicsonze = new DeicsOnze();      deicsonze->setSampleRate(sr); diff --git a/muse/synti/deicsonze/deicsonze.h b/muse/synti/deicsonze/deicsonze.h index 8a975e0f..f33d7e7a 100644 --- a/muse/synti/deicsonze/deicsonze.h +++ b/muse/synti/deicsonze/deicsonze.h @@ -475,8 +475,8 @@ class DeicsOnze : public Mess {    virtual const char* getPatchName(int ch, int number, int) const;    virtual const MidiPatch* getPatchInfo(int, const MidiPatch *) const;    virtual int getControllerInfo(int arg1, const char** arg2,  -				int* arg3, int* arg4, int* arg5) const; -  virtual void getInitData(int* length, const unsigned char** data) const; +				int* arg3, int* arg4, int* arg5); +  virtual void getInitData(int* length, const unsigned char** data);    virtual bool playNote(int channel, int pitch, int velo);    virtual void process(float** buffer, int offset, int n); diff --git a/muse/synti/fluid/fluid.cpp b/muse/synti/fluid/fluid.cpp index fbd8701c..601b1899 100644 --- a/muse/synti/fluid/fluid.cpp +++ b/muse/synti/fluid/fluid.cpp @@ -22,9 +22,7 @@  //   instantiate  //--------------------------------------------------------- -class QWidget; - -static Mess* instantiate(int sr, QWidget*, const char* name) +static Mess* instantiate(int sr, const char* name)        {        ISynth* synth = new ISynth();        synth->setSampleRate(sr); diff --git a/muse/synti/fluidsynth/fluidsynti.cpp b/muse/synti/fluidsynth/fluidsynti.cpp index b947df2b..57e72262 100644 --- a/muse/synti/fluidsynth/fluidsynti.cpp +++ b/muse/synti/fluidsynth/fluidsynti.cpp @@ -156,7 +156,7 @@ void FluidSynth::process(float** ports, int offset, int len)  //   getInitData  // Prepare data that will restore the synth's state on load  //--------------------------------------------------------- -void FluidSynth::getInitData(int* n, const unsigned char** data) const +void FluidSynth::getInitData(int* n, const unsigned char** data)        {        // Data setup:        // FS_INIT_DATA (1 byte) @@ -823,7 +823,7 @@ void FluidSynth::setController(int channel, int id, int val, bool fromGui)  //---------------------------------------------------------  //   getControllerInfo  //--------------------------------------------------------- -int FluidSynth::getControllerInfo(int id, const char** name, int* controller, int* min, int* max) const +int FluidSynth::getControllerInfo(int id, const char** name, int* controller, int* min, int* max)        {        if (id >= NUM_CONTROLLER)              return 0; @@ -1149,7 +1149,7 @@ bool FluidSynth::popSoundfont (int ext_id)  class QWidget; -static Mess* instantiate(int sr, QWidget*, const char* name) +static Mess* instantiate(int sr, const char* name)        {        printf("fluidsynth sampleRate %d\n", sr);        FluidSynth* synth = new FluidSynth(sr); diff --git a/muse/synti/fluidsynth/fluidsynti.h b/muse/synti/fluidsynth/fluidsynti.h index f41d4322..c66b1faf 100644 --- a/muse/synti/fluidsynth/fluidsynti.h +++ b/muse/synti/fluidsynth/fluidsynti.h @@ -97,10 +97,10 @@ public:        virtual bool sysex(int, const unsigned char*);        virtual bool setController(int, int, int);        void setController(int, int , int, bool); -      virtual void getInitData(int*, const unsigned char**) const; +      virtual void getInitData(int*, const unsigned char**);        virtual const char* getPatchName(int, int, int) const;        virtual const MidiPatch* getPatchInfo(int i, const MidiPatch* patch) const; -      virtual int getControllerInfo(int, const char**, int*, int*, int*) const; +      virtual int getControllerInfo(int, const char**, int*, int*, int*);        virtual bool processEvent(const MidiEvent&);        virtual bool hasGui() const { return true; } diff --git a/muse/synti/libsynti/mess.h b/muse/synti/libsynti/mess.h index 72eabffc..033ebb42 100644 --- a/muse/synti/libsynti/mess.h +++ b/muse/synti/libsynti/mess.h @@ -58,8 +58,8 @@ class Mess {        virtual bool playNote(int, int, int) { return false; }  	virtual bool sysex(int, const unsigned char*) { return false; } -      virtual void getInitData(int*, const unsigned char**) const {} -      virtual int getControllerInfo(int, const char**, int*, int*, int*) const {return 0;} +      virtual void getInitData(int*, const unsigned char**) {} +      virtual int getControllerInfo(int, const char**, int*, int*, int*) {return 0;}        virtual const char* getPatchName(int, int, int) const { return "?"; }        virtual const MidiPatch* getPatchInfo(int, const MidiPatch*) const { return 0; }        virtual const char* getBankName(int) const { return 0; } @@ -89,7 +89,7 @@ struct MESS {        int majorMessVersion, minorMessVersion;           // QWidget* parent allows for a threaded GUI using the Qt Library           // can be ignored by synti -      Mess* (*instantiate)(int sr, QWidget* parent, const char* name); +      Mess* (*instantiate)(int sr, const char* name);        };  extern "C" { diff --git a/muse/synti/mus/mus.cpp b/muse/synti/mus/mus.cpp index 635bd53d..825ba8d5 100644 --- a/muse/synti/mus/mus.cpp +++ b/muse/synti/mus/mus.cpp @@ -231,7 +231,7 @@ int main(int argc, char* argv[])        //        //    instantiate Synthesizer        // -      mess = descr->instantiate(sampleRate, 0, instanceName.toLocal8Bit().data()); +      mess = descr->instantiate(sampleRate, instanceName.toLocal8Bit().data());        if (mess == 0) {              fprintf(stderr, "%s: instantiate failed\n",                 argv[0]); diff --git a/muse/synti/organ/organ.cpp b/muse/synti/organ/organ.cpp index 0bdcc6a4..4b84fbfb 100644 --- a/muse/synti/organ/organ.cpp +++ b/muse/synti/organ/organ.cpp @@ -561,7 +561,7 @@ void Organ::getInitData(int* n, const unsigned char**p)  //---------------------------------------------------------  int Organ::getControllerInfo(int id, const char** name, int* controller, -   int* min, int* max) const +   int* min, int* max)        {        if (id >= NUM_CONTROLLER)              return 0; @@ -619,7 +619,7 @@ void Organ::setGeometry(int x, int y, int w, int h)  //    construct a new synthesizer instance  //--------------------------------------------------------- -static Mess* instantiate(int sr, QWidget*, const char* name) +static Mess* instantiate(int sr, const char* name)        {        Organ* synth = new Organ(sr);        if (synth->init(name)) { diff --git a/muse/synti/organ/organ.h b/muse/synti/organ/organ.h index 5f3835e1..ec458f10 100644 --- a/muse/synti/organ/organ.h +++ b/muse/synti/organ/organ.h @@ -175,7 +175,7 @@ class Organ : public Mess {        virtual bool setController(int channel, int ctrl, int val);  	virtual bool sysex(int, const unsigned char*); -      virtual int getControllerInfo(int, const char**, int*, int*, int*) const; +      virtual int getControllerInfo(int, const char**, int*, int*, int*);        virtual void getInitData(int*, const unsigned char**);        virtual bool guiVisible() const; diff --git a/muse/synti/s1/s1.cpp b/muse/synti/s1/s1.cpp index ff02f6fe..2dca23ee 100644 --- a/muse/synti/s1/s1.cpp +++ b/muse/synti/s1/s1.cpp @@ -135,9 +135,7 @@ void S1::process(float** buffer, int offset, int n)  //   inst  //--------------------------------------------------------- -class QWidget; - -static Mess* instantiate(int sr, QWidget*, const char*) +static Mess* instantiate(int sr, const char*)        {        S1* s1 = new S1();        s1->setSampleRate(sr); diff --git a/muse/synti/simpledrums/simpledrums.cpp b/muse/synti/simpledrums/simpledrums.cpp index b5b3a1b4..5b7d1c96 100644 --- a/muse/synti/simpledrums/simpledrums.cpp +++ b/muse/synti/simpledrums/simpledrums.cpp @@ -627,7 +627,7 @@ const MidiPatch* SimpleSynth::getPatchInfo(int index, const MidiPatch* patch) co      \return 0 when done, otherwise return next desired controller index   */  //--------------------------------------------------------- -int SimpleSynth::getControllerInfo(int index, const char** name, int* controller, int* min, int* max) const +int SimpleSynth::getControllerInfo(int index, const char** name, int* controller, int* min, int* max)        {        SS_TRACE_IN        if (index >= SS_NR_OF_CONTROLLERS) { @@ -838,7 +838,7 @@ bool SimpleSynth::init(const char* name)      \param data - data that is sent as a sysex to the synth on reload of project   */  //--------------------------------------------------------- -void SimpleSynth::getInitData(int* n, const unsigned char** data) const +void SimpleSynth::getInitData(int* n, const unsigned char** data)        {        SS_TRACE_IN        // Calculate length of data @@ -1304,7 +1304,7 @@ static void* loadSampleThread(void* p)        } -static Mess* instantiate(int sr, QWidget*, const char* name) +static Mess* instantiate(int sr, const char* name)        {        printf("SimpleSynth sampleRate %d\n", sr);        SimpleSynth* synth = new SimpleSynth(sr); diff --git a/muse/synti/simpledrums/simpledrums.h b/muse/synti/simpledrums/simpledrums.h index f27b908a..01621fbf 100644 --- a/muse/synti/simpledrums/simpledrums.h +++ b/muse/synti/simpledrums/simpledrums.h @@ -121,10 +121,10 @@ class SimpleSynth : public Mess        virtual bool sysex(int arg1, const unsigned char* arg2);        virtual const char* getPatchName(int arg1, int arg2, int arg3) const;        virtual const MidiPatch* getPatchInfo(int arg1, const MidiPatch* arg2) const; -      virtual int getControllerInfo(int arg1, const char** arg2, int* arg3, int* arg4, int* arg5) const; +      virtual int getControllerInfo(int arg1, const char** arg2, int* arg3, int* arg4, int* arg5);        virtual void process(float** data, int offset, int len);        virtual void showGui(bool arg1); -      virtual void getInitData(int*, const unsigned char**) const; +      virtual void getInitData(int*, const unsigned char**);        bool init(const char* name);        void guiSendSampleLoaded(bool success, int ch, const char* filename);        void guiSendError(const char* errorstring); diff --git a/muse/synti/vam/vam.cpp b/muse/synti/vam/vam.cpp index 7ee9778f..bc5c035a 100644 --- a/muse/synti/vam/vam.cpp +++ b/muse/synti/vam/vam.cpp @@ -7,7 +7,7 @@  //      Werner Schweer's organ softsynth for MusE.  //	The music-dsp source archive.  // -//  (C) Copyright 2002 Jotsif Lindman Hönlund (jotsif@linux.nu) +//  (C) Copyright 2002 Jotsif Lindman Hölund (jotsif@linux.nu)  //  // This program is free software; you can redistribute it and/or  // modify it under the terms of the GNU General Public License @@ -777,9 +777,7 @@ void VAM::setGeometry(int x, int y, int w, int h)  //   inst  //--------------------------------------------------------- -class QWidget; - -static Mess* instantiate(int sr, QWidget*, const char* name) +static Mess* instantiate(int sr, const char* name)        {        VAM* vam = new VAM(sr);        if (vam->init(name)) { diff --git a/muse/synti/zynaddsubfx/COPYING b/muse/synti/zynaddsubfx/COPYING new file mode 100644 index 00000000..c8f74939 --- /dev/null +++ b/muse/synti/zynaddsubfx/COPYING @@ -0,0 +1,347 @@ + +NOTE! The GPL below is copyrighted by the Free Software Foundation, but +the instance of code that it refers to (the ZynAddSubFX application)  +is copyrighted by the author (Nasca Octavian Paul) who actually wrote it. +--------------------------------------------------------------------------- + + +		    GNU GENERAL PUBLIC LICENSE +		       Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. +                       59 Temple Place, Suite 330, Boston, MA  02111-1307  USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +			    Preamble + +  The licenses for most software are designed to take away your +freedom to share and change it.  By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users.  This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it.  (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.)  You can apply it to +your programs, too. + +  When we speak of free software, we are referring to freedom, not +price.  Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + +  To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + +  For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have.  You must make sure that they, too, receive or can get the +source code.  And you must show them these terms so they know their +rights. + +  We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + +  Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software.  If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + +  Finally, any free program is threatened constantly by software +patents.  We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary.  To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + +  The precise terms and conditions for copying, distribution and +modification follow. + +		    GNU GENERAL PUBLIC LICENSE +   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + +  0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License.  The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language.  (Hereinafter, translation is included without limitation in +the term "modification".)  Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope.  The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + +  1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + +  2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + +    a) You must cause the modified files to carry prominent notices +    stating that you changed the files and the date of any change. + +    b) You must cause any work that you distribute or publish, that in +    whole or in part contains or is derived from the Program or any +    part thereof, to be licensed as a whole at no charge to all third +    parties under the terms of this License. + +    c) If the modified program normally reads commands interactively +    when run, you must cause it, when started running for such +    interactive use in the most ordinary way, to print or display an +    announcement including an appropriate copyright notice and a +    notice that there is no warranty (or else, saying that you provide +    a warranty) and that users may redistribute the program under +    these conditions, and telling the user how to view a copy of this +    License.  (Exception: if the Program itself is interactive but +    does not normally print such an announcement, your work based on +    the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole.  If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works.  But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + +  3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + +    a) Accompany it with the complete corresponding machine-readable +    source code, which must be distributed under the terms of Sections +    1 and 2 above on a medium customarily used for software interchange; or, + +    b) Accompany it with a written offer, valid for at least three +    years, to give any third party, for a charge no more than your +    cost of physically performing source distribution, a complete +    machine-readable copy of the corresponding source code, to be +    distributed under the terms of Sections 1 and 2 above on a medium +    customarily used for software interchange; or, + +    c) Accompany it with the information you received as to the offer +    to distribute corresponding source code.  (This alternative is +    allowed only for noncommercial distribution and only if you +    received the program in object code or executable form with such +    an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it.  For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable.  However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + +  4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License.  Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + +  5. You are not required to accept this License, since you have not +signed it.  However, nothing else grants you permission to modify or +distribute the Program or its derivative works.  These actions are +prohibited by law if you do not accept this License.  Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + +  6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions.  You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + +  7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License.  If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all.  For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices.  Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + +  8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded.  In such case, this License incorporates +the limitation as if written in the body of this License. + +  9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time.  Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number.  If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation.  If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + +  10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission.  For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this.  Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + +			    NO WARRANTY + +  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + +  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + +		     END OF TERMS AND CONDITIONS + +	    How to Apply These Terms to Your New Programs + +  If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + +  To do so, attach the following notices to the program.  It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + +    <one line to give the program's name and a brief idea of what it does.> +    Copyright (C) <year>  <name of author> + +    This program 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 2 of the License, or +    (at your option) any later version. + +    This program 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 program; if not, write to the Free Software +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + +    Gnomovision version 69, Copyright (C) year name of author +    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. +    This is free software, and you are welcome to redistribute it +    under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License.  Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary.  Here is a sample; alter the names: + +  Yoyodyne, Inc., hereby disclaims all copyright interest in the program +  `Gnomovision' (which makes passes at compilers) written by James Hacker. + +  <signature of Ty Coon>, 1 April 1989 +  Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs.  If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library.  If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/muse/synti/zynaddsubfx/Effects/EffectMgr.C b/muse/synti/zynaddsubfx/Effects/EffectMgr.C index 354bc684..efdb672a 100644 --- a/muse/synti/zynaddsubfx/Effects/EffectMgr.C +++ b/muse/synti/zynaddsubfx/Effects/EffectMgr.C @@ -23,13 +23,14 @@  #include <stdlib.h>  #include <stdio.h>  #include "EffectMgr.h" +#include "../Misc/Master.h" -EffectMgr::EffectMgr(int insertion_,pthread_mutex_t *mutex_){ +EffectMgr::EffectMgr(int insertion_,Master* master_){      setpresettype("Peffect");      efx=NULL;      nefx=0;      insertion=insertion_; -    mutex=mutex_; +    master=master_;      efxoutl=new REALTYPE[SOUND_BUFFER_SIZE];      efxoutr=new REALTYPE[SOUND_BUFFER_SIZE];;      for (int i=0;i<SOUND_BUFFER_SIZE;i++){ @@ -117,9 +118,9 @@ void EffectMgr::changepreset_nolock(unsigned char npreset){   * Change the preset of the current effect(with thread locking)   */  void EffectMgr::changepreset(unsigned char npreset){ -    pthread_mutex_lock(mutex); +    master->lock();      changepreset_nolock(npreset); -    pthread_mutex_unlock(mutex); +    master->unlock();  }; @@ -135,9 +136,9 @@ void EffectMgr::seteffectpar_nolock(int npar,unsigned char value){   * Change a parameter of the current effect (with thread locking)   */  void EffectMgr::seteffectpar(int npar,unsigned char value){ -    pthread_mutex_lock(mutex); +    master->lock();      seteffectpar_nolock(npar,value); -    pthread_mutex_unlock(mutex); +    master->unlock();  };  /* diff --git a/muse/synti/zynaddsubfx/Effects/EffectMgr.h b/muse/synti/zynaddsubfx/Effects/EffectMgr.h index 42e9379d..6216fa33 100644 --- a/muse/synti/zynaddsubfx/Effects/EffectMgr.h +++ b/muse/synti/zynaddsubfx/Effects/EffectMgr.h @@ -38,10 +38,11 @@  #include "../Params/FilterParams.h"  #include "../Params/Presets.h" +class Master;  class EffectMgr:public Presets{      public: -	EffectMgr(int insertion_,pthread_mutex_t *mutex_); +	EffectMgr(int insertion_,Master*);  	~EffectMgr();  	void add2XML(XMLwrapper *xml); @@ -76,7 +77,7 @@ class EffectMgr:public Presets{      private:  	int nefx;  	Effect *efx; -	pthread_mutex_t *mutex; +	Master* master;  	bool dryonly;  }; diff --git a/muse/synti/zynaddsubfx/Misc/Bank.C b/muse/synti/zynaddsubfx/Misc/Bank.C index 7d8c6f00..9b2e8f75 100644 --- a/muse/synti/zynaddsubfx/Misc/Bank.C +++ b/muse/synti/zynaddsubfx/Misc/Bank.C @@ -214,20 +214,23 @@ void Bank::loadfromslot(unsigned int ninstrument,Part *part){  /*   * Makes current a bank directory   */ -int Bank::loadbank(const char *bankdirname){ -    DIR *dir=opendir(bankdirname); -    clearbank(); +int Bank::loadbank(const char *bankdirname) +      { +      DIR *dir = opendir(bankdirname); +      clearbank(); -    if (dir==NULL) return(-1); +      if (dir==NULL)  +            return -1; -    if (dirname!=NULL) delete(dirname); -    dirname=new char[strlen(bankdirname)+1]; -    snprintf(dirname,strlen(bankdirname)+1,"%s",bankdirname); +      if (dirname!=NULL)  +            delete(dirname); +      dirname = new char[strlen(bankdirname)+1]; +      snprintf(dirname, strlen(bankdirname)+1, "%s",bankdirname); -    bankfiletitle=dirname; +      bankfiletitle=dirname; -   // printf("loadbank %s/\n",bankdirname); -    struct dirent *fn; +      // printf("loadbank %s/\n",bankdirname); +      struct dirent *fn;      while ((fn=readdir(dir))){  	const char *filename= fn->d_name; diff --git a/muse/synti/zynaddsubfx/Misc/Master.C b/muse/synti/zynaddsubfx/Misc/Master.C index 8b68d560..99a1ac28 100644 --- a/muse/synti/zynaddsubfx/Misc/Master.C +++ b/muse/synti/zynaddsubfx/Misc/Master.C @@ -32,7 +32,7 @@  Master::Master(){      swaplr=0; -    pthread_mutex_init(&mutex,NULL); +    busy = false;      fft=new FFTwrapper(OSCIL_SIZE);      tmpmixl=new REALTYPE[SOUND_BUFFER_SIZE]; @@ -53,16 +53,16 @@ Master::Master(){        memset(audiooutr, 0, sizeof(REALTYPE) * SOUND_BUFFER_SIZE);      for (int npart=0;npart<NUM_MIDI_PARTS;npart++) -	part[npart]=new Part(µtonal,fft,&mutex); +	part[npart]=new Part(µtonal,fft,this);      //Insertion Effects init              for (int nefx=0;nefx<NUM_INS_EFX;nefx++) -    	insefx[nefx]=new EffectMgr(1,&mutex); +    	insefx[nefx]=new EffectMgr(1,this);      //System Effects init              for (int nefx=0;nefx<NUM_SYS_EFX;nefx++) { -	sysefx[nefx]=new EffectMgr(0,&mutex); +	sysefx[nefx]=new EffectMgr(0,this);      }; @@ -436,7 +436,6 @@ Master::~Master(){      delete [] tmpmixr;      delete (fft); -    pthread_mutex_destroy(&mutex);  }; @@ -556,9 +555,9 @@ int Master::getalldata(char **data){      xml->beginbranch("MASTER"); -    pthread_mutex_lock(&mutex); +    busy = true;      add2XML(xml); -    pthread_mutex_unlock(&mutex); +    busy = false;      xml->endbranch(); @@ -576,9 +575,9 @@ void Master::putalldata(char *data,int size){      if (xml->enterbranch("MASTER")==0) return; -    pthread_mutex_lock(&mutex); +    busy = true;  	getfromXML(xml); -    pthread_mutex_unlock(&mutex); +    busy = false;      xml->exitbranch(); diff --git a/muse/synti/zynaddsubfx/Misc/Master.h b/muse/synti/zynaddsubfx/Misc/Master.h index 10a183f3..51feabdd 100644 --- a/muse/synti/zynaddsubfx/Misc/Master.h +++ b/muse/synti/zynaddsubfx/Misc/Master.h @@ -130,7 +130,10 @@ class Master{  	Bank bank;  	FFTwrapper *fft; -	pthread_mutex_t mutex; +      volatile bool busy;     // if true,  is busy and cannot accept +                              // events or deliver data +      void lock()   { busy = true; } +      void unlock() { busy = false; }      private:  	REALTYPE volume;	 diff --git a/muse/synti/zynaddsubfx/Misc/Part.C b/muse/synti/zynaddsubfx/Misc/Part.C index a40ea031..ceeeb7b6 100644 --- a/muse/synti/zynaddsubfx/Misc/Part.C +++ b/muse/synti/zynaddsubfx/Misc/Part.C @@ -20,16 +20,17 @@  */ +#include "Master.h"  #include "Part.h"  #include "Microtonal.h"  #include <stdlib.h>  #include <stdio.h>  #include <string.h> -Part::Part(Microtonal *microtonal_,FFTwrapper *fft_, pthread_mutex_t *mutex_){ +Part::Part(Microtonal *microtonal_,FFTwrapper *fft_, Master* master_){      microtonal=microtonal_;          fft=fft_; -    mutex=mutex_; +    master=master_;      partoutl=new REALTYPE [SOUND_BUFFER_SIZE];      partoutr=new REALTYPE [SOUND_BUFFER_SIZE];      tmpoutl=new REALTYPE [SOUND_BUFFER_SIZE]; @@ -42,13 +43,13 @@ Part::Part(Microtonal *microtonal_,FFTwrapper *fft_, pthread_mutex_t *mutex_){      kit[0].adpars=new ADnoteParameters(fft);      kit[0].subpars=new SUBnoteParameters(); -    kit[0].padpars=new PADnoteParameters(fft,mutex); +    kit[0].padpars=new PADnoteParameters(fft,master);  //    ADPartParameters=kit[0].adpars;  //    SUBPartParameters=kit[0].subpars;      //Part's Insertion Effects init      for (int nefx=0;nefx<NUM_PART_EFX;nefx++)  -    	partefx[nefx]=new EffectMgr(1,mutex); +    	partefx[nefx]=new EffectMgr(1,master);      for (int n=0;n<NUM_PART_EFX+1;n++) {  	partfxinputl[n]=new REALTYPE [SOUND_BUFFER_SIZE]; @@ -632,7 +633,7 @@ void Part::setkititemstatus(int kititem,int Penabled_){      } else {  	if (kit[kititem].adpars==NULL) kit[kititem].adpars=new ADnoteParameters(fft);  	if (kit[kititem].subpars==NULL) kit[kititem].subpars=new SUBnoteParameters(); -	if (kit[kititem].padpars==NULL) kit[kititem].padpars=new PADnoteParameters(fft,mutex); +	if (kit[kititem].padpars==NULL) kit[kititem].padpars=new PADnoteParameters(fft,master);      };      if (resetallnotes) 	for (int k=0;k<POLIPHONY;k++) KillNotePos(k); diff --git a/muse/synti/zynaddsubfx/Misc/Part.h b/muse/synti/zynaddsubfx/Misc/Part.h index 2c569750..28ea9816 100644 --- a/muse/synti/zynaddsubfx/Misc/Part.h +++ b/muse/synti/zynaddsubfx/Misc/Part.h @@ -38,10 +38,12 @@  #include "../Effects/EffectMgr.h"  #include "XMLwrapper.h" +class Master; +  class Part{      public: -      Part(Microtonal *microtonal_,FFTwrapper *fft_,pthread_mutex_t *mutex_); +      Part(Microtonal *microtonal_,FFTwrapper *fft_, Master* master);        ~Part();        /* Midi commands implemented */       @@ -138,7 +140,7 @@ class Part{        bool Pefxbypass[NUM_PART_EFX];//if the effects are bypassed -      pthread_mutex_t *mutex; +      Master* master;        int lastnote;       diff --git a/muse/synti/zynaddsubfx/Params/PADnoteParameters.C b/muse/synti/zynaddsubfx/Params/PADnoteParameters.C index 2baf53b6..0c62e53b 100644 --- a/muse/synti/zynaddsubfx/Params/PADnoteParameters.C +++ b/muse/synti/zynaddsubfx/Params/PADnoteParameters.C @@ -21,12 +21,13 @@  */  #include <math.h>  #include "PADnoteParameters.h" +#include "../Misc/Master.h" -PADnoteParameters::PADnoteParameters(FFTwrapper *fft_,pthread_mutex_t *mutex_):Presets(){ +PADnoteParameters::PADnoteParameters(FFTwrapper *fft_,Master* master_):Presets(){      setpresettype("Ppadsyth");      fft=fft_; -    mutex=mutex_; +    master=master_;      resonance=new Resonance();      oscilgen=new OscilGen(fft_,resonance); @@ -508,12 +509,12 @@ printf("applyparameters %d\n", lockmutex);  	//replace the current sample with the new computed sample  	if (lockmutex){ -	    pthread_mutex_lock(mutex); +	    master->lock();  	     deletesample(nsample);  	     sample[nsample].smp=newsample.smp;      	     sample[nsample].size=samplesize;  	     sample[nsample].basefreq=basefreq*basefreqadjust; -	    pthread_mutex_unlock(mutex); +	    master->unlock();  	} else {  	    deletesample(nsample);  	    sample[nsample].smp=newsample.smp; @@ -527,9 +528,9 @@ printf("applyparameters %d\n", lockmutex);      //delete the additional samples that might exists and are not useful      if (lockmutex){ -        pthread_mutex_lock(mutex); +        master->lock();  	for (int i=samplemax;i<PAD_MAX_SAMPLES;i++) deletesample(i); -        pthread_mutex_unlock(mutex); +        master->unlock();      } else {  	for (int i=samplemax;i<PAD_MAX_SAMPLES;i++) deletesample(i);      }; diff --git a/muse/synti/zynaddsubfx/Params/PADnoteParameters.h b/muse/synti/zynaddsubfx/Params/PADnoteParameters.h index dcb883e4..a2328e86 100644 --- a/muse/synti/zynaddsubfx/Params/PADnoteParameters.h +++ b/muse/synti/zynaddsubfx/Params/PADnoteParameters.h @@ -35,10 +35,11 @@  #include "FilterParams.h"  #include "Presets.h" +class Master;  class PADnoteParameters:public Presets{      public: -	PADnoteParameters(FFTwrapper *fft_,pthread_mutex_t *mutex_); +	PADnoteParameters(FFTwrapper *fft_,Master* master);  	~PADnoteParameters();  	void defaults(); @@ -160,7 +161,7 @@ class PADnoteParameters:public Presets{  	void deletesample(int n);  	FFTwrapper *fft; -	pthread_mutex_t *mutex; +	Master* master;  }; diff --git a/muse/synti/zynaddsubfx/UI/BankUI.fl b/muse/synti/zynaddsubfx/UI/BankUI.fl index 90df024d..cf1cfe9e 100644 --- a/muse/synti/zynaddsubfx/UI/BankUI.fl +++ b/muse/synti/zynaddsubfx/UI/BankUI.fl @@ -250,9 +250,9 @@ if ((what==2)&&(bank->emptyslot(slot)==0)&&(mode!=4)) {//Rename slot  };  if ((what==1)&&(mode==1)&&(!bank->emptyslot(slot))){//Reads from slot -    pthread_mutex_lock(&master->mutex); +    master->busy=true;       bank->loadfromslot(slot,master->part[*npart]); -    pthread_mutex_unlock(&master->mutex); +    master->busy=false;      master->part[*npart]->applyparameters();      snprintf((char *)master->part[*npart]->Pname,PART_MAX_NAME_LEN,"%s",bank->getname(slot));       cbwig->do_callback(); @@ -266,9 +266,9 @@ if ((what==1)&&(mode==2)){//save(write) to slot       if (!bank->emptyslot(slot)){         if (!fl_ask("Overwrite the slot no. %d ?",slot+1)) goto nooverwriteslot;        }; -       pthread_mutex_lock(&master->mutex); +       master->busy=true;          bank->savetoslot(slot,master->part[*npart]); -       pthread_mutex_unlock(&master->mutex); +       master->busy=false;         bs[slot]->refresh();         mode=1;readbutton->value(1);writebutton->value(0); diff --git a/muse/synti/zynaddsubfx/UI/MasterUI.fl b/muse/synti/zynaddsubfx/UI/MasterUI.fl index 384154ce..15a6fcc1 100644 --- a/muse/synti/zynaddsubfx/UI/MasterUI.fl +++ b/muse/synti/zynaddsubfx/UI/MasterUI.fl @@ -81,7 +81,7 @@ oldrmsdbr=0.0;} {}  int ox=x(); int oy=y(); int lx=w(); int ly=h(); -pthread_mutex_lock(&master->mutex); +master->lock();  REALTYPE dbl=rap2dB(master->vuoutpeakl);  REALTYPE dbr=rap2dB(master->vuoutpeakr);  REALTYPE rmsdbl=rap2dB(master->vurmspeakl); @@ -89,7 +89,7 @@ REALTYPE rmsdbr=rap2dB(master->vurmspeakr);  REALTYPE maxdbl=rap2dB(master->vumaxoutpeakl);  REALTYPE maxdbr=rap2dB(master->vumaxoutpeakr);  int clipped=master->vuclipped; -pthread_mutex_unlock(&master->mutex); +master->unlock();  dbl=(MIN_DB-dbl)/MIN_DB;   if (dbl<0.0) dbl=0.0; @@ -181,9 +181,9 @@ if ((maxdbr>MIN_DB-20)){  int ox=x(); int oy=y(); int lx=w(); int ly=h();  if (!active_r()){ -  pthread_mutex_lock(&master->mutex); +  master->lock();     int fakedb=master->fakepeakpart[npart]; -  pthread_mutex_unlock(&master->mutex); +  master->unlock();    fl_rectf(ox,oy,lx,ly,140,140,140);    if (fakedb>0){      fakedb=(int)(fakedb/255.0*ly)+4; @@ -194,9 +194,9 @@ if (!active_r()){  };  //draw the vu lines -pthread_mutex_lock(&master->mutex); +master->lock();   REALTYPE db=rap2dB(master->vuoutpeakpart[npart]); -pthread_mutex_unlock(&master->mutex); +master->unlock();  db=(MIN_DB-db)/MIN_DB;   if (db<0.0) db=0.0; @@ -242,9 +242,9 @@ Fl::add_timeout(1.0/25.0,tick,v);//25 fps} {}               break;     case FL_PUSH:               if (npart>=0) break; -             pthread_mutex_lock(&master->mutex); +             master->lock();               master->vuresetpeaks(); -             pthread_mutex_unlock(&master->mutex); +             master->unlock();               break;  };  return(1);} {} @@ -351,9 +351,9 @@ bankui->show();}        }        Fl_Check_Button partenabled {          label 01 -        callback {pthread_mutex_lock(&master->mutex); +        callback {master->lock();   master->partonoff(npart,(int) o->value()); -pthread_mutex_unlock(&master->mutex); +master->unlock();  if ((int) o->value()==0) panellistitemgroup->deactivate();    else { @@ -455,13 +455,13 @@ if (fl_ask("Exit and leave the unsaved data?")) {  filename=fl_file_chooser("Open:","({*.xsz})",NULL,0);  if (filename==NULL) return; -pthread_mutex_lock(&master->mutex); +master->lock();    //clear all parameters    master->microtonal.defaults();    //load the data    int result=master->microtonal.loadXML(filename); -pthread_mutex_unlock(&master->mutex); +master->unlock();   delete microtonalui;   @@ -488,9 +488,9 @@ if (result) {  }; -pthread_mutex_lock(&master->mutex); +master->lock();  result=master->microtonal.saveXML(filename); -pthread_mutex_unlock(&master->mutex); +master->unlock();  if (result<0) fl_alert("Error: Could not save the file."); @@ -527,9 +527,9 @@ updatepanel();}              label {&Clear Instrument...}              callback {if (fl_ask("Clear instrument's parameters ?")){  //       int npart=(int)npartcounter->value()-1; -       pthread_mutex_lock(&master->mutex); +       master->lock();         master->part[npart]->defaultsinstrument(); -       pthread_mutex_unlock(&master->mutex); +       master->unlock();         npartcounter->do_callback();  }; @@ -544,7 +544,7 @@ filename=fl_file_chooser("Load:","({*.xiz})",NULL,0);  if (filename==NULL) return; -pthread_mutex_lock(&master->mutex); +master->lock();  //  int npart=(int)npartcounter->value()-1;    //clear all instrument parameters, first @@ -553,7 +553,7 @@ pthread_mutex_lock(&master->mutex);    //load the instr. parameters    int result=master->part[npart]->loadXMLinstrument(filename); -pthread_mutex_unlock(&master->mutex); +master->unlock();  master->part[npart]->applyparameters();  npartcounter->do_callback(); @@ -579,9 +579,9 @@ if (result) {  }; -pthread_mutex_lock(&master->mutex); +master->lock();  result=master->part[npart]->saveXML(filename); -pthread_mutex_unlock(&master->mutex); +master->unlock();  if (result<0) fl_alert("Error: Could not save the file."); @@ -669,9 +669,9 @@ if (result!=0) fl_alert("Error: Could not save the file.");}        Fl_Button {} {          label {Panic!}          callback {virkeyboard->relaseallkeys(); -pthread_mutex_lock(&master->mutex); +master->lock();  master->shutup=1; -pthread_mutex_unlock(&master->mutex);} +master->unlock();}          xywh {293 29 92 31} box PLASTIC_UP_BOX color 231 labelfont 1        }        Fl_Group partuigroup { @@ -702,9 +702,9 @@ syseffectui->refresh(master->sysefx[nsyseff]);}            }            Fl_Choice sysefftype {              label EffType -            callback {pthread_mutex_lock(&master->mutex); +            callback {master->lock();  master->sysefx[nsyseff]->changeeffect((int) o->value()); -pthread_mutex_unlock(&master->mutex); +master->unlock();  syseffectui->refresh(master->sysefx[nsyseff]);}              xywh {315 125 70 15} down_box BORDER_BOX labelsize 11              code0 {o->value(master->sysefx[nsyseff]->geteffect());} @@ -767,9 +767,9 @@ syseffectui->refresh(master->sysefx[nsyseff]);}            }            Fl_Button {} {              label P -            callback {pthread_mutex_lock(&master->mutex); +            callback {master->lock();  presetsui->paste(master->sysefx[nsyseff],syseffectui); -pthread_mutex_unlock(&master->mutex);} +master->unlock();}              xywh {245 124 25 15} box THIN_UP_BOX color 179 labelfont 1 labelsize 12 labelcolor 7            }          } @@ -799,9 +799,9 @@ if (master->Pinsparts[ninseff]!=-1) {            }            Fl_Choice insefftype {              label EffType -            callback {pthread_mutex_lock(&master->mutex); +            callback {master->lock();  master->insefx[ninseff]->changeeffect((int) o->value()); -pthread_mutex_unlock(&master->mutex); +master->unlock();  inseffectui->refresh(master->insefx[ninseff]);  inseffectui->show();}              xywh {315 125 70 15} down_box BORDER_BOX labelsize 11 @@ -880,9 +880,9 @@ master->insefx[ninseff]->cleanup();} open            }            Fl_Button {} {              label P -            callback {pthread_mutex_lock(&master->mutex); +            callback {master->lock();  presetsui->paste(master->insefx[ninseff],inseffectui); -pthread_mutex_unlock(&master->mutex);} +master->unlock();}              xywh {245 124 25 15} box THIN_UP_BOX color 179 labelfont 1 labelsize 12 labelcolor 7            }          } @@ -1131,7 +1131,7 @@ filename=fl_file_chooser("Load:","({*.xiz})",NULL,0);  if (filename==NULL) return; -pthread_mutex_lock(&master->mutex); +master->lock();  //  int npart=(int)npartcounter->value()-1;    //clear all instrument parameters, first @@ -1140,7 +1140,7 @@ pthread_mutex_lock(&master->mutex);    //load the instr. parameters    int result=master->part[npart]->loadXMLinstrument(filename); -pthread_mutex_unlock(&master->mutex); +master->unlock();  master->part[npart]->applyparameters();  simplenpartcounter->do_callback(); @@ -1272,9 +1272,9 @@ simplemaxkcounter->do_callback();}        }        Fl_Check_Button partenabled {          label Enabled -        callback {pthread_mutex_lock(&master->mutex); +        callback {master->lock();   master->partonoff(npart,(int) o->value()); -pthread_mutex_unlock(&master->mutex); +master->unlock();  if ((int) o->value()==0) simplelistitemgroup->deactivate();    else { @@ -1318,9 +1318,9 @@ simplerefresh();}              }              Fl_Choice simplesysefftype {                label EffType -              callback {pthread_mutex_lock(&master->mutex); +              callback {master->lock();  master->sysefx[nsyseff]->changeeffect((int) o->value()); -pthread_mutex_unlock(&master->mutex); +master->unlock();  simplesyseffectui->refresh(master->sysefx[nsyseff]);}                xywh {515 80 70 15} down_box BORDER_BOX labelsize 11 align 5                code0 {o->value(master->sysefx[nsyseff]->geteffect());} @@ -1378,9 +1378,9 @@ simplesyseffectui->refresh(master->sysefx[nsyseff]);}              }              Fl_Button {} {                label P -              callback {pthread_mutex_lock(&master->mutex); +              callback {master->lock();  presetsui->paste(master->sysefx[nsyseff],simplesyseffectui); -pthread_mutex_unlock(&master->mutex);} +master->unlock();}                xywh {560 65 25 15} box THIN_UP_BOX color 179 labelfont 1 labelsize 12 labelcolor 7              }            } @@ -1410,9 +1410,9 @@ if (master->Pinsparts[ninseff]!=-1) {              }              Fl_Choice simpleinsefftype {                label EffType -              callback {pthread_mutex_lock(&master->mutex); +              callback {master->lock();  master->insefx[ninseff]->changeeffect((int) o->value()); -pthread_mutex_unlock(&master->mutex); +master->unlock();  simpleinseffectui->refresh(master->insefx[ninseff]);  simpleinseffectui->show();}                xywh {515 80 70 15} down_box BORDER_BOX labelsize 11 align 5 @@ -1486,9 +1486,9 @@ master->insefx[ninseff]->cleanup();} open              } {}              Fl_Button {} {                label P -              callback {pthread_mutex_lock(&master->mutex); +              callback {master->lock();  presetsui->paste(master->insefx[ninseff],simpleinseffectui); -pthread_mutex_unlock(&master->mutex);} +master->unlock();}                xywh {560 65 25 15} box THIN_UP_BOX color 179 labelfont 1 labelsize 12 labelcolor 7              }            } @@ -1521,9 +1521,9 @@ pthread_mutex_unlock(&master->mutex);}        Fl_Button {} {          label {Stop ALL sounds!}          callback {virkeyboard->relaseallkeys(); -pthread_mutex_lock(&master->mutex); +master->lock();  master->shutup=1; -pthread_mutex_unlock(&master->mutex);} +master->unlock();}          xywh {5 149 115 31} box PLASTIC_UP_BOX color 231 labelfont 1 labelsize 12        }        Fl_Button {} { @@ -1690,9 +1690,9 @@ simplesyseffsend->value(master->Psysefxvol[nsyseff][npart]);} {}      code {if (fl_ask("Clear *ALL* the parameters ?")){         delete microtonalui; -       pthread_mutex_lock(&master->mutex); +       master->lock();  	master->defaults(); -       pthread_mutex_unlock(&master->mutex); +       master->unlock();         npartcounter->value(1);         refresh_master_ui(); @@ -1707,13 +1707,13 @@ filename=fl_file_chooser("Open:","({*.xmz})",NULL,0);  if (filename==NULL) return; -pthread_mutex_lock(&master->mutex); +master->lock();    //clear all parameters    master->defaults();    //load the data    int result=master->loadXML(filename); -pthread_mutex_unlock(&master->mutex); +master->unlock();  master->applyparameters();  npartcounter->value(1); @@ -1741,9 +1741,9 @@ if (result) {  }; -pthread_mutex_lock(&master->mutex); +master->lock();  result=master->saveXML(filename); -pthread_mutex_unlock(&master->mutex); +master->unlock();  if (result<0) fl_alert("Error: Could not save the file.");  	else setfilelabel(filename); diff --git a/muse/synti/zynaddsubfx/UI/OscilGenUI.fl b/muse/synti/zynaddsubfx/UI/OscilGenUI.fl index 8527719a..0bd394ec 100644 --- a/muse/synti/zynaddsubfx/UI/OscilGenUI.fl +++ b/muse/synti/zynaddsubfx/UI/OscilGenUI.fl @@ -71,10 +71,10 @@ REALTYPE x;  REALTYPE spc[n];  for (i=0;i<n;i++) spc[i]=0.0; -pthread_mutex_lock(&master->mutex); +master->lock();  if (oscbase==0) oscil->getspectrum(n,spc,0);      else oscil->getspectrum(n,spc,1); -pthread_mutex_unlock(&master->mutex); +master->unlock();  //normalize  REALTYPE max=0; @@ -178,10 +178,10 @@ master=master_;} {}    Function {draw()} {} {      code {int ox=x(),oy=y(),lx=w(),ly=h()-1,i;  REALTYPE smps[OSCIL_SIZE]; -pthread_mutex_lock(&master->mutex); +master->lock();  if (oscbase==0) oscil->get(smps,-1.0);      else oscil->getcurrentbasefunction(smps); -pthread_mutex_unlock(&master->mutex); +master->unlock();  if (damage()!=1){   fl_color(0,0,0); @@ -250,14 +250,14 @@ if (Fl::event_button3()) o->value(x);  if (x==64) o->selection_color(0);      else o->selection_color(222); -pthread_mutex_lock(&master->mutex); +master->lock();   oscil->Phmag[n]=x;   if (x==64) {      oscil->Phphase[n]=64;      phase->value(64);   };   oscil->prepare(); -pthread_mutex_unlock(&master->mutex); +master->unlock();  display->redraw();  oldosc->redraw(); @@ -276,10 +276,10 @@ if (cbwidget!=NULL) {  if (Fl::event_button3()) o->value(x);     else x=(int)o->value(); -pthread_mutex_lock(&master->mutex); +master->lock();   oscil->Phphase[n]=x;   oscil->prepare(); -pthread_mutex_unlock(&master->mutex); +master->unlock();  display->redraw();  oldosc->redraw(); @@ -627,13 +627,13 @@ if (autoclearbutton->value()){     sabutton->do_callback();  }; -pthread_mutex_lock(&master->mutex); +master->lock();   for (int i=0;i<MAX_AD_HARMONICS;i++){     if (oscil->Phmag[i]==64) h[i]->mag->selection_color(0);        else h[i]->mag->selection_color(222);   };   oscil->prepare(); -pthread_mutex_unlock(&master->mutex); +master->unlock();  basefuncdisplaygroup->redraw();  redrawoscil();} @@ -664,9 +664,9 @@ for (int i=0;i<MAX_AD_HARMONICS;i++){  //harmonics->redraw(); -pthread_mutex_lock(&master->mutex); +master->lock();   oscil->prepare(); -pthread_mutex_unlock(&master->mutex); +master->unlock();  redrawoscil();}          xywh {670 505 55 15} box THIN_UP_BOX labelfont 1 labelsize 12 @@ -1020,9 +1020,9 @@ redrawoscil();}          label Sine          callback {if (!fl_ask("Convert to SINE?")) return; -pthread_mutex_lock(&master->mutex); +master->lock();   oscil->convert2sine(0); -pthread_mutex_unlock(&master->mutex); +master->unlock();  redrawoscil();  refresh();} @@ -1108,9 +1108,9 @@ adhrtype->value(oscil->Padaptiveharmonicspar);  for (int i=0;i<MAX_AD_HARMONICS;i++) h[i]->refresh(); -pthread_mutex_lock(&master->mutex); +master->lock();   oscil->prepare(); -pthread_mutex_unlock(&master->mutex); +master->unlock();  basefuncdisplaygroup->redraw();  redrawoscil();} {} diff --git a/muse/synti/zynaddsubfx/UI/PADnoteUI.fl b/muse/synti/zynaddsubfx/UI/PADnoteUI.fl index 12d34842..45c1f9a8 100644 --- a/muse/synti/zynaddsubfx/UI/PADnoteUI.fl +++ b/muse/synti/zynaddsubfx/UI/PADnoteUI.fl @@ -147,9 +147,9 @@ int n=OSCIL_SIZE/2;  REALTYPE spc[n];  for (int i=0;i<n;i++) spc[i]=0.0; -pthread_mutex_lock(&master->mutex); +master->busy=true;  pars->oscilgen->getspectrum(n,spc,0); -pthread_mutex_unlock(&master->mutex); +master->busy=false;  //normalize diff --git a/muse/synti/zynaddsubfx/UI/PartUI.fl b/muse/synti/zynaddsubfx/UI/PartUI.fl index f40d3de2..a3a91782 100644 --- a/muse/synti/zynaddsubfx/UI/PartUI.fl +++ b/muse/synti/zynaddsubfx/UI/PartUI.fl @@ -202,9 +202,9 @@ if (part->kit[n].Ppadenabled!=0) padeditbutton->activate();          callback {int answer=1;  if (o->value()==0) answer=fl_ask("Delete the item?");  if (answer!=0){ -pthread_mutex_lock(&master->mutex); +master->busy=true;   part->setkititemstatus(n,(int) o->value()); -pthread_mutex_unlock(&master->mutex); +master->busy=false;  if (o->value()==0) partkititemgroup->deactivate();  else partkititemgroup->activate(); @@ -243,9 +243,9 @@ this->redraw();} {        callback {int answer=1;  if (o->value()==0) answer=fl_ask("Delete the item?");  if (answer!=0){ -pthread_mutex_lock(&master->mutex); +master->busy=true;   part->setkititemstatus(n,(int) o->value()); -pthread_mutex_unlock(&master->mutex); +master->busy=false;  if (o->value()==0) partkititemgroup->deactivate();  else partkititemgroup->activate(); @@ -431,9 +431,9 @@ part->setkeylimit(val);} open        }        Fl_Check_Button {} {          label Enabled -        callback {pthread_mutex_lock(&master->mutex); +        callback {master->busy=true;  master->partonoff(npart,(int) o->value()); -pthread_mutex_unlock(&master->mutex); +master->busy=false;  if (part->Penabled==0) partgroupui->deactivate();      else partgroupui->activate();}          xywh {90 5 75 20} down_box DOWN_BOX labelfont 1 labelsize 12 @@ -620,9 +620,9 @@ sendtochoice->value(x);}        }        Fl_Choice insefftype {          label EffType -        callback {pthread_mutex_lock(part->mutex); +        callback {master->busy=true;  part->partefx[ninseff]->changeeffect((int) o->value()); -pthread_mutex_unlock(part->mutex); +master->busy=false;  inseffectui->refresh(part->partefx[ninseff]);}          xywh {155 110 70 15} down_box BORDER_BOX labelsize 11 align 6          code0 {o->value(part->partefx[ninseff]->geteffect());} @@ -714,9 +714,9 @@ if (x==2) part->partefx[ninseff]->setdryonly(true);        }        Fl_Button {} {          label P -        callback {pthread_mutex_lock(&master->mutex); +        callback {master->busy=true;  presetsui->paste(part->partefx[ninseff],inseffectui); -pthread_mutex_unlock(&master->mutex);} +master->busy=false;}          xywh {120 127 25 15} box THIN_UP_BOX color 179 labelfont 1 labelsize 12 labelcolor 7        }      } diff --git a/muse/synti/zynaddsubfx/UI/VirKeyboard.fl b/muse/synti/zynaddsubfx/UI/VirKeyboard.fl index bd0fa8ba..aed2c930 100644 --- a/muse/synti/zynaddsubfx/UI/VirKeyboard.fl +++ b/muse/synti/zynaddsubfx/UI/VirKeyboard.fl @@ -183,9 +183,9 @@ if (rndvelocity!=0){    vel=midivel*(127.0-rndvelocity)/127.0+RND*rndvelocity;  }; -pthread_mutex_lock(&master->mutex); +master->busy=true;   master->NoteOn(midich,nk+midioct*12,(int)vel); -pthread_mutex_unlock(&master->mutex);} {} +master->busy=false;} {}    }    Function {relasekey(int nk,int type)} {} {      code {if ((nk<0)||(nk>=N_OCT*12)) return; @@ -197,9 +197,9 @@ pressed[nk]=0;  damage(1); -pthread_mutex_lock(&master->mutex); +master->busy=true;   master->NoteOff(midich,nk+12*midioct); -pthread_mutex_unlock(&master->mutex);} {} +master->busy=false;} {}    }    Function {relaseallkeys(int type)} {} {      code {for (int i=0;i<N_OCT*12;i++) relasekey(i,type);} {} @@ -272,9 +272,9 @@ virkeyboardwindow->hide();}          label Cval          callback {int ctl=midictl; -pthread_mutex_lock(&master->mutex); +master->busy=true;   master->SetController(virkeys->midich,ctl,(int) o->value()); -pthread_mutex_unlock(&master->mutex); +master->busy=false;  virkeys->take_focus();}          tooltip {Controller value} xywh {605 10 15 115} type {Vert Fill} box ENGRAVED_BOX selection_color 229 labelsize 8 align 5 minimum 127 maximum 0 step 1 value 64 textsize 7        } @@ -354,9 +354,9 @@ virkeys->take_focus();}        }        Fl_Roller pitchwheelroller {          label Pwh -        callback {pthread_mutex_lock(&master->mutex); +        callback {master->lock();   master->SetController(virkeys->midich,C_pitchwheel,-(int) o->value()); -pthread_mutex_unlock(&master->mutex); +master->unlock();  virkeys->take_focus();}          tooltip {Pitch Wheel} xywh {625 10 20 95} box PLASTIC_UP_BOX labelsize 8 align 1 when 3 minimum -8192 maximum 8192 step 64        } diff --git a/muse/synti/zynaddsubfx/main.cpp b/muse/synti/zynaddsubfx/main.cpp index 4f7f8820..7fd863d2 100644 --- a/muse/synti/zynaddsubfx/main.cpp +++ b/muse/synti/zynaddsubfx/main.cpp @@ -1,24 +1,25 @@ -/* -  ZynAddSubFX - a software synthesizer - -  main.c  -  Main file of the synthesizer -  Copyright (C) 2002-2005 Nasca Octavian Paul -  Author: Nasca Octavian Paul - -  This program is free software; you can redistribute it and/or modify -  it under the terms of version 2 of the GNU General Public License  -  as published by the Free Software Foundation. - -  This program 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 (version 2) for more details. - -  You should have received a copy of the GNU General Public License (version 2) -  along with this program; if not, write to the Free Software Foundation, -  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA - -*/ +//============================================================================= +//  MusE +//  Linux Music Editor +//  $Id:$ +// +//  Copyright (C) 2002-2006 by Werner Schweer and others +// +//  ZynAddSubFX - a software synthesizer +//  Copyright (C) 2002-2005 Nasca Octavian Paul +// +//  This program is free software; you can redistribute it and/or modify +//  it under the terms of the GNU General Public License version 2. +// +//  This program 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 program; if not, write to the Free Software +//  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +//=============================================================================  #include <stdlib.h>  #include <stdio.h> @@ -29,8 +30,6 @@  #include "Misc/Util.h"  #include "MasterUI.h" -int swaplr = 0;   //1 for left-right swapping -  //=========================================================  //    MESS interface  //========================================================= @@ -42,26 +41,38 @@ int instances = -1;  //   Zynadd  //--------------------------------------------------------- -class Zynadd : public Mess { +class Zynadd : public Mess, public Master  +      {        virtual void process(float** buffer, int offset, int n);        virtual bool processEvent(const MidiEvent&); -      virtual void getInitData(int*, const unsigned char**) const; -      virtual int getControllerInfo(int, const char**, int*, int*, int*) const; +      virtual void getInitData(int*, const unsigned char**); +      virtual int getControllerInfo(int, const char**, int*, int*, int*);        virtual const char* getPatchName(int, int, int) const;        virtual const char* getBankName(int) const;        virtual const MidiPatch* getPatchInfo(int, const MidiPatch*) const; +      virtual bool hasGui() const { return true; } +      virtual bool guiVisible() const { return _guiVisible; } +      virtual void showGui(bool val);        mutable MidiPatch patch;        mutable int currentBank; +      bool _guiVisible; +      bool loadBank(int); +      char* messPatch[MAX_NUM_BANKS][128]; +     public:        int Pexitprogram;  	MasterUI* ui; -      Master* vmaster;  	pthread_t thr;        Zynadd();        ~Zynadd(); + +      enum { +            GUI_NO_CMD, GUI_REFRESH, GUI_HIDE, GUI_SHOW +            }; +      int guiCmd;        };  //--------------------------------------------------------- @@ -71,40 +82,69 @@ class Zynadd : public Mess {  void* guiThread(void *arg)        {        Zynadd* z = (Zynadd *) arg; - -      z->ui = new MasterUI(z->vmaster, &z->Pexitprogram); - +      z->ui = new MasterUI(z, &z->Pexitprogram);        z->ui->showUI(); - -//      while (z->Pexitprogram == 0)  -//            sleep(2); - -      while (z->Pexitprogram == 0)  +      while (z->Pexitprogram == 0) { +            switch(z->guiCmd) { +                  case Zynadd::GUI_REFRESH: +                        z->ui->refresh_master_ui(); +                        break; +                  case Zynadd::GUI_HIDE: +                        switch (config.cfg.UserInterfaceMode) { +	                        case 0:    +                                    z->ui->selectuiwindow->hide(); +	                              break; +	                        case 1: +                                    z->ui->masterwindow->hide(); +	                              break; +	                        case 2: +                                    z->ui->simplemasterwindow->hide(); +	                              break; +                              } +                        break; +                  case Zynadd::GUI_SHOW: +                        z->ui->showUI(); +                        break; +                  } +            z->guiCmd = Zynadd::GUI_NO_CMD;              Fl::wait(0.01); - +            }        delete(z->ui);        Fl::wait(0.01); -        pthread_exit(0); -      return(0); +      return 0;        }  //---------------------------------------------------------  //   Zynadd  //--------------------------------------------------------- -Zynadd::Zynadd() : Mess(2) +Zynadd::Zynadd() : Mess(2), Master()        {        instances++;        swaplr        = config.cfg.SwapStereo;        Pexitprogram  = 0;        currentBank   = -1; +      guiCmd        = 0; + +      swaplr = 0;   //1 for left-right swapping +      memset(messPatch, 0, sizeof(messPatch)); +      bank.rescanforbanks(); +      defaults(); + +      for (int i = 1; i < MAX_NUM_BANKS; ++i) { +            if (bank.banks[i].dir == 0) +                  break; +            loadBank(i); +            for (unsigned int k = 0; k < 128; ++k) { +            	if (!bank.emptyslot(k)) { +                        messPatch[i][k] = strdup(bank.getname(k)); +                        } +                  } +            } -      vmaster           = new Master(); -      vmaster->swaplr = swaplr; -      vmaster->bank.rescanforbanks(); -      vmaster->defaults();        pthread_create(&thr, NULL, guiThread, this); +      _guiVisible = true;        }  //--------------------------------------------------------- @@ -119,23 +159,83 @@ Zynadd::~Zynadd()        }  //--------------------------------------------------------- +//    showGui +//--------------------------------------------------------- + +void Zynadd::showGui(bool val) +      { +      if (val != _guiVisible) +            guiCmd = val ? GUI_SHOW : GUI_HIDE; +      _guiVisible = val; +      } + +//--------------------------------------------------------- +//    loadBank +//--------------------------------------------------------- + +bool Zynadd::loadBank(int n) +      { +      if (n != currentBank) { +            if (bank.banks[n].dir == 0) { +                  printf("Zynaddsubfx: empty bank %d\n", n); +                        return false; +                  } +            bank.loadbank(bank.banks[n].dir); +            currentBank = n; +            } +      return true; +      } + +//---------------------------------------------------------  //   getBankName  //---------------------------------------------------------  const char* Zynadd::getBankName(int n) const        {        n += 1;     // bank 0 is always empty ?! -//    printf("Zyn: getBankName %d <%s>\n", n, vmaster->bank.banks[n].name); -      return vmaster->bank.banks[n].name; +//    printf("Zyn: getBankName %d <%s>\n", n, bank.banks[n].name); +      return bank.banks[n].name;        }  //---------------------------------------------------------  //   getControllerInfo  //--------------------------------------------------------- -int Zynadd::getControllerInfo(int, const char**, int*, int*, int*) const +struct ZynCtrl { +      const char* name; +      int num; +      int min; +      int max; +      }; + +int Zynadd::getControllerInfo(int i, const char** name, int* num, int* min, int* max)        { -      return 0; +      static const ZynCtrl ctrl[] = { +            { "Pitch",          0x40000, -8191, 8190 }, +            { "ProgramChange",  0x40001,  0, 0xffffff }, +            { "Modulation",           1,  0, 127     }, +            { "MainVolume",           7,  0, 127     }, +            { "Pan",                 10,  0, 127     }, +            { "Expression",          11,  0, 127     }, +            { "Sustain",             64,  0, 127     }, +            { "Portamento",          65,  0, 127     }, +            { "FilterQ",	       71,  0, 127     }, +            { "FilterCutoff",	       74,  0, 127     }, +            { "Bandwidth",           75,  0, 127     }, +            { "ModulationAmp",       76,  0, 127     }, +            { "ResonanceCenter",     77,  0, 127     }, +            { "ResonanceBandwidth",  78,  0, 127     }, +            { "AllSoundsOff",       120,  0, 127     }, +            { "ResetAllController", 121,  0, 127     }, +            { "AllNotesOff",        123,  0, 127     }, +            }; +      if ((unsigned)i >= sizeof(ctrl)/sizeof(*ctrl)) +            return 0; +      *name = ctrl[i].name; +      *num  = ctrl[i].num; +      *min  = ctrl[i].min; +      *max  = ctrl[i].max; +      return i+1;;        }  //--------------------------------------------------------- @@ -144,11 +244,9 @@ int Zynadd::getControllerInfo(int, const char**, int*, int*, int*) const  const char* Zynadd::getPatchName(int, int val, int) const        { -      int bank = (val >> 8) + 1; -      if (bank != currentBank) -            return "--?--"; +      int bankNo = (val >> 8) + 1;        int program = val & 0x7f; -      return vmaster->bank.getname(program); +      return messPatch[bankNo][program];        }  //--------------------------------------------------------- @@ -159,16 +257,10 @@ const MidiPatch* Zynadd::getPatchInfo(int, const MidiPatch* p) const        {        if (!p)              return 0; - -      int bank = ((p->hbank << 8) & 0xff) + ((p->lbank) & 0xff) + 1; -      if (bank != currentBank) { -// printf("load new bank %d <%s>\n", bank, vmaster->bank.banks[bank].dir); -            vmaster->bank.loadbank(vmaster->bank.banks[bank].dir); -            currentBank = bank; -            } +      int bn = ((p->hbank << 8) & 0xff) + ((p->lbank) & 0xff) + 1;        for (unsigned int i = p->prog + 1; i < 128; ++i) { -            if (!vmaster->bank.emptyslot(i)) { -                  patch.name  = vmaster->bank.getname(i); +            if (messPatch[bn][i]) { +                  patch.name  = messPatch[bn][i];                    patch.typ   = 0xff;                    patch.prog  = i;                    patch.hbank = p->hbank; @@ -183,9 +275,9 @@ const MidiPatch* Zynadd::getPatchInfo(int, const MidiPatch* p) const  //    getInitData  //--------------------------------------------------------- -void Zynadd::getInitData(int* n, const unsigned char** data) const +void Zynadd::getInitData(int* n, const unsigned char** data)        { -      *n = vmaster->getalldata((char **)data); +      *n = getalldata((char **)data);        }  //--------------------------------------------------------- @@ -197,9 +289,12 @@ void Zynadd::process(float** outputs, int offset, int n)        {        float* outl = outputs[0] + offset;        float* outr = outputs[1] + offset; -//      pthread_mutex_lock(&vmaster->mutex); -      vmaster->GetAudioOutSamples(n, outl, outr); -//      pthread_mutex_unlock(&vmaster->mutex); +      if (busy) { +            memset(outl, 0, sizeof(float) * n); +            memset(outr, 0, sizeof(float) * n); +            return; +            } +      GetAudioOutSamples(n, outl, outr);        }  //--------------------------------------------------------- @@ -208,42 +303,37 @@ void Zynadd::process(float** outputs, int offset, int n)  bool Zynadd::processEvent(const MidiEvent& e)        { +      if (busy) +            return true;        int ch = e.channel(); -//	pthread_mutex_lock(&vmaster->mutex);        switch(e.type()) {              case 0x80:  // note off -	            vmaster->NoteOff(ch, e.dataA()); +	            NoteOff(ch, e.dataA());                    break;              case 0x90:  // note on -                  vmaster->NoteOn(ch, e.dataA(), e.dataB()); +                  NoteOn(ch, e.dataA(), e.dataB());  		      break;  	      case 0xb0:  // controller                    switch(e.dataA()) {                          case 0x40000:     // pitch -	                        vmaster->SetController(ch, C_pitchwheel, e.dataB()); +	                        SetController(ch, C_pitchwheel, e.dataB());                                break;                          case 0x40001:     // program change                                { -                              int bank = (e.dataB() >> 8) + 1; -                              if (bank != currentBank) { -                                    if (vmaster->bank.banks[bank].dir == 0) { -                                          printf("Zynaddsubfx: empty bank %d\n", bank); -                                          return false; -                                          } -                                    vmaster->bank.loadbank(vmaster->bank.banks[bank].dir); -                                    currentBank = bank; -                                    } +                              int bankNo = (e.dataB() >> 8) + 1; +                              if (!loadBank(bankNo)) +                                    return false;                                int program = e.dataB() & 0x7f; -                              if (vmaster->bank.emptyslot(program)) { +                              if (bank.emptyslot(program)) {                                      printf("Zynaddsubfx: programslot %d is empty!\n", program);                                      break;                                      }                                for (int npart = 0; npart < NUM_MIDI_PARTS; npart++) { -                                    Part* part = vmaster->part[npart]; -	                              if ((ch == part->Prcvchn) && (part->Penabled != 0)) -	                                    vmaster->bank.loadfromslot(program, part); +                                    Part* p = part[npart]; +	                              if ((ch == p->Prcvchn) && (p->Penabled != 0)) +	                                    bank.loadfromslot(program, p);                                      } -                              // TODO: gui does not change +                              guiCmd = GUI_REFRESH;                                }                                break;                          default: @@ -271,19 +361,16 @@ bool Zynadd::processEvent(const MidiEvent& e)                             	      case 98:   ctl = C_nrpnlo; break;                             	      default:   ctl = C_NULL; break;                             	      } -	      	            vmaster->SetController(ch, ctl, e.dataB()); +	      	            SetController(ch, ctl, e.dataB());                                }                                break;                          }                    break;              case 0xf0: -//	            pthread_mutex_unlock(&vmaster->mutex); -                  vmaster->putalldata((char*)e.data(), e.len()); -//	            pthread_mutex_lock(&vmaster->mutex); +                  putalldata((char*)e.data(), e.len());                    break;              } -//	pthread_mutex_unlock(&vmaster->mutex);        return false;        } @@ -291,9 +378,7 @@ bool Zynadd::processEvent(const MidiEvent& e)  //   instantiate  //--------------------------------------------------------- -class QWidget; - -static Mess* instantiate(int sr, QWidget*, const char*) +static Mess* instantiate(int sr, const char*)        {        if (instances == -1) {              config.init(); | 
