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

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Philippe Coval
  • Date: 2008-06-19 00:30:30 UTC
  • mto: (5.1.2 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20080619003030-h719szrhsngou7c6
Tags: upstream-1.0
ImportĀ upstreamĀ versionĀ 1.0

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