Subversion Repositories svn.mios

Rev

Rev 504 | Rev 666 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 504 Rev 628
Line 18... Line 18...
18
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
 */
19
 */
20
20
21
package org.midibox.sidlibr;
21
package org.midibox.sidlibr;
22
22
-
 
23
import java.awt.event.ActionEvent;
-
 
24
import java.awt.event.ActionListener;
23
import java.util.Observable;
25
import java.util.Observable;
24
import java.util.Observer;
26
import java.util.Observer;
25
27
26
import org.midibox.midi.MidiUtils;
-
 
27
import javax.sound.midi.Receiver;
-
 
28
-
 
29
import org.midibox.sidlibr.Patch;
-
 
30
import org.midibox.sidedit.SIDSysexInfo;
-
 
31
import javax.swing.*;
-
 
32
import java.awt.event.*;
-
 
33
-
 
34
import javax.sound.midi.MidiMessage;
-
 
35
import javax.sound.midi.SysexMessage;
-
 
36
import java.io.IOException;
-
 
37
public class SIDLibController extends Observable implements Observer, ActionListener  {
28
public class SIDLibController extends Observable implements Observer,
-
 
29
        ActionListener {
38
    private Object copyPasteBuffer;
30
    private Object copyPasteBuffer;
39
    private FileHandler fileHandler = new FileHandler();   
31
    private FileHandler fileHandler = new FileHandler();
40
   
32
41
    private int currentPatchNumber = 0;
33
    private int currentPatchNumber = 0;
42
    private int currentBankNumber = 0;
34
    private int currentBankNumber = 0;
43
    private int[] requestBankIndices;
35
    private int[] requestBankIndices;
44
    private Bank[] patchBanks = new Bank[7];
36
    private Bank[] patchBanks = new Bank[7];
45
    private EnsBank ensBank;
37
    private EnsBank ensBank;
46
   
38
47
    private Boolean openEditor = false;
39
    private Boolean openEditor = false;
48
    private int coresHardware = 15; // AND mask for selected cores --- we assume, that all cores are available by default
40
    private int coresHardware = 15; // AND mask for selected cores --- we
-
 
41
    // assume, that all cores are available by
-
 
42
    // default
49
    private int coresSelected = 1;
43
    private int coresSelected = 1;
50
       
44
51
    private SysExController sysexController;
45
    private SysExController sysexController;
52
   
46
53
    public SIDLibController(SysExController sysexController) {
47
    public SIDLibController(SysExController sysexController) {
Line 56... Line 50...
56
        //ensBank = new EnsBank(sysexController.getReceiver());
50
        // ensBank = new EnsBank(sysexController.getReceiver());
57
        for (int i=0; i<patchBanks.length;i++) {
51
        for (int i = 0; i < patchBanks.length; i++) {
58
            patchBanks[i] = new Bank(sysexController.getReceiver());
52
            patchBanks[i] = new Bank(sysexController.getReceiver());
59
        }
53
        }
60
        requestBankIndices = new int[128];
54
        requestBankIndices = new int[128];
61
        for(int i=0;i<requestBankIndices.length;i++) {requestBankIndices[i] = i;}
55
        for (int i = 0; i < requestBankIndices.length; i++) {
-
 
56
            requestBankIndices[i] = i;
-
 
57
        }
62
    }
58
    }
63
   
59
64
    public void scanHardware(){
60
    public void scanHardware() {
65
        sysexController.scanHardware();
61
        sysexController.scanHardware();
66
    }
62
    }
Line 81... Line 77...
81
            clearChanged();
77
            clearChanged();
82
        } else {
78
        } else {
83
            if (sysexController.isDone()) {
79
            if (sysexController.isDone()) {
84
                // Sends notification to SIDV2librarianGUI when done...
80
                // Sends notification to SIDV2librarianGUI when done...
85
                openEditor = true;
81
                openEditor = true;
86
                sysexController.dumpPatchToBuffer(patchBanks[currentBankNumber].getPatchAt(currentPatchNumber), getCores());
82
                sysexController.dumpPatchToBuffer(patchBanks[currentBankNumber]
-
 
83
                        .getPatchAt(currentPatchNumber), getCores());
87
            }
84
            }
88
        }
85
        }
89
    }
86
    }
90
   
87
91
    public Patch getCurrentPatch() {
88
    public Patch getCurrentPatch() {
Line 120... Line 117...
120
        patchBanks[bankNumber].setPatchAt(patchNumber,p);          
117
        patchBanks[bankNumber].setPatchAt(patchNumber, p);
121
    }
118
    }
122
119
123
    // ****************** Edit functions ***********************
120
    // ****************** Edit functions ***********************
124
    public void editCopy() {
121
    public void editCopy() {
125
        copyPasteBuffer = patchBanks[currentBankNumber].getPatchAt(currentPatchNumber);    
122
        copyPasteBuffer = patchBanks[currentBankNumber]
-
 
123
                .getPatchAt(currentPatchNumber);
126
    }
124
    }
127
   
125
128
    public void editPaste() {
126
    public void editPaste() {
-
 
127
        if ((copyPasteBuffer.getClass() == Patch.class)
-
 
128
                && (patchBanks[currentBankNumber]
129
        if ((copyPasteBuffer.getClass()==Patch.class) && (patchBanks[currentBankNumber].getPatchAt(currentPatchNumber).getClass()==Patch.class)) {
129
                        .getPatchAt(currentPatchNumber).getClass() == Patch.class)) {
130
            patchBanks[currentBankNumber].setPatchAt(currentPatchNumber,((Patch)copyPasteBuffer).clone());
130
            patchBanks[currentBankNumber].setPatchAt(currentPatchNumber,
-
 
131
                    ((Patch) copyPasteBuffer).clone());
131
        }      
132
        }
132
        setChanged();
133
        setChanged();
133
        notifyObservers("Data changed");
134
        notifyObservers("Data changed");
134
        clearChanged();
135
        clearChanged();
135
    }
136
    }
Line 143... Line 144...
143
         notifyObservers("Data changed");
144
        notifyObservers("Data changed");
144
         clearChanged();
145
        clearChanged();
145
    }
146
    }
146
   
147
147
    public void editCut() {
148
    public void editCut() {
148
        copyPasteBuffer = patchBanks[currentBankNumber].getPatchAt(currentPatchNumber);
149
        copyPasteBuffer = patchBanks[currentBankNumber]
-
 
150
                .getPatchAt(currentPatchNumber);
149
        patchBanks[currentBankNumber].setPatchAt(currentPatchNumber, new Patch(sysexController.getReceiver()));
151
        patchBanks[currentBankNumber].setPatchAt(currentPatchNumber, new Patch(
-
 
152
                sysexController.getReceiver()));
150
        setChanged();
153
        setChanged();
151
        notifyObservers("Data changed");
154
        notifyObservers("Data changed");
152
        clearChanged();
155
        clearChanged();
153
    }
156
    }
154
   
157
155
    public void editClear() {
158
    public void editClear() {
156
        patchBanks[currentBankNumber].setPatchAt(currentPatchNumber, new Patch(sysexController.getReceiver()));
159
        patchBanks[currentBankNumber].setPatchAt(currentPatchNumber, new Patch(
-
 
160
                sysexController.getReceiver()));
157
        setChanged();
161
        setChanged();
158
        notifyObservers("Data changed");
162
        notifyObservers("Data changed");
159
        clearChanged();
163
        clearChanged();
160
    }
164
    }
161
   
165
Line 171... Line 175...
171
        notifyObservers("Data changed");
175
        notifyObservers("Data changed");
172
        clearChanged();
176
        clearChanged();
173
    }
177
    }
174
   
178
175
    public void initCurrentPatch(Object object) {
179
    public void initCurrentPatch(Object object) {
176
        patchBanks[currentBankNumber].setPatchAt(currentPatchNumber, new Patch(sysexController.getReceiver()));
180
        patchBanks[currentBankNumber].setPatchAt(currentPatchNumber, new Patch(
-
 
181
                sysexController.getReceiver()));
177
        patchBanks[currentBankNumber].getPatchAt(currentPatchNumber).setEngine(object);
182
        patchBanks[currentBankNumber].getPatchAt(currentPatchNumber).setEngine(
-
 
183
                object);
178
        setChanged();
184
        setChanged();
179
        notifyObservers("Data changed");   
185
        notifyObservers("Data changed");
180
        clearChanged();
186
        clearChanged();
181
    }
187
    }
182
   
188
Line 184... Line 190...
184
    public void update(Observable observable, Object object) {
190
    public void update(Observable observable, Object object) {
185
        if (object=="Hardware scan") {
191
        if (object == "Hardware scan") {
186
            coresHardware = (Integer)sysexController.pickMeUp;
192
            coresHardware = (Integer) sysexController.pickMeUp;
187
            System.out.println(coresHardware);
193
            System.out.println(coresHardware);
188
        } else if (object=="Patch ready") {
194
        } else if (object == "Patch ready") {
-
 
195
            patchBanks[sysexController.requestBank].setPatchAt(
189
            patchBanks[sysexController.requestBank].setPatchAt(sysexController.requestPatch[sysexController.requestCount], (Patch)sysexController.pickMeUp);
196
                    sysexController.requestPatch[sysexController.requestCount],
-
 
197
                    (Patch) sysexController.pickMeUp);
190
            setChanged();
198
            setChanged();
191
            notifyObservers("Data changed");
199
            notifyObservers("Data changed");
192
            clearChanged();
200
            clearChanged();
193
        } else if (object=="Ensemble ready") {
201
        } else if (object == "Ensemble ready") {
194
            //ensBanks[currentBankNumber].setEnsAt(currentPatchNumber, (Ensemble)sysexController.pickMeUp);
202
            // ensBanks[currentBankNumber].setEnsAt(currentPatchNumber,
-
 
203
            // (Ensemble)sysexController.pickMeUp);
195
            setChanged();
204
            setChanged();
196
            notifyObservers("Data changed");
205
            notifyObservers("Data changed");
197
            clearChanged();        
206
            clearChanged();
198
        } else if ((object=="Dump completed")&&(openEditor)) {
207
        } else if ((object == "Dump completed") && (openEditor)) {
199
            openEditor = false;
208
            openEditor = false;
Line 203... Line 212...
203
        }
212
        }
204
    }
213
    }
205
   
214
206
    public void actionPerformed(ActionEvent ae) {
215
    public void actionPerformed(ActionEvent ae) {
207
        if (ae.getActionCommand().equals("Load bank")) {
216
        if (ae.getActionCommand().equals("Load bank")) {
208
            Bank tempBank = fileHandler.loadPatchBank(sysexController.getReceiver());
217
            Bank tempBank = fileHandler.loadPatchBank(sysexController
-
 
218
                    .getReceiver());
209
            if (tempBank!=null) {
219
            if (tempBank != null) {
210
                patchBanks[currentBankNumber] = tempBank;
220
                patchBanks[currentBankNumber] = tempBank;
211
                setChanged();
221
                setChanged();
212
                notifyObservers("Data changed");
222
                notifyObservers("Data changed");
213
                clearChanged();
223
                clearChanged();
214
            }
224
            }
215
        } else if (ae.getActionCommand().equals("Save bank")) {
225
        } else if (ae.getActionCommand().equals("Save bank")) {
216
            fileHandler.savePatchBank(patchBanks[currentBankNumber], currentBankNumber);           
226
            fileHandler.savePatchBank(patchBanks[currentBankNumber],
-
 
227
                    currentBankNumber);
217
        } else if (ae.getActionCommand().equals("Load patch")) {
228
        } else if (ae.getActionCommand().equals("Load patch")) {
218
            Patch tempPatch = fileHandler.loadPatch(sysexController.getReceiver());
229
            Patch tempPatch = fileHandler.loadPatch(sysexController
-
 
230
                    .getReceiver());
219
            if (tempPatch!=null) {
231
            if (tempPatch != null) {
220
                patchBanks[currentBankNumber].setPatchAt(currentPatchNumber, tempPatch);
232
                patchBanks[currentBankNumber].setPatchAt(currentPatchNumber,
-
 
233
                        tempPatch);
221
                setChanged();
234
                setChanged();
222
                notifyObservers("Data changed");
235
                notifyObservers("Data changed");
223
                clearChanged();
236
                clearChanged();
224
            }
237
            }
225
        } else if (ae.getActionCommand().equals("Save patch")) {
238
        } else if (ae.getActionCommand().equals("Save patch")) {
-
 
239
            fileHandler.savePatch(patchBanks[currentBankNumber]
226
            fileHandler.savePatch(patchBanks[currentBankNumber].getPatchAt(currentPatchNumber), currentBankNumber, currentPatchNumber);        
240
                    .getPatchAt(currentPatchNumber), currentBankNumber,
-
 
241
                    currentPatchNumber);
227
        } else if (ae.getActionCommand().equals("Edit")) {
242
        } else if (ae.getActionCommand().equals("Edit")) {
228
            editCurrentPatch();
243
            editCurrentPatch();
229
        } else if (ae.getActionCommand().equals("Rename")) {
244
        } else if (ae.getActionCommand().equals("Rename")) {
230
            editRename();
245
            editRename();
231
        } else if (ae.getActionCommand().equals("Cut")) {
246
        } else if (ae.getActionCommand().equals("Cut")) {
Line 247... Line 262...
247
        } else if (ae.getActionCommand().equals("Init current bank")) {
262
        } else if (ae.getActionCommand().equals("Init current bank")) {
248
            initCurrentBank();
263
            initCurrentBank();
249
        } else if (ae.getActionCommand().equals("Scan hardware")) {
264
        } else if (ae.getActionCommand().equals("Scan hardware")) {
250
            sysexController.scanHardware();
265
            sysexController.scanHardware();
251
        } else if (ae.getActionCommand().equals("Transmit patch to buffer")) {
266
        } else if (ae.getActionCommand().equals("Transmit patch to buffer")) {
252
            sysexController.dumpPatchToBuffer(patchBanks[currentBankNumber].getPatchAt(currentPatchNumber), getCores());           
267
            sysexController.dumpPatchToBuffer(patchBanks[currentBankNumber]
-
 
268
                    .getPatchAt(currentPatchNumber), getCores());
253
        } else if (ae.getActionCommand().equals("Transmit patch to memory")) {
269
        } else if (ae.getActionCommand().equals("Transmit patch to memory")) {
-
 
270
            sysexController.dumpPatch(
-
 
271
                    new Patch[] { patchBanks[currentBankNumber]
-
 
272
                            .getPatchAt(currentPatchNumber) },
254
            sysexController.dumpPatch(new Patch[]{patchBanks[currentBankNumber].getPatchAt(currentPatchNumber)}, new int[]{currentPatchNumber}, currentBankNumber);        
273
                    new int[] { currentPatchNumber }, currentBankNumber);
255
        } else if (ae.getActionCommand().equals("Transmit bank to memory")) {
274
        } else if (ae.getActionCommand().equals("Transmit bank to memory")) {
256
            sysexController.dumpPatchBank(patchBanks[currentBankNumber], currentBankNumber);
275
            sysexController.dumpPatchBank(patchBanks[currentBankNumber],
-
 
276
                    currentBankNumber);
257
        } else if (ae.getActionCommand().equals("Receive patch from buffer")) {
277
        } else if (ae.getActionCommand().equals("Receive patch from buffer")) {
258
            sysexController.requestPatchBuffer(0, currentPatchNumber, currentBankNumber);              
278
            sysexController.requestPatchBuffer(0, currentPatchNumber,
-
 
279
                    currentBankNumber);
259
        } else if (ae.getActionCommand().equals("Receive patch from memory")) {                      
280
        } else if (ae.getActionCommand().equals("Receive patch from memory")) {
260
            sysexController.requestPatch(new int[]{currentPatchNumber}, currentBankNumber);            
281
            sysexController.requestPatch(new int[] { currentPatchNumber },
-
 
282
                    currentBankNumber);
261
        } else if (ae.getActionCommand().equals("Receive bank from memory")) {
283
        } else if (ae.getActionCommand().equals("Receive bank from memory")) {
262
            sysexController.requestPatch(requestBankIndices, currentBankNumber);               
284
            sysexController.requestPatch(requestBankIndices, currentBankNumber);
263
        }
285
        }
264
    }
286
    }
265
}
287
}