/[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 3068 - (hide annotations) (download)
Mon Jan 2 22:13:01 2017 UTC (7 years, 3 months ago) by schoenebeck
File size: 8164 byte(s)
- Preparations for Xcode project update.

1 schoenebeck 1213 /*
2 schoenebeck 3068 * Copyright (C) 2007 - 2017 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 3068 #ifdef LIBLINUXSAMPLER_HEADER_FILE
23     # include LIBLINUXSAMPLER_HEADER_FILE(plugins/InstrumentEditorFactory.h)
24     # include LIBLINUXSAMPLER_HEADER_FILE(engines/Engine.h)
25     # include LIBLINUXSAMPLER_HEADER_FILE(engines/EngineChannel.h)
26     #else
27     # include <linuxsampler/plugins/InstrumentEditorFactory.h>
28     # include <linuxsampler/engines/Engine.h>
29     # include <linuxsampler/engines/EngineChannel.h>
30     #endif
31    
32 schoenebeck 1656 #include "../gigedit/gigedit.h"
33 schoenebeck 1680 #include "../gigedit/global.h"
34 schoenebeck 1213
35     #include <iostream>
36 schoenebeck 1322 #include <sigc++/bind.h>
37 schoenebeck 1656 #include <glibmm/main.h>
38 schoenebeck 1213
39     REGISTER_INSTRUMENT_EDITOR(LinuxSamplerPlugin)
40    
41     LinuxSamplerPlugin::LinuxSamplerPlugin() {
42 schoenebeck 1654 pApp = new GigEdit;
43 schoenebeck 1213 }
44    
45 schoenebeck 1654 LinuxSamplerPlugin::~LinuxSamplerPlugin() {
46 persson 2841 if (pApp) delete static_cast<GigEdit*>(pApp);
47 schoenebeck 1654 }
48    
49 schoenebeck 1877 int LinuxSamplerPlugin::Main(void* pInstrument, String sTypeName, String sTypeVersion, void* /*pUserData*/) {
50     return Main(pInstrument, sTypeName, sTypeVersion);
51     }
52    
53 schoenebeck 1213 int LinuxSamplerPlugin::Main(void* pInstrument, String sTypeName, String sTypeVersion) {
54     std::cout << "Entered Gigedit Main() loop :)\n" << std::flush;
55     gig::Instrument* pGigInstr = static_cast<gig::Instrument*>(pInstrument);
56 persson 2841 GigEdit* app = static_cast<GigEdit*>(pApp);
57 schoenebeck 1654
58 schoenebeck 1322 // connect notification signals
59 schoenebeck 1654 app->signal_file_structure_to_be_changed().connect(
60 schoenebeck 1322 sigc::bind(
61     sigc::mem_fun(
62     *this, &LinuxSamplerPlugin::NotifyDataStructureToBeChanged
63     ),
64     "gig::File"
65     )
66     );
67 schoenebeck 1654 app->signal_file_structure_changed().connect(
68 schoenebeck 1322 sigc::bind(
69     sigc::mem_fun(
70     *this, &LinuxSamplerPlugin::NotifyDataStructureChanged
71     ),
72     "gig::File"
73     )
74     );
75 schoenebeck 1654 app->signal_samples_to_be_removed().connect(
76 schoenebeck 1322 sigc::mem_fun(*this, &LinuxSamplerPlugin::__onSamplesToBeRemoved)
77     );
78 schoenebeck 1654 app->signal_samples_removed().connect(
79 schoenebeck 1322 sigc::mem_fun(*this, &LinuxSamplerPlugin::NotifySamplesRemoved)
80     );
81 schoenebeck 1654 app->signal_region_to_be_changed().connect(
82 schoenebeck 1322 sigc::bind(
83     sigc::mem_fun(
84     *this, &LinuxSamplerPlugin::NotifyDataStructureToBeChanged
85     ),
86     "gig::Region"
87     )
88     );
89 schoenebeck 1654 app->signal_region_changed().connect(
90 schoenebeck 1322 sigc::bind(
91     sigc::mem_fun(
92     *this, &LinuxSamplerPlugin::NotifyDataStructureChanged
93     ),
94     "gig::Region"
95     )
96     );
97 schoenebeck 1654 app->signal_dimreg_to_be_changed().connect(
98 schoenebeck 1322 sigc::bind(
99     sigc::mem_fun(
100     *this, &LinuxSamplerPlugin::NotifyDataStructureToBeChanged
101     ),
102     "gig::DimensionRegion"
103     )
104     );
105 schoenebeck 1654 app->signal_dimreg_changed().connect(
106 schoenebeck 1322 sigc::bind(
107     sigc::mem_fun(
108     *this, &LinuxSamplerPlugin::NotifyDataStructureChanged
109     ),
110     "gig::DimensionRegion"
111     )
112     );
113 schoenebeck 1853 app->signal_sample_changed().connect(
114     sigc::bind(
115     sigc::mem_fun(
116     *this, &LinuxSamplerPlugin::NotifyDataStructureChanged
117     ),
118     "gig::Sample"
119     )
120     );
121 schoenebeck 1654 app->signal_sample_ref_changed().connect(
122 schoenebeck 1322 sigc::mem_fun(*this, &LinuxSamplerPlugin::NotifySampleReferenceChanged)
123     );
124 schoenebeck 1654
125 schoenebeck 1660 app->signal_keyboard_key_hit().connect(
126     sigc::mem_fun(*this, &LinuxSamplerPlugin::__onVirtualKeyboardKeyHit)
127     );
128     app->signal_keyboard_key_released().connect(
129     sigc::mem_fun(*this, &LinuxSamplerPlugin::__onVirtualKeyboardKeyReleased)
130     );
131 schoenebeck 2689 app->signal_switch_sampler_instrument().connect(
132     sigc::mem_fun(*this, &LinuxSamplerPlugin::__requestSamplerToSwitchInstrument)
133     );
134 schoenebeck 2903 app->signal_script_to_be_changed.connect(
135     sigc::bind(
136     sigc::mem_fun(
137     *this, &LinuxSamplerPlugin::NotifyDataStructureToBeChanged
138     ),
139     "gig::Script"
140     )
141     );
142     app->signal_script_changed.connect(
143     sigc::bind(
144     sigc::mem_fun(
145     *this, &LinuxSamplerPlugin::NotifyDataStructureChanged
146     ),
147     "gig::Script"
148     )
149     );
150 schoenebeck 1660
151 schoenebeck 1656 // register a timeout job to gigedit's main loop, so we can poll the
152     // the sampler periodically for MIDI events (I HOPE it works on all
153     // archs, because gigedit is actually running in another thread than
154     // the one that is calling this timeout handler register code)
155     const Glib::RefPtr<Glib::TimeoutSource> timeout_source =
156     Glib::TimeoutSource::create(100); // poll every 100ms
157     timeout_source->connect(
158     sigc::mem_fun(this, &LinuxSamplerPlugin::__onPollPeriod)
159     );
160     timeout_source->attach(Glib::MainContext::get_default());
161 schoenebeck 1654
162 schoenebeck 1322 // run gigedit application
163 schoenebeck 1654 return app->run(pGigInstr);
164 schoenebeck 1213 }
165    
166 schoenebeck 1656 bool LinuxSamplerPlugin::__onPollPeriod() {
167 schoenebeck 1680 #if HAVE_LINUXSAMPLER_VIRTUAL_MIDI_DEVICE
168 persson 2841 GigEdit* app = static_cast<GigEdit*>(pApp);
169 schoenebeck 1654 if (!NotesChanged()) return true;
170     for (int iKey = 0; iKey < 128; iKey++)
171     if (NoteChanged(iKey))
172 schoenebeck 1664 NoteIsActive(iKey) ?
173     app->on_note_on_event(iKey, NoteOnVelocity(iKey)) :
174     app->on_note_off_event(iKey, NoteOffVelocity(iKey));
175 schoenebeck 1654 return true;
176 schoenebeck 1680 #else
177     return false;
178     #endif
179 schoenebeck 1654 }
180    
181 schoenebeck 1322 void LinuxSamplerPlugin::__onSamplesToBeRemoved(std::list<gig::Sample*> lSamples) {
182     // we have to convert the gig::Sample* list to a void* list first
183     std::set<void*> samples;
184     for (
185     std::list<gig::Sample*>::iterator iter = lSamples.begin();
186 persson 2841 iter != lSamples.end(); ++iter
187 schoenebeck 1322 ) samples.insert((void*)*iter);
188     // finally send notification to sampler
189     NotifySamplesToBeRemoved(samples);
190     }
191    
192 schoenebeck 1660 void LinuxSamplerPlugin::__onVirtualKeyboardKeyHit(int Key, int Velocity) {
193 schoenebeck 1680 #if HAVE_LINUXSAMPLER_VIRTUAL_MIDI_DEVICE
194 schoenebeck 1660 SendNoteOnToSampler(Key, Velocity);
195 schoenebeck 1680 #endif
196 schoenebeck 1660 }
197    
198     void LinuxSamplerPlugin::__onVirtualKeyboardKeyReleased(int Key, int Velocity) {
199 schoenebeck 1680 #if HAVE_LINUXSAMPLER_VIRTUAL_MIDI_DEVICE
200 schoenebeck 1660 SendNoteOffToSampler(Key, Velocity);
201 schoenebeck 1680 #endif
202 schoenebeck 1660 }
203    
204 schoenebeck 2689 void LinuxSamplerPlugin::__requestSamplerToSwitchInstrument(gig::Instrument* pInstrument) {
205     if (!pInstrument) return;
206    
207     LinuxSampler::EngineChannel* pEngineChannel = GetEngineChannel();
208     if (!pEngineChannel) return;
209    
210     LinuxSampler::Engine* pEngine = pEngineChannel->GetEngine();
211     if (!pEngine) return;
212    
213     LinuxSampler::InstrumentManager* pInstrumentManager = pEngine->GetInstrumentManager();
214     if (!pInstrumentManager) return;
215    
216     gig::File* pFile = (gig::File*) pInstrument->GetParent();
217    
218     // resolve instrument's index number in its gig file
219     int index = -1;
220     for (int i = 0; pFile->GetInstrument(i); ++i) {
221     if (pFile->GetInstrument(i) == pInstrument) {
222     index = i;
223     break;
224     }
225     }
226     if (index < 0) return;
227    
228     LinuxSampler::InstrumentManager::instrument_id_t id;
229     id.FileName = pFile->GetFileName();
230     id.Index = index;
231     pInstrumentManager->LoadInstrumentInBackground(id, pEngineChannel);
232     }
233    
234 schoenebeck 1213 bool LinuxSamplerPlugin::IsTypeSupported(String sTypeName, String sTypeVersion) {
235     return sTypeName == gig::libraryName() &&
236     sTypeVersion == gig::libraryVersion();
237     }
238    
239     String LinuxSamplerPlugin::Name() {
240     return "gigedit";
241     }
242    
243     String LinuxSamplerPlugin::Version() {
244     return VERSION; // gigedit's version
245     }
246    
247     String LinuxSamplerPlugin::Description() {
248     return "Gigedit is an instrument editor for gig files.";
249     }

  ViewVC Help
Powered by ViewVC