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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1229 by schoenebeck, Sun Jun 10 11:23:15 2007 UTC revision 1664 by schoenebeck, Mon Feb 4 00:40:03 2008 UTC
# Line 1  Line 1 
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
# Line 19  Line 19 
19    
20  #include "linuxsamplerplugin.h"  #include "linuxsamplerplugin.h"
21    
22  #include <gig.h>  #include <linuxsampler/plugins/InstrumentEditorFactory.h>
 #include <linuxsampler/engines/InstrumentEditorFactory.h>  
23  #include "../gigedit/gigedit.h"  #include "../gigedit/gigedit.h"
24    
25  #include <iostream>  #include <iostream>
26    #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      return GigEdit::run(pGigInstr);      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) {  bool LinuxSamplerPlugin::IsTypeSupported(String sTypeName, String sTypeVersion) {

Legend:
Removed from v.1229  
changed lines
  Added in v.1664

  ViewVC Help
Powered by ViewVC