/[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 1322 by schoenebeck, Tue Sep 4 11:04:56 2007 UTC revision 1877 by schoenebeck, Fri Mar 27 12:18:12 2009 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2007 Andreas Persson   * Copyright (C) 2007, 2008 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 19  Line 19 
19    
20  #include "linuxsamplerplugin.h"  #include "linuxsamplerplugin.h"
21    
22  #include <linuxsampler/engines/InstrumentEditorFactory.h>  #include <linuxsampler/plugins/InstrumentEditorFactory.h>
23  #include "../gigedit/gigedit.h"  #include "../gigedit/gigedit.h"
24    #include "../gigedit/global.h"
25    
26  #include <iostream>  #include <iostream>
27  #include <sigc++/bind.h>  #include <sigc++/bind.h>
28    #include <glibmm/main.h>
29    
30  REGISTER_INSTRUMENT_EDITOR(LinuxSamplerPlugin)  REGISTER_INSTRUMENT_EDITOR(LinuxSamplerPlugin)
31    
32  LinuxSamplerPlugin::LinuxSamplerPlugin() {  LinuxSamplerPlugin::LinuxSamplerPlugin() {
33        pApp = new GigEdit;
34    }
35    
36    LinuxSamplerPlugin::~LinuxSamplerPlugin() {
37        if (pApp) delete (GigEdit*) pApp;
38    }
39    
40    int LinuxSamplerPlugin::Main(void* pInstrument, String sTypeName, String sTypeVersion, void* /*pUserData*/) {
41        return Main(pInstrument, sTypeName, sTypeVersion);
42  }  }
43    
44  int LinuxSamplerPlugin::Main(void* pInstrument, String sTypeName, String sTypeVersion) {  int LinuxSamplerPlugin::Main(void* pInstrument, String sTypeName, String sTypeVersion) {
45      std::cout << "Entered Gigedit Main() loop :)\n" << std::flush;      std::cout << "Entered Gigedit Main() loop :)\n" << std::flush;
46      gig::Instrument* pGigInstr = static_cast<gig::Instrument*>(pInstrument);      gig::Instrument* pGigInstr = static_cast<gig::Instrument*>(pInstrument);
47      GigEdit app;      GigEdit* app = (GigEdit*) pApp;
48    
49      // connect notification signals      // connect notification signals
50      app.signal_file_structure_to_be_changed().connect(      app->signal_file_structure_to_be_changed().connect(
51          sigc::bind(          sigc::bind(
52              sigc::mem_fun(              sigc::mem_fun(
53                  *this, &LinuxSamplerPlugin::NotifyDataStructureToBeChanged                  *this, &LinuxSamplerPlugin::NotifyDataStructureToBeChanged
# Line 43  int LinuxSamplerPlugin::Main(void* pInst Line 55  int LinuxSamplerPlugin::Main(void* pInst
55              "gig::File"              "gig::File"
56          )          )
57      );      );
58      app.signal_file_structure_changed().connect(      app->signal_file_structure_changed().connect(
59          sigc::bind(          sigc::bind(
60              sigc::mem_fun(              sigc::mem_fun(
61                  *this, &LinuxSamplerPlugin::NotifyDataStructureChanged                  *this, &LinuxSamplerPlugin::NotifyDataStructureChanged
# Line 51  int LinuxSamplerPlugin::Main(void* pInst Line 63  int LinuxSamplerPlugin::Main(void* pInst
63              "gig::File"              "gig::File"
64          )          )
65      );      );
66      app.signal_samples_to_be_removed().connect(      app->signal_samples_to_be_removed().connect(
67          sigc::mem_fun(*this, &LinuxSamplerPlugin::__onSamplesToBeRemoved)          sigc::mem_fun(*this, &LinuxSamplerPlugin::__onSamplesToBeRemoved)
68      );      );
69      app.signal_samples_removed().connect(      app->signal_samples_removed().connect(
70          sigc::mem_fun(*this, &LinuxSamplerPlugin::NotifySamplesRemoved)          sigc::mem_fun(*this, &LinuxSamplerPlugin::NotifySamplesRemoved)
71      );      );
72      app.signal_region_to_be_changed().connect(      app->signal_region_to_be_changed().connect(
73          sigc::bind(          sigc::bind(
74              sigc::mem_fun(              sigc::mem_fun(
75                  *this, &LinuxSamplerPlugin::NotifyDataStructureToBeChanged                  *this, &LinuxSamplerPlugin::NotifyDataStructureToBeChanged
# Line 65  int LinuxSamplerPlugin::Main(void* pInst Line 77  int LinuxSamplerPlugin::Main(void* pInst
77              "gig::Region"              "gig::Region"
78          )          )
79      );      );
80      app.signal_region_changed().connect(      app->signal_region_changed().connect(
81          sigc::bind(          sigc::bind(
82              sigc::mem_fun(              sigc::mem_fun(
83                  *this, &LinuxSamplerPlugin::NotifyDataStructureChanged                  *this, &LinuxSamplerPlugin::NotifyDataStructureChanged
# Line 73  int LinuxSamplerPlugin::Main(void* pInst Line 85  int LinuxSamplerPlugin::Main(void* pInst
85              "gig::Region"              "gig::Region"
86          )          )
87      );      );
88      app.signal_dimreg_to_be_changed().connect(      app->signal_dimreg_to_be_changed().connect(
89          sigc::bind(          sigc::bind(
90              sigc::mem_fun(              sigc::mem_fun(
91                  *this, &LinuxSamplerPlugin::NotifyDataStructureToBeChanged                  *this, &LinuxSamplerPlugin::NotifyDataStructureToBeChanged
# Line 81  int LinuxSamplerPlugin::Main(void* pInst Line 93  int LinuxSamplerPlugin::Main(void* pInst
93              "gig::DimensionRegion"              "gig::DimensionRegion"
94          )          )
95      );      );
96      app.signal_dimreg_changed().connect(      app->signal_dimreg_changed().connect(
97          sigc::bind(          sigc::bind(
98              sigc::mem_fun(              sigc::mem_fun(
99                  *this, &LinuxSamplerPlugin::NotifyDataStructureChanged                  *this, &LinuxSamplerPlugin::NotifyDataStructureChanged
# Line 89  int LinuxSamplerPlugin::Main(void* pInst Line 101  int LinuxSamplerPlugin::Main(void* pInst
101              "gig::DimensionRegion"              "gig::DimensionRegion"
102          )          )
103      );      );
104      app.signal_sample_ref_changed().connect(      app->signal_sample_changed().connect(
105            sigc::bind(
106                sigc::mem_fun(
107                    *this, &LinuxSamplerPlugin::NotifyDataStructureChanged
108                ),
109                "gig::Sample"
110            )
111        );
112        app->signal_sample_ref_changed().connect(
113          sigc::mem_fun(*this, &LinuxSamplerPlugin::NotifySampleReferenceChanged)          sigc::mem_fun(*this, &LinuxSamplerPlugin::NotifySampleReferenceChanged)
114      );      );
115    
116        app->signal_keyboard_key_hit().connect(
117            sigc::mem_fun(*this, &LinuxSamplerPlugin::__onVirtualKeyboardKeyHit)
118        );
119        app->signal_keyboard_key_released().connect(
120            sigc::mem_fun(*this, &LinuxSamplerPlugin::__onVirtualKeyboardKeyReleased)
121        );
122    
123        // register a timeout job to gigedit's main loop, so we can poll the
124        // the sampler periodically for MIDI events (I HOPE it works on all
125        // archs, because gigedit is actually running in another thread than
126        // the one that is calling this timeout handler register code)
127        const Glib::RefPtr<Glib::TimeoutSource> timeout_source =
128            Glib::TimeoutSource::create(100); // poll every 100ms
129        timeout_source->connect(
130            sigc::mem_fun(this, &LinuxSamplerPlugin::__onPollPeriod)
131        );
132        timeout_source->attach(Glib::MainContext::get_default());
133    
134      // run gigedit application      // run gigedit application
135      return app.run(pGigInstr);      return app->run(pGigInstr);
136    }
137    
138    bool LinuxSamplerPlugin::__onPollPeriod() {
139        #if HAVE_LINUXSAMPLER_VIRTUAL_MIDI_DEVICE
140        GigEdit* app = (GigEdit*) pApp;
141        if (!NotesChanged()) return true;
142        for (int iKey = 0; iKey < 128; iKey++)
143            if (NoteChanged(iKey))
144                NoteIsActive(iKey) ?
145                    app->on_note_on_event(iKey, NoteOnVelocity(iKey)) :
146                    app->on_note_off_event(iKey, NoteOffVelocity(iKey));
147        return true;
148        #else
149        return false;
150        #endif
151  }  }
152    
153  void LinuxSamplerPlugin::__onSamplesToBeRemoved(std::list<gig::Sample*> lSamples) {  void LinuxSamplerPlugin::__onSamplesToBeRemoved(std::list<gig::Sample*> lSamples) {
# Line 107  void LinuxSamplerPlugin::__onSamplesToBe Line 161  void LinuxSamplerPlugin::__onSamplesToBe
161      NotifySamplesToBeRemoved(samples);      NotifySamplesToBeRemoved(samples);
162  }  }
163    
164    void LinuxSamplerPlugin::__onVirtualKeyboardKeyHit(int Key, int Velocity) {
165        #if HAVE_LINUXSAMPLER_VIRTUAL_MIDI_DEVICE
166        SendNoteOnToSampler(Key, Velocity);
167        #endif
168    }
169    
170    void LinuxSamplerPlugin::__onVirtualKeyboardKeyReleased(int Key, int Velocity) {
171        #if HAVE_LINUXSAMPLER_VIRTUAL_MIDI_DEVICE
172        SendNoteOffToSampler(Key, Velocity);
173        #endif
174    }
175    
176  bool LinuxSamplerPlugin::IsTypeSupported(String sTypeName, String sTypeVersion) {  bool LinuxSamplerPlugin::IsTypeSupported(String sTypeName, String sTypeVersion) {
177      return sTypeName == gig::libraryName() &&      return sTypeName == gig::libraryName() &&
178             sTypeVersion == gig::libraryVersion();             sTypeVersion == gig::libraryVersion();

Legend:
Removed from v.1322  
changed lines
  Added in v.1877

  ViewVC Help
Powered by ViewVC