Subversion Repositories svn.mios

Rev

Rev 250 | Rev 696 | 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.sidedit.gui.drum;
22
 
23
import java.awt.BorderLayout;
628 adamjking 24
import java.awt.Dimension;
213 tk 25
import java.awt.FlowLayout;
26
import java.awt.Font;
27
import java.awt.GridBagConstraints;
28
import java.awt.GridBagLayout;
29
import java.awt.event.ActionEvent;
30
import java.awt.event.ActionListener;
31
import java.util.Vector;
32
 
33
import javax.swing.BorderFactory;
34
import javax.swing.BoxLayout;
35
import javax.swing.JComboBox;
36
import javax.swing.JLabel;
37
import javax.swing.JPanel;
38
 
39
import org.midibox.sidedit.SIDSysexParameterControl;
628 adamjking 40
import org.midibox.sidedit.gui.SequencerButton;
41
import org.midibox.sidedit.gui.controls.SIDSysexParameterControlGUI;
42
 
43
public class SequencerGUI extends JPanel implements ActionListener {
44
    private JPanel seqPanel, currentPanel, seq1, seq2, seq3, seq4, seq5, seq6,
45
            seq7, seq8;
213 tk 46
    private JComboBox combo;
628 adamjking 47
    private int[] snapvals = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
48
 
213 tk 49
    protected SequencerGUI(Vector V1GUIv, Vector V2GUIv) {
50
        setLayout(new BorderLayout());
51
        this.setOpaque(false);
628 adamjking 52
 
53
        JPanel mainPanel = new JPanel();
213 tk 54
        mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
55
        mainPanel.setOpaque(false);
628 adamjking 56
 
213 tk 57
        seqPanel = new JPanel();
58
        seqPanel.setLayout(new BoxLayout(seqPanel, BoxLayout.X_AXIS));
59
        seqPanel.setBorder(BorderFactory.createEtchedBorder());
60
        seqPanel.setBorder(BorderFactory.createTitledBorder("Sequencer data"));
61
        seqPanel.setOpaque(false);
628 adamjking 62
 
213 tk 63
        JPanel comboPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0));
64
        comboPanel.setOpaque(false);
628 adamjking 65
        String[] s = { "Sequence #1", "Sequence #2", "Sequence #3",
66
                "Sequence #4", "Sequence #5", "Sequence #6", "Sequence #7",
67
                "Sequence #8" };
213 tk 68
        combo = new JComboBox(s);
628 adamjking 69
        combo.setPreferredSize(new Dimension(110, 20));
213 tk 70
        combo.setFont(new Font("sansserif", Font.BOLD, 11));
71
        combo.addActionListener(this);
72
        comboPanel.add(combo);
628 adamjking 73
        seqPanel.add(comboPanel);
74
 
75
        seq1 = createSeqData(V2GUIv, 0);
76
        seq2 = createSeqData(V2GUIv, 1);
77
        seq3 = createSeqData(V2GUIv, 2);
78
        seq4 = createSeqData(V2GUIv, 3);
79
        seq5 = createSeqData(V2GUIv, 4);
80
        seq6 = createSeqData(V2GUIv, 5);
81
        seq7 = createSeqData(V2GUIv, 6);
82
        seq8 = createSeqData(V2GUIv, 7);
83
 
213 tk 84
        currentPanel = seq1;
85
        seqPanel.add(currentPanel);
628 adamjking 86
 
87
        mainPanel.add(createConfig(V1GUIv, "Sequencer setup"));
213 tk 88
        mainPanel.add(seqPanel);
628 adamjking 89
        this.add(mainPanel, BorderLayout.NORTH);
213 tk 90
    }
628 adamjking 91
 
92
    protected JPanel createConfig(Vector vGUI, String s) {
213 tk 93
        JPanel configPanel = new JPanel();
628 adamjking 94
        configPanel.setLayout(new BoxLayout(configPanel, BoxLayout.X_AXIS));
213 tk 95
        configPanel.setBorder(BorderFactory.createEtchedBorder());
96
        configPanel.setBorder(BorderFactory.createTitledBorder(s));
97
        configPanel.setOpaque(false);
628 adamjking 98
 
213 tk 99
        configPanel.add((SIDSysexParameterControlGUI) vGUI.elementAt(3));
100
        configPanel.add((SIDSysexParameterControlGUI) vGUI.elementAt(4));
628 adamjking 101
        configPanel.add((SIDSysexParameterControlGUI) vGUI.elementAt(0));
213 tk 102
        configPanel.add((SIDSysexParameterControlGUI) vGUI.elementAt(1));
628 adamjking 103
        configPanel.add((SIDSysexParameterControlGUI) vGUI.elementAt(2));
213 tk 104
        return configPanel;
628 adamjking 105
    }
213 tk 106
 
628 adamjking 107
    protected JPanel createSeqData(Vector vGUI, int seqNr) {
213 tk 108
        JPanel chanPanel = new JPanel();
628 adamjking 109
        chanPanel.setLayout(new GridBagLayout());
213 tk 110
        chanPanel.setOpaque(false);
628 adamjking 111
 
112
        GridBagConstraints c = new GridBagConstraints();
113
        c.fill = GridBagConstraints.HORIZONTAL;
213 tk 114
        c.anchor = GridBagConstraints.CENTER;
628 adamjking 115
 
213 tk 116
        // Loop over all channels
628 adamjking 117
        for (int chan = 0; chan < 8; chan++) {
213 tk 118
            // Dummy panel to fill
628 adamjking 119
            c.gridx = 0;
120
            c.gridy = (2 * chan) + 2;
121
            c.gridheight = 1;
213 tk 122
            JPanel transp = new JPanel();
123
            transp.setOpaque(false);
124
            chanPanel.add(transp, c);
628 adamjking 125
 
213 tk 126
            // Row labels
628 adamjking 127
            c.gridwidth = 2;
128
            if (chan == 0) {
129
                c.gridx = 0;
130
                c.gridy = (2 * chan);
131
                chanPanel.add(createSeqLabel("Step"), c);
132
            }
133
            c.gridx = 0;
134
            c.gridy = (2 * chan) + 1;
135
            chanPanel.add(createSeqLabel("Chan." + Integer.toString(chan + 1)),
136
                    c);
137
            c.gridwidth = 1;
138
 
139
            int offset = (32 * chan) + (seqNr * 256);
140
            for (int col = 0; col < 16; col++) {
213 tk 141
                // Column labels
628 adamjking 142
                if (chan == 0) {
143
                    JLabel label = new JLabel(Integer.toString(col + 1));
213 tk 144
                    label.setHorizontalAlignment(JLabel.CENTER);
628 adamjking 145
                    label.setFont(new Font("serif", Font.BOLD, 10));
213 tk 146
                    label.setOpaque(false);
628 adamjking 147
                    c.gridx = col + 2;
148
                    c.gridy = (2 * chan);
213 tk 149
                    chanPanel.add(label, c);
150
                }
628 adamjking 151
 
250 rutgerv 152
                // Buttons
628 adamjking 153
                c.gridx = col + 2;
154
                c.gridy = 1 + (2 * chan);
155
                SIDSysexParameterControl mp1 = ((SIDSysexParameterControlGUI) vGUI
156
                        .elementAt(0 + offset + col)).getMidiParameter();
157
                SIDSysexParameterControl mp2 = ((SIDSysexParameterControlGUI) vGUI
158
                        .elementAt(0 + offset + col + 16)).getMidiParameter();
159
                chanPanel.add(new SequencerButton(mp1, mp2), c);
160
            }
213 tk 161
        }
628 adamjking 162
        return chanPanel;
163
    }
164
 
213 tk 165
    public JLabel createSeqLabel(String s) {
166
        JLabel label = new JLabel(s);
167
        label.setVerticalAlignment(JLabel.CENTER);
628 adamjking 168
        label.setFont(new Font("serif", Font.BOLD, 10));
169
        label.setOpaque(false);
170
        label.setPreferredSize(new Dimension(35, 10));
213 tk 171
        return label;
172
    }
628 adamjking 173
 
213 tk 174
    public void actionPerformed(ActionEvent ae) {
628 adamjking 175
        if (ae.getSource() == combo) {
213 tk 176
            seqPanel.remove(currentPanel);
177
            switch (combo.getSelectedIndex()) {
628 adamjking 178
            case 0:
179
                currentPanel = seq1;
180
                break;
181
            case 1:
182
                currentPanel = seq2;
183
                break;
184
            case 2:
185
                currentPanel = seq3;
186
                break;
187
            case 3:
188
                currentPanel = seq4;
189
                break;
190
            case 4:
191
                currentPanel = seq5;
192
                break;
193
            case 5:
194
                currentPanel = seq6;
195
                break;
196
            case 6:
197
                currentPanel = seq7;
198
                break;
199
            case 7:
200
                currentPanel = seq8;
201
                break;
213 tk 202
            }
203
            seqPanel.add(currentPanel);
204
            this.repaint();
205
        }
206
    }
207
}