Put jack driver stuff in drivers/jack/jack_audio.c
[pineappletracker.git] / hively / gui.c
blob8468da0825c1c065fe7c02cfc6fbc6531767417c
1 #include <ncurses.h>
2 #include "hvl_replay.h"
3 #include "pineapple.h"
4 #include "gui.h"
6 int currtrack = 1;
7 int currinstr = 1;
8 int currtab = 0;
9 int songy = 0;
11 int disptick = 0;
12 char *dispmesg = "";
13 int note;
15 void _display(void);
17 void _display(void){
18 int cx = (getmaxx(stdscr)/2)-(strlen(dispmesg)/2)-1;
19 int cy = getmaxy(stdscr)/2;
21 mvaddch(cy-1, cx, ACS_ULCORNER);
22 for(int i=cx+1; i<cx+strlen(dispmesg)+1; i++)
23 mvaddch(cy-1, i, ACS_HLINE);
24 mvaddch(cy-1, cx+strlen(dispmesg)+1, ACS_URCORNER);
26 mvaddch(cy, cx, ACS_VLINE);
27 mvaddstr(cy, cx+1, dispmesg);
28 mvaddch(cy, cx+strlen(dispmesg)+1, ACS_VLINE);
30 mvaddch(cy+1, cx, ACS_LLCORNER);
31 for(int i=cx+1; i<cx+strlen(dispmesg)+1; i++)
32 mvaddch(cy+1, i, ACS_HLINE);
33 mvaddch(cy+1, cx+strlen(dispmesg)+1, ACS_LRCORNER);
36 static char *notenames[] = {"C-", "C#", "D-", "D#", "E-", "F-", "F#", "G-", "G#", "A-", "A#", "H-"};
38 char *keymap[2] = {
39 "zsxdcvgbhnjm,l.;/",
40 "q2w3er5t6y7ui9o0p"
43 void setdisplay(char *str){
44 disptick = 350;
45 dispmesg = str;
48 int freqkey(int c){
49 char *s;
50 int f = -1;
52 if(c == '-' || c == KEY_DC) return 0;
53 if(c > 0 && c < 256){
54 s = strchr(keymap[0], c);
55 if(s){
56 f = (s - (keymap[0])) + octave * 12 + 1;
57 }else{
58 s = strchr(keymap[1], c);
59 if(s){
60 f = (s - (keymap[1])) + octave * 12 + 12 + 1;
64 if(f > 12 * 9 + 1) return -1;
65 return f;
68 void iedplonk(int x) {
69 setdisplay("\\o/");
70 note = x;
71 tune->curNote = x;
72 //hvl_process_step(tune, &tune->ht_Voices[0]);
73 //hvl_process_frame(tune, &tune->ht_Voices[0]);
74 //hvl_set_audio(&tune->ht_Voices[0], tune->ht_Frequency);
75 plonked = 1;
78 void initgui(){
79 initscr();
81 nonl();
82 noecho();
83 keypad(stdscr, FALSE);
85 nodelay(stdscr, TRUE);
87 //atexit(endwin());
90 void drawposed(){
91 int i, j;
92 char buf[1024];
93 unsigned char trans;
94 move(0,0);
95 for(i = 0; i<tune->ht_PositionNr; i++){
96 snprintf(buf, sizeof(buf), "%02x", i);
97 addstr(buf);
98 addch(ACS_VLINE);
99 for(j= 0; j<4; j++){
100 trans = tune->ht_Positions[i].pos_Transpose[j]; //this makes the transpose column display 'fe' instead of 'fffffffffe'..., which is weird since trans is unsigned
101 snprintf(buf, sizeof(buf), "%02x:%02x", tune->ht_Positions[i].pos_Track[j], trans);
102 addstr(buf);
103 if(j !=3)
104 addch(' ');
106 move(i + 1, 0);
107 if(songy == i) attrset(A_BOLD);
109 int c = 0;
110 snprintf(buf, sizeof(buf), "Name: %s", tune->ht_Name);
111 mvaddstr(c++, 60, buf);
112 snprintf(buf, sizeof(buf), "PosNr: %02x", tune->ht_PosNr);
113 mvaddstr(c++, 60, buf);
114 snprintf(buf, sizeof(buf), "PositionNr: %02x", tune->ht_PositionNr);
115 mvaddstr(c++, 60, buf);
116 snprintf(buf, sizeof(buf), "Restart: %02x", tune->ht_Restart);
117 mvaddstr(c++, 60, buf);
118 snprintf(buf, sizeof(buf), "NoteNr: %02x", tune->ht_NoteNr);
119 mvaddstr(c++, 60, buf);
120 snprintf(buf, sizeof(buf), "TrackLength: %02x", tune->ht_TrackLength);
121 mvaddstr(c++, 60, buf);
122 snprintf(buf, sizeof(buf), "TrackNr: %02x", tune->ht_TrackNr);
123 mvaddstr(c++, 60, buf);
124 snprintf(buf, sizeof(buf), "Tempo: %02x", tune->ht_Tempo);
125 mvaddstr(c++,60, buf);
126 snprintf(buf, sizeof(buf), "StepWaitFrames: %02x", tune->ht_StepWaitFrames);
127 mvaddstr(c++,60, buf);
128 snprintf(buf, sizeof(buf), "SongEndReached: %02x", tune->ht_SongEndReached);
129 mvaddstr(c++,60, buf);
130 snprintf(buf, sizeof(buf), "Freq: %d", tune->ht_Frequency);
131 mvaddstr(c++,60, buf);
132 snprintf(buf, sizeof(buf), "GetNewPosition: %02x", tune->ht_GetNewPosition);
133 mvaddstr(c++,60, buf);
134 //for(int i = 0; i <tune->ht_Channels; i++) {
135 for(int i = 0; i < 2; i++) {
136 snprintf(buf, sizeof(buf), "VC %x TrackPeriod: %x", i, tune->ht_Voices[i].vc_TrackPeriod);
137 mvaddstr(c++,60, buf);
138 snprintf(buf, sizeof(buf), "VC %x SamplePos: %x", i, tune->ht_Voices[i].vc_SamplePos);
139 mvaddstr(c++,60, buf);
140 snprintf(buf, sizeof(buf), "VC %x Delta: %x", i, tune->ht_Voices[i].vc_Delta);
141 mvaddstr(c++,60, buf);
142 snprintf(buf, sizeof(buf), "VC %x WaveLength: %x", i, tune->ht_Voices[i].vc_WaveLength);
143 mvaddstr(c++,60, buf);
144 snprintf(buf, sizeof(buf), "VC %x PerfCurrent: %x", i, tune->ht_Voices[i].vc_PerfCurrent);
145 mvaddstr(c++,60, buf);
146 snprintf(buf, sizeof(buf), "VC %x PerfSpeed: %x", i, tune->ht_Voices[i].vc_PerfSpeed);
147 mvaddstr(c++,60, buf);
148 snprintf(buf, sizeof(buf), "VC %x FilterOn: %x", i, tune->ht_Voices[i].vc_FilterOn);
149 mvaddstr(c++,60, buf);
150 snprintf(buf, sizeof(buf), "VC %x FilterPos: %x", i, tune->ht_Voices[i].vc_FilterPos);
151 mvaddstr(c++,60, buf);
152 snprintf(buf, sizeof(buf), "VC %x SquarePos: %x", i, tune->ht_Voices[i].vc_SquarePos);
153 mvaddstr(c++,60, buf);
155 snprintf(buf, sizeof(buf), "SpeedMultiplier: %02x", tune->ht_SpeedMultiplier);
156 mvaddstr(c++, 60, buf);
157 snprintf(buf, sizeof(buf), "InstrumentNr: %02x", tune->ht_InstrumentNr);
158 mvaddstr(c++, 60, buf);
159 snprintf(buf, sizeof(buf), "Note: %s%d", notenames[(note-1) % 12], (note-1) / 12);
160 mvaddstr(c++, 60, buf);
163 void drawtracked(){
164 int i;
165 char buf[1024];
166 snprintf(buf, sizeof(buf), "Track: %02x", currtrack);
167 mvaddstr(0, 26, buf);
168 move(0, 35);
169 for(i = 0; i < tune->ht_TrackLength; i++){
170 snprintf(buf, sizeof(buf), "%02x", i);
171 addstr(buf);
172 addch(ACS_VLINE);
174 if(tune->ht_Tracks[currtrack][i].stp_Note)
175 //snprintf(buf, sizeof(buf), "%s%d ", notenames[(tune->ht_Tracks[currtrack][i].stp_Note - 1) % 12], (tune->ht_Tracks[currtrack][i].stp_Note - 1) / 12);
176 snprintf(buf, sizeof(buf), "%d ", tune->ht_Tracks[currtrack][i].stp_Note);
177 else
178 snprintf(buf, sizeof(buf), "--- ");
179 addstr(buf);
181 if(tune->ht_Tracks[currtrack][i].stp_Instrument)
182 snprintf(buf, sizeof(buf), "%02x ", tune->ht_Tracks[currtrack][i].stp_Instrument);
183 else
184 snprintf(buf, sizeof(buf), "-- ");
185 addstr(buf);
187 if(tune->ht_Tracks[currtrack][i].stp_FX)
188 snprintf(buf, sizeof(buf), "%02x ", tune->ht_Tracks[currtrack][i].stp_FX);
189 else
190 snprintf(buf, sizeof(buf), "-- ");
191 addstr(buf);
193 if(tune->ht_Tracks[currtrack][i].stp_FXParam)
194 snprintf(buf, sizeof(buf), "%02x ", tune->ht_Tracks[currtrack][i].stp_FXParam);
195 else
196 snprintf(buf, sizeof(buf), "-- ");
197 addstr(buf);
199 if(tune->ht_Tracks[currtrack][i].stp_FXb)
200 snprintf(buf, sizeof(buf), "%02x ", tune->ht_Tracks[currtrack][i].stp_FX);
201 else
202 snprintf(buf, sizeof(buf), "-- ");
203 addstr(buf);
205 if(tune->ht_Tracks[currtrack][i].stp_FXbParam)
206 snprintf(buf, sizeof(buf), "%02x ", tune->ht_Tracks[currtrack][i].stp_FXParam);
207 else
208 snprintf(buf, sizeof(buf), "-- ");
209 addstr(buf);
211 if((i == tune->ht_NoteNr))
212 addch('*');
214 move(i + 1, 35);
218 void drawgui(){
219 erase();
220 drawposed();
221 drawtracked();
223 switch(currtab) {
224 case 0:
225 move(songy, songx);
226 break;
227 case 1:
228 move(tracky, trackx);
229 break;
232 refresh();
234 if(disptick > 0){
235 _display();
236 disptick--;
240 void handleinput(){
241 int c, x;
242 if((c = getch()) != ERR){
243 switch(c){
244 case 'Q':
245 erase();
246 refresh();
247 endwin();
248 exit(0);
249 break;
250 case 'J':
251 if(currtrack > 1)
252 currtrack--;
253 break;
254 case 'K':
255 if(currtrack < 0xff)
256 currtrack++;
257 break;
258 case 'h':
259 case KEY_LEFT:
260 act_mvleft();
261 break;
262 case 'j':
263 case KEY_DOWN:
264 act_mvdown();
265 break;
266 case 'k':
267 case KEY_UP:
268 act_mvup();
269 break;
270 case 'l':
271 case KEY_RIGHT:
272 act_mvright();
273 break;
274 case CTRL('H'):
275 currtab--;
276 if(currtab < 0)
277 currtab = 2;
278 break;
279 case CTRL('L'):
280 currtab++;
281 currtab %= 3;
282 break;
283 case KEY_TAB:
284 currtab++;
285 currtab %= 3;
286 break;
287 case ENTER:
288 play = 1;
289 break;
290 case ' ':
291 play = 0;
292 plonked = 0;
293 break;
294 default:
295 x = freqkey(c);
296 if(x > 0) iedplonk(x);
297 break;
302 void guiloop(){
303 ESCDELAY=50;
304 for(;;){
305 drawgui();
306 handleinput();