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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1877 - (hide annotations) (download)
Fri Mar 27 12:18:12 2009 UTC (15 years ago) by schoenebeck
File size: 6229 byte(s)
* updated LinuxSampler plugin of gigedit to the latest liblinuxsampler
  C++ API changes

1 schoenebeck 1213 /*
2 schoenebeck 1654 * Copyright (C) 2007, 2008 Andreas Persson
3 schoenebeck 1213 *
4     * This program is free software; you can redistribute it and/or
5     * modify it under the terms of the GNU General Public License as
6     * published by the Free Software Foundation; either version 2, or (at
7     * your option) any later version.
8     *
9     * This program is distributed in the hope that it will be useful, but
10     * WITHOUT ANY WARRANTY; without even the implied warranty of
11     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12     * General Public License for more details.
13     *
14     * You should have received a copy of the GNU General Public License
15     * along with program; see the file COPYING. If not, write to the Free
16     * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
17     * 02110-1301 USA.
18     */
19    
20     #include "linuxsamplerplugin.h"
21    
22 schoenebeck 1376 #include <linuxsampler/plugins/InstrumentEditorFactory.h>
23 schoenebeck 1656 #include "../gigedit/gigedit.h"
24 schoenebeck 1680 #include "../gigedit/global.h"
25 schoenebeck 1213
26     #include <iostream>
27 schoenebeck 1322 #include <sigc++/bind.h>
28 schoenebeck 1656 #include <glibmm/main.h>
29 schoenebeck 1213
30     REGISTER_INSTRUMENT_EDITOR(LinuxSamplerPlugin)
31    
32     LinuxSamplerPlugin::LinuxSamplerPlugin() {
33 schoenebeck 1654 pApp = new GigEdit;
34 schoenebeck 1213 }
35    
36 schoenebeck 1654 LinuxSamplerPlugin::~LinuxSamplerPlugin() {
37     if (pApp) delete (GigEdit*) pApp;
38     }
39    
40 schoenebeck 1877 int LinuxSamplerPlugin::Main(void* pInstrument, String sTypeName, String sTypeVersion, void* /*pUserData*/) {
41     return Main(pInstrument, sTypeName, sTypeVersion);
42     }
43    
44 schoenebeck 1213 int LinuxSamplerPlugin::Main(void* pInstrument, String sTypeName, String sTypeVersion) {
45     std::cout << "Entered Gigedit Main() loop :)\n" << std::flush;
46     gig::Instrument* pGigInstr = static_cast<gig::Instrument*>(pInstrument);
47 schoenebeck 1654 GigEdit* app = (GigEdit*) pApp;
48    
49 schoenebeck 1322 // connect notification signals
50 schoenebeck 1654 app->signal_file_structure_to_be_changed().connect(
51 schoenebeck 1322 sigc::bind(
52     sigc::mem_fun(
53     *this, &LinuxSamplerPlugin::NotifyDataStructureToBeChanged
54     ),
55     "gig::File"
56     )
57     );
58 schoenebeck 1654 app->signal_file_structure_changed().connect(
59 schoenebeck 1322 sigc::bind(
60     sigc::mem_fun(
61     *this, &LinuxSamplerPlugin::NotifyDataStructureChanged
62     ),
63     "gig::File"
64     )
65     );
66 schoenebeck 1654 app->signal_samples_to_be_removed().connect(
67 schoenebeck 1322 sigc::mem_fun(*this, &LinuxSamplerPlugin::__onSamplesToBeRemoved)
68     );
69 schoenebeck 1654 app->signal_samples_removed().connect(
70 schoenebeck 1322 sigc::mem_fun(*this, &LinuxSamplerPlugin::NotifySamplesRemoved)
71     );
72 schoenebeck 1654 app->signal_region_to_be_changed().connect(
73 schoenebeck 1322 sigc::bind(
74     sigc::mem_fun(
75     *this, &LinuxSamplerPlugin::NotifyDataStructureToBeChanged
76     ),
77     "gig::Region"
78     )
79     );
80 schoenebeck 1654 app->signal_region_changed().connect(
81 schoenebeck 1322 sigc::bind(
82     sigc::mem_fun(
83     *this, &LinuxSamplerPlugin::NotifyDataStructureChanged
84     ),
85     "gig::Region"
86     )
87     );
88 schoenebeck 1654 app->signal_dimreg_to_be_changed().connect(
89 schoenebeck 1322 sigc::bind(
90     sigc::mem_fun(
91     *this, &LinuxSamplerPlugin::NotifyDataStructureToBeChanged
92     ),
93     "gig::DimensionRegion"
94     )
95     );
96 schoenebeck 1654 app->signal_dimreg_changed().connect(
97 schoenebeck 1322 sigc::bind(
98     sigc::mem_fun(
99     *this, &LinuxSamplerPlugin::NotifyDataStructureChanged
100     ),
101     "gig::DimensionRegion"
102     )
103     );
104 schoenebeck 1853 app->signal_sample_changed().connect(
105     sigc::bind(
106     sigc::mem_fun(
107     *this, &LinuxSamplerPlugin::NotifyDataStructureChanged
108     ),
109     "gig::Sample"
110     )
111     );
112 schoenebeck 1654 app->signal_sample_ref_changed().connect(
113 schoenebeck 1322 sigc::mem_fun(*this, &LinuxSamplerPlugin::NotifySampleReferenceChanged)
114     );
115 schoenebeck 1654
116 schoenebeck 1660 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 schoenebeck 1656 // 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 schoenebeck 1654
134 schoenebeck 1322 // run gigedit application
135 schoenebeck 1654 return app->run(pGigInstr);
136 schoenebeck 1213 }
137    
138 schoenebeck 1656 bool LinuxSamplerPlugin::__onPollPeriod() {
139 schoenebeck 1680 #if HAVE_LINUXSAMPLER_VIRTUAL_MIDI_DEVICE
140 schoenebeck 1654 GigEdit* app = (GigEdit*) pApp;
141     if (!NotesChanged()) return true;
142     for (int iKey = 0; iKey < 128; iKey++)
143     if (NoteChanged(iKey))
144 schoenebeck 1664 NoteIsActive(iKey) ?
145     app->on_note_on_event(iKey, NoteOnVelocity(iKey)) :
146     app->on_note_off_event(iKey, NoteOffVelocity(iKey));
147 schoenebeck 1654 return true;
148 schoenebeck 1680 #else
149     return false;
150     #endif
151 schoenebeck 1654 }
152    
153 schoenebeck 1322 void LinuxSamplerPlugin::__onSamplesToBeRemoved(std::list<gig::Sample*> lSamples) {
154     // we have to convert the gig::Sample* list to a void* list first
155     std::set<void*> samples;
156     for (
157     std::list<gig::Sample*>::iterator iter = lSamples.begin();
158     iter != lSamples.end(); iter++
159     ) samples.insert((void*)*iter);
160     // finally send notification to sampler
161     NotifySamplesToBeRemoved(samples);
162     }
163    
164 schoenebeck 1660 void LinuxSamplerPlugin::__onVirtualKeyboardKeyHit(int Key, int Velocity) {
165 schoenebeck 1680 #if HAVE_LINUXSAMPLER_VIRTUAL_MIDI_DEVICE
166 schoenebeck 1660 SendNoteOnToSampler(Key, Velocity);
167 schoenebeck 1680 #endif
168 schoenebeck 1660 }
169    
170     void LinuxSamplerPlugin::__onVirtualKeyboardKeyReleased(int Key, int Velocity) {
171 schoenebeck 1680 #if HAVE_LINUXSAMPLER_VIRTUAL_MIDI_DEVICE
172 schoenebeck 1660 SendNoteOffToSampler(Key, Velocity);
173 schoenebeck 1680 #endif
174 schoenebeck 1660 }
175    
176 schoenebeck 1213 bool LinuxSamplerPlugin::IsTypeSupported(String sTypeName, String sTypeVersion) {
177     return sTypeName == gig::libraryName() &&
178     sTypeVersion == gig::libraryVersion();
179     }
180    
181     String LinuxSamplerPlugin::Name() {
182     return "gigedit";
183     }
184    
185     String LinuxSamplerPlugin::Version() {
186     return VERSION; // gigedit's version
187     }
188    
189     String LinuxSamplerPlugin::Description() {
190     return "Gigedit is an instrument editor for gig files.";
191     }

  ViewVC Help
Powered by ViewVC