1 //=========================================================
2 //  MusE
3 //  Linux Music Editor
4 //  $Id: mitplugin.cpp,v 1.1.1.1 2003/10/27 18:52:40 wschweer Exp $
5 //
6 //  (C) Copyright 2001 Werner Schweer (ws@seh.de)
7 //
8 //  This program is free software; you can redistribute it and/or
9 //  modify it under the terms of the GNU General Public License
10 //  as published by the Free Software Foundation; version 2 of
11 //  the License, or (at your option) any later version.
12 //
13 //  This program is distributed in the hope that it will be useful,
14 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
15 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 //  GNU General Public License for more details.
17 //
18 //  You should have received a copy of the GNU General Public License
19 //  along with this program; if not, write to the Free Software
20 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 //
22 //=========================================================
23 
24 #include <QAction>
25 
26 #include "mitplugin.h"
27 #include "app.h"
28 #include "event.h"
29 
30 #include "midiitransform.h"
31 #include "mittranspose.h"
32 #include "midifilterimpl.h"
33 #include "mrconfig.h"
34 
35 #ifdef BUILD_EXPERIMENTAL
36 #include "rhythm.h"
37 #endif
38 
39 // Forwards from header:
40 #include "xml.h"
41 #include "mpevent.h"
42 
43 namespace MusEGui {
44 
45 //---------------------------------------------------------
46 //   startMidiInputPlugin
47 //---------------------------------------------------------
48 
startMidiInputPlugin(int id)49 void MusE::startMidiInputPlugin(int id)
50       {
51       bool flag = false;
52       QWidget* w = 0;
53       QAction* act = 0;
54       if (id == 0) {
55             if (!MusEGlobal::mitPluginTranspose) {
56                   // NOTE: For deleting parentless dialogs and widgets, please add them to MusE::deleteParentlessDialogs().
57                   MusEGlobal::mitPluginTranspose = new MITPluginTranspose();
58                   MusECore::mitPlugins.push_back(MusEGlobal::mitPluginTranspose);
59                   connect(MusEGlobal::mitPluginTranspose, SIGNAL(hideWindow()),
60                      SLOT(hideMitPluginTranspose()));
61                   }
62             w = MusEGlobal::mitPluginTranspose;
63             act = midiTrpAction;
64             }
65       else if (id == 1) {
66             if (!midiInputTransform) {
67                   // NOTE: For deleting parentless dialogs and widgets, please add them to MusE::deleteParentlessDialogs().
68                   midiInputTransform = new MidiInputTransformDialog();
69                   connect(midiInputTransform, SIGNAL(hideWindow()),
70                      SLOT(hideMidiInputTransform()));
71                   }
72             w = midiInputTransform;
73             act = midiInputTrfAction;
74             }
75       else if (id == 2) {
76             if (!midiFilterConfig) {
77                   // NOTE: For deleting parentless dialogs and widgets, please add them to MusE::deleteParentlessDialogs().
78                   midiFilterConfig = new MidiFilterConfig();
79                   connect(midiFilterConfig, SIGNAL(hideWindow()),
80                      SLOT(hideMidiFilterConfig()));
81                   }
82             w = midiFilterConfig;
83             act = midiInputFilterAction;
84             }
85       else if (id == 3) {
86             if (!midiRemoteConfig) {
87                   // NOTE: For deleting parentless dialogs and widgets, please add them to MusE::deleteParentlessDialogs().
88                   midiRemoteConfig = new MRConfig();
89                   connect(midiRemoteConfig, SIGNAL(hideWindow()),
90                      SLOT(hideMidiRemoteConfig()));
91                   }
92             w = midiRemoteConfig;
93             act = midiRemoteAction;
94             }
95 #ifdef BUILD_EXPERIMENTAL
96       else if (id == 4) {
97             if (!midiRhythmGenerator) {
98                   // NOTE: For deleting parentless dialogs and widgets, please add them to MusE::deleteParentlessDialogs().
99                   midiRhythmGenerator = new RhythmGen();
100                   connect(midiRhythmGenerator, SIGNAL(hideWindow()),
101                      SLOT(hideMidiRhythmGenerator()));
102                   }
103             w = midiRhythmGenerator;
104             act = midiRhythmAction;
105             }
106 #endif
107       if (w) {
108             flag = !w->isVisible();
109             if (flag)
110                   w->show();
111             else
112                   w->hide();
113             }
114       if (act) act->setChecked(flag);
115       }
116 
hideMitPluginTranspose()117 void MusE::hideMitPluginTranspose()
118       {
119       midiTrpAction->setChecked(false);
120       }
hideMidiInputTransform()121 void MusE::hideMidiInputTransform()
122       {
123       midiInputTrfAction->setChecked(false);
124       }
hideMidiFilterConfig()125 void MusE::hideMidiFilterConfig()
126       {
127       midiInputFilterAction->setChecked(false);
128       }
hideMidiRemoteConfig()129 void MusE::hideMidiRemoteConfig()
130       {
131       midiRemoteAction->setChecked(false);
132       }
133 #ifdef BUILD_EXPERIMENTAL
hideMidiRhythmGenerator()134 void MusE::hideMidiRhythmGenerator()
135       {
136       midiRhythmAction->setChecked(false);
137       }
138 #endif
139 
140 //---------------------------------------------------------
141 //   startMidiTransformer
142 //---------------------------------------------------------
143 
startMidiTransformer()144 void MusE::startMidiTransformer()
145       {
146       if (midiTransformerDialog == 0)
147             // NOTE: For deleting parentless dialogs and widgets, please add them to MusE::deleteParentlessDialogs().
148             midiTransformerDialog = new MidiTransformerDialog;
149       midiTransformerDialog->show();
150       }
151 
152 } // namespace MusEGui
153 
154 namespace MusECore {
155 
156 MITPluginList mitPlugins;
157 
~MITPlugin()158 MITPlugin::~MITPlugin(){}
readStatus(Xml &)159 void MITPlugin::readStatus(Xml&) {}
writeStatus(int,Xml &) const160 void MITPlugin::writeStatus(int, Xml&) const {}
161 
162 //---------------------------------------------------------
163 //   processMidiInputTransformPlugins
164 //---------------------------------------------------------
165 
processMidiInputTransformPlugins(MEvent & event)166 void processMidiInputTransformPlugins(MEvent& event)
167       {
168       for (iMITPlugin i = mitPlugins.begin(); i != mitPlugins.end(); ++i)
169             (*i)->process(event);
170       }
171 
172 //---------------------------------------------------------
173 //   writeStatusMidiInputTransformPlugins
174 //---------------------------------------------------------
175 
writeStatusMidiInputTransformPlugins(int level,Xml & xml)176 void writeStatusMidiInputTransformPlugins(int level, Xml& xml)
177       {
178       for (iMITPlugin i = mitPlugins.begin(); i != mitPlugins.end(); ++i) {
179             xml.tag(level++, "mplugin name=\"%d\"");
180             (*i)->writeStatus(level, xml);
181             xml.etag(level, "mplugin");
182             }
183       }
184 
185 } // namespace MusECore
186