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 |
24 |
|
|
25 |
#include <iostream> |
#include <iostream> |
26 |
#include <sigc++/bind.h> |
#include <sigc++/bind.h> |
27 |
|
#include <glibmm/main.h> |
28 |
|
|
29 |
REGISTER_INSTRUMENT_EDITOR(LinuxSamplerPlugin) |
REGISTER_INSTRUMENT_EDITOR(LinuxSamplerPlugin) |
30 |
|
|
31 |
LinuxSamplerPlugin::LinuxSamplerPlugin() { |
LinuxSamplerPlugin::LinuxSamplerPlugin() { |
32 |
|
pApp = new GigEdit; |
33 |
|
} |
34 |
|
|
35 |
|
LinuxSamplerPlugin::~LinuxSamplerPlugin() { |
36 |
|
if (pApp) delete (GigEdit*) pApp; |
37 |
} |
} |
38 |
|
|
39 |
int LinuxSamplerPlugin::Main(void* pInstrument, String sTypeName, String sTypeVersion) { |
int LinuxSamplerPlugin::Main(void* pInstrument, String sTypeName, String sTypeVersion) { |
40 |
std::cout << "Entered Gigedit Main() loop :)\n" << std::flush; |
std::cout << "Entered Gigedit Main() loop :)\n" << std::flush; |
41 |
gig::Instrument* pGigInstr = static_cast<gig::Instrument*>(pInstrument); |
gig::Instrument* pGigInstr = static_cast<gig::Instrument*>(pInstrument); |
42 |
GigEdit app; |
GigEdit* app = (GigEdit*) pApp; |
43 |
|
|
44 |
// connect notification signals |
// connect notification signals |
45 |
app.signal_file_structure_to_be_changed().connect( |
app->signal_file_structure_to_be_changed().connect( |
46 |
sigc::bind( |
sigc::bind( |
47 |
sigc::mem_fun( |
sigc::mem_fun( |
48 |
*this, &LinuxSamplerPlugin::NotifyDataStructureToBeChanged |
*this, &LinuxSamplerPlugin::NotifyDataStructureToBeChanged |
50 |
"gig::File" |
"gig::File" |
51 |
) |
) |
52 |
); |
); |
53 |
app.signal_file_structure_changed().connect( |
app->signal_file_structure_changed().connect( |
54 |
sigc::bind( |
sigc::bind( |
55 |
sigc::mem_fun( |
sigc::mem_fun( |
56 |
*this, &LinuxSamplerPlugin::NotifyDataStructureChanged |
*this, &LinuxSamplerPlugin::NotifyDataStructureChanged |
58 |
"gig::File" |
"gig::File" |
59 |
) |
) |
60 |
); |
); |
61 |
app.signal_samples_to_be_removed().connect( |
app->signal_samples_to_be_removed().connect( |
62 |
sigc::mem_fun(*this, &LinuxSamplerPlugin::__onSamplesToBeRemoved) |
sigc::mem_fun(*this, &LinuxSamplerPlugin::__onSamplesToBeRemoved) |
63 |
); |
); |
64 |
app.signal_samples_removed().connect( |
app->signal_samples_removed().connect( |
65 |
sigc::mem_fun(*this, &LinuxSamplerPlugin::NotifySamplesRemoved) |
sigc::mem_fun(*this, &LinuxSamplerPlugin::NotifySamplesRemoved) |
66 |
); |
); |
67 |
app.signal_region_to_be_changed().connect( |
app->signal_region_to_be_changed().connect( |
68 |
sigc::bind( |
sigc::bind( |
69 |
sigc::mem_fun( |
sigc::mem_fun( |
70 |
*this, &LinuxSamplerPlugin::NotifyDataStructureToBeChanged |
*this, &LinuxSamplerPlugin::NotifyDataStructureToBeChanged |
72 |
"gig::Region" |
"gig::Region" |
73 |
) |
) |
74 |
); |
); |
75 |
app.signal_region_changed().connect( |
app->signal_region_changed().connect( |
76 |
sigc::bind( |
sigc::bind( |
77 |
sigc::mem_fun( |
sigc::mem_fun( |
78 |
*this, &LinuxSamplerPlugin::NotifyDataStructureChanged |
*this, &LinuxSamplerPlugin::NotifyDataStructureChanged |
80 |
"gig::Region" |
"gig::Region" |
81 |
) |
) |
82 |
); |
); |
83 |
app.signal_dimreg_to_be_changed().connect( |
app->signal_dimreg_to_be_changed().connect( |
84 |
sigc::bind( |
sigc::bind( |
85 |
sigc::mem_fun( |
sigc::mem_fun( |
86 |
*this, &LinuxSamplerPlugin::NotifyDataStructureToBeChanged |
*this, &LinuxSamplerPlugin::NotifyDataStructureToBeChanged |
88 |
"gig::DimensionRegion" |
"gig::DimensionRegion" |
89 |
) |
) |
90 |
); |
); |
91 |
app.signal_dimreg_changed().connect( |
app->signal_dimreg_changed().connect( |
92 |
sigc::bind( |
sigc::bind( |
93 |
sigc::mem_fun( |
sigc::mem_fun( |
94 |
*this, &LinuxSamplerPlugin::NotifyDataStructureChanged |
*this, &LinuxSamplerPlugin::NotifyDataStructureChanged |
96 |
"gig::DimensionRegion" |
"gig::DimensionRegion" |
97 |
) |
) |
98 |
); |
); |
99 |
app.signal_sample_ref_changed().connect( |
app->signal_sample_ref_changed().connect( |
100 |
sigc::mem_fun(*this, &LinuxSamplerPlugin::NotifySampleReferenceChanged) |
sigc::mem_fun(*this, &LinuxSamplerPlugin::NotifySampleReferenceChanged) |
101 |
); |
); |
102 |
|
|
103 |
|
app->signal_keyboard_key_hit().connect( |
104 |
|
sigc::mem_fun(*this, &LinuxSamplerPlugin::__onVirtualKeyboardKeyHit) |
105 |
|
); |
106 |
|
app->signal_keyboard_key_released().connect( |
107 |
|
sigc::mem_fun(*this, &LinuxSamplerPlugin::__onVirtualKeyboardKeyReleased) |
108 |
|
); |
109 |
|
|
110 |
|
// register a timeout job to gigedit's main loop, so we can poll the |
111 |
|
// the sampler periodically for MIDI events (I HOPE it works on all |
112 |
|
// archs, because gigedit is actually running in another thread than |
113 |
|
// the one that is calling this timeout handler register code) |
114 |
|
const Glib::RefPtr<Glib::TimeoutSource> timeout_source = |
115 |
|
Glib::TimeoutSource::create(100); // poll every 100ms |
116 |
|
timeout_source->connect( |
117 |
|
sigc::mem_fun(this, &LinuxSamplerPlugin::__onPollPeriod) |
118 |
|
); |
119 |
|
timeout_source->attach(Glib::MainContext::get_default()); |
120 |
|
|
121 |
// run gigedit application |
// run gigedit application |
122 |
return app.run(pGigInstr); |
return app->run(pGigInstr); |
123 |
|
} |
124 |
|
|
125 |
|
bool LinuxSamplerPlugin::__onPollPeriod() { |
126 |
|
GigEdit* app = (GigEdit*) pApp; |
127 |
|
if (!NotesChanged()) return true; |
128 |
|
for (int iKey = 0; iKey < 128; iKey++) |
129 |
|
if (NoteChanged(iKey)) |
130 |
|
NoteIsActive(iKey) ? // we don't care about velocity yet |
131 |
|
app->on_note_on_event(iKey, 127) : |
132 |
|
app->on_note_off_event(iKey, 127); |
133 |
|
return true; |
134 |
} |
} |
135 |
|
|
136 |
void LinuxSamplerPlugin::__onSamplesToBeRemoved(std::list<gig::Sample*> lSamples) { |
void LinuxSamplerPlugin::__onSamplesToBeRemoved(std::list<gig::Sample*> lSamples) { |
144 |
NotifySamplesToBeRemoved(samples); |
NotifySamplesToBeRemoved(samples); |
145 |
} |
} |
146 |
|
|
147 |
|
void LinuxSamplerPlugin::__onVirtualKeyboardKeyHit(int Key, int Velocity) { |
148 |
|
SendNoteOnToSampler(Key, Velocity); |
149 |
|
} |
150 |
|
|
151 |
|
void LinuxSamplerPlugin::__onVirtualKeyboardKeyReleased(int Key, int Velocity) { |
152 |
|
SendNoteOffToSampler(Key, Velocity); |
153 |
|
} |
154 |
|
|
155 |
bool LinuxSamplerPlugin::IsTypeSupported(String sTypeName, String sTypeVersion) { |
bool LinuxSamplerPlugin::IsTypeSupported(String sTypeName, String sTypeVersion) { |
156 |
return sTypeName == gig::libraryName() && |
return sTypeName == gig::libraryName() && |
157 |
sTypeVersion == gig::libraryVersion(); |
sTypeVersion == gig::libraryVersion(); |