/[svn]/gigedit/trunk/src/plugin/linuxsamplerplugin.cpp
ViewVC logotype

Diff of /gigedit/trunk/src/plugin/linuxsamplerplugin.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1376 by schoenebeck, Wed Oct 3 19:15:47 2007 UTC revision 2689 by schoenebeck, Sun Jan 4 17:19:19 2015 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2007 Andreas Persson   * Copyright (C) 2007 - 2015 Andreas Persson
3   *   *
4   * This program is free software; you can redistribute it and/or   * This program is free software; you can redistribute it and/or
5   * modify it under the terms of the GNU General Public License as   * modify it under the terms of the GNU General Public License as
# Line 20  Line 20 
20  #include "linuxsamplerplugin.h"  #include "linuxsamplerplugin.h"
21    
22  #include <linuxsampler/plugins/InstrumentEditorFactory.h>  #include <linuxsampler/plugins/InstrumentEditorFactory.h>
23    #include <linuxsampler/engines/Engine.h>
24    #include <linuxsampler/engines/EngineChannel.h>
25  #include "../gigedit/gigedit.h"  #include "../gigedit/gigedit.h"
26    #include "../gigedit/global.h"
27    
28  #include <iostream>  #include <iostream>
29  #include <sigc++/bind.h>  #include <sigc++/bind.h>
30    #include <glibmm/main.h>
31    
32  REGISTER_INSTRUMENT_EDITOR(LinuxSamplerPlugin)  REGISTER_INSTRUMENT_EDITOR(LinuxSamplerPlugin)
33    
34  LinuxSamplerPlugin::LinuxSamplerPlugin() {  LinuxSamplerPlugin::LinuxSamplerPlugin() {
35        pApp = new GigEdit;
36    }
37    
38    LinuxSamplerPlugin::~LinuxSamplerPlugin() {
39        if (pApp) delete (GigEdit*) pApp;
40    }
41    
42    int LinuxSamplerPlugin::Main(void* pInstrument, String sTypeName, String sTypeVersion, void* /*pUserData*/) {
43        return Main(pInstrument, sTypeName, sTypeVersion);
44  }  }
45    
46  int LinuxSamplerPlugin::Main(void* pInstrument, String sTypeName, String sTypeVersion) {  int LinuxSamplerPlugin::Main(void* pInstrument, String sTypeName, String sTypeVersion) {
47      std::cout << "Entered Gigedit Main() loop :)\n" << std::flush;      std::cout << "Entered Gigedit Main() loop :)\n" << std::flush;
48      gig::Instrument* pGigInstr = static_cast<gig::Instrument*>(pInstrument);      gig::Instrument* pGigInstr = static_cast<gig::Instrument*>(pInstrument);
49      GigEdit app;      GigEdit* app = (GigEdit*) pApp;
50    
51      // connect notification signals      // connect notification signals
52      app.signal_file_structure_to_be_changed().connect(      app->signal_file_structure_to_be_changed().connect(
53          sigc::bind(          sigc::bind(
54              sigc::mem_fun(              sigc::mem_fun(
55                  *this, &LinuxSamplerPlugin::NotifyDataStructureToBeChanged                  *this, &LinuxSamplerPlugin::NotifyDataStructureToBeChanged
# Line 43  int LinuxSamplerPlugin::Main(void* pInst Line 57  int LinuxSamplerPlugin::Main(void* pInst
57              "gig::File"              "gig::File"
58          )          )
59      );      );
60      app.signal_file_structure_changed().connect(      app->signal_file_structure_changed().connect(
61          sigc::bind(          sigc::bind(
62              sigc::mem_fun(              sigc::mem_fun(
63                  *this, &LinuxSamplerPlugin::NotifyDataStructureChanged                  *this, &LinuxSamplerPlugin::NotifyDataStructureChanged
# Line 51  int LinuxSamplerPlugin::Main(void* pInst Line 65  int LinuxSamplerPlugin::Main(void* pInst
65              "gig::File"              "gig::File"
66          )          )
67      );      );
68      app.signal_samples_to_be_removed().connect(      app->signal_samples_to_be_removed().connect(
69          sigc::mem_fun(*this, &LinuxSamplerPlugin::__onSamplesToBeRemoved)          sigc::mem_fun(*this, &LinuxSamplerPlugin::__onSamplesToBeRemoved)
70      );      );
71      app.signal_samples_removed().connect(      app->signal_samples_removed().connect(
72          sigc::mem_fun(*this, &LinuxSamplerPlugin::NotifySamplesRemoved)          sigc::mem_fun(*this, &LinuxSamplerPlugin::NotifySamplesRemoved)
73      );      );
74      app.signal_region_to_be_changed().connect(      app->signal_region_to_be_changed().connect(
75          sigc::bind(          sigc::bind(
76              sigc::mem_fun(              sigc::mem_fun(
77                  *this, &LinuxSamplerPlugin::NotifyDataStructureToBeChanged                  *this, &LinuxSamplerPlugin::NotifyDataStructureToBeChanged
# Line 65  int LinuxSamplerPlugin::Main(void* pInst Line 79  int LinuxSamplerPlugin::Main(void* pInst
79              "gig::Region"              "gig::Region"
80          )          )
81      );      );
82      app.signal_region_changed().connect(      app->signal_region_changed().connect(
83          sigc::bind(          sigc::bind(
84              sigc::mem_fun(              sigc::mem_fun(
85                  *this, &LinuxSamplerPlugin::NotifyDataStructureChanged                  *this, &LinuxSamplerPlugin::NotifyDataStructureChanged
# Line 73  int LinuxSamplerPlugin::Main(void* pInst Line 87  int LinuxSamplerPlugin::Main(void* pInst
87              "gig::Region"              "gig::Region"
88          )          )
89      );      );
90      app.signal_dimreg_to_be_changed().connect(      app->signal_dimreg_to_be_changed().connect(
91          sigc::bind(          sigc::bind(
92              sigc::mem_fun(              sigc::mem_fun(
93                  *this, &LinuxSamplerPlugin::NotifyDataStructureToBeChanged                  *this, &LinuxSamplerPlugin::NotifyDataStructureToBeChanged
# Line 81  int LinuxSamplerPlugin::Main(void* pInst Line 95  int LinuxSamplerPlugin::Main(void* pInst
95              "gig::DimensionRegion"              "gig::DimensionRegion"
96          )          )
97      );      );
98      app.signal_dimreg_changed().connect(      app->signal_dimreg_changed().connect(
99          sigc::bind(          sigc::bind(
100              sigc::mem_fun(              sigc::mem_fun(
101                  *this, &LinuxSamplerPlugin::NotifyDataStructureChanged                  *this, &LinuxSamplerPlugin::NotifyDataStructureChanged
# Line 89  int LinuxSamplerPlugin::Main(void* pInst Line 103  int LinuxSamplerPlugin::Main(void* pInst
103              "gig::DimensionRegion"              "gig::DimensionRegion"
104          )          )
105      );      );
106      app.signal_sample_ref_changed().connect(      app->signal_sample_changed().connect(
107            sigc::bind(
108                sigc::mem_fun(
109                    *this, &LinuxSamplerPlugin::NotifyDataStructureChanged
110                ),
111                "gig::Sample"
112            )
113        );
114        app->signal_sample_ref_changed().connect(
115          sigc::mem_fun(*this, &LinuxSamplerPlugin::NotifySampleReferenceChanged)          sigc::mem_fun(*this, &LinuxSamplerPlugin::NotifySampleReferenceChanged)
116      );      );
117    
118        app->signal_keyboard_key_hit().connect(
119            sigc::mem_fun(*this, &LinuxSamplerPlugin::__onVirtualKeyboardKeyHit)
120        );
121        app->signal_keyboard_key_released().connect(
122            sigc::mem_fun(*this, &LinuxSamplerPlugin::__onVirtualKeyboardKeyReleased)
123        );
124        app->signal_switch_sampler_instrument().connect(
125            sigc::mem_fun(*this, &LinuxSamplerPlugin::__requestSamplerToSwitchInstrument)
126        );
127    
128        // register a timeout job to gigedit's main loop, so we can poll the
129        // the sampler periodically for MIDI events (I HOPE it works on all
130        // archs, because gigedit is actually running in another thread than
131        // the one that is calling this timeout handler register code)
132        const Glib::RefPtr<Glib::TimeoutSource> timeout_source =
133            Glib::TimeoutSource::create(100); // poll every 100ms
134        timeout_source->connect(
135            sigc::mem_fun(this, &LinuxSamplerPlugin::__onPollPeriod)
136        );
137        timeout_source->attach(Glib::MainContext::get_default());
138    
139      // run gigedit application      // run gigedit application
140      return app.run(pGigInstr);      return app->run(pGigInstr);
141    }
142    
143    bool LinuxSamplerPlugin::__onPollPeriod() {
144        #if HAVE_LINUXSAMPLER_VIRTUAL_MIDI_DEVICE
145        GigEdit* app = (GigEdit*) pApp;
146        if (!NotesChanged()) return true;
147        for (int iKey = 0; iKey < 128; iKey++)
148            if (NoteChanged(iKey))
149                NoteIsActive(iKey) ?
150                    app->on_note_on_event(iKey, NoteOnVelocity(iKey)) :
151                    app->on_note_off_event(iKey, NoteOffVelocity(iKey));
152        return true;
153        #else
154        return false;
155        #endif
156  }  }
157    
158  void LinuxSamplerPlugin::__onSamplesToBeRemoved(std::list<gig::Sample*> lSamples) {  void LinuxSamplerPlugin::__onSamplesToBeRemoved(std::list<gig::Sample*> lSamples) {
# Line 107  void LinuxSamplerPlugin::__onSamplesToBe Line 166  void LinuxSamplerPlugin::__onSamplesToBe
166      NotifySamplesToBeRemoved(samples);      NotifySamplesToBeRemoved(samples);
167  }  }
168    
169    void LinuxSamplerPlugin::__onVirtualKeyboardKeyHit(int Key, int Velocity) {
170        #if HAVE_LINUXSAMPLER_VIRTUAL_MIDI_DEVICE
171        SendNoteOnToSampler(Key, Velocity);
172        #endif
173    }
174    
175    void LinuxSamplerPlugin::__onVirtualKeyboardKeyReleased(int Key, int Velocity) {
176        #if HAVE_LINUXSAMPLER_VIRTUAL_MIDI_DEVICE
177        SendNoteOffToSampler(Key, Velocity);
178        #endif
179    }
180    
181    void LinuxSamplerPlugin::__requestSamplerToSwitchInstrument(gig::Instrument* pInstrument) {
182        if (!pInstrument) return;
183    
184        LinuxSampler::EngineChannel* pEngineChannel = GetEngineChannel();
185        if (!pEngineChannel) return;
186    
187        LinuxSampler::Engine* pEngine = pEngineChannel->GetEngine();
188        if (!pEngine) return;
189    
190        LinuxSampler::InstrumentManager* pInstrumentManager = pEngine->GetInstrumentManager();
191        if (!pInstrumentManager) return;
192    
193        gig::File* pFile = (gig::File*) pInstrument->GetParent();
194    
195        // resolve instrument's index number in its gig file
196        int index = -1;
197        for (int i = 0; pFile->GetInstrument(i); ++i) {
198            if (pFile->GetInstrument(i) == pInstrument) {
199                index = i;
200                break;
201            }
202        }
203        if (index < 0) return;
204    
205        LinuxSampler::InstrumentManager::instrument_id_t id;
206        id.FileName = pFile->GetFileName();
207        id.Index    = index;
208        pInstrumentManager->LoadInstrumentInBackground(id, pEngineChannel);
209    }
210    
211  bool LinuxSamplerPlugin::IsTypeSupported(String sTypeName, String sTypeVersion) {  bool LinuxSamplerPlugin::IsTypeSupported(String sTypeName, String sTypeVersion) {
212      return sTypeName == gig::libraryName() &&      return sTypeName == gig::libraryName() &&
213             sTypeVersion == gig::libraryVersion();             sTypeVersion == gig::libraryVersion();

Legend:
Removed from v.1376  
changed lines
  Added in v.2689

  ViewVC Help
Powered by ViewVC