1 |
schoenebeck |
1374 |
/*************************************************************************** |
2 |
|
|
* * |
3 |
|
|
* Copyright (C) 2007 Christian Schoenebeck * |
4 |
|
|
* * |
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 |
|
|
|
25 |
schoenebeck |
1374 |
#include <algorithm> |
26 |
|
|
#include <functional> |
27 |
|
|
|
28 |
|
|
namespace LinuxSampler { |
29 |
|
|
|
30 |
|
|
InstrumentEditor::InstrumentEditor() : Thread(false, false, -1, 0) { |
31 |
|
|
pInstrument = NULL; |
32 |
|
|
} |
33 |
|
|
|
34 |
|
|
void InstrumentEditor::Launch(void* pInstrument, String sTypeName, String sTypeVersion) { |
35 |
|
|
dmsg(1,("InstrumentEditor::Launch(instr=%x,type=%s,version=%s)\n", pInstrument, sTypeName.c_str(), sTypeVersion.c_str())); |
36 |
|
|
// prepare the editor's mandatory parameters |
37 |
|
|
this->pInstrument = pInstrument; |
38 |
|
|
this->sTypeName = sTypeName; |
39 |
|
|
this->sTypeVersion = sTypeVersion; |
40 |
|
|
// start the editor in its own thread |
41 |
|
|
StartThread(); |
42 |
|
|
} |
43 |
|
|
|
44 |
|
|
int InstrumentEditor::Main() { |
45 |
|
|
dmsg(1,("InstrumentEditor::Main()\n")); |
46 |
|
|
// run the editor's main loop |
47 |
|
|
int iResult = Main(pInstrument, sTypeName, sTypeVersion); |
48 |
|
|
// reset editor parameters |
49 |
|
|
this->pInstrument = NULL; |
50 |
|
|
this->sTypeName = ""; |
51 |
|
|
this->sTypeVersion = ""; |
52 |
|
|
dmsg(1,("Instrument editor '%s' returned with exit status %d\n", Name().c_str(), iResult)); |
53 |
|
|
// notify all registered listeners |
54 |
|
|
std::for_each( |
55 |
|
|
listeners.begin(), listeners.end(), |
56 |
|
|
std::bind2nd(std::mem_fun(&InstrumentEditorListener::OnInstrumentEditorQuit), this) |
57 |
|
|
); |
58 |
|
|
// done |
59 |
|
|
return iResult; |
60 |
|
|
} |
61 |
|
|
|
62 |
|
|
void InstrumentEditor::AddListener(InstrumentEditorListener* pListener) { |
63 |
|
|
listeners.insert(pListener); |
64 |
|
|
} |
65 |
|
|
|
66 |
|
|
void InstrumentEditor::RemoveListener(InstrumentEditorListener* pListener) { |
67 |
|
|
listeners.erase(pListener); |
68 |
|
|
} |
69 |
|
|
|
70 |
|
|
void InstrumentEditor::NotifySamplesToBeRemoved(std::set<void*> Samples) { |
71 |
|
|
for ( // notify all registered listeners |
72 |
|
|
std::set<InstrumentEditorListener*>::iterator iter = listeners.begin(); |
73 |
|
|
iter != listeners.end(); iter++ |
74 |
|
|
) (*iter)->OnSamplesToBeRemoved(Samples, this); |
75 |
|
|
} |
76 |
|
|
|
77 |
|
|
void InstrumentEditor::NotifySamplesRemoved() { |
78 |
|
|
for ( // notify all registered listeners |
79 |
|
|
std::set<InstrumentEditorListener*>::iterator iter = listeners.begin(); |
80 |
|
|
iter != listeners.end(); iter++ |
81 |
|
|
) (*iter)->OnSamplesRemoved(this); |
82 |
|
|
} |
83 |
|
|
|
84 |
|
|
void InstrumentEditor::NotifyDataStructureToBeChanged(void* pStruct, String sStructType) { |
85 |
|
|
for ( // notify all registered listeners |
86 |
|
|
std::set<InstrumentEditorListener*>::iterator iter = listeners.begin(); |
87 |
|
|
iter != listeners.end(); iter++ |
88 |
|
|
) (*iter)->OnDataStructureToBeChanged(pStruct, sStructType, this); |
89 |
|
|
} |
90 |
|
|
|
91 |
|
|
void InstrumentEditor::NotifyDataStructureChanged(void* pStruct, String sStructType) { |
92 |
|
|
for ( // notify all registered listeners |
93 |
|
|
std::set<InstrumentEditorListener*>::iterator iter = listeners.begin(); |
94 |
|
|
iter != listeners.end(); iter++ |
95 |
|
|
) (*iter)->OnDataStructureChanged(pStruct, sStructType, this); |
96 |
|
|
} |
97 |
|
|
|
98 |
|
|
void InstrumentEditor::NotifySampleReferenceChanged(void* pOldSample, void* pNewSample) { |
99 |
|
|
for ( // notify all registered listeners |
100 |
|
|
std::set<InstrumentEditorListener*>::iterator iter = listeners.begin(); |
101 |
|
|
iter != listeners.end(); iter++ |
102 |
|
|
) (*iter)->OnSampleReferenceChanged(pOldSample, pNewSample, this); |
103 |
|
|
} |
104 |
|
|
|
105 |
|
|
} // namespace LinuxSampler |