1 |
/* |
/* |
2 |
* Copyright (C) 2007, 2008 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 |
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> |
36 |
} |
} |
37 |
|
|
38 |
LinuxSamplerPlugin::~LinuxSamplerPlugin() { |
LinuxSamplerPlugin::~LinuxSamplerPlugin() { |
39 |
if (pApp) delete (GigEdit*) pApp; |
if (pApp) delete static_cast<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*) pApp; |
GigEdit* app = static_cast<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( |
103 |
"gig::DimensionRegion" |
"gig::DimensionRegion" |
104 |
) |
) |
105 |
); |
); |
106 |
|
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( |
app->signal_sample_ref_changed().connect( |
115 |
sigc::mem_fun(*this, &LinuxSamplerPlugin::NotifySampleReferenceChanged) |
sigc::mem_fun(*this, &LinuxSamplerPlugin::NotifySampleReferenceChanged) |
116 |
); |
); |
121 |
app->signal_keyboard_key_released().connect( |
app->signal_keyboard_key_released().connect( |
122 |
sigc::mem_fun(*this, &LinuxSamplerPlugin::__onVirtualKeyboardKeyReleased) |
sigc::mem_fun(*this, &LinuxSamplerPlugin::__onVirtualKeyboardKeyReleased) |
123 |
); |
); |
124 |
|
app->signal_switch_sampler_instrument().connect( |
125 |
|
sigc::mem_fun(*this, &LinuxSamplerPlugin::__requestSamplerToSwitchInstrument) |
126 |
|
); |
127 |
|
app->signal_script_to_be_changed.connect( |
128 |
|
sigc::bind( |
129 |
|
sigc::mem_fun( |
130 |
|
*this, &LinuxSamplerPlugin::NotifyDataStructureToBeChanged |
131 |
|
), |
132 |
|
"gig::Script" |
133 |
|
) |
134 |
|
); |
135 |
|
app->signal_script_changed.connect( |
136 |
|
sigc::bind( |
137 |
|
sigc::mem_fun( |
138 |
|
*this, &LinuxSamplerPlugin::NotifyDataStructureChanged |
139 |
|
), |
140 |
|
"gig::Script" |
141 |
|
) |
142 |
|
); |
143 |
|
|
144 |
// register a timeout job to gigedit's main loop, so we can poll the |
// register a timeout job to gigedit's main loop, so we can poll the |
145 |
// the sampler periodically for MIDI events (I HOPE it works on all |
// the sampler periodically for MIDI events (I HOPE it works on all |
157 |
} |
} |
158 |
|
|
159 |
bool LinuxSamplerPlugin::__onPollPeriod() { |
bool LinuxSamplerPlugin::__onPollPeriod() { |
160 |
GigEdit* app = (GigEdit*) pApp; |
#if HAVE_LINUXSAMPLER_VIRTUAL_MIDI_DEVICE |
161 |
|
GigEdit* app = static_cast<GigEdit*>(pApp); |
162 |
if (!NotesChanged()) return true; |
if (!NotesChanged()) return true; |
163 |
for (int iKey = 0; iKey < 128; iKey++) |
for (int iKey = 0; iKey < 128; iKey++) |
164 |
if (NoteChanged(iKey)) |
if (NoteChanged(iKey)) |
165 |
NoteIsActive(iKey) ? // we don't care about velocity yet |
NoteIsActive(iKey) ? |
166 |
app->on_note_on_event(iKey, 127) : |
app->on_note_on_event(iKey, NoteOnVelocity(iKey)) : |
167 |
app->on_note_off_event(iKey, 127); |
app->on_note_off_event(iKey, NoteOffVelocity(iKey)); |
168 |
return true; |
return true; |
169 |
|
#else |
170 |
|
return false; |
171 |
|
#endif |
172 |
} |
} |
173 |
|
|
174 |
void LinuxSamplerPlugin::__onSamplesToBeRemoved(std::list<gig::Sample*> lSamples) { |
void LinuxSamplerPlugin::__onSamplesToBeRemoved(std::list<gig::Sample*> lSamples) { |
176 |
std::set<void*> samples; |
std::set<void*> samples; |
177 |
for ( |
for ( |
178 |
std::list<gig::Sample*>::iterator iter = lSamples.begin(); |
std::list<gig::Sample*>::iterator iter = lSamples.begin(); |
179 |
iter != lSamples.end(); iter++ |
iter != lSamples.end(); ++iter |
180 |
) samples.insert((void*)*iter); |
) samples.insert((void*)*iter); |
181 |
// finally send notification to sampler |
// finally send notification to sampler |
182 |
NotifySamplesToBeRemoved(samples); |
NotifySamplesToBeRemoved(samples); |
183 |
} |
} |
184 |
|
|
185 |
void LinuxSamplerPlugin::__onVirtualKeyboardKeyHit(int Key, int Velocity) { |
void LinuxSamplerPlugin::__onVirtualKeyboardKeyHit(int Key, int Velocity) { |
186 |
|
#if HAVE_LINUXSAMPLER_VIRTUAL_MIDI_DEVICE |
187 |
SendNoteOnToSampler(Key, Velocity); |
SendNoteOnToSampler(Key, Velocity); |
188 |
|
#endif |
189 |
} |
} |
190 |
|
|
191 |
void LinuxSamplerPlugin::__onVirtualKeyboardKeyReleased(int Key, int Velocity) { |
void LinuxSamplerPlugin::__onVirtualKeyboardKeyReleased(int Key, int Velocity) { |
192 |
|
#if HAVE_LINUXSAMPLER_VIRTUAL_MIDI_DEVICE |
193 |
SendNoteOffToSampler(Key, Velocity); |
SendNoteOffToSampler(Key, Velocity); |
194 |
|
#endif |
195 |
|
} |
196 |
|
|
197 |
|
void LinuxSamplerPlugin::__requestSamplerToSwitchInstrument(gig::Instrument* pInstrument) { |
198 |
|
if (!pInstrument) return; |
199 |
|
|
200 |
|
LinuxSampler::EngineChannel* pEngineChannel = GetEngineChannel(); |
201 |
|
if (!pEngineChannel) return; |
202 |
|
|
203 |
|
LinuxSampler::Engine* pEngine = pEngineChannel->GetEngine(); |
204 |
|
if (!pEngine) return; |
205 |
|
|
206 |
|
LinuxSampler::InstrumentManager* pInstrumentManager = pEngine->GetInstrumentManager(); |
207 |
|
if (!pInstrumentManager) return; |
208 |
|
|
209 |
|
gig::File* pFile = (gig::File*) pInstrument->GetParent(); |
210 |
|
|
211 |
|
// resolve instrument's index number in its gig file |
212 |
|
int index = -1; |
213 |
|
for (int i = 0; pFile->GetInstrument(i); ++i) { |
214 |
|
if (pFile->GetInstrument(i) == pInstrument) { |
215 |
|
index = i; |
216 |
|
break; |
217 |
|
} |
218 |
|
} |
219 |
|
if (index < 0) return; |
220 |
|
|
221 |
|
LinuxSampler::InstrumentManager::instrument_id_t id; |
222 |
|
id.FileName = pFile->GetFileName(); |
223 |
|
id.Index = index; |
224 |
|
pInstrumentManager->LoadInstrumentInBackground(id, pEngineChannel); |
225 |
} |
} |
226 |
|
|
227 |
bool LinuxSamplerPlugin::IsTypeSupported(String sTypeName, String sTypeVersion) { |
bool LinuxSamplerPlugin::IsTypeSupported(String sTypeName, String sTypeVersion) { |