/[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 1656 - (show annotations) (download)
Sat Feb 2 08:18:19 2008 UTC (16 years, 2 months ago) by schoenebeck
File size: 5103 byte(s)
* bugfix: key highlighting of active keys on the virtual keyboard is now
  working on multiple invocations from the sampler as well
* renamed misleading names regarding the gig format's "keyswitching"
  feature (the dimension is now displayed as "keyswitching" instead of
  "keyboard" in the dimregchooser widget and the two parameters for
  defining the actual keyswitching area on the keyboard in the instruments
  properties dialog are now called "Keyswitching range low/high" instead of
  "Dimension key range low/high")

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 // register a timeout job to gigedit's main loop, so we can poll the
104 // the sampler periodically for MIDI events (I HOPE it works on all
105 // archs, because gigedit is actually running in another thread than
106 // the one that is calling this timeout handler register code)
107 const Glib::RefPtr<Glib::TimeoutSource> timeout_source =
108 Glib::TimeoutSource::create(100); // poll every 100ms
109 timeout_source->connect(
110 sigc::mem_fun(this, &LinuxSamplerPlugin::__onPollPeriod)
111 );
112 timeout_source->attach(Glib::MainContext::get_default());
113
114 // run gigedit application
115 return app->run(pGigInstr);
116 }
117
118 bool LinuxSamplerPlugin::__onPollPeriod() {
119 GigEdit* app = (GigEdit*) pApp;
120 if (!NotesChanged()) return true;
121 for (int iKey = 0; iKey < 128; iKey++)
122 if (NoteChanged(iKey))
123 NoteIsActive(iKey) ? // we don't care about velocity yet
124 app->on_note_on_event(iKey, 127) :
125 app->on_note_off_event(iKey, 127);
126 return true;
127 }
128
129 void LinuxSamplerPlugin::__onSamplesToBeRemoved(std::list<gig::Sample*> lSamples) {
130 // we have to convert the gig::Sample* list to a void* list first
131 std::set<void*> samples;
132 for (
133 std::list<gig::Sample*>::iterator iter = lSamples.begin();
134 iter != lSamples.end(); iter++
135 ) samples.insert((void*)*iter);
136 // finally send notification to sampler
137 NotifySamplesToBeRemoved(samples);
138 }
139
140 bool LinuxSamplerPlugin::IsTypeSupported(String sTypeName, String sTypeVersion) {
141 return sTypeName == gig::libraryName() &&
142 sTypeVersion == gig::libraryVersion();
143 }
144
145 String LinuxSamplerPlugin::Name() {
146 return "gigedit";
147 }
148
149 String LinuxSamplerPlugin::Version() {
150 return VERSION; // gigedit's version
151 }
152
153 String LinuxSamplerPlugin::Description() {
154 return "Gigedit is an instrument editor for gig files.";
155 }

  ViewVC Help
Powered by ViewVC