-
Notifications
You must be signed in to change notification settings - Fork 2
/
Tools.pde
204 lines (193 loc) · 4.77 KB
/
Tools.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
// this tab contains Tools
void showOtherScreenElements() {
// when we listen to a song
//
// first perform a forward fft on one of song's buffers
// I'm using the mix buffer
// but you can use any one you like
if (showFFT) {
if (!(fft==null)) {
fft.forward(song.mix);
stroke(255, 0, 0, 128);
// draw the spectrum as a series of vertical lines
// I multiple the value of getBand by 4
// so that we can see the lines better
for (int i = 0; i < fft.specSize(); i++)
{
line(i, height, i, height - fft.getBand(i)*4);
} // for
} // if
} // if
//
fill(255);
try {
// show played
String text1 ="Played "
+ strFromMillis ( song.position() )
+ " of "
+ strFromMillis ( songLength )
+ ".";
text ( text1, width - (textWidth(text1)), 30 );
// show pause
if (!song.isPlaying()) {
fill(255);
text ("pause", width/2-17, 54);
} // if
} // try
catch (Exception e) {
// e.printStackTrace();
// do nothing
}
//
buttonShowSongListOrOneSong.display();
buttonPrevious.display();
buttonNext.display();
//
statusMsg.statusMsgShow();
//
} // func
// ------------------------------------------------------------
void showListFunction( String headline, String[] localArray, int indexHighlight ) {
// data for list
final int ys = 122; // y start-pos
final int yi = 21; // y line difference
//
int y = ys;
// headline
textSize(17);
fill(255, 2, 2);
text ( headline, 25, y);
//
textSize(12);
y+=31;
//
// perform checks on start / end of list (when scrolling)
// from and to is the range to be displayed
if (from+14 > localArray.length)
from=localArray.length-14;
if (from<0)
from =0;
int to=from+14;
if (to > localArray.length)
to=localArray.length;
//
for (int i = from; i < to; i++) {
// line background
if (i%2 == 1)
fill(25);
else
fill(125);
noStroke();
rect(-1, y-14, width+3, 21);
// text
fill(255);
text((localArray[i]), 15, y);
//
// this is used for song:
if (indexHighlight>-1) { // if defined
if (i==indexHighlight) { // and current line
// current song
fill(255, 0, 0); // highlight it with a >
noStroke();
trianglePointingRight(5, y-5);
} // if
} // if
y+=yi; // next line
} // for
} // func
void makeButtonsForList ( String[] localArray ) {
// make buttons for list
buttonsList.clear();
for (int i = 0; i < localArray.length; i++) {
buttonsList.add (new Button( -1, 122+31+(i*21)-14,
width+10, 21,
false, color (0),
false, color (255),
"",
"",
i) ) ;
} // for
} // func
// -------------------------------------------------------------
String strFromMillis ( int m ) {
// returns a string that represents a given amount of millis "m"
// as hours:minutes:seconds
// (can't do days etc.)
float sec;
int min;
//
sec = m / 1000;
min = floor(sec / 60);
sec = floor(sec % 60);
// over one hour?
if (min>59) {
int hrs = floor(min / 60);
min = floor (min % 60);
return hrs+":"+nf(min, 2)+":"+nf(int(sec), 2);
}
else
{
return min+":"+nf(int(sec), 2);
}
} //
//
String showSongWithoutFolder() {
// returns short name of current file
if ( meta == null ) {
println("meta==null");
return "?";
} // if
else {
String pathGlobal2=new String(pathGlobal.getAbsolutePath());
if (pathGlobal2.charAt(pathGlobal2.length()-1) == '.')
pathGlobal2=pathGlobal2.substring(0, pathGlobal2.length()-2);
return meta.fileName().substring(pathGlobal2.length() + 1);
} // else
} // func
//
String showSongWithoutFolder2( String songNameLong ) {
// returns short name of given file songNameLong
if (songNameLong.length() > pathGlobal.getAbsolutePath().length() + 1) {
String pathGlobal2=pathGlobal.getAbsolutePath();
if (pathGlobal2.charAt(pathGlobal2.length()-1) == '.')
pathGlobal2=pathGlobal2.substring(0, pathGlobal2.length()-2);
return songNameLong.substring(pathGlobal2.length() + 1);
}
else
return "?";
}
//
void textTab (String s, float x, float y)
{
// makes \t as tab for a table for one line
// (only for 2 columns yet)
//
// indent:
int indent = 90;
//
s=trim ( s );
String [] texts = split (s, "\t");
s=null;
texts[0]=trim(texts[0]);
text (texts[0], x, y);
//
// do we have a second part?
if (texts.length>1 && texts[1]!=null) {
// is the indent too small
if (textWidth(texts[0]) > indent) {
indent = int (textWidth(texts[0]) + 10);
} // if
//
texts[1]=trim(texts[1]);
text (texts[1], x+indent, y);
} // if
} // func
//
void stop()
{
song.close();
minim.stop();
//
super.stop();
}
//