/[svn]/linuxsampler/trunk/src/plugins/InstrumentEditor.cpp
ViewVC logotype

Annotation of /linuxsampler/trunk/src/plugins/InstrumentEditor.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1653 - (hide annotations) (download)
Wed Jan 30 01:51:46 2008 UTC (16 years, 3 months ago) by schoenebeck
File size: 6548 byte(s)
* added support for notifying instrument editors on note-on / note-off
  events (e.g. to highlight the pressed keys on the virtual keyboard
  of gigedit)
* fixed return value of recently added Thread::TestCancel() method
* be verbose on DLL load errors (on Linux)

1 schoenebeck 1374 /***************************************************************************
2     * *
3 schoenebeck 1653 * Copyright (C) 2007, 2008 Christian Schoenebeck *
4 schoenebeck 1374 * *
5     * This program is free software; you can redistribute it and/or modify *
6     * it under the terms of the GNU General Public License as published by *
7     * the Free Software Foundation; either version 2 of the License, or *
8     * (at your option) any later version. *
9     * *
10     * This program is distributed in the hope that it will be useful, *
11     * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13     * GNU General Public License for more details. *
14     * *
15     * You should have received a copy of the GNU General Public License *
16     * along with this program; if not, write to the Free Software *
17     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
18     * MA 02111-1307 USA *
19     ***************************************************************************/
20    
21     #include "InstrumentEditor.h"
22    
23 schoenebeck 1425 #include "../common/global_private.h"
24 schoenebeck 1653 #include "../common/atomic.h"
25 schoenebeck 1425
26 schoenebeck 1374 #include <algorithm>
27     #include <functional>
28    
29 schoenebeck 1653 #define MIDI_KEYS 128
30    
31 schoenebeck 1374 namespace LinuxSampler {
32    
33     InstrumentEditor::InstrumentEditor() : Thread(false, false, -1, 0) {
34     pInstrument = NULL;
35 schoenebeck 1653 pNotesChanged = new atomic_t;
36     pNoteChanged = new atomic_t[MIDI_KEYS];
37     pNoteIsActive = new atomic_t[MIDI_KEYS];
38     atomic_t zero = ATOMIC_INIT(0);
39     for (int i = 0; i < MIDI_KEYS; i++) {
40     ((atomic_t*)pNoteChanged)[i] = zero;
41     ((atomic_t*)pNoteIsActive)[i] = zero;
42     }
43     *((atomic_t*)pNotesChanged) = zero;
44 schoenebeck 1374 }
45    
46 schoenebeck 1653 InstrumentEditor::~InstrumentEditor() {
47     if (pNoteIsActive) delete[] (atomic_t*)pNoteIsActive;
48     if (pNoteChanged) delete[] (atomic_t*)pNoteChanged;
49     if (pNotesChanged) delete (atomic_t*)pNotesChanged;
50     }
51    
52 schoenebeck 1374 void InstrumentEditor::Launch(void* pInstrument, String sTypeName, String sTypeVersion) {
53     dmsg(1,("InstrumentEditor::Launch(instr=%x,type=%s,version=%s)\n", pInstrument, sTypeName.c_str(), sTypeVersion.c_str()));
54     // prepare the editor's mandatory parameters
55     this->pInstrument = pInstrument;
56     this->sTypeName = sTypeName;
57     this->sTypeVersion = sTypeVersion;
58     // start the editor in its own thread
59     StartThread();
60     }
61    
62     int InstrumentEditor::Main() {
63     dmsg(1,("InstrumentEditor::Main()\n"));
64     // run the editor's main loop
65     int iResult = Main(pInstrument, sTypeName, sTypeVersion);
66     // reset editor parameters
67     this->pInstrument = NULL;
68     this->sTypeName = "";
69     this->sTypeVersion = "";
70     dmsg(1,("Instrument editor '%s' returned with exit status %d\n", Name().c_str(), iResult));
71     // notify all registered listeners
72     std::for_each(
73     listeners.begin(), listeners.end(),
74     std::bind2nd(std::mem_fun(&InstrumentEditorListener::OnInstrumentEditorQuit), this)
75     );
76     // done
77     return iResult;
78     }
79    
80 schoenebeck 1653 void InstrumentEditor::SendNoteOnToEditor(uint8_t Key, uint8_t /*Velocity*/) {
81     if (Key >= MIDI_KEYS) return;
82     atomic_inc( &((atomic_t*)pNoteIsActive)[Key] );
83     atomic_inc( &((atomic_t*)pNoteChanged)[Key] );
84     atomic_inc( (atomic_t*)pNotesChanged );
85     }
86    
87     void InstrumentEditor::SendNoteOffToEditor(uint8_t Key, uint8_t /*Velocity*/) {
88     if (Key >= MIDI_KEYS) return;
89     atomic_dec( &((atomic_t*)pNoteIsActive)[Key] );
90     atomic_inc( &((atomic_t*)pNoteChanged)[Key] );
91     atomic_inc( (atomic_t*)pNotesChanged );
92     }
93    
94     bool InstrumentEditor::NotesChanged() {
95     int c = atomic_read( (atomic_t*)pNotesChanged );
96     atomic_sub(c, (atomic_t*)pNotesChanged );
97     return c;
98     }
99    
100     bool InstrumentEditor::NoteChanged(uint8_t Key) {
101     int c = atomic_read( &((atomic_t*)pNoteChanged)[Key] );
102     atomic_sub(c, &((atomic_t*)pNoteChanged)[Key] );
103     return c;
104     }
105    
106     bool InstrumentEditor::NoteIsActive(uint8_t Key) {
107     return atomic_read( &((atomic_t*)pNoteIsActive)[Key] );
108     }
109    
110 schoenebeck 1374 void InstrumentEditor::AddListener(InstrumentEditorListener* pListener) {
111     listeners.insert(pListener);
112     }
113    
114     void InstrumentEditor::RemoveListener(InstrumentEditorListener* pListener) {
115     listeners.erase(pListener);
116     }
117    
118     void InstrumentEditor::NotifySamplesToBeRemoved(std::set<void*> Samples) {
119     for ( // notify all registered listeners
120     std::set<InstrumentEditorListener*>::iterator iter = listeners.begin();
121     iter != listeners.end(); iter++
122     ) (*iter)->OnSamplesToBeRemoved(Samples, this);
123     }
124    
125     void InstrumentEditor::NotifySamplesRemoved() {
126     for ( // notify all registered listeners
127     std::set<InstrumentEditorListener*>::iterator iter = listeners.begin();
128     iter != listeners.end(); iter++
129     ) (*iter)->OnSamplesRemoved(this);
130     }
131    
132     void InstrumentEditor::NotifyDataStructureToBeChanged(void* pStruct, String sStructType) {
133     for ( // notify all registered listeners
134     std::set<InstrumentEditorListener*>::iterator iter = listeners.begin();
135     iter != listeners.end(); iter++
136     ) (*iter)->OnDataStructureToBeChanged(pStruct, sStructType, this);
137     }
138    
139     void InstrumentEditor::NotifyDataStructureChanged(void* pStruct, String sStructType) {
140     for ( // notify all registered listeners
141     std::set<InstrumentEditorListener*>::iterator iter = listeners.begin();
142     iter != listeners.end(); iter++
143     ) (*iter)->OnDataStructureChanged(pStruct, sStructType, this);
144     }
145    
146     void InstrumentEditor::NotifySampleReferenceChanged(void* pOldSample, void* pNewSample) {
147     for ( // notify all registered listeners
148     std::set<InstrumentEditorListener*>::iterator iter = listeners.begin();
149     iter != listeners.end(); iter++
150     ) (*iter)->OnSampleReferenceChanged(pOldSample, pNewSample, this);
151     }
152    
153     } // namespace LinuxSampler

  ViewVC Help
Powered by ViewVC