~ubuntu-branches/ubuntu/oneiric/tuxguitar/oneiric

« back to all changes in this revision

Viewing changes to src/org/herac/tuxguitar/gui/actions/track/ChangeTrackPropertiesAction.java

  • Committer: Bazaar Package Importer
  • Author(s): Philippe Coval
  • Date: 2007-02-04 01:41:23 UTC
  • Revision ID: james.westby@ubuntu.com-20070204014123-9pv7okph0iaiqkvw
Tags: upstream-0.9.1
ImportĀ upstreamĀ versionĀ 0.9.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Created on 17-dic-2005
 
3
 *
 
4
 * TODO To change the template for this generated file go to
 
5
 * Window - Preferences - Java - Code Style - Code Templates
 
6
 */
 
7
package org.herac.tuxguitar.gui.actions.track;
 
8
 
 
9
import java.util.ArrayList;
 
10
import java.util.List;
 
11
 
 
12
import javax.sound.midi.Instrument;
 
13
import javax.sound.midi.Soundbank;
 
14
 
 
15
import org.eclipse.swt.SWT;
 
16
import org.eclipse.swt.events.PaintEvent;
 
17
import org.eclipse.swt.events.PaintListener;
 
18
import org.eclipse.swt.events.SelectionAdapter;
 
19
import org.eclipse.swt.events.SelectionEvent;
 
20
import org.eclipse.swt.events.TypedEvent;
 
21
import org.eclipse.swt.graphics.Color;
 
22
import org.eclipse.swt.graphics.RGB;
 
23
import org.eclipse.swt.layout.GridData;
 
24
import org.eclipse.swt.layout.GridLayout;
 
25
import org.eclipse.swt.widgets.Button;
 
26
import org.eclipse.swt.widgets.ColorDialog;
 
27
import org.eclipse.swt.widgets.Combo;
 
28
import org.eclipse.swt.widgets.Composite;
 
29
import org.eclipse.swt.widgets.Group;
 
30
import org.eclipse.swt.widgets.Label;
 
31
import org.eclipse.swt.widgets.Shell;
 
32
import org.eclipse.swt.widgets.Spinner;
 
33
import org.eclipse.swt.widgets.Text;
 
34
import org.herac.tuxguitar.gui.TuxGuitar;
 
35
import org.herac.tuxguitar.gui.actions.Action;
 
36
import org.herac.tuxguitar.gui.editors.TablatureEditor;
 
37
import org.herac.tuxguitar.gui.editors.tab.SongTrackCoords;
 
38
import org.herac.tuxguitar.gui.helper.SyncThread;
 
39
import org.herac.tuxguitar.gui.undo.undoables.JoinedUndoable;
 
40
import org.herac.tuxguitar.gui.undo.undoables.track.UndoableInfoTrack;
 
41
import org.herac.tuxguitar.gui.undo.undoables.track.UndoableInstrumentTrack;
 
42
import org.herac.tuxguitar.gui.undo.undoables.track.UndoableTrackGeneric;
 
43
import org.herac.tuxguitar.song.models.InstrumentString;
 
44
import org.herac.tuxguitar.song.models.RGBColor;
 
45
import org.herac.tuxguitar.song.models.SongTrack;
 
46
 
 
47
/**
 
48
 * @author julian
 
49
 * 
 
50
 * TODO To change the template for this generated type comment go to Window - Preferences - Java - Code Style - Code Templates
 
51
 */
 
52
public class ChangeTrackPropertiesAction extends Action {
 
53
    public static final String NAME = "action.track.properties";
 
54
    
 
55
    private static final String[] NOTE_NAMES = new String[]{"C","C#","D","D#","E","F","F#","G","G#","A","Bb","B"};
 
56
    
 
57
        //private static final int MINIMUN_WIDTH = 200;
 
58
        //private static final int MINIMUN_HEIGHT = 10;     
 
59
    
 
60
    private static final int MINIMUN_LEFT_CONTROLS_WIDTH = 180;
 
61
    
 
62
    private static final int MINIMUN_BUTTON_WIDTH = 80;
 
63
    private static final int MINIMUN_BUTTON_HEIGHT = 25;
 
64
    
 
65
    private static final int MAX_STRINGS = 7;
 
66
    private static final int MIN_STRINGS = 4;
 
67
    private static final int MAX_OCTAVES = 10;
 
68
    private static final int MAX_NOTES = 12;
 
69
    private Shell dialog;
 
70
    private Text nameText;
 
71
    private RGBColor trackColor;
 
72
    private List tempStrings;    
 
73
    private Spinner stringCountSpinner;
 
74
    private Combo[] stringCombos = new Combo[MAX_STRINGS];
 
75
    private Combo offsetCombo;
 
76
    private int stringCount;
 
77
    private Combo instrumentCombo;
 
78
    private Button percussionCheckBox;
 
79
    
 
80
    public ChangeTrackPropertiesAction(TablatureEditor tablatureEditor) {
 
81
        super(NAME,true, tablatureEditor);
 
82
    }
 
83
 
 
84
    public boolean doAction(TypedEvent e) {
 
85
        showDialog(getEditor().getTablature().getShell());
 
86
        return true;
 
87
    }
 
88
 
 
89
    public void showDialog(Shell shell) {
 
90
        SongTrackCoords trackCoords = getEditor().getTablature().getCaret().getSongTrackCoords();
 
91
        if (trackCoords != null) {
 
92
            this.stringCount = trackCoords.getTrack().getStrings().size();
 
93
            this.trackColor = (RGBColor) trackCoords.getTrack().getColor().clone();
 
94
            this.initTempStrings(trackCoords.getTrack().getStrings());
 
95
 
 
96
            this.dialog = new Shell(shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
 
97
            this.dialog.setLayout(new GridLayout());
 
98
            this.dialog.setText(TuxGuitar.getProperty("track.properties"));
 
99
            
 
100
            Composite composite = new Composite(dialog,SWT.NONE);
 
101
            composite.setLayout(new GridLayout(2,false));
 
102
            composite.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
 
103
            
 
104
            Composite left = new Composite(composite,SWT.NONE);
 
105
            left.setLayout(new GridLayout());
 
106
            left.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));            
 
107
            Composite right = new Composite(composite,SWT.NONE);
 
108
            right.setLayout(new GridLayout());
 
109
            right.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
 
110
            Composite bottom = new Composite(dialog,SWT.NONE);
 
111
            bottom.setLayout(new GridLayout());
 
112
            bottom.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));            
 
113
            
 
114
            //GENERAL            
 
115
            initTrackInfo(makeGroup(left,1,TuxGuitar.getProperty("track.properties.general")), trackCoords);
 
116
 
 
117
            //INSTRUMENT
 
118
            initInstrumentFields(makeGroup(left,1,TuxGuitar.getProperty("instrument.instrument")), trackCoords);
 
119
            
 
120
            //TUNNING
 
121
            initTunningInfo(makeGroup(right,2,TuxGuitar.getProperty("tunning")), trackCoords);
 
122
 
 
123
            //BUTTONS
 
124
            initButtons(bottom);
 
125
 
 
126
            updateTunningGroup(!trackCoords.getTrack().isPercussionTrack());
 
127
            
 
128
            dialog.pack();
 
129
            dialog.open();
 
130
 
 
131
            int x = shell.getBounds().x + (shell.getBounds().width - dialog.getSize().x) / 2;
 
132
            int y = shell.getBounds().y + (shell.getBounds().height - dialog.getSize().y) / 2;
 
133
            dialog.setLocation(x, y);
 
134
                        
 
135
                while (!dialog.isDisposed()) {
 
136
                if (!dialog.getDisplay().readAndDispatch()) {
 
137
                        dialog.getDisplay().sleep();
 
138
                }
 
139
            }
 
140
        }
 
141
    }
 
142
    
 
143
        private Group makeGroup(Composite parent,int horizontalSpan,String text){
 
144
        Group group = new Group(parent, SWT.SHADOW_ETCHED_IN);
 
145
        group.setLayoutData(makeGridData(horizontalSpan));
 
146
        group.setText(text);
 
147
        
 
148
        return group;
 
149
        }
 
150
        
 
151
        private GridData makeGridData(int horizontalSpan){
 
152
                GridData data = new GridData(SWT.FILL,SWT.FILL,true,true);              
 
153
                data.horizontalSpan = horizontalSpan;           
 
154
                return data;
 
155
        }       
 
156
 
 
157
    private void initTrackInfo(Composite composite,SongTrackCoords trackCoords) {                       
 
158
        composite.setLayout(new GridLayout(/*2,false*/));       
 
159
        Composite top = new Composite(composite, SWT.NONE);
 
160
        top.setLayout(new GridLayout(/*2,false*/));
 
161
        top.setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,true));        
 
162
        Composite bottom = new Composite(composite, SWT.NONE);
 
163
        bottom.setLayout(new GridLayout(/*2,false*/));
 
164
        bottom.setLayoutData(new GridData(SWT.FILL,SWT.BOTTOM,true,true));      
 
165
        
 
166
        //-----------------------NAME---------------------------------
 
167
        Label nameLabel = new Label(top, SWT.NONE);
 
168
        nameLabel.setLayoutData(new GridData(SWT.FILL,SWT.CENTER,true,true));
 
169
        nameLabel.setText(TuxGuitar.getProperty("track.name") + ":");
 
170
              
 
171
        this.nameText = new Text(top, SWT.BORDER);
 
172
        nameText.setLayoutData(getAlignmentData(MINIMUN_LEFT_CONTROLS_WIDTH,SWT.FILL));
 
173
        nameText.setText(trackCoords.getTrack().getName());
 
174
        
 
175
        
 
176
        //-----------------------COLOR---------------------------------
 
177
        Label colorLabel = new Label(bottom, SWT.NONE);
 
178
        colorLabel.setText(TuxGuitar.getProperty("track.color") + ":");
 
179
        colorLabel.setLayoutData(new GridData(SWT.FILL,SWT.CENTER,true,true));
 
180
        
 
181
        final Button colorButton = new Button(bottom, SWT.PUSH);
 
182
        colorButton.setLayoutData(getAlignmentData(MINIMUN_LEFT_CONTROLS_WIDTH,SWT.FILL));
 
183
        colorButton.addSelectionListener(new SelectionAdapter() {
 
184
            public void widgetSelected(SelectionEvent event) {
 
185
                ColorDialog dlg = new ColorDialog(dialog);
 
186
                dlg.setRGB(dialog.getDisplay().getSystemColor(SWT.COLOR_BLACK).getRGB());
 
187
                dlg.setText(TuxGuitar.getProperty("choose-color"));
 
188
                RGB rgb = dlg.open();
 
189
                if (rgb != null) {
 
190
                    trackColor.setR(rgb.red);
 
191
                    trackColor.setG(rgb.green);
 
192
                    trackColor.setB(rgb.blue);       
 
193
                    colorButton.redraw();
 
194
                }
 
195
            }
 
196
        });
 
197
        colorButton.addPaintListener(new PaintListener() {              
 
198
                        public void paintControl(PaintEvent e) {
 
199
                                Color color = new Color(dialog.getDisplay(), trackColor.getR(), trackColor.getG(), trackColor.getB());
 
200
                        e.gc.setBackground(color);
 
201
                        e.gc.fillRectangle(5,5,colorButton.getSize().x - 10,colorButton.getSize().y - 10);
 
202
                        color.dispose();
 
203
                        }               
 
204
                });
 
205
       
 
206
    }
 
207
 
 
208
    private void initTunningInfo(Composite composite,SongTrackCoords trackCoords) {
 
209
        composite.setLayout(new GridLayout(2,true));            
 
210
        initTunningData(composite,trackCoords);
 
211
        initTunningCombos(composite);           
 
212
    }
 
213
 
 
214
    private void initTunningCombos(Composite parent) {
 
215
        Composite composite = new Composite(parent, SWT.NONE);
 
216
        composite.setLayout(new GridLayout(/*MAX_STRINGS, false*/));
 
217
        composite.setLayoutData(new GridData(SWT.RIGHT,SWT.FILL,true,true));
 
218
        String[] tunningTexts = getAllValueNames();
 
219
        for (int i = 0; i < MAX_STRINGS; i++) {
 
220
            this.stringCombos[i] = new Combo(composite, SWT.DROP_DOWN | SWT.READ_ONLY);
 
221
            this.stringCombos[i].setItems(tunningTexts);
 
222
        }
 
223
    }
 
224
 
 
225
    private void initTunningData(Composite parent,SongTrackCoords trackCoords) {
 
226
        Composite composite = new Composite(parent, SWT.NONE);
 
227
        composite.setLayout(new GridLayout(/*2, false*/));      
 
228
        composite.setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,true));
 
229
        
 
230
        Composite top = new Composite(composite, SWT.NONE);
 
231
        top.setLayout(new GridLayout());
 
232
        top.setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,true));
 
233
        
 
234
        Composite bottom = new Composite(composite, SWT.NONE);
 
235
        bottom.setLayout(new GridLayout());
 
236
        bottom.setLayoutData(new GridData(SWT.FILL,SWT.BOTTOM,true,true));
 
237
        
 
238
        //---------------------------------STRING--------------------------------        
 
239
        Label stringCountLabel = new Label(top, SWT.NONE);
 
240
        stringCountLabel.setText(TuxGuitar.getProperty("tunning.strings") + ":");
 
241
        stringCountLabel.setLayoutData(new GridData(SWT.LEFT,SWT.CENTER,true,true));
 
242
        
 
243
        this.stringCountSpinner = new Spinner(top, SWT.BORDER);
 
244
        stringCountSpinner.setLayoutData(getAlignmentData(80,SWT.FILL));
 
245
        stringCountSpinner.setMinimum(MIN_STRINGS);
 
246
        stringCountSpinner.setMaximum(MAX_STRINGS);
 
247
        stringCountSpinner.setSelection(this.stringCount);        
 
248
        stringCountSpinner.addSelectionListener(new SelectionAdapter() {
 
249
            public void widgetSelected(SelectionEvent e) {
 
250
                stringCount = stringCountSpinner.getSelection();
 
251
                setDefaultTunning();
 
252
                updateTunningGroup(!percussionCheckBox.getSelection());
 
253
            }
 
254
        });
 
255
 
 
256
        
 
257
        //---------------------------------OFFSET--------------------------------
 
258
        Label offsetLabel = new Label(bottom, SWT.NONE);
 
259
        offsetLabel.setText(TuxGuitar.getProperty("tunning.offset") + ":");
 
260
        offsetLabel.setLayoutData(new GridData(SWT.LEFT,SWT.CENTER,true,true));
 
261
        //offsetLabel.setLayoutData(new GridData(SWT.RIGHT,SWT.CENTER,true,true));
 
262
        
 
263
        offsetCombo = new Combo(bottom, SWT.DROP_DOWN | SWT.READ_ONLY);
 
264
        offsetCombo.setLayoutData(getAlignmentData(80,SWT.LEFT));
 
265
        //offsetCombo.setLayoutData(new GridData(100,SWT.DEFAULT));
 
266
        for(int i = SongTrack.MIN_OFFSET;i <= SongTrack.MAX_OFFSET;i ++){
 
267
                offsetCombo.add(Integer.toString(i));
 
268
                if(i == trackCoords.getTrack().getOffset()){
 
269
                        offsetCombo.select(i - SongTrack.MIN_OFFSET);
 
270
                }
 
271
        }               
 
272
    }
 
273
 
 
274
    private GridData getAlignmentData(int minimumWidth,int horizontalAlignment){
 
275
        GridData data = new GridData();
 
276
        data.minimumWidth = minimumWidth;
 
277
        data.horizontalAlignment = horizontalAlignment;
 
278
        data.verticalAlignment = SWT.DEFAULT;
 
279
        data.grabExcessHorizontalSpace = true;
 
280
        data.grabExcessVerticalSpace = true;
 
281
        return data;
 
282
    }
 
283
 
 
284
    private void initButtons(final Composite parent) {
 
285
        Composite composite = new Composite(parent, SWT.NONE);
 
286
        composite.setLayout(new GridLayout(2,false));
 
287
        composite.setLayoutData(new GridData(SWT.END,SWT.FILL,true,true));      
 
288
        
 
289
        GridData data = new GridData(SWT.FILL,SWT.FILL,true,true);    
 
290
        data.minimumWidth = MINIMUN_BUTTON_WIDTH;
 
291
        data.minimumHeight = MINIMUN_BUTTON_HEIGHT;
 
292
        
 
293
        Button buttonOK = new Button(composite, SWT.PUSH);
 
294
        buttonOK.setText(TuxGuitar.getProperty("ok"));
 
295
        buttonOK.setLayoutData(data);
 
296
        buttonOK.addSelectionListener(new SelectionAdapter() {
 
297
            public void widgetSelected(SelectionEvent arg0) {
 
298
                updateTrackProperties();
 
299
                //--------------update and redraw------------------------------------------------------
 
300
                new SyncThread(new Runnable() {
 
301
                    public void run() {
 
302
                        if(!TuxGuitar.isDisposed()){
 
303
                                updateTablature();
 
304
                                TuxGuitar.instance().getMixer().update();
 
305
                                redraw();                        
 
306
                                dialog.dispose();
 
307
                        }
 
308
                    }
 
309
                }).start();
 
310
            }
 
311
        });
 
312
 
 
313
        Button buttonCancel = new Button(composite, SWT.PUSH);
 
314
        buttonCancel.setText(TuxGuitar.getProperty("cancel"));
 
315
        buttonCancel.setLayoutData(data);
 
316
        buttonCancel.addSelectionListener(new SelectionAdapter() {
 
317
            public void widgetSelected(SelectionEvent arg0) {
 
318
                dialog.dispose();
 
319
            }
 
320
        });
 
321
 
 
322
    }
 
323
 
 
324
    private void initInstrumentFields(Composite composite,SongTrackCoords trackCoords) {
 
325
        composite.setLayout(new GridLayout(/*2,false*/));  
 
326
        
 
327
        Composite top = new Composite(composite, SWT.NONE);
 
328
        top.setLayout(new GridLayout());
 
329
        top.setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,true));
 
330
        
 
331
        Composite bottom = new Composite(composite, SWT.NONE);
 
332
        bottom.setLayout(new GridLayout());
 
333
        bottom.setLayoutData(new GridData(SWT.FILL,SWT.BOTTOM,true,true));      
 
334
        
 
335
        Instrument[] instruments = getInstruments();
 
336
        final SongTrack track = trackCoords.getTrack();
 
337
        //------------Instrument Combo-------------------------------------
 
338
        Label instrumentLabel = new Label(top, SWT.NONE);
 
339
        instrumentLabel.setText(TuxGuitar.getProperty("instrument.instrument") + ":");
 
340
        instrumentLabel.setLayoutData(new GridData(SWT.FILL,SWT.CENTER,true,true));
 
341
        
 
342
        this.instrumentCombo = new Combo(top, SWT.DROP_DOWN | SWT.READ_ONLY);
 
343
        this.instrumentCombo.setLayoutData(getAlignmentData(MINIMUN_LEFT_CONTROLS_WIDTH,SWT.FILL));
 
344
        if (instruments != null) {
 
345
            int count = instruments.length;
 
346
            if (count > 128) {
 
347
                count = 128;
 
348
            }
 
349
            for (int i = 0; i < count; i++) {
 
350
                instruments[i].getName();
 
351
                instrumentCombo.add(instruments[i].getName());
 
352
            }
 
353
            instrumentCombo.select(track.getChannel().getInstrument());
 
354
        }
 
355
        instrumentCombo.setEnabled(!track.isPercussionTrack() && instruments != null);
 
356
 
 
357
        //--------------------Precusion CheckBox-------------------------------
 
358
        //GridData gridData = new GridData();
 
359
        //gridData.horizontalSpan = 2;
 
360
        this.percussionCheckBox = new Button(bottom, SWT.CHECK);
 
361
        this.percussionCheckBox.setText(TuxGuitar.getProperty("instrument.percussion-track"));
 
362
        this.percussionCheckBox.setLayoutData(new GridData(SWT.FILL,SWT.CENTER,true,true));
 
363
        //percussionCheckBox.setLayoutData(gridData);
 
364
        if (instruments != null) {
 
365
            percussionCheckBox.setSelection(track.isPercussionTrack());
 
366
            percussionCheckBox.addSelectionListener(new SelectionAdapter() {
 
367
                public void widgetSelected(SelectionEvent arg0) {
 
368
                    instrumentCombo.setEnabled(!percussionCheckBox.getSelection());
 
369
                    
 
370
                    setDefaultTunning();
 
371
                    updateTunningGroup(!percussionCheckBox.getSelection());                                            
 
372
                }
 
373
            });
 
374
        } else {
 
375
            percussionCheckBox.setEnabled(false);
 
376
        }
 
377
        //-----------------------------------------------------------
 
378
    }
 
379
 
 
380
    private Instrument[] getInstruments() {
 
381
        Instrument[] instruments = null;
 
382
        Soundbank sb = TuxGuitar.instance().getPlayer().getSoundbank();
 
383
        if (sb != null) {
 
384
            instruments = sb.getInstruments();
 
385
        }
 
386
        return instruments;
 
387
    }
 
388
 
 
389
    private void updateTrackProperties() {
 
390
        SongTrackCoords trackCoords = getEditor().getTablature().getCaret().getSongTrackCoords();
 
391
        
 
392
        String trackName = this.nameText.getText();
 
393
        RGBColor trakColor = this.trackColor;
 
394
        
 
395
        List strings = new ArrayList();
 
396
        for (int i = 0; i < stringCount; i++) {
 
397
            strings.add(new InstrumentString((i + 1), stringCombos[i].getSelectionIndex()));
 
398
        }        
 
399
 
 
400
        boolean percussion = percussionCheckBox.getSelection();
 
401
        int offset = ((percussion)?0:SongTrack.MIN_OFFSET + offsetCombo.getSelectionIndex());
 
402
        int instrument = ((instrumentCombo.getSelectionIndex() >= 0)?instrumentCombo.getSelectionIndex():0);
 
403
       
 
404
        
 
405
        boolean infoChanges = hasInfoChanges(trackCoords,trackName,trackColor,offset);
 
406
        boolean tunningChanges = hasTunningChanges(trackCoords,strings);
 
407
        boolean instrumentChanges = hasInstrumentChanges(trackCoords,instrument,percussion);
 
408
        
 
409
        if(infoChanges || tunningChanges || instrumentChanges){
 
410
                JoinedUndoable undoable = new JoinedUndoable();
 
411
                
 
412
                UndoableTrackGeneric undoableGeneric = null;
 
413
                if(tunningChanges){
 
414
                        undoableGeneric = UndoableTrackGeneric.startUndo(trackCoords.getTrack());
 
415
                }
 
416
                
 
417
                //--------------------------------------info---------------------------------------
 
418
                if(infoChanges){
 
419
                        UndoableInfoTrack undoableInfo = null;
 
420
                        if(!tunningChanges){
 
421
                                undoableInfo = UndoableInfoTrack.startUndo(trackCoords.getTrack());
 
422
                        }
 
423
                        getEditor().getSongManager().getTrackManager().changeInfo(trackCoords.getTrack(),trackName,trackColor,offset);
 
424
                        if(!tunningChanges){
 
425
                                undoable.addUndoableEdit(undoableInfo.endUndo(trackCoords.getTrack()));
 
426
                        }
 
427
                }
 
428
                //--------------------------------------tunning---------------------------------------
 
429
                if(tunningChanges){
 
430
                        getEditor().getSongManager().getTrackManager().changeInstrumentStrings(trackCoords.getTrack(),strings);
 
431
                }
 
432
                //-----------------------------instrument----------------------------------------------        
 
433
                if(instrumentChanges){
 
434
                        UndoableInstrumentTrack undoableInstrument = null;
 
435
                        if(!tunningChanges){
 
436
                                undoableInstrument = UndoableInstrumentTrack.startUndo(trackCoords.getTrack());
 
437
                        }               
 
438
                        getEditor().getSongManager().getTrackManager().changeInstrument(trackCoords.getTrack(),instrument,percussion);                  
 
439
                        if(!tunningChanges){
 
440
                                undoable.addUndoableEdit(undoableInstrument.endUndo(trackCoords.getTrack()));
 
441
                        }
 
442
                }
 
443
                if(tunningChanges){
 
444
                        undoable.addUndoableEdit(undoableGeneric.endUndo(trackCoords.getTrack()));
 
445
                }               
 
446
                getEditor().getUndoManager().addEdit(undoable.endUndo());               
 
447
                if (TuxGuitar.instance().getPlayer().isRunning()) {
 
448
                        TuxGuitar.instance().getPlayer().updatePrograms();
 
449
                }               
 
450
        }
 
451
    }
 
452
    
 
453
    private boolean hasInfoChanges(SongTrackCoords trackCoords,String name,RGBColor color,int offset){
 
454
        if(!name.equals(trackCoords.getTrack().getName())){
 
455
                return true;
 
456
        }
 
457
        if(!color.isEqual(trackCoords.getTrack().getColor())){
 
458
                return true;
 
459
        }       
 
460
        if(offset != trackCoords.getTrack().getOffset()){
 
461
                return true;
 
462
        }
 
463
        return false;
 
464
    }
 
465
    
 
466
    private boolean hasTunningChanges(SongTrackCoords trackCoords,List newStrings){
 
467
        List oldStrings = trackCoords.getTrack().getStrings();          
 
468
        //check the number of strings
 
469
        if(oldStrings.size() != newStrings.size()){
 
470
                return true;
 
471
        }       
 
472
        //check the tunning of strings
 
473
        for(int i = 0;i < oldStrings.size();i++){                               
 
474
                InstrumentString oldString = (InstrumentString)oldStrings.get(i);
 
475
                boolean stringExists = false;           
 
476
                for(int j = 0;j < newStrings.size();j++){
 
477
                        InstrumentString newString = (InstrumentString)newStrings.get(j);
 
478
                        if(newString.isEqual(oldString)){
 
479
                                stringExists = true;
 
480
                        }
 
481
                }               
 
482
                if(!stringExists){
 
483
                        return true;
 
484
                }
 
485
        }
 
486
        return false;
 
487
    }
 
488
    
 
489
    private boolean hasInstrumentChanges(SongTrackCoords trackCoords,int instrument,boolean percussion){
 
490
        return ((trackCoords.getTrack().getChannel().getInstrument() != instrument) || (trackCoords.getTrack().isPercussionTrack() != percussion));
 
491
    }
 
492
    
 
493
    private void updateTunningGroup(boolean enabled) {          
 
494
        /*
 
495
        int selectedIndex = tempStrings.size() - 1;
 
496
        Iterator it = tempStrings.iterator();
 
497
        while (it.hasNext()) {
 
498
            InstrumentString string = (InstrumentString) it.next();
 
499
            stringCombos[selectedIndex].select(string.getValue());
 
500
            stringCombos[selectedIndex].setVisible(true);
 
501
            stringCombos[selectedIndex].setEnabled(enabled);
 
502
            selectedIndex--;
 
503
        }
 
504
        */
 
505
        for (int i = 0; i < tempStrings.size(); i++) {
 
506
            InstrumentString string = (InstrumentString)tempStrings.get(i);
 
507
            stringCombos[i].select(string.getValue());
 
508
            stringCombos[i].setVisible(true);
 
509
            stringCombos[i].setEnabled(enabled);                
 
510
        }
 
511
        
 
512
        for (int i = tempStrings.size(); i < MAX_STRINGS; i++) {
 
513
                stringCombos[i].select(0);
 
514
                stringCombos[i].setVisible(false);
 
515
        }
 
516
        offsetCombo.setEnabled(enabled);
 
517
    }
 
518
 
 
519
    private void initTempStrings(List realStrings) {
 
520
        this.tempStrings = new ArrayList();
 
521
        for (int i = 0; i < realStrings.size(); i++) {
 
522
            InstrumentString realString = (InstrumentString) realStrings.get(i);
 
523
            tempStrings.add(realString.clone());
 
524
        }
 
525
    }
 
526
 
 
527
    private void setDefaultTunning() {
 
528
        this.tempStrings.clear();
 
529
        if (percussionCheckBox.getSelection()) {
 
530
            for (int i = 1; i <= stringCount; i++) {
 
531
                this.tempStrings.add(new InstrumentString(i, 0));
 
532
            }
 
533
        } 
 
534
        else {
 
535
            switch (stringCount) {
 
536
            case 7:
 
537
                this.tempStrings.add(new InstrumentString(1, 64));
 
538
                this.tempStrings.add(new InstrumentString(2, 59));
 
539
                this.tempStrings.add(new InstrumentString(3, 55));
 
540
                this.tempStrings.add(new InstrumentString(4, 50));
 
541
                this.tempStrings.add(new InstrumentString(5, 45));
 
542
                this.tempStrings.add(new InstrumentString(6, 40));
 
543
                this.tempStrings.add(new InstrumentString(7, 35));
 
544
                break;
 
545
            case 6:
 
546
                this.tempStrings.add(new InstrumentString(1, 64));
 
547
                this.tempStrings.add(new InstrumentString(2, 59));
 
548
                this.tempStrings.add(new InstrumentString(3, 55));
 
549
                this.tempStrings.add(new InstrumentString(4, 50));
 
550
                this.tempStrings.add(new InstrumentString(5, 45));
 
551
                this.tempStrings.add(new InstrumentString(6, 40));
 
552
                break;
 
553
            case 5:
 
554
                this.tempStrings.add(new InstrumentString(1, 43));
 
555
                this.tempStrings.add(new InstrumentString(2, 38));
 
556
                this.tempStrings.add(new InstrumentString(3, 33));
 
557
                this.tempStrings.add(new InstrumentString(4, 28));
 
558
                this.tempStrings.add(new InstrumentString(5, 23));
 
559
                break;
 
560
            case 4:
 
561
                this.tempStrings.add(new InstrumentString(1, 43));
 
562
                this.tempStrings.add(new InstrumentString(2, 38));
 
563
                this.tempStrings.add(new InstrumentString(3, 33));
 
564
                this.tempStrings.add(new InstrumentString(4, 28));
 
565
                break;
 
566
            }
 
567
        }
 
568
    }
 
569
 
 
570
    private String[] getAllValueNames() {
 
571
        String[] valueNames = new String[MAX_NOTES * MAX_OCTAVES];
 
572
        for (int i = 0; i < valueNames.length; i++) {
 
573
            valueNames[i] =  NOTE_NAMES[ (i -  ((i / MAX_NOTES) * MAX_NOTES) ) ] + (i / MAX_NOTES);;
 
574
        }
 
575
        return valueNames;
 
576
    }
 
577
 
 
578
}
 
 
b'\\ No newline at end of file'