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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

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 1213
25     #include <iostream>
26 schoenebeck 1322 #include <sigc++/bind.h>
27 schoenebeck 1656 #include <glibmm/main.h>
28 schoenebeck 1213
29     REGISTER_INSTRUMENT_EDITOR(LinuxSamplerPlugin)
30    
31     LinuxSamplerPlugin::LinuxSamplerPlugin() {
32 schoenebeck 1654 pApp = new GigEdit;
33 schoenebeck 1213 }
34    
35 schoenebeck 1654 LinuxSamplerPlugin::~LinuxSamplerPlugin() {
36     if (pApp) delete (GigEdit*) pApp;
37     }
38    
39 schoenebeck 1213 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 schoenebeck 1654 GigEdit* app = (GigEdit*) pApp;
43    
44 schoenebeck 1322 // connect notification signals
45 schoenebeck 1654 app->signal_file_structure_to_be_changed().connect(
46 schoenebeck 1322 sigc::bind(
47     sigc::mem_fun(
48     *this, &LinuxSamplerPlugin::NotifyDataStructureToBeChanged
49     ),
50     "gig::File"
51     )
52     );
53 schoenebeck 1654 app->signal_file_structure_changed().connect(
54 schoenebeck 1322 sigc::bind(
55     sigc::mem_fun(
56     *this, &LinuxSamplerPlugin::NotifyDataStructureChanged
57     ),
58     "gig::File"
59     )
60     );
61 schoenebeck 1654 app->signal_samples_to_be_removed().connect(
62 schoenebeck 1322 sigc::mem_fun(*this, &LinuxSamplerPlugin::__onSamplesToBeRemoved)
63     );
64 schoenebeck 1654 app->signal_samples_removed().connect(
65 schoenebeck 1322 sigc::mem_fun(*this, &LinuxSamplerPlugin::NotifySamplesRemoved)
66     );
67 schoenebeck 1654 app->signal_region_to_be_changed().connect(
68 schoenebeck 1322 sigc::bind(
69     sigc::mem_fun(
70     *this, &LinuxSamplerPlugin::NotifyDataStructureToBeChanged
71     ),
72     "gig::Region"
73     )
74     );
75 schoenebeck 1654 app->signal_region_changed().connect(
76 schoenebeck 1322 sigc::bind(
77     sigc::mem_fun(
78     *this, &LinuxSamplerPlugin::NotifyDataStructureChanged
79     ),
80     "gig::Region"
81     )
82     );
83 schoenebeck 1654 app->signal_dimreg_to_be_changed().connect(
84 schoenebeck 1322 sigc::bind(
85     sigc::mem_fun(
86     *this, &LinuxSamplerPlugin::NotifyDataStructureToBeChanged
87     ),
88     "gig::DimensionRegion"
89     )
90     );
91 schoenebeck 1654 app->signal_dimreg_changed().connect(
92 schoenebeck 1322 sigc::bind(
93     sigc::mem_fun(
94     *this, &LinuxSamplerPlugin::NotifyDataStructureChanged
95     ),
96     "gig::DimensionRegion"
97     )
98     );
99 schoenebeck 1654 app->signal_sample_ref_changed().connect(
100 schoenebeck 1322 sigc::mem_fun(*this, &LinuxSamplerPlugin::NotifySampleReferenceChanged)
101     );
102 schoenebeck 1654
103 schoenebeck 1660 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 schoenebeck 1656 // 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 schoenebeck 1654
121 schoenebeck 1322 // run gigedit application
122 schoenebeck 1654 return app->run(pGigInstr);
123 schoenebeck 1213 }
124    
125 schoenebeck 1656 bool LinuxSamplerPlugin::__onPollPeriod() {
126 schoenebeck 1654 GigEdit* app = (GigEdit*) pApp;
127     if (!NotesChanged()) return true;
128     for (int iKey = 0; iKey < 128; iKey++)
129     if (NoteChanged(iKey))
130 schoenebeck 1664 NoteIsActive(iKey) ?
131     app->on_note_on_event(iKey, NoteOnVelocity(iKey)) :
132     app->on_note_off_event(iKey, NoteOffVelocity(iKey));
133 schoenebeck 1654 return true;
134     }
135    
136 schoenebeck 1322 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 schoenebeck 1660 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 schoenebeck 1213 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