-
Notifications
You must be signed in to change notification settings - Fork 0
/
SongWriter.pde
149 lines (112 loc) · 3.49 KB
/
SongWriter.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
import java.util.Scanner;
import java.io.*;
import java.util.Map;
import java.util.Map.Entry;
import java.util.List;
import java.util.Set;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
String[] artistNames = {"EDEN", "Jon Bellion", "Post Malone", "Watsky", "Glass Animals","Shawn Mendes","Drake","Ariana Grande","alt-J"};
//String[] artistNames = {"EDEN","Glass Animals"};
Artist[] artists = new Artist[artistNames.length];
NewSong topSong;
color bg = color(40, 50, 60);
boolean isNextSong;
float lineHeight;
float defaultX, defaultY;
float defaultSpeed = .72;
float speed = defaultSpeed;
int prevSongIndex = 0;
PFont lyricFont;
PFont artistFont;
void setup() {
size(1280, 800);
background(bg);
defaultX = 250;
defaultY = height;
for (int x = 0; x < artistNames.length; x++)
artists[x] = new Artist(artistNames[x]);
// ---------------------------------------------------------------
// SETUP FONT
//String[] fontList = PFont.list();
//printArray(fontList);
//PFont myFont = createFont("Monospaced.bold", 12);
//PFont myFont = createFont("HelveticaNeue-UltraLight", 24);
//PFont myFont = createFont("CourierNewPSMT", 14);
//PFont myFont = createFont("CourierNewPS-BoldMT", 14);
//PFont myFont = createFont("Courier", 14);
//lyricFont = createFont("PTMono-Regular", 14);
//artistFont = createFont("PTMono-Regular", 26);
lyricFont = createFont("Monospaced.bold", 18);
artistFont = createFont("Monospaced.bold", 32);
textFont(lyricFont);
//print(songToString(songs));
// ----------------------------------------------------------------
// DRAW INFO
//noLoop();
artists[0].generateNewSong();
NewSong song = artists[0].getNewSong();
//text(song.getSong(), 20,20);
//println(song.getSong());
topSong = song;
isNextSong = false;
lineHeight = textDescent() + textAscent() + 7.5;
}
//int num = 100;
void draw() {
background(bg);
drawLyrics();
if (topSong.getEndY() < 0 ) {
println("removing topSong");
topSong = topSong.getNext();
isNextSong = false;
}
if (!isNextSong) {
println("creating next song");
thread("addNextSong");
isNextSong = true;
}
topSong.move();
}
void drawLyrics() {
NewSong temp = topSong;
int count = 0;
while (temp != null) {
// draw lyrics
textFont(lyricFont);
textAlign(LEFT);
text(temp.getSong(), temp.getX(), temp.getY());
// draw the artist name
// the gross min(,max()) expression will keep the artist name on screen until the song
// is almost completely off screen
textFont(artistFont);
textAlign(RIGHT);
float textY = min(temp.getEndY() - 120 , max(30,temp.getY()) );
text(temp.getArtist(), 10, textY , temp.getX() - 30, textY + 1000);
// draw positions
textFont(lyricFont);
//text(temp.getX() + ":" + temp.getY(), 800, 20 + count++*lineHeight);
temp = temp.getNext();
}
}
// run on new thread!!
void addNextSong() {
int num;
do
num = int(random(artists.length));
while (num == prevSongIndex);
artists[num].generateNewSong();
topSong.setNext(artists[num].getNewSong());
topSong.getNext().setPos(topSong.getX(), topSong.getEndY() + 50);
println("created nextsong");
//isNextSong = true;
prevSongIndex = num;
}
void keyPressed() {
speed = 9;
}
void keyReleased() {
speed = defaultSpeed;
}