diff options
| author | Florian Jung <flo@windfisch.org> | 2011-06-28 12:38:56 +0000 | 
|---|---|---|
| committer | Florian Jung <flo@windfisch.org> | 2011-06-28 12:38:56 +0000 | 
| commit | 1ee2c8cb621fdc9b165b891f6d8d4607dadabf9b (patch) | |
| tree | 27174350316c57d48f8ecaad54f7919f0ba106e1 /muse2/synti/fluid | |
| parent | 2f4a98c62adf7241944ea7949d4b6a50d4b4af36 (diff) | |
| parent | 933aeb536f3d90eb38bc96308de628eeedd81755 (diff) | |
merged with current trunk. i hope this works...
Diffstat (limited to 'muse2/synti/fluid')
| -rw-r--r-- | muse2/synti/fluid/common_defs.h | 12 | ||||
| -rw-r--r-- | muse2/synti/fluid/fluid.cpp | 85 | ||||
| -rw-r--r-- | muse2/synti/fluid/fluid.h | 9 | ||||
| -rw-r--r-- | muse2/synti/fluid/fluidgui.cpp | 50 | ||||
| -rw-r--r-- | muse2/synti/fluid/fluidgui.h | 6 | 
5 files changed, 137 insertions, 25 deletions
| diff --git a/muse2/synti/fluid/common_defs.h b/muse2/synti/fluid/common_defs.h new file mode 100644 index 00000000..6aa62bc0 --- /dev/null +++ b/muse2/synti/fluid/common_defs.h @@ -0,0 +1,12 @@ +#ifndef __FLUID_UNIQUE_ID_H +#define __FLUID_UNIQUE_ID_H + +// Make sure this number is unique among all the MESS synths. +#define FLUID_UNIQUE_ID      0 + +//#define FLUID_DEBUG       + +enum SfOp { SF_REPLACE = 1, SF_ADD, SF_REMOVE }; + +#endif + diff --git a/muse2/synti/fluid/fluid.cpp b/muse2/synti/fluid/fluid.cpp index ad3d06a6..c06e672e 100644 --- a/muse2/synti/fluid/fluid.cpp +++ b/muse2/synti/fluid/fluid.cpp @@ -28,6 +28,7 @@  #include "muse/midictrl.h" +//#include "common_defs.h"  #include "muse/midi.h"  #include "fluid.h"  #include "fluidgui.h" @@ -186,7 +187,6 @@ bool ISynth::sysex(int len, const unsigned char* data)                                }                          }                    } -              //---------------------------------------------              //  Universal Realtime              //--------------------------------------------- @@ -194,55 +194,68 @@ bool ISynth::sysex(int len, const unsigned char* data)              else if (data[0] == 0x7f) {                    if (data[1] == 0x7f) {  // device Id                          if ((data[2] == 0x4) && (data[3] == 0x1)) { +                           if(len == 6) +                           {                                float v = (data[5]*128 + data[4])/32767.0;                                fluid_synth_set_gain(_fluidsynth, v);                                return false;                                } +                           }                             }                    } -              //---------------------------------------------              //  MusE Soft Synth              //--------------------------------------------- -            else if (data[0] == 0x7c) { +            else if (data[0] == MUSE_SYNTH_SYSEX_MFG_ID) {                    int n = len - 3;                    if (n < 1) { +                        #ifdef FS_DEBUG                          printf("fluid: bad sysEx:\n"); +                        #endif                          return false;                          }                    char buffer[n+1];                    memcpy(buffer, (char*)data+3, n);                    buffer[n] = 0; -                  if (data[1] == 0) {     // fluid -                        if (data[2] == 1) {  // load sound font +                  if (data[1] == FLUID_UNIQUE_ID) {     // fluid +                        //if (data[2] == 1) {  // load sound font +                        if (data[2] == SF_REPLACE) {  // load sound font                                sysexSoundFont(SF_REPLACE, buffer);                                return false;                                } -                        else if (data[2] == 2) {  // load sound font +                        //else if (data[2] == 2) {  // load sound font +                        else if (data[2] == SF_ADD) {  // load sound font                                sysexSoundFont(SF_ADD, buffer);                                return false;                                } -                        else if (data[2] == 3) {  // load sound font +                        //else if (data[2] == 3) {  // load sound font +                        else if (data[2] == SF_REMOVE) {  // load sound font                                sysexSoundFont(SF_REMOVE, buffer);                                return false;                                }                          }                    } +                          else if (data[0] == 0x41) {   // roland -                  if (data[1] == 0x10 && data[2] == 0x42 && data[3] == 0x12 -                     && data[4] == 0x40 && data[5] == 00 && data[6] == 0x7f -                     && data[7] == 0x41) { -                        // gs on -                        gmOn(true); -                        return false; -                        } -                  } -            } +                  if (data[1] == 0x10 && data[2] == 0x42 && data[3] == 0x12) +                  { +                     if (len == 8) { +                       if(data[4] == 0x40 && data[5] == 00 && data[6] == 0x7f && data[7] == 0x41) { +                          // gs on +                          gmOn(true); +                          return false; +                       }     +                     } +                  }       +                } +            }       +      #ifdef FS_DEBUG        printf("fluid: unknown sysex received, len %d:\n", len);        for (int i = 0; i < len; ++i)              printf("%02x ", data[i]);        printf("\n"); +      #endif        return false;        } @@ -292,6 +305,8 @@ void ISynth::showNativeGui(bool flag)  ISynth::~ISynth()        { +      if(gui)         +        delete gui;  // p4.0.27        // TODO delete settings        if (_fluidsynth)              delete_fluid_synth(_fluidsynth); @@ -390,7 +405,9 @@ const char* ISynth::getPatchName(int /*ch*/, int val, int, bool /*drum*/) const        const char* name = "<unknown>";        if (_busy) { +            //#ifdef FS_DEBUG              printf("fluid: getPatchName(): busy!\n"); +            //#endif              return name;              }        fluid_font = fluid_synth_get_sfont_by_id(_fluidsynth, hbank); @@ -399,8 +416,12 @@ const char* ISynth::getPatchName(int /*ch*/, int val, int, bool /*drum*/) const              if (preset)                    name = (*preset->get_name)(preset);              else +            { +                  //#ifdef FS_DEBUG                    fprintf(stderr, "no fluid preset for bank %d prog %d\n",                       lbank, prog); +                  //#endif    +            }                       }        else              fprintf(stderr, "ISynth::getPatchName(): no fluid font id=%d found\n", hbank); @@ -414,7 +435,9 @@ const char* ISynth::getPatchName(int /*ch*/, int val, int, bool /*drum*/) const  const MidiPatch* ISynth::getPatchInfo(int ch, const MidiPatch* p) const        {        if (_busy) { +            //#ifdef FS_DEBUG              printf("fluid: getPatchInfo(): busy!\n"); +            //#endif              return 0;              }        if (p == 0) { @@ -459,13 +482,14 @@ void ISynth::getInitData(int* len, const unsigned char** data)              if (initBuffer)                    delete [] initBuffer;              initBuffer = new unsigned char[n]; +            initLen = n;    // p4.0.27 Tim.              } -      initBuffer[0] = 0x7c; -      initBuffer[1] = 0x00; +      initBuffer[0] = MUSE_SYNTH_SYSEX_MFG_ID; +      initBuffer[1] = FLUID_UNIQUE_ID;        initBuffer[2] = SF_REPLACE;        strcpy((char*)(initBuffer+3), sfont);        *len = n; -      *data = initBuffer; +      *data = (unsigned char*)initBuffer;        }  //--------------------------------------------------------- @@ -482,11 +506,15 @@ void ISynth::sysexSoundFont(SfOp op, const char* data)              case SF_REPLACE:              case SF_ADD:                    if (sfont && (strcmp(sfont, data) == 0)) { +                        #ifdef FS_DEBUG                          fprintf(stderr, "fluid: font already loaded\n"); +                        #endif                          break;                          }                    if (_busy) { +                        //#ifdef FS_DEBUG                          fprintf(stderr, "fluid: busy!\n"); +                        //#endif                          break;                          }                    _busy = true; @@ -528,18 +556,35 @@ void ISynth::noRTHelper()                    }              int id = getFontId();              if (id != -1) { +                  #ifdef FS_DEBUG                    fprintf(stderr, "ISynth: unload old font\n"); +                  #endif                    fluid_synth_sfunload(synth(), (unsigned)id, true);                    } -            int rv = fluid_synth_sfload(synth(), getFont(), true); +            const char* fontname = getFont(); +            int rv = fluid_synth_sfload(synth(), fontname, true);              if (rv == -1) {                    fprintf(stderr, "ISynth: sfload %s failed\n",                       fluid_synth_error(synth()));                    }              else {                    setFontId(rv); +                   +                  // Inform the gui.      p4.0.27 Tim +                  int slen = strlen(fontname); +                  int n = slen + 2; +                  unsigned char d[n]; +                  d[0] = FS_SEND_SOUNDFONT_NAME; +                  if(slen != 0) +                    memcpy(d + 1, fontname, slen); +                  d[1 + slen] = 0; +                  MidiPlayEvent ev(0,0, ME_SYSEX, d, n); +                  gui->writeEvent(ev); +                   +                  #ifdef FS_DEBUG                    fprintf(stderr, "ISynth: sfont %s loaded as %d\n ",                       getFont(), rv); +                  #endif                       }              fluid_synth_set_gain(synth(), 1.0);  //?              _busy = false; diff --git a/muse2/synti/fluid/fluid.h b/muse2/synti/fluid/fluid.h index e80f1463..02b111e4 100644 --- a/muse2/synti/fluid/fluid.h +++ b/muse2/synti/fluid/fluid.h @@ -20,8 +20,9 @@  #include <list>  #include <fluidsynth.h>  #include "libsynti/mess.h" +#include "common_defs.h" -enum SfOp { SF_REPLACE = 1, SF_ADD, SF_REMOVE }; +//enum SfOp { SF_REPLACE = 1, SF_ADD, SF_REMOVE };  class FLUIDGui;  //--------------------------------------------------------- @@ -73,8 +74,12 @@ class ISynth : public Mess {     public:        ISynth(); -      ~ISynth(); +      virtual ~ISynth(); +      // This is only a kludge required to support old songs' midistates. Do not use in any new synth. +      // Note for Fluid, do nothing because unlike other synths, Fluid already had correct sysex headers. +      //virtual int oldMidiStateHeader(const unsigned char** data) const;   +              fluid_synth_t* synth() { return _fluidsynth; }        const fluid_synth_t* synth() const { return _fluidsynth; }        char* getFont() const  { return sfont; } diff --git a/muse2/synti/fluid/fluidgui.cpp b/muse2/synti/fluid/fluidgui.cpp index af8d937c..1f948a7d 100644 --- a/muse2/synti/fluid/fluidgui.cpp +++ b/muse2/synti/fluid/fluidgui.cpp @@ -15,9 +15,12 @@  #include <QFileDialog>  #include <QFileInfo>  #include <QMessageBox> +#include <QSocketNotifier> +#include "common_defs.h"  #include "fluidgui.h"  #include "muse/midi.h" +#include "muse/mpevent.h"  #include "muse/icons.h"  //--------------------------------------------------------- @@ -28,6 +31,10 @@ FLUIDGui::FLUIDGui()     : QDialog(0, Qt::Window), MessGui()        {        setupUi(this); +      //Connect socketnotifier to fifo +      QSocketNotifier* s = new QSocketNotifier(readFd, QSocketNotifier::Read); +      connect(s, SIGNAL(activated(int)), SLOT(readMessage(int))); +              fdialogButton->setIcon(QIcon(*openIcon));        connect(fdialogButton, SIGNAL(clicked()), SLOT(soundFontFileDialog()));        connect(loadButton, SIGNAL(clicked()), SLOT(loadFont())); @@ -60,9 +67,9 @@ void FLUIDGui::loadFont()        int len     = strlen(path) + 1 + 3;        unsigned char buffer[len];        int k       = 0; -      buffer[k++] = 0x7c; -      buffer[k++] = 0x00;       // fluid -      buffer[k++] = 0x01;       // load sound font +      buffer[k++] = MUSE_SYNTH_SYSEX_MFG_ID; +      buffer[k++] = FLUID_UNIQUE_ID;       // fluid +      buffer[k++] = SF_REPLACE;       // load sound font        strcpy((char*)(&buffer[k]), path);        sendSysex(buffer, len);        } @@ -80,3 +87,40 @@ void FLUIDGui::soundFontFileDialog()              }        } +void FLUIDGui::processEvent(const MidiPlayEvent& ev)  +{ +      // p4.0.27  +      if (ev.type() == ME_SYSEX)   { +            const unsigned char* data = ev.data(); +            switch (*data) { +                  case FS_SEND_SOUNDFONT_NAME: { +                        //const char* filename = data+1; +                        //pathEntry->setText(QString(filename)); +                        pathEntry->setText((const char*)(data+1)); +                        break; +                        } +                  default: +                          #ifdef FS_DEBUG +                          printf("FLUIDGui::processEvent() : Unknown Sysex received: %d\n", ev.type()); +                          #endif +                        break; +            } +      } +      else +      { +          #ifdef FS_DEBUG +          printf("FLUIDGui::processEvent - unknown event of type %dreceived from synth.\n", ev.type()); +          #endif +      }     +} + +//--------------------------------------------------------- +//   readMessage +//--------------------------------------------------------- + +void FLUIDGui::readMessage(int) +      { +      MessGui::readMessage();   // p4.0.27 +      } + + diff --git a/muse2/synti/fluid/fluidgui.h b/muse2/synti/fluid/fluidgui.h index 3e564538..2752567f 100644 --- a/muse2/synti/fluid/fluidgui.h +++ b/muse2/synti/fluid/fluidgui.h @@ -12,6 +12,10 @@  #include "ui_fluidguibase.h"  #include "libsynti/gui.h" +#define FS_SEND_SOUNDFONT_NAME 1 + +//#define FS_DEBUG   +  class QDialog;  //--------------------------------------------------------- @@ -23,11 +27,13 @@ class FLUIDGui : public QDialog, public Ui::FLUIDGuiBase, public MessGui {        Q_OBJECT     private slots: +      void readMessage(int);        void soundFontFileDialog();        void loadFont();     public:        FLUIDGui(); +      virtual void processEvent(const MidiPlayEvent&);        };  #endif | 
