Subversion Repositories svn.mios

Rev

Rev 290 | Rev 294 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
213 tk 1
/*
2
 * @(#)SIDV2librarian.java  beta1   2008/01/21
3
 *
4
 * Copyright (C) 2008    Rutger Vlek (rutgervlek@hotmail.com)
5
 *                     
6
 * This application is free software; you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation; either version 2 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This application is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this application; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
 */
20
 
21
package org.midibox.apps.SIDV2librarian;
22
 
23
import java.util.Observable;
24
import java.util.prefs.Preferences;
25
import java.util.Observer;
26
import javax.swing.JOptionPane;
27
import org.midibox.midi.MidiDeviceRouting;
28
import org.midibox.midi.gui.MidiDeviceRoutingGUI;
29
import org.midibox.sidlibr.SysExControllerDevice;
30
import org.midibox.sidlibr.SIDLibController;
31
 
32
 
33
public class SIDV2librarian{
34
    private Preferences prefs = Preferences.userNodeForPackage(this.getClass());
35
    private MidiDeviceRouting midiDeviceRouting;
36
    private SysExControllerDevice sysexControllerDevice;
37
    private SIDLibController sidLibController;
38
    private MidiDeviceRoutingGUI midiDeviceRoutingGUI;
39
    private boolean allowPrefs = false;
40
 
41
    public SIDV2librarian() {
42
        sysexControllerDevice = new SysExControllerDevice("MidiBox SID V2 Editor");
290 rutgerv 43
        midiDeviceRouting = new MidiDeviceRouting(sysexControllerDevice);  
44
        midiDeviceRoutingGUI = new MidiDeviceRoutingGUI(midiDeviceRouting);        
213 tk 45
        sidLibController = new SIDLibController(sysexControllerDevice.getSysExController());
46
 
47
        if (prefs.getInt("DEVICES_HASH", 0)==midiDeviceRouting.hashCode()) {
48
            recallConnections();           
49
        } else {
50
            JOptionPane.showMessageDialog(null,"Your MIDI configuration has changed, please check connections!","MIDI configuration changed!",JOptionPane.OK_OPTION);          
51
        }      
52
        allowPrefs = true;
53
    }
54
 
55
    public MidiDeviceRouting getMidiDeviceRouting() {
56
        return midiDeviceRouting;
57
    }
58
 
59
    public MidiDeviceRoutingGUI getMidiDeviceRoutingGUI() {
60
        return midiDeviceRoutingGUI;
61
    }
62
 
63
    public SysExControllerDevice getSysExControllerDevice() {
64
        return sysexControllerDevice;
65
    }
66
 
67
    public SIDLibController getSIDLibController() {
68
        return sidLibController;
69
    }
70
 
290 rutgerv 71
    private void recallConnections() {
72
        int input = prefs.getInt("INPUT_DEVICE", 0);
73
        int output = prefs.getInt("OUTPUT_DEVICE", 0);
74
        midiDeviceRouting.setInputDevice(input);
75
        midiDeviceRouting.setOutputDevice(output);     
213 tk 76
    }
293 rutgerv 77
 
78
    public void closeMidi() {
79
        midiDeviceRouting.closeMidi();
80
    }
213 tk 81
 
82
    public void storeConnections() {
290 rutgerv 83
        int input = midiDeviceRouting.getInputDeviceIndex();
84
        int output = midiDeviceRouting.getOutputDeviceIndex();
85
        prefs.putInt("INPUT_DEVICE", input);
86
        prefs.putInt("OUTPUT_DEVICE", output);
87
        prefs.putInt("DEVICES_HASH", midiDeviceRouting.hashCode());
213 tk 88
    }
89
}