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

« back to all changes in this revision

Viewing changes to TuxGuitar/src/org/herac/tuxguitar/gui/editors/tab/layout/ViewLayout.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 04-ene-2006
 
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.editors.tab.layout;
 
8
 
 
9
import java.util.ArrayList;
 
10
import java.util.Iterator;
 
11
import java.util.List;
 
12
 
 
13
import org.eclipse.swt.graphics.Point;
 
14
import org.eclipse.swt.graphics.Rectangle;
 
15
import org.herac.tuxguitar.gui.TuxGuitar;
 
16
import org.herac.tuxguitar.gui.editors.TGPainter;
 
17
import org.herac.tuxguitar.gui.editors.tab.Caret;
 
18
import org.herac.tuxguitar.gui.editors.tab.TGBeatImpl;
 
19
import org.herac.tuxguitar.gui.editors.tab.TGChordImpl;
 
20
import org.herac.tuxguitar.gui.editors.tab.TGLyricImpl;
 
21
import org.herac.tuxguitar.gui.editors.tab.TGMeasureHeaderImpl;
 
22
import org.herac.tuxguitar.gui.editors.tab.TGMeasureImpl;
 
23
import org.herac.tuxguitar.gui.editors.tab.TGResources;
 
24
import org.herac.tuxguitar.gui.editors.tab.TGTrackImpl;
 
25
import org.herac.tuxguitar.gui.editors.tab.Tablature;
 
26
import org.herac.tuxguitar.gui.system.config.TGConfigKeys;
 
27
import org.herac.tuxguitar.gui.system.config.TGConfigManager;
 
28
import org.herac.tuxguitar.song.managers.TGSongManager;
 
29
import org.herac.tuxguitar.song.models.TGDuration;
 
30
import org.herac.tuxguitar.song.models.TGMeasure;
 
31
import org.herac.tuxguitar.song.models.TGNote;
 
32
 
 
33
/**
 
34
 * @author julian
 
35
 *
 
36
 * TODO To change the template for this generated type comment go to
 
37
 * Window - Preferences - Java - Code Style - Code Templates
 
38
 */
 
39
public abstract class ViewLayout {
 
40
        public static final int MODE_PAGE = 1;
 
41
        public static final int MODE_LINEAR = 2;
 
42
        public static final int DEFAULT_MODE = MODE_LINEAR;
 
43
        
 
44
        public static final int DISPLAY_COMPACT = 0x01;
 
45
        public static final int DISPLAY_MULTITRACK = 0x02;
 
46
        public static final int DISPLAY_SCORE = 0x04;
 
47
        public static final int DISPLAY_TABLATURE = 0x08;
 
48
        public static final int DISPLAY_CHORD_NAME = 0x10;
 
49
        public static final int DISPLAY_CHORD_DIAGRAM = 0x20;
 
50
        
 
51
        private Tablature tablature;
 
52
        private float scale;
 
53
        private float fontScale;
 
54
        private int style;
 
55
        private int width;
 
56
        private int height;
 
57
        private int minBufferSeparator;
 
58
        private int minTopSpacing;
 
59
        private int minScoreTabSpacing;
 
60
        private int stringSpacing;
 
61
        private int scoreLineSpacing;
 
62
        private int scoreSpacing;
 
63
        private int trackSpacing;
 
64
        private int firstTrackSpacing;
 
65
        private int firstMeasureSpacing;
 
66
        private int chordFretIndexSpacing;
 
67
        private int chordStringSpacing;
 
68
        private int chordFretSpacing;
 
69
        private int chordNoteSize;
 
70
        private int repeatEndingSpacing;
 
71
        private int effectSpacing;
 
72
        private int tupletoSpacing;
 
73
        private int textSpacing;
 
74
        private boolean bufferEnabled;
 
75
        private boolean playModeEnabled;
 
76
        
 
77
        private List trackPositions;
 
78
        
 
79
        private TGResources resources;
 
80
        
 
81
        public ViewLayout(Tablature tablature,int style){
 
82
                this(tablature, style, 1.0f );
 
83
        }
 
84
        
 
85
        public ViewLayout(Tablature tablature,int style, float scale){
 
86
                this.tablature = tablature;
 
87
                this.trackPositions = new ArrayList();
 
88
                this.playModeEnabled = false;
 
89
                this.resources = new TGResources(this);
 
90
                this.style = style;
 
91
                if((this.style & DISPLAY_TABLATURE) == 0 && (this.style & DISPLAY_SCORE) == 0 ){
 
92
                        this.style |= DISPLAY_TABLATURE;
 
93
                }
 
94
                this.init( scale );
 
95
        }
 
96
        
 
97
        protected void init( float initScale ){
 
98
                TGConfigManager config =  TuxGuitar.instance().getConfig();
 
99
                this.setBufferEnabled(true);
 
100
                this.setStringSpacing( (int)(config.getIntConfigValue(TGConfigKeys.TAB_LINE_SPACING) * initScale ) );
 
101
                this.setScoreLineSpacing( (int)(config.getIntConfigValue(TGConfigKeys.SCORE_LINE_SPACING) * initScale ) );
 
102
                this.setScale( checkScale() );
 
103
                this.setFontScale( getScale() );
 
104
                this.setFirstMeasureSpacing( Math.round( 20f * getScale() ) );
 
105
                this.setMinBufferSeparator( Math.round( 20f * getScale() ) );
 
106
                this.setMinTopSpacing( Math.round( 30f * getScale() ) );
 
107
                this.setMinScoreTabSpacing( Math.round( config.getIntConfigValue(TGConfigKeys.MIN_SCORE_TABLATURE_SPACING) * getScale() ) );
 
108
                this.setScoreSpacing( (( getScoreLineSpacing() * 4) + getMinScoreTabSpacing() ) );
 
109
                this.setFirstTrackSpacing( Math.round(config.getIntConfigValue(TGConfigKeys.FIRST_TRACK_SPACING) * getScale() ) );
 
110
                this.setTrackSpacing( Math.round(config.getIntConfigValue(TGConfigKeys.TRACK_SPACING) * getScale() ) );
 
111
                
 
112
                this.setChordFretIndexSpacing( Math.round( 8f * getScale() ) );
 
113
                this.setChordStringSpacing( Math.round( 5f * getScale() ) );
 
114
                this.setChordFretSpacing( Math.round( 6f * getScale() ) );
 
115
                this.setChordNoteSize( Math.round( 4f * getScale() ) );
 
116
                this.setRepeatEndingSpacing( Math.round( 20f * getScale() ) );
 
117
                this.setTextSpacing( Math.round( 15f * getScale() ) );
 
118
                this.setTupletoSpacing( Math.round( 10f * getScale() ) );
 
119
                this.setEffectSpacing( Math.round( 8f * getScale() ) );
 
120
        }
 
121
        
 
122
        public abstract void paintSong(TGPainter painter,Rectangle clientArea,int fromX,int fromY);
 
123
        
 
124
        public abstract int getMode();
 
125
        
 
126
        public void paint(TGPainter painter,Rectangle clientArea,int fromX,int fromY){
 
127
                this.playModeEnabled = false;
 
128
                paintSong(painter,clientArea,fromX,fromY);
 
129
        }
 
130
        
 
131
        public void paintMeasure(TGMeasureImpl measure,TGPainter painter,int spacing) {
 
132
                measure.setSpacing(spacing);
 
133
                measure.paintMeasure(this,painter);
 
134
        }
 
135
        
 
136
        public void updateSong(){
 
137
                updateTracks();
 
138
                updateCaret();
 
139
        }
 
140
        
 
141
        public void updateTracks() {
 
142
                int trackCount = getSongManager().getSong().countTracks();
 
143
                int measureCount = getSongManager().getSong().countMeasureHeaders();
 
144
                for (int measureIdx = 0; measureIdx < measureCount; measureIdx++) {
 
145
                        TGMeasureHeaderImpl header = (TGMeasureHeaderImpl)getSongManager().getSong().getMeasureHeader(measureIdx);
 
146
                        header.update(this, measureIdx);
 
147
                        for (int trackIdx = 0; trackIdx < trackCount; trackIdx++) {
 
148
                                TGTrackImpl track = (TGTrackImpl)getSongManager().getSong().getTrack(trackIdx);
 
149
                                TGMeasureImpl measure = (TGMeasureImpl) track.getMeasure(measureIdx);
 
150
                                measure.create(this);
 
151
                        }
 
152
                        for (int trackIdx = 0; trackIdx < trackCount; trackIdx++) {
 
153
                                TGTrackImpl track = (TGTrackImpl)getSongManager().getSong().getTrack(trackIdx);
 
154
                                TGMeasureImpl measure = (TGMeasureImpl)track.getMeasure(measureIdx);
 
155
                                track.update(this);
 
156
                                measure.update(this);
 
157
                        }
 
158
                }
 
159
        }
 
160
        
 
161
        private void updateCaret(){
 
162
                this.tablature.getCaret().update();
 
163
        }
 
164
        
 
165
        public void fireUpdate(int measureNumber){
 
166
                int measureIndex = (measureNumber - 1);
 
167
                int trackCount = getSongManager().getSong().countTracks();
 
168
                TGMeasureHeaderImpl header = (TGMeasureHeaderImpl)getSongManager().getSong().getMeasureHeader(measureIndex);
 
169
                header.update(this, measureIndex);
 
170
                for (int trackIdx = 0; trackIdx < trackCount; trackIdx++) {
 
171
                        TGTrackImpl track = (TGTrackImpl)getSongManager().getSong().getTrack(trackIdx);
 
172
                        TGMeasureImpl measure = null;
 
173
                        measure =  (TGMeasureImpl) track.getMeasure(measureIndex);
 
174
                        measure.create(this);
 
175
                }
 
176
                for (int trackIdx = 0; trackIdx < trackCount; trackIdx++) {
 
177
                        TGTrackImpl track = (TGTrackImpl)getSongManager().getSong().getTrack(trackIdx);
 
178
                        TGMeasureImpl measure =  (TGMeasureImpl) track.getMeasure(measureIndex);
 
179
                        measure.update(this);
 
180
                }
 
181
                updateCaret();
 
182
        }
 
183
        
 
184
        public void reloadStyles(){
 
185
                this.getResources().load();
 
186
        }
 
187
        
 
188
        /**
 
189
         * Pinta las lineas
 
190
         */
 
191
        public void paintLines(TGTrackImpl track,TrackSpacing ts,TGPainter painter,int x,int y,int width) {
 
192
                if(width > 0){
 
193
                        setLineStyle(painter);
 
194
                        int tempX = ((x < 0)?0:x);
 
195
                        int tempY = y;
 
196
                        
 
197
                        //partitura
 
198
                        if( (this.style & DISPLAY_SCORE) != 0 ){
 
199
                                int posY = tempY + ts.getPosition(TrackSpacing.POSITION_SCORE_MIDDLE_LINES);
 
200
                                
 
201
                                painter.initPath();
 
202
                                for(int i = 1;i <= 5;i ++){
 
203
                                        painter.moveTo(tempX, posY);
 
204
                                        painter.lineTo(tempX + width,posY);
 
205
                                        posY += getScoreLineSpacing();
 
206
                                }
 
207
                                painter.closePath();
 
208
                        }
 
209
                        //tablatura
 
210
                        if((this.style & DISPLAY_TABLATURE) != 0){
 
211
                                tempY += ts.getPosition(TrackSpacing.POSITION_TABLATURE);
 
212
                                
 
213
                                painter.initPath();
 
214
                                for(int i = 0; i < track.stringCount();i++){
 
215
                                        painter.moveTo(tempX,tempY);
 
216
                                        painter.lineTo(tempX + width,tempY);
 
217
                                        tempY += getStringSpacing();
 
218
                                }
 
219
                                painter.closePath();
 
220
                        }
 
221
                }
 
222
        }
 
223
        
 
224
        /**
 
225
         * Pinta el caret
 
226
         */
 
227
        public void paintCaret(TGPainter painter) {
 
228
                if(isCaretVisible() && ((this.style & (DISPLAY_TABLATURE | DISPLAY_SCORE) ) != 0 )){
 
229
                        Caret caret = getTablature().getCaret();
 
230
                        if(!caret.getMeasure().isOutOfBounds()){
 
231
                                caret.paintCaret(this,painter);
 
232
                        }
 
233
                }
 
234
        }
 
235
        
 
236
        /**
 
237
         * Pinta el compas y las notas que estan sonando
 
238
         */
 
239
        public void paintPlayMode(TGPainter painter,TGMeasureImpl measure,TGBeatImpl beat,boolean paintMeasure){
 
240
                this.playModeEnabled = true;
 
241
                
 
242
                //pinto el compas
 
243
                if(paintMeasure){
 
244
                        measure.paintMeasure(this,painter);
 
245
                }
 
246
                //pinto el pulso
 
247
                beat.paint(this,painter,measure.getPosX()  + measure.getHeaderImpl().getLeftSpacing(this), measure.getPosY());
 
248
                
 
249
                //pinto los lyrics
 
250
                ((TGLyricImpl)measure.getTrackImpl().getLyrics()).paintCurrentNoteBeats(painter,this,measure,measure.getPosX(), measure.getPosY());
 
251
                
 
252
                this.playModeEnabled = false;
 
253
        }
 
254
        
 
255
        protected float checkScale(){
 
256
                float v1 = ((this.style & DISPLAY_SCORE) != 0 ? (getScoreLineSpacing() * 1.25f ) : 0 );
 
257
                float v2 = ((this.style & DISPLAY_TABLATURE) != 0 ? getStringSpacing() : 0 );
 
258
                float scale = (Math.max(v1,v2) / 10.0f);
 
259
                return scale;
 
260
        }
 
261
        
 
262
        protected void checkDefaultSpacing(TrackSpacing ts){
 
263
                int checkPosition = -1;
 
264
                //int minBufferSeparator = (Math.round( getMinBufferSeparator() * getScale() ));
 
265
                int minBufferSeparator = getMinBufferSeparator();
 
266
                if( (this.style & DISPLAY_SCORE) != 0 ){
 
267
                        int bufferSeparator = (ts.getPosition(TrackSpacing.POSITION_SCORE_UP_LINES) - ts.getPosition(TrackSpacing.POSITION_BUFFER_SEPARATOR));
 
268
                        if(bufferSeparator < minBufferSeparator ) {
 
269
                                ts.setSize(TrackSpacing.POSITION_BUFFER_SEPARATOR,minBufferSeparator - bufferSeparator);
 
270
                        }
 
271
                        checkPosition = ts.getPosition(TrackSpacing.POSITION_SCORE_MIDDLE_LINES);
 
272
                }
 
273
                else if((this.style & DISPLAY_TABLATURE) != 0){
 
274
                        int bufferSeparator = (ts.getPosition(TrackSpacing.POSITION_TABLATURE) - ts.getPosition(TrackSpacing.POSITION_BUFFER_SEPARATOR));
 
275
                        if(bufferSeparator < minBufferSeparator ) {
 
276
                                ts.setSize(TrackSpacing.POSITION_BUFFER_SEPARATOR,minBufferSeparator - bufferSeparator);
 
277
                        }
 
278
                        checkPosition = ts.getPosition(TrackSpacing.POSITION_TABLATURE);
 
279
                }
 
280
                
 
281
                if(checkPosition >= 0 && checkPosition < getMinTopSpacing()){
 
282
                        ts.setSize(TrackSpacing.POSITION_TOP, (getMinTopSpacing() - checkPosition));
 
283
                }
 
284
        }
 
285
        
 
286
        /**
 
287
         * Calcula el espacio minimo entre negras, dependiendo de la duracion de la nota 
 
288
         */
 
289
        public int getSpacingForQuarter(TGDuration duration){
 
290
                double spacing = (((double)TGDuration.QUARTER_TIME / (double)duration.getTime()) * getMinSpacing(duration));
 
291
                return  (int)spacing;
 
292
        }
 
293
        
 
294
        /**
 
295
         * Calcula el Espacio minimo que quedara entre nota y nota
 
296
         */
 
297
        protected float getMinSpacing(TGDuration duration){
 
298
                float scale = getScale();
 
299
                switch(duration.getValue()){
 
300
                        case TGDuration.WHOLE:
 
301
                                return (50.0f * scale);
 
302
                        case TGDuration.HALF:
 
303
                                return (30.0f * scale);
 
304
                        case TGDuration.QUARTER:
 
305
                                return (25.0f * scale);
 
306
                        case TGDuration.EIGHTH:
 
307
                                return (20.0f * scale);
 
308
                        default:
 
309
                                return (18.0f * scale);
 
310
                }
 
311
        }
 
312
        
 
313
        /**
 
314
         * Calcula el Espacio que ocupara el pulso
 
315
         */
 
316
        public float getBeatWidth(TGBeatImpl beat){
 
317
                float scale = getScale();
 
318
                TGDuration duration = beat.getDuration();
 
319
                if(duration != null){
 
320
                        switch(duration.getValue()){
 
321
                                case TGDuration.WHOLE:
 
322
                                        return (30.0f * scale);
 
323
                                case TGDuration.HALF:
 
324
                                        return (25.0f * scale);
 
325
                                case TGDuration.QUARTER:
 
326
                                        return (21.0f * scale);
 
327
                                case TGDuration.EIGHTH:
 
328
                                        return (20.0f * scale);
 
329
                                case TGDuration.SIXTEENTH:
 
330
                                        return (19.0f * scale);
 
331
                                case TGDuration.THIRTY_SECOND:
 
332
                                        return (18.0f * scale);
 
333
                                default:
 
334
                                        return (17.0f * scale);
 
335
                        }
 
336
                }
 
337
                return (20.0f * scale);
 
338
        }
 
339
        
 
340
        public boolean isCaretVisible(){
 
341
                return true;
 
342
        }
 
343
        
 
344
        public boolean isPlayModeEnabled(){
 
345
                return this.playModeEnabled;
 
346
        }
 
347
        
 
348
        public void setMeasureNumberStyle(TGPainter painter){
 
349
                painter.setFont(getResources().getDefaultFont());
 
350
                painter.setBackground(getResources().getBackgroundColor());
 
351
                painter.setForeground(getResources().getColorRed());
 
352
        }
 
353
        
 
354
        public void setDivisionsStyle(TGPainter painter, boolean fill){
 
355
                painter.setFont(getResources().getDefaultFont());
 
356
                painter.setBackground( (fill ? getResources().getColorBlack() :getResources().getBackgroundColor() ));
 
357
                painter.setForeground(getResources().getColorBlack());
 
358
        }
 
359
        
 
360
        public void setTempoStyle(TGPainter painter, boolean fontStyle){
 
361
                painter.setFont(getResources().getDefaultFont());
 
362
                painter.setForeground(getResources().getColorBlack());
 
363
                painter.setBackground( ( fontStyle ? getResources().getBackgroundColor() : getResources().getColorBlack() ));
 
364
        }
 
365
        
 
366
        public void setTripletFeelStyle(TGPainter painter, boolean fontStyle){
 
367
                painter.setFont(getResources().getDefaultFont());
 
368
                painter.setForeground(getResources().getColorBlack());
 
369
                painter.setBackground( ( fontStyle ? getResources().getBackgroundColor() : getResources().getColorBlack() ));
 
370
        }
 
371
        
 
372
        public void setMeasurePlayingStyle(TGPainter painter){
 
373
                painter.setBackground(getResources().getBackgroundColor());
 
374
                painter.setForeground(getResources().getColorBlack());
 
375
        }
 
376
        
 
377
        public void setGraceStyle(TGPainter painter){
 
378
                painter.setFont(getResources().getGraceFont());
 
379
                painter.setBackground(getResources().getBackgroundColor());
 
380
        }
 
381
        
 
382
        public void setLyricStyle(TGPainter painter,boolean playMode){
 
383
                painter.setFont(getResources().getLyricFont());
 
384
                painter.setBackground(getResources().getBackgroundColor());
 
385
                painter.setForeground( (playMode ? getResources().getPlayNoteColor() : getResources().getColorBlack()) );
 
386
        }
 
387
        
 
388
        public void setTextStyle(TGPainter painter){
 
389
                painter.setFont(getResources().getTextFont());
 
390
                painter.setBackground(getResources().getBackgroundColor());
 
391
                painter.setForeground(getResources().getColorBlack());
 
392
        }
 
393
        
 
394
        public void setTimeSignatureStyle(TGPainter painter){
 
395
                painter.setFont(getResources().getTimeSignatureFont());
 
396
                painter.setForeground(getResources().getColorBlack());
 
397
                painter.setBackground(getResources().getBackgroundColor());
 
398
        }
 
399
        
 
400
        public void setKeySignatureStyle(TGPainter painter){
 
401
                painter.setBackground(getResources().getColorBlack());
 
402
        }
 
403
        
 
404
        public void setClefStyle(TGPainter painter){
 
405
                painter.setBackground(getResources().getColorBlack());
 
406
        }
 
407
        
 
408
        public void setLineStyle(TGPainter painter){
 
409
                painter.setLineWidth(1);
 
410
                painter.setForeground(getResources().getLineColor());
 
411
        }
 
412
        
 
413
        public void setCaretStyle(TGPainter painter){
 
414
                painter.setForeground(getResources().getLineColor());
 
415
        }
 
416
        
 
417
        public void setScoreSilenceStyle(TGPainter painter,boolean playMode){
 
418
                painter.setForeground( (playMode ? getResources().getPlayNoteColor() : getResources().getScoreNoteColor() ));
 
419
                painter.setBackground( (playMode ? getResources().getPlayNoteColor() : getResources().getScoreNoteColor() ));
 
420
        }
 
421
        
 
422
        public void setTabSilenceStyle(TGPainter painter,boolean playMode){
 
423
                painter.setForeground( (playMode ? getResources().getPlayNoteColor() : getResources().getTabNoteColor() ));
 
424
                painter.setBackground( (playMode ? getResources().getPlayNoteColor() : getResources().getTabNoteColor() ));
 
425
        }
 
426
        
 
427
        public void setScoreNoteStyle(TGPainter painter,boolean playing){
 
428
                painter.setForeground( (playing ? getResources().getPlayNoteColor() : getResources().getScoreNoteColor() ));
 
429
                painter.setBackground( (playing ? getResources().getPlayNoteColor() : getResources().getScoreNoteColor() ));
 
430
        }
 
431
        
 
432
        public void setScoreNoteFooterStyle(TGPainter painter){
 
433
                painter.setForeground( getResources().getScoreNoteColor());
 
434
                painter.setBackground( getResources().getScoreNoteColor());
 
435
        }
 
436
        
 
437
        public void setScoreEffectStyle(TGPainter painter){
 
438
                painter.setForeground( getResources().getScoreNoteColor());
 
439
                painter.setBackground( getResources().getScoreNoteColor());
 
440
        }
 
441
        
 
442
        public void setTabNoteStyle(TGPainter painter,boolean playMode){
 
443
                painter.setForeground( (playMode ? getResources().getPlayNoteColor() : getResources().getTabNoteColor() ));
 
444
                painter.setBackground( getResources().getBackgroundColor() );
 
445
                painter.setFont(getResources().getNoteFont());
 
446
        }
 
447
        
 
448
        public void setTabNoteFooterStyle(TGPainter painter){
 
449
                painter.setForeground( getResources().getTabNoteColor());
 
450
                painter.setBackground( getResources().getTabNoteColor());
 
451
        }
 
452
        
 
453
        public void setTabEffectStyle(TGPainter painter){
 
454
                painter.setForeground( getResources().getTabNoteColor());
 
455
                painter.setBackground( getResources().getTabNoteColor());
 
456
        }
 
457
        
 
458
        public void setPlayNoteColor(TGPainter painter){
 
459
                painter.setForeground(getResources().getPlayNoteColor());
 
460
                painter.setBackground(getResources().getPlayNoteColor());
 
461
        }
 
462
        
 
463
        public void setOfflineEffectStyle(TGPainter painter){
 
464
                painter.setForeground(getResources().getColorBlack());
 
465
                painter.setBackground(getResources().getBackgroundColor());
 
466
                painter.setFont(getResources().getDefaultFont());
 
467
        }
 
468
        
 
469
        public void setDotStyle(TGPainter painter){
 
470
                painter.setForeground(getResources().getColorBlack());
 
471
                painter.setBackground(getResources().getColorBlack());
 
472
        }
 
473
        
 
474
        public void setTupletoStyle(TGPainter painter){
 
475
                painter.setForeground(getResources().getColorBlack());
 
476
                painter.setBackground(getResources().getBackgroundColor());
 
477
                painter.setFont(getResources().getDefaultFont());
 
478
        }
 
479
        
 
480
        public void setRepeatEndingStyle(TGPainter painter){
 
481
                painter.setForeground(getResources().getColorBlack());
 
482
                painter.setBackground(getResources().getBackgroundColor());
 
483
                painter.setFont(getResources().getDefaultFont());
 
484
        }
 
485
        
 
486
        public void setChordStyle(TGChordImpl chord){
 
487
                chord.setFont(getResources().getChordFont());
 
488
                chord.setForegroundColor(getResources().getColorBlack());
 
489
                chord.setBackgroundColor(getResources().getBackgroundColor());
 
490
                chord.setColor(getResources().getLineColor());
 
491
                chord.setNoteColor(getResources().getTabNoteColor());
 
492
                chord.setTonicColor(getResources().getTabNoteColor());
 
493
                chord.setStyle(this.style);
 
494
                chord.setFretSpacing(getChordFretSpacing());
 
495
                chord.setStringSpacing(getChordStringSpacing());
 
496
                chord.setNoteSize(getChordNoteSize());
 
497
                chord.setFirstFretSpacing(getChordFretIndexSpacing());
 
498
                chord.setFirstFretFont(getResources().getChordFretFont());
 
499
        }
 
500
        
 
501
        public Rectangle getNoteOrientation(TGPainter painter,int x,int y,TGNote note){
 
502
                String noteAsString = null;
 
503
                if (note.isTiedNote()){
 
504
                        noteAsString = "L";
 
505
                        noteAsString = (note.getEffect().isGhostNote())?"(" + noteAsString + ")":noteAsString;
 
506
                }else if(note.getEffect().isDeadNote()){
 
507
                        noteAsString = "X";
 
508
                        noteAsString = (note.getEffect().isGhostNote())?"(" + noteAsString + ")":noteAsString;
 
509
                }else{
 
510
                        noteAsString = Integer.toString(note.getValue());
 
511
                        noteAsString = (note.getEffect().isGhostNote())?"(" + noteAsString + ")":noteAsString;
 
512
                }
 
513
                return getOrientation(painter,x,y,noteAsString);
 
514
        }
 
515
        
 
516
        public Rectangle getOrientation(TGPainter painter,int x,int y,String s){
 
517
                Point point = painter.getStringExtent(s);
 
518
                return new Rectangle((x - (point.x / 2)),(y - (point.y / 2)),point.x, point.y );
 
519
        }
 
520
        
 
521
        public TGSongManager getSongManager() {
 
522
                return getTablature().getSongManager();
 
523
        }
 
524
        
 
525
        public Tablature getTablature() {
 
526
                return this.tablature;
 
527
        }
 
528
        
 
529
        public void setTablature(Tablature tablature) {
 
530
                this.tablature = tablature;
 
531
        }
 
532
        
 
533
        public TGResources getResources(){
 
534
                return this.resources;
 
535
        }
 
536
        
 
537
        public int getHeight() {
 
538
                return this.height;
 
539
        }
 
540
        
 
541
        public void setHeight(int height) {
 
542
                this.height = height;
 
543
        }
 
544
        
 
545
        public int getWidth() {
 
546
                return this.width;
 
547
        }
 
548
        
 
549
        public void setWidth(int width) {
 
550
                this.width = width;
 
551
        }
 
552
        
 
553
        public int getStyle(){
 
554
                return this.style;
 
555
        }
 
556
        
 
557
        public void setStyle(int style){
 
558
                this.style = style;
 
559
        }
 
560
        
 
561
        public float getScale() {
 
562
                return this.scale;
 
563
        }
 
564
        
 
565
        public void setScale(float scale) {
 
566
                this.scale = scale;
 
567
        }
 
568
        
 
569
        public float getFontScale() {
 
570
                return this.fontScale;
 
571
        }
 
572
        
 
573
        public void setFontScale(float fontScale) {
 
574
                this.fontScale = fontScale;
 
575
        }
 
576
        
 
577
        public boolean isBufferEnabled() {
 
578
                return this.bufferEnabled;
 
579
        }
 
580
        
 
581
        public void setBufferEnabled(boolean bufferEnabled) {
 
582
                this.bufferEnabled = bufferEnabled;
 
583
        }
 
584
        
 
585
        public int getFirstMeasureSpacing() {
 
586
                return this.firstMeasureSpacing;
 
587
        }
 
588
        
 
589
        public void setFirstMeasureSpacing(int firstMeasureSpacing) {
 
590
                this.firstMeasureSpacing = firstMeasureSpacing;
 
591
        }
 
592
        
 
593
        public int getMinBufferSeparator() {
 
594
                return this.minBufferSeparator;
 
595
        }
 
596
        
 
597
        public void setMinBufferSeparator(int minBufferSeparator) {
 
598
                this.minBufferSeparator = minBufferSeparator;
 
599
        }
 
600
        
 
601
        public int getMinTopSpacing() {
 
602
                return this.minTopSpacing;
 
603
        }
 
604
        
 
605
        public void setMinTopSpacing(int minTopSpacing) {
 
606
                this.minTopSpacing = minTopSpacing;
 
607
        }
 
608
        
 
609
        public int getMinScoreTabSpacing() {
 
610
                return this.minScoreTabSpacing;
 
611
        }
 
612
        
 
613
        public void setMinScoreTabSpacing(int minScoreTabSpacing) {
 
614
                this.minScoreTabSpacing = minScoreTabSpacing;
 
615
        }
 
616
        
 
617
        public int getScoreLineSpacing() {
 
618
                return this.scoreLineSpacing;
 
619
        }
 
620
        
 
621
        public void setScoreLineSpacing(int scoreLineSpacing) {
 
622
                this.scoreLineSpacing = scoreLineSpacing;
 
623
        }
 
624
        
 
625
        public int getScoreSpacing() {
 
626
                return this.scoreSpacing;
 
627
        }
 
628
        
 
629
        public void setScoreSpacing(int scoreSpacing) {
 
630
                this.scoreSpacing = scoreSpacing;
 
631
        }
 
632
        
 
633
        public int getFirstTrackSpacing() {
 
634
                return this.firstTrackSpacing;
 
635
        }
 
636
        
 
637
        public void setFirstTrackSpacing(int firstTrackSpacing) {
 
638
                this.firstTrackSpacing = firstTrackSpacing;
 
639
        }
 
640
        
 
641
        public int getTrackSpacing() {
 
642
                return this.trackSpacing;
 
643
        }
 
644
        
 
645
        public void setTrackSpacing(int trackSpacing) {
 
646
                this.trackSpacing = trackSpacing;
 
647
        }
 
648
        
 
649
        public int getStringSpacing() {
 
650
                return this.stringSpacing;
 
651
        }
 
652
        
 
653
        public void setStringSpacing(int stringSpacing) {
 
654
                this.stringSpacing = stringSpacing;
 
655
        }
 
656
        
 
657
        public int getChordFretIndexSpacing() {
 
658
                return this.chordFretIndexSpacing;
 
659
        }
 
660
        
 
661
        public void setChordFretIndexSpacing(int chordFretIndexSpacing) {
 
662
                this.chordFretIndexSpacing = chordFretIndexSpacing;
 
663
        }
 
664
        
 
665
        public int getChordStringSpacing() {
 
666
                return this.chordStringSpacing;
 
667
        }
 
668
        
 
669
        public void setChordStringSpacing(int chordStringSpacing) {
 
670
                this.chordStringSpacing = chordStringSpacing;
 
671
        }
 
672
        
 
673
        public int getChordFretSpacing() {
 
674
                return this.chordFretSpacing;
 
675
        }
 
676
        
 
677
        public void setChordFretSpacing(int chordFretSpacing) {
 
678
                this.chordFretSpacing = chordFretSpacing;
 
679
        }
 
680
        
 
681
        public int getChordNoteSize() {
 
682
                return this.chordNoteSize;
 
683
        }
 
684
        
 
685
        public void setChordNoteSize(int chordNoteSize) {
 
686
                this.chordNoteSize = chordNoteSize;
 
687
        }
 
688
        
 
689
        public int getRepeatEndingSpacing() {
 
690
                return this.repeatEndingSpacing;
 
691
        }
 
692
        
 
693
        public void setRepeatEndingSpacing(int repeatEndingSpacing) {
 
694
                this.repeatEndingSpacing = repeatEndingSpacing;
 
695
        }
 
696
        
 
697
        public int getTupletoSpacing() {
 
698
                return this.tupletoSpacing;
 
699
        }
 
700
        
 
701
        public void setTupletoSpacing(int tupletoSpacing) {
 
702
                this.tupletoSpacing = tupletoSpacing;
 
703
        }
 
704
        
 
705
        public int getTextSpacing() {
 
706
                return this.textSpacing;
 
707
        }
 
708
        
 
709
        public void setTextSpacing(int textSpacing) {
 
710
                this.textSpacing = textSpacing;
 
711
        }
 
712
        
 
713
        public int getEffectSpacing() {
 
714
                return this.effectSpacing;
 
715
        }
 
716
        
 
717
        public void setEffectSpacing(int effectSpacing) {
 
718
                this.effectSpacing = effectSpacing;
 
719
        }
 
720
        
 
721
        public int getDefaultChordSpacing(){
 
722
                int spacing = 0;
 
723
                if( (this.style & DISPLAY_CHORD_DIAGRAM) != 0 ){
 
724
                        spacing += ( (TGChordImpl.MAX_FRETS * getChordFretSpacing()) + getChordFretSpacing());
 
725
                }
 
726
                if( (this.style & DISPLAY_CHORD_NAME) != 0 ){
 
727
                        spacing += Math.round( (15f * getScale()) );
 
728
                }
 
729
                return spacing;
 
730
        }
 
731
        
 
732
        public boolean isFirstMeasure(TGMeasure measure){
 
733
                return (measure.getNumber() == 1);
 
734
        }
 
735
        
 
736
        public boolean isLastMeasure(TGMeasure measure){
 
737
                return (measure.getNumber() == getSongManager().getSong().countMeasureHeaders());
 
738
        }
 
739
        
 
740
        protected void clearTrackPositions(){
 
741
                this.trackPositions.clear();
 
742
        }
 
743
        
 
744
        protected void addTrackPosition(int track,int posY,int height){
 
745
                this.trackPositions.add(new TrackPosition(track,posY,height));
 
746
        }
 
747
        
 
748
        public int getTrackNumberAt(int y){
 
749
                TrackPosition trackPos = getTrackPositionAt(y);
 
750
                return ((trackPos != null)?trackPos.getTrack():-1);
 
751
        }
 
752
        
 
753
        public TrackPosition getTrackPositionAt(int y){
 
754
                TrackPosition trackPos = null;
 
755
                int minorDistance = 0;
 
756
                
 
757
                Iterator it = this.trackPositions.iterator();
 
758
                while(it.hasNext()){
 
759
                        TrackPosition pos = (TrackPosition)it.next();
 
760
                        int distanceY = Math.min(Math.abs(y - (pos.getPosY())), Math.abs(y - (pos.getPosY() + pos.getHeight() - 10)));
 
761
                        if(trackPos == null || distanceY < minorDistance){
 
762
                                trackPos = pos;
 
763
                                minorDistance = distanceY;
 
764
                        }
 
765
                }
 
766
                return trackPos;
 
767
        }
 
768
        
 
769
        public void disposeLayout(){
 
770
                this.getResources().dispose();
 
771
        }
 
772
        
 
773
        public class TrackPosition{
 
774
                private int track;
 
775
                private int posY;
 
776
                private int height;
 
777
                
 
778
                public TrackPosition(int track,int posY,int height){
 
779
                        this.track = track;
 
780
                        this.posY = posY;
 
781
                        this.height = height;
 
782
                }
 
783
                
 
784
                public int getPosY() {
 
785
                        return this.posY;
 
786
                }
 
787
                
 
788
                public int getHeight() {
 
789
                        return this.height;
 
790
                }
 
791
                
 
792
                public int getTrack() {
 
793
                        return this.track;
 
794
                }
 
795
        }
 
796
}