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 |
1213 |
int LinuxSamplerPlugin::Main(void* pInstrument, String sTypeName, String sTypeVersion) { |
41 |
|
|
std::cout << "Entered Gigedit Main() loop :)\n" << std::flush; |
42 |
|
|
gig::Instrument* pGigInstr = static_cast<gig::Instrument*>(pInstrument); |
43 |
schoenebeck |
1654 |
GigEdit* app = (GigEdit*) pApp; |
44 |
|
|
|
45 |
schoenebeck |
1322 |
// connect notification signals |
46 |
schoenebeck |
1654 |
app->signal_file_structure_to_be_changed().connect( |
47 |
schoenebeck |
1322 |
sigc::bind( |
48 |
|
|
sigc::mem_fun( |
49 |
|
|
*this, &LinuxSamplerPlugin::NotifyDataStructureToBeChanged |
50 |
|
|
), |
51 |
|
|
"gig::File" |
52 |
|
|
) |
53 |
|
|
); |
54 |
schoenebeck |
1654 |
app->signal_file_structure_changed().connect( |
55 |
schoenebeck |
1322 |
sigc::bind( |
56 |
|
|
sigc::mem_fun( |
57 |
|
|
*this, &LinuxSamplerPlugin::NotifyDataStructureChanged |
58 |
|
|
), |
59 |
|
|
"gig::File" |
60 |
|
|
) |
61 |
|
|
); |
62 |
schoenebeck |
1654 |
app->signal_samples_to_be_removed().connect( |
63 |
schoenebeck |
1322 |
sigc::mem_fun(*this, &LinuxSamplerPlugin::__onSamplesToBeRemoved) |
64 |
|
|
); |
65 |
schoenebeck |
1654 |
app->signal_samples_removed().connect( |
66 |
schoenebeck |
1322 |
sigc::mem_fun(*this, &LinuxSamplerPlugin::NotifySamplesRemoved) |
67 |
|
|
); |
68 |
schoenebeck |
1654 |
app->signal_region_to_be_changed().connect( |
69 |
schoenebeck |
1322 |
sigc::bind( |
70 |
|
|
sigc::mem_fun( |
71 |
|
|
*this, &LinuxSamplerPlugin::NotifyDataStructureToBeChanged |
72 |
|
|
), |
73 |
|
|
"gig::Region" |
74 |
|
|
) |
75 |
|
|
); |
76 |
schoenebeck |
1654 |
app->signal_region_changed().connect( |
77 |
schoenebeck |
1322 |
sigc::bind( |
78 |
|
|
sigc::mem_fun( |
79 |
|
|
*this, &LinuxSamplerPlugin::NotifyDataStructureChanged |
80 |
|
|
), |
81 |
|
|
"gig::Region" |
82 |
|
|
) |
83 |
|
|
); |
84 |
schoenebeck |
1654 |
app->signal_dimreg_to_be_changed().connect( |
85 |
schoenebeck |
1322 |
sigc::bind( |
86 |
|
|
sigc::mem_fun( |
87 |
|
|
*this, &LinuxSamplerPlugin::NotifyDataStructureToBeChanged |
88 |
|
|
), |
89 |
|
|
"gig::DimensionRegion" |
90 |
|
|
) |
91 |
|
|
); |
92 |
schoenebeck |
1654 |
app->signal_dimreg_changed().connect( |
93 |
schoenebeck |
1322 |
sigc::bind( |
94 |
|
|
sigc::mem_fun( |
95 |
|
|
*this, &LinuxSamplerPlugin::NotifyDataStructureChanged |
96 |
|
|
), |
97 |
|
|
"gig::DimensionRegion" |
98 |
|
|
) |
99 |
|
|
); |
100 |
schoenebeck |
1654 |
app->signal_sample_ref_changed().connect( |
101 |
schoenebeck |
1322 |
sigc::mem_fun(*this, &LinuxSamplerPlugin::NotifySampleReferenceChanged) |
102 |
|
|
); |
103 |
schoenebeck |
1654 |
|
104 |
schoenebeck |
1660 |
app->signal_keyboard_key_hit().connect( |
105 |
|
|
sigc::mem_fun(*this, &LinuxSamplerPlugin::__onVirtualKeyboardKeyHit) |
106 |
|
|
); |
107 |
|
|
app->signal_keyboard_key_released().connect( |
108 |
|
|
sigc::mem_fun(*this, &LinuxSamplerPlugin::__onVirtualKeyboardKeyReleased) |
109 |
|
|
); |
110 |
|
|
|
111 |
schoenebeck |
1656 |
// register a timeout job to gigedit's main loop, so we can poll the |
112 |
|
|
// the sampler periodically for MIDI events (I HOPE it works on all |
113 |
|
|
// archs, because gigedit is actually running in another thread than |
114 |
|
|
// the one that is calling this timeout handler register code) |
115 |
|
|
const Glib::RefPtr<Glib::TimeoutSource> timeout_source = |
116 |
|
|
Glib::TimeoutSource::create(100); // poll every 100ms |
117 |
|
|
timeout_source->connect( |
118 |
|
|
sigc::mem_fun(this, &LinuxSamplerPlugin::__onPollPeriod) |
119 |
|
|
); |
120 |
|
|
timeout_source->attach(Glib::MainContext::get_default()); |
121 |
schoenebeck |
1654 |
|
122 |
schoenebeck |
1322 |
// run gigedit application |
123 |
schoenebeck |
1654 |
return app->run(pGigInstr); |
124 |
schoenebeck |
1213 |
} |
125 |
|
|
|
126 |
schoenebeck |
1656 |
bool LinuxSamplerPlugin::__onPollPeriod() { |
127 |
schoenebeck |
1680 |
#if HAVE_LINUXSAMPLER_VIRTUAL_MIDI_DEVICE |
128 |
schoenebeck |
1654 |
GigEdit* app = (GigEdit*) pApp; |
129 |
|
|
if (!NotesChanged()) return true; |
130 |
|
|
for (int iKey = 0; iKey < 128; iKey++) |
131 |
|
|
if (NoteChanged(iKey)) |
132 |
schoenebeck |
1664 |
NoteIsActive(iKey) ? |
133 |
|
|
app->on_note_on_event(iKey, NoteOnVelocity(iKey)) : |
134 |
|
|
app->on_note_off_event(iKey, NoteOffVelocity(iKey)); |
135 |
schoenebeck |
1654 |
return true; |
136 |
schoenebeck |
1680 |
#else |
137 |
|
|
return false; |
138 |
|
|
#endif |
139 |
schoenebeck |
1654 |
} |
140 |
|
|
|
141 |
schoenebeck |
1322 |
void LinuxSamplerPlugin::__onSamplesToBeRemoved(std::list<gig::Sample*> lSamples) { |
142 |
|
|
// we have to convert the gig::Sample* list to a void* list first |
143 |
|
|
std::set<void*> samples; |
144 |
|
|
for ( |
145 |
|
|
std::list<gig::Sample*>::iterator iter = lSamples.begin(); |
146 |
|
|
iter != lSamples.end(); iter++ |
147 |
|
|
) samples.insert((void*)*iter); |
148 |
|
|
// finally send notification to sampler |
149 |
|
|
NotifySamplesToBeRemoved(samples); |
150 |
|
|
} |
151 |
|
|
|
152 |
schoenebeck |
1660 |
void LinuxSamplerPlugin::__onVirtualKeyboardKeyHit(int Key, int Velocity) { |
153 |
schoenebeck |
1680 |
#if HAVE_LINUXSAMPLER_VIRTUAL_MIDI_DEVICE |
154 |
schoenebeck |
1660 |
SendNoteOnToSampler(Key, Velocity); |
155 |
schoenebeck |
1680 |
#endif |
156 |
schoenebeck |
1660 |
} |
157 |
|
|
|
158 |
|
|
void LinuxSamplerPlugin::__onVirtualKeyboardKeyReleased(int Key, int Velocity) { |
159 |
schoenebeck |
1680 |
#if HAVE_LINUXSAMPLER_VIRTUAL_MIDI_DEVICE |
160 |
schoenebeck |
1660 |
SendNoteOffToSampler(Key, Velocity); |
161 |
schoenebeck |
1680 |
#endif |
162 |
schoenebeck |
1660 |
} |
163 |
|
|
|
164 |
schoenebeck |
1213 |
bool LinuxSamplerPlugin::IsTypeSupported(String sTypeName, String sTypeVersion) { |
165 |
|
|
return sTypeName == gig::libraryName() && |
166 |
|
|
sTypeVersion == gig::libraryVersion(); |
167 |
|
|
} |
168 |
|
|
|
169 |
|
|
String LinuxSamplerPlugin::Name() { |
170 |
|
|
return "gigedit"; |
171 |
|
|
} |
172 |
|
|
|
173 |
|
|
String LinuxSamplerPlugin::Version() { |
174 |
|
|
return VERSION; // gigedit's version |
175 |
|
|
} |
176 |
|
|
|
177 |
|
|
String LinuxSamplerPlugin::Description() { |
178 |
|
|
return "Gigedit is an instrument editor for gig files."; |
179 |
|
|
} |