Subversion Repositories svn.mios

Rev

Rev 272 | 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.sidedit.gui.controls;
22
 
23
import java.awt.event.ActionEvent;
24
 
25
import javax.swing.BoxLayout;
26
import javax.swing.JPanel;
27
import javax.swing.JToggleButton;
28
 
628 adamjking 29
import org.midibox.sidedit.SIDSysexParameterControl;
213 tk 30
import org.midibox.utils.gui.ImageLoader;
31
import org.midibox.utils.gui.MyButtonUI;
32
 
628 adamjking 33
public class SIDSysexParameterControlWaveSelect extends
34
        SIDSysexParameterControlGUI {
213 tk 35
 
36
    private JToggleButton b0, b1, b2, b3, b4, b5, b6;
628 adamjking 37
    private int bitmask0 = (int) Math.pow(2, 4); // Off
38
    private int bitmask1 = (int) Math.pow(2, 0); // Triangle
39
    private int bitmask2 = (int) Math.pow(2, 1); // Saw
40
    private int bitmask3 = (int) Math.pow(2, 2); // Pulse
41
    private int bitmask4 = (int) Math.pow(2, 3); // Noise
42
    private int bitmask5 = (int) Math.pow(2, 5); // Sync
43
    private int bitmask6 = (int) Math.pow(2, 6); // Ringmod
44
 
45
    public SIDSysexParameterControlWaveSelect(
46
            SIDSysexParameterControl midiParameter, boolean showLabel,
213 tk 47
            String labelLocation, boolean valueBelow, boolean showValue) {
48
        super(midiParameter, showLabel, labelLocation, valueBelow, showValue);
628 adamjking 49
 
213 tk 50
        JPanel panel = new JPanel();
51
        panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
52
        panel.setOpaque(false);
53
        b0 = new JToggleButton();
54
        b1 = new JToggleButton();
55
        b2 = new JToggleButton();
56
        b3 = new JToggleButton();
57
        b4 = new JToggleButton();
58
        b5 = new JToggleButton();
59
        b6 = new JToggleButton();
628 adamjking 60
        b0.setUI(new MyButtonUI(ImageLoader.getImageIcon("off_on.png"),
61
                ImageLoader.getImageIcon("off.png")));
62
        b1.setUI(new MyButtonUI(ImageLoader.getImageIcon("tri_on.png"),
63
                ImageLoader.getImageIcon("tri.png")));
64
        b2.setUI(new MyButtonUI(ImageLoader.getImageIcon("saw_on.png"),
65
                ImageLoader.getImageIcon("saw.png")));
66
        b3.setUI(new MyButtonUI(ImageLoader.getImageIcon("pulse_on.png"),
67
                ImageLoader.getImageIcon("pulse.png")));
68
        b4.setUI(new MyButtonUI(ImageLoader.getImageIcon("noise_on.png"),
69
                ImageLoader.getImageIcon("noise.png")));
70
        b5.setUI(new MyButtonUI(ImageLoader.getImageIcon("sync_on.png"),
71
                ImageLoader.getImageIcon("sync.png")));
72
        b6.setUI(new MyButtonUI(ImageLoader.getImageIcon("ringmod_on.png"),
73
                ImageLoader.getImageIcon("ringmod.png")));
74
        // panel.add(b0); // This is the 'Off' button, which should be invisible
75
        // because it's pressed automatically in the background
213 tk 76
        panel.add(b1);
77
        panel.add(b2);
78
        panel.add(b3);
79
        panel.add(b4);
80
        panel.add(b5);
81
        panel.add(b6);
82
        add(panel);
83
        b0.addActionListener(this);
628 adamjking 84
        b1.addActionListener(this);
85
        b2.addActionListener(this);
86
        b3.addActionListener(this);
87
        b4.addActionListener(this);
88
        b5.addActionListener(this);
213 tk 89
        b6.addActionListener(this);
90
        b0.addMouseListener(this);
628 adamjking 91
        b1.addMouseListener(this);
92
        b2.addMouseListener(this);
93
        b3.addMouseListener(this);
94
        b4.addMouseListener(this);
95
        b5.addMouseListener(this);
213 tk 96
        b6.addMouseListener(this);
97
        updateGraphics();
98
    }
99
 
100
    public void actionPerformed(ActionEvent ae) {
101
        super.actionPerformed(ae);
628 adamjking 102
        if (ae.getSource().getClass() == JToggleButton.class) {
103
            if ((ae.getSource() == b4) && b4.isSelected()) { // Noise button
104
                // disables all
105
                // others
213 tk 106
                b0.setSelected(false);
107
                b1.setSelected(false);
108
                b2.setSelected(false);
109
                b3.setSelected(false);
628 adamjking 110
            } else if ((ae.getSource() == b0) && b0.isSelected()) { // Off
111
                // button
112
                // disables
113
                // all
114
                // others
213 tk 115
                b1.setSelected(false);
116
                b2.setSelected(false);
117
                b3.setSelected(false);
118
                b4.setSelected(false);
628 adamjking 119
            } else if (((ae.getSource() == b1) || (ae.getSource() == b2) || (ae
120
                    .getSource() == b3))
121
                    && (b1.isSelected() || b2.isSelected() || b3.isSelected())) {
213 tk 122
                b0.setSelected(false);
123
                b4.setSelected(false);
628 adamjking 124
            }
125
 
126
            if (!(b0.isSelected() || b1.isSelected() || b2.isSelected()
127
                    || b3.isSelected() || b4.isSelected())) {
213 tk 128
                b0.setSelected(true);
129
            }
628 adamjking 130
 
213 tk 131
            if (update) {
628 adamjking 132
                update = false;
213 tk 133
                int newval = 0;
628 adamjking 134
                newval = newval | (b0.isSelected() ? bitmask0 : 0);
135
                newval = newval | (b1.isSelected() ? bitmask1 : 0);
136
                newval = newval | (b2.isSelected() ? bitmask2 : 0);
137
                newval = newval | (b3.isSelected() ? bitmask3 : 0);
138
                newval = newval | (b4.isSelected() ? bitmask4 : 0);
139
                newval = newval | (b5.isSelected() ? bitmask5 : 0);
140
                newval = newval | (b6.isSelected() ? bitmask6 : 0);
213 tk 141
                midiParameter.setMidiValue(newval, true);
142
                for (int c = 0; c < midiParameters.size(); c++) {
628 adamjking 143
                    SIDSysexParameterControl mp = (SIDSysexParameterControl) midiParameters
144
                            .elementAt(c);
272 rutgerv 145
                    mp.setMidiValue(newval, false);
213 tk 146
                }
147
                update = true;
148
            }
628 adamjking 149
        }
150
    }
151
 
213 tk 152
    public void updateGraphics() {
153
        super.updateGraphics();
154
        if (update) {
155
            update = false;
156
            b0.setSelected((midiParameter.getMidiValue() & bitmask0) != 0);
157
            b1.setSelected((midiParameter.getMidiValue() & bitmask1) != 0);
158
            b2.setSelected((midiParameter.getMidiValue() & bitmask2) != 0);
159
            b3.setSelected((midiParameter.getMidiValue() & bitmask3) != 0);
160
            b4.setSelected((midiParameter.getMidiValue() & bitmask4) != 0);
161
            b5.setSelected((midiParameter.getMidiValue() & bitmask5) != 0);
162
            b6.setSelected((midiParameter.getMidiValue() & bitmask6) != 0);
163
            update = true;
164
        }
165
    }
166
}