/[svn]/gigedit/trunk/src/plugin/linuxsamplerplugin.cpp
ViewVC logotype

Contents of /gigedit/trunk/src/plugin/linuxsamplerplugin.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1664 - (show annotations) (download)
Mon Feb 4 00:40:03 2008 UTC (12 years, 3 months ago) by schoenebeck
File size: 5613 byte(s)
* show absolute velocity values of "real" MIDI sources
  in the editor as well

1 /*
2 * Copyright (C) 2007, 2008 Andreas Persson
3 *
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 #include <linuxsampler/plugins/InstrumentEditorFactory.h>
23 #include "../gigedit/gigedit.h"
24
25 #include <iostream>
26 #include <sigc++/bind.h>
27 #include <glibmm/main.h>
28
29 REGISTER_INSTRUMENT_EDITOR(LinuxSamplerPlugin)
30
31 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) {
40 std::cout << "Entered Gigedit Main() loop :)\n" << std::flush;
41 gig::Instrument* pGigInstr = static_cast<gig::Instrument*>(pInstrument);
42 GigEdit* app = (GigEdit*) pApp;
43
44 // connect notification signals
45 app->signal_file_structure_to_be_changed().connect(
46 sigc::bind(
47 sigc::mem_fun(
48 *this, &LinuxSamplerPlugin::NotifyDataStructureToBeChanged
49 ),
50 "gig::File"
51 )
52 );
53 app->signal_file_structure_changed().connect(
54 sigc::bind(
55 sigc::mem_fun(
56 *this, &LinuxSamplerPlugin::NotifyDataStructureChanged
57 ),
58 "gig::File"
59 )
60 );
61 app->signal_samples_to_be_removed().connect(
62 sigc::mem_fun(*this, &LinuxSamplerPlugin::__onSamplesToBeRemoved)
63 );
64 app->signal_samples_removed().connect(
65 sigc::mem_fun(*this, &LinuxSamplerPlugin::NotifySamplesRemoved)
66 );
67 app->signal_region_to_be_changed().connect(
68 sigc::bind(
69 sigc::mem_fun(
70 *this, &LinuxSamplerPlugin::NotifyDataStructureToBeChanged
71 ),
72 "gig::Region"
73 )
74 );
75 app->signal_region_changed().connect(
76 sigc::bind(
77 sigc::mem_fun(
78 *this, &LinuxSamplerPlugin::NotifyDataStructureChanged
79 ),
80 "gig::Region"
81 )
82 );
83 app->signal_dimreg_to_be_changed().connect(
84 sigc::bind(
85 sigc::mem_fun(
86 *this, &LinuxSamplerPlugin::NotifyDataStructureToBeChanged
87 ),
88 "gig::DimensionRegion"
89 )
90 );
91 app->signal_dimreg_changed().connect(
92 sigc::bind(
93 sigc::mem_fun(
94 *this, &LinuxSamplerPlugin::NotifyDataStructureChanged
95 ),
96 "gig::DimensionRegion"
97 )
98 );
99 app->signal_sample_ref_changed().connect(
100 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
122 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) ?
131 app->on_note_on_event(iKey, NoteOnVelocity(iKey)) :
132 app->on_note_off_event(iKey, NoteOffVelocity(iKey));
133 return true;
134 }
135
136 void LinuxSamplerPlugin::__onSamplesToBeRemoved(std::list<gig::Sample*> lSamples) {
137 // we have to convert the gig::Sample* list to a void* list first
138 std::set<void*> samples;
139 for (
140 std::list<gig::Sample*>::iterator iter = lSamples.begin();
141 iter != lSamples.end(); iter++
142 ) samples.insert((void*)*iter);
143 // finally send notification to sampler
144 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) {
156 return sTypeName == gig::libraryName() &&
157 sTypeVersion == gig::libraryVersion();
158 }
159
160 String LinuxSamplerPlugin::Name() {
161 return "gigedit";
162 }
163
164 String LinuxSamplerPlugin::Version() {
165 return VERSION; // gigedit's version
166 }
167
168 String LinuxSamplerPlugin::Description() {
169 return "Gigedit is an instrument editor for gig files.";
170 }

  ViewVC Help
Powered by ViewVC