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