| 1 |
/* |
| 2 |
CheeseCutter v2 (C) Abaddon. Licensed under GNU GPL. |
| 3 |
*/ |
| 4 |
|
| 5 |
module ui.ui; |
| 6 |
import derelict.sdl2.sdl; |
| 7 |
import std.conv; |
| 8 |
import main; |
| 9 |
import ct.base; |
| 10 |
import com.session; |
| 11 |
import ct.purge; |
| 12 |
import ui.help; |
| 13 |
import ui.input; |
| 14 |
import audio.player; |
| 15 |
import ui.tables; |
| 16 |
import ui.dialogs; |
| 17 |
import seq.fplay; |
| 18 |
import com.fb; |
| 19 |
import com.util; |
| 20 |
import seq.sequencer; |
| 21 |
import audio.audio; |
| 22 |
import std.string; |
| 23 |
import std.file; |
| 24 |
import std.stdio; |
| 25 |
import audio.audio, audio.timer, audio.callback; |
| 26 |
|
| 27 |
enum PAGESTEP = 16; |
| 28 |
enum CONFIRM_TIMEOUT = 90; |
| 29 |
enum UPDATE_RATE = 2; // 50 / n times per second |
| 30 |
|
| 31 |
private int tickcounter1, tickcounter3 = -1; |
| 32 |
private int clearcounter, optimizecounter, escapecounter, restartcounter; |
| 33 |
|
| 34 |
struct Rectangle { |
| 35 |
int x, y; |
| 36 |
int height, width; |
| 37 |
alias height h; |
| 38 |
alias width w; |
| 39 |
|
| 40 |
string toString() { |
| 41 |
return format("%d %d %d %d",x, y, h, w); |
| 42 |
} |
| 43 |
|
| 44 |
bool overlaps(int cx, int cy) { |
| 45 |
return cx >= x && cx < x + width && cy >= y && cy < y + height; |
| 46 |
} |
| 47 |
|
| 48 |
Rectangle relativeTo(int scrx, int scry) { |
| 49 |
return Rectangle(scrx - x, scry - y); |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
abstract class Window { |
| 54 |
Rectangle area; |
| 55 |
Input input; |
| 56 |
protected ContextHelp help; |
| 57 |
|
| 58 |
this(Rectangle a) { |
| 59 |
this(a, ui.help.HELPMAIN); |
| 60 |
} |
| 61 |
|
| 62 |
this(Rectangle a, ContextHelp ctx) { |
| 63 |
contextHelp = ctx; |
| 64 |
area = a; |
| 65 |
} |
| 66 |
|
| 67 |
abstract void update(); |
| 68 |
int keypress(Keyinfo key) { return 0; } |
| 69 |
int keyrelease(Keyinfo key) { return 0; } |
| 70 |
void refresh() {} |
| 71 |
void deactivate() {} |
| 72 |
void activate() { refresh(); } |
| 73 |
void clickedAt(int scrx, int scry, int button) {} |
| 74 |
|
| 75 |
protected: |
| 76 |
|
| 77 |
@property void contextHelp(ContextHelp h) { help = h; } |
| 78 |
@property ContextHelp contextHelp() { return help; } |
| 79 |
|
| 80 |
final void drawFrame() { drawFrame(area); } |
| 81 |
|
| 82 |
static void drawFrame(Rectangle a) { |
| 83 |
int x,y; |
| 84 |
for(y=a.y;y<a.y+a.height;y++) { |
| 85 |
screen.setChar(a.x-1,y,0); |
| 86 |
screen.setChar(a.x,y, 0x500|216); |
| 87 |
screen.setChar(a.x+a.width-1,y, 0x500|216); |
| 88 |
screen.setChar(a.x+a.width,y,0); |
| 89 |
screen.data[a.x+1 + y * screen.width .. a.x + a.width - 1 + y * screen.width] = 0x00; |
| 90 |
screen.setColor(a.x+a.width+1,y+1,11,0); |
| 91 |
} |
| 92 |
for(x=a.x;x<a.x+a.width;x++) { |
| 93 |
screen.setChar(x,a.y, 0x0500|192); |
| 94 |
screen.setChar(x,a.y+a.height-1, 0x0500|192); |
| 95 |
screen.setColor(x+2,a.y+a.height, 11, 0); |
| 96 |
} |
| 97 |
|
| 98 |
screen.setChar(a.x,a.y,0x500 | 201); |
| 99 |
screen.setChar(a.x+a.width-1,a.y,0x500 | 215); |
| 100 |
screen.setChar(a.x,a.y+a.height-1,0x500 | 195); |
| 101 |
screen.setChar(a.x+a.width-1,a.y+a.height-1,0x500 | 212); |
| 102 |
} |
| 103 |
|
| 104 |
final void drawRuler(int y) { |
| 105 |
for(int x = area.x;x < area.x + area.width; x++) { |
| 106 |
screen.setChar(x, area.y + y, 0x0500|192); |
| 107 |
} |
| 108 |
} |
| 109 |
|
| 110 |
} |
| 111 |
|
| 112 |
struct Hotspot { |
| 113 |
Rectangle area; |
| 114 |
void delegate(int) callback; |
| 115 |
} |
| 116 |
|
| 117 |
class WindowSwitcher : Window { |
| 118 |
Window[] windows; |
| 119 |
char[] hotkeys; |
| 120 |
Window activeWindow; |
| 121 |
int activeWindowNum; |
| 122 |
|
| 123 |
this(Rectangle s, Window[] w) { |
| 124 |
super(s); |
| 125 |
windows = w; |
| 126 |
activeWindowNum = 0; |
| 127 |
activateWindow(); |
| 128 |
} |
| 129 |
|
| 130 |
this(Rectangle s, Window[] w, string h) { |
| 131 |
this(s, w); |
| 132 |
hotkeys = cast(char[])h; |
| 133 |
} |
| 134 |
|
| 135 |
this(Rectangle s, Window[] w, char[] h) { |
| 136 |
this(s, w); |
| 137 |
hotkeys = h; |
| 138 |
} |
| 139 |
|
| 140 |
this(Rectangle s, Window[] w, char[] h, int mk) { |
| 141 |
this(s, w); |
| 142 |
hotkeys = h; |
| 143 |
} |
| 144 |
|
| 145 |
void activateWindow() { |
| 146 |
activateWindow(activeWindowNum); |
| 147 |
} |
| 148 |
|
| 149 |
void activateWindow(ulong n){ |
| 150 |
activateWindow(cast(int)n); |
| 151 |
} |
| 152 |
|
| 153 |
void activateWindow(int n) { |
| 154 |
if(activeWindow !is null) |
| 155 |
activeWindow.deactivate(); |
| 156 |
activeWindow = windows[n]; |
| 157 |
activeWindow.activate(); |
| 158 |
activeWindowNum = n; |
| 159 |
input = activeWindow.input; |
| 160 |
refresh(); |
| 161 |
} |
| 162 |
|
| 163 |
override void update() { |
| 164 |
activeWindow.update(); |
| 165 |
} |
| 166 |
|
| 167 |
override void activate() { |
| 168 |
activeWindow.activate(); |
| 169 |
} |
| 170 |
|
| 171 |
override void deactivate() { |
| 172 |
activeWindow.deactivate(); |
| 173 |
} |
| 174 |
|
| 175 |
override void refresh() { |
| 176 |
foreach(w; windows) w.refresh(); |
| 177 |
} |
| 178 |
|
| 179 |
override int keypress(Keyinfo key) { |
| 180 |
if(key.mods & KMOD_ALT) { |
| 181 |
foreach(i, hk; hotkeys) { |
| 182 |
if(key.raw == hk) { |
| 183 |
activeWindowNum = cast(int)i; |
| 184 |
activateWindow(); |
| 185 |
return OK; |
| 186 |
} |
| 187 |
} |
| 188 |
} |
| 189 |
switch(key.raw) { |
| 190 |
case SDLK_TAB: |
| 191 |
key.mods & KMOD_SHIFT ? activeWindowNum-- : activeWindowNum++ ; |
| 192 |
/+ |
| 193 |
if(activeWindowNum < 0) activeWindowNum = cast(int)(windows.length - 1); |
| 194 |
if(activeWindowNum >= windows.length) |
| 195 |
activeWindowNum %= windows.length; |
| 196 |
+/ |
| 197 |
activeWindowNum = umod(activeWindowNum, 0, cast(int)windows.length - 1); |
| 198 |
activateWindow(); |
| 199 |
return OK; |
| 200 |
default: |
| 201 |
return activeWindow.keypress(key); |
| 202 |
} |
| 203 |
assert(0); |
| 204 |
} |
| 205 |
|
| 206 |
override ContextHelp contextHelp() { |
| 207 |
return activeWindow.contextHelp(); |
| 208 |
} |
| 209 |
|
| 210 |
override void clickedAt(int scrx, int scry, int button) { |
| 211 |
// activateAt(scrx - activeWindow.area.x, scry - activeWindow.area.y); |
| 212 |
} |
| 213 |
} |
| 214 |
|
| 215 |
class Infobar : Window { |
| 216 |
private { |
| 217 |
const int x1, x2; |
| 218 |
int idx; |
| 219 |
} |
| 220 |
InputString inputTitle, inputAuthor, inputReleased; |
| 221 |
|
| 222 |
this(Rectangle a) { |
| 223 |
super(a); |
| 224 |
x1 = area.x; |
| 225 |
x2 = x1 + (com.fb.mode > 0 ? 64 : 48); |
| 226 |
} |
| 227 |
|
| 228 |
override void update() { |
| 229 |
int headerColor = state.keyjamStatus ? 14 : 12; |
| 230 |
if(escapecounter) headerColor = 7; |
| 231 |
|
| 232 |
screen.clrtoeol(0, headerColor); |
| 233 |
|
| 234 |
enum hdr = "CheeseCutter 2.10" ~ com.util.versionInfo; |
| 235 |
screen.cprint(4, 0, 1, headerColor, hdr); |
| 236 |
screen.cprint(screen.width - 14, 0, 1, headerColor, "F12 = Help"); |
| 237 |
int c1 = audio.player.isPlaying ? 13 : 12; |
| 238 |
screen.fprint(x1,area.y,format("`05Time: `0%x%02d:%02d / $%02x", |
| 239 |
c1,audio.timer.min, audio.timer.sec, |
| 240 |
audio.callback.linesPerFrame & 255)); |
| 241 |
|
| 242 |
screen.fprint(x1 + 19,area.y, |
| 243 |
format("`05Oct: `0d%d `05Spd: `0d%X `05St: `0d%d ", |
| 244 |
state.octave, song.speed, seq.sequencer.stepValue)); |
| 245 |
screen.fprint(x2+3, area.y+1, |
| 246 |
format("`05Rate: `0d%-1d*%dhz `05SID: `0d%s%s ", |
| 247 |
song.multiplier, audio.player.ntsc ? 60 : 50, |
| 248 |
audio.player.usefp ? audio.player.curfp.id : audio.player.sidtype ? "8580" : "6581", |
| 249 |
audio.player.badline ? "&0fb" : " ")); |
| 250 |
screen.fprint(x1,area.y+1,format("`05Filename: `0d%s", state.filename.leftJustify(38))); |
| 251 |
//screen.fprint(x2,area.y,format("`05 `b1T`01itle: `0d%-32s", std.string.toString(cast(char *)song.title))); |
| 252 |
screen.fprint(x2,area.y, |
| 253 |
format("`05%s `0d%-32s", ([" `b1T`01itle:", " `01Author:", "`01Release:" ])[idx], |
| 254 |
song.title)); |
| 255 |
screen.fprint(x2,area.y+2,format("`05 Player: `0d%s", ztos(song.playerID))); |
| 256 |
} |
| 257 |
|
| 258 |
override void refresh() { |
| 259 |
inputTitle = new InputString(cast(string)(song.title), cast(int)(song.title.length)); |
| 260 |
inputReleased = new InputString(cast(string)(song.release), cast(int)( song.release.length)); |
| 261 |
inputAuthor = new InputString(cast(string)(song.author), cast(int)(song.author.length)); |
| 262 |
input = ([ inputTitle, inputAuthor, inputReleased ])[idx]; |
| 263 |
input.setCoord(x2 + 9,area.y); |
| 264 |
} |
| 265 |
|
| 266 |
override void activate() { |
| 267 |
idx = 0; |
| 268 |
refresh(); |
| 269 |
} |
| 270 |
|
| 271 |
override void deactivate() { |
| 272 |
outputStrings(); |
| 273 |
} |
| 274 |
|
| 275 |
private void outputStrings() { |
| 276 |
song.title[0..32] = (cast(InputString)inputTitle).toString(true)[0..32]; |
| 277 |
song.release[0..32] = (cast(InputString)inputReleased).toString(true)[0..32]; |
| 278 |
song.author[0..32] = (cast(InputString)inputAuthor).toString(true)[0..32]; |
| 279 |
} |
| 280 |
|
| 281 |
override int keypress(Keyinfo key) { |
| 282 |
int r = input.keypress(key); |
| 283 |
if(r == RETURN) { |
| 284 |
idx++; |
| 285 |
if(idx > 2) { |
| 286 |
idx = 0; |
| 287 |
return RETURN; |
| 288 |
} |
| 289 |
outputStrings(); |
| 290 |
refresh(); |
| 291 |
} |
| 292 |
else if(r == CANCEL) { |
| 293 |
idx = 0; update(); |
| 294 |
return RETURN; |
| 295 |
} |
| 296 |
return OK; |
| 297 |
} |
| 298 |
} |
| 299 |
|
| 300 |
class Statusline : Window { |
| 301 |
int counter; |
| 302 |
string message; |
| 303 |
|
| 304 |
this(Rectangle a) { |
| 305 |
super(a); |
| 306 |
} |
| 307 |
|
| 308 |
void display(string msg) { |
| 309 |
message = msg; |
| 310 |
counter = CONFIRM_TIMEOUT; |
| 311 |
screen.clrtoeol(2, 0); |
| 312 |
update(); |
| 313 |
} |
| 314 |
|
| 315 |
override void deactivate() { |
| 316 |
counter = 0; |
| 317 |
update(); |
| 318 |
} |
| 319 |
|
| 320 |
override void update() { |
| 321 |
if(counter) |
| 322 |
screen.fprint(4, 2, "`0f " ~ message); |
| 323 |
else screen.clrtoeol(2, 0); |
| 324 |
} |
| 325 |
|
| 326 |
void timerEvent() { |
| 327 |
if(counter > 0) { |
| 328 |
--counter; |
| 329 |
if(!counter) update(); |
| 330 |
} |
| 331 |
} |
| 332 |
} |
| 333 |
|
| 334 |
final private class Toplevel : WindowSwitcher { |
| 335 |
InputKeyjam inputKeyjam; |
| 336 |
InsTable instable; |
| 337 |
CmdTable cmdtable; |
| 338 |
WindowSwitcher bottomTabSwitcher; |
| 339 |
WaveTable wavetable; |
| 340 |
PulseTable pulsetable; |
| 341 |
FilterTable filtertable; |
| 342 |
ChordTable chordtable; |
| 343 |
Sequencer sequencer; |
| 344 |
Fplay fplay; |
| 345 |
UI ui; |
| 346 |
Hotspot[] hotspots; |
| 347 |
bool followplay; |
| 348 |
|
| 349 |
this(UI ui) { |
| 350 |
this.ui = ui; |
| 351 |
int zone1x = 0; |
| 352 |
int zone2x = screen.width / 2 + zone1x - 1; |
| 353 |
int zone1y = 4; |
| 354 |
int zone1h = screen.height / 2 - 5; |
| 355 |
int zone2y = screen.height / 2; |
| 356 |
int zone2h = screen.height - zone2y - 5; |
| 357 |
|
| 358 |
inputKeyjam = new InputKeyjam(); |
| 359 |
sequencer = new Sequencer(Rectangle(zone1x, zone1y, screen.height - 10, zone2x - zone1x)); |
| 360 |
fplay = new Fplay(Rectangle(zone1x, zone1y, screen.height - 10, zone2x - zone1x)); |
| 361 |
instable = new InsTable(Rectangle(zone2x, zone1y, zone1h, 3 + 8 * 3 + 12)); |
| 362 |
|
| 363 |
int tx = zone2x; |
| 364 |
wavetable = new WaveTable(Rectangle(tx, zone2y, zone2h, 8)); |
| 365 |
tx += com.fb.border + 8; |
| 366 |
pulsetable = new PulseTable(Rectangle(tx, zone2y, zone2h, 14)); |
| 367 |
tx += com.fb.border + 14; |
| 368 |
filtertable = new FilterTable(Rectangle(tx, zone2y, zone2h, 14)); |
| 369 |
tx += com.fb.border + 14; |
| 370 |
cmdtable = new CmdTable(Rectangle(tx, zone2y, zone2h, 10)); |
| 371 |
tx += com.fb.border + 10; |
| 372 |
|
| 373 |
Rectangle ca; |
| 374 |
|
| 375 |
if(com.fb.mode == 0) { |
| 376 |
ca = Rectangle(tx - 6, zone1y, zone1h, 6); |
| 377 |
} |
| 378 |
else ca = Rectangle(tx, zone2y, zone2h, 6); |
| 379 |
chordtable = new ChordTable(ca); |
| 380 |
bottomTabSwitcher = new WindowSwitcher(Rectangle(zone2x, zone2y, zone2h, |
| 381 |
tx + com.fb.border + 10), |
| 382 |
[cast(Window)wavetable, pulsetable, |
| 383 |
filtertable, cmdtable, chordtable], |
| 384 |
"wpfmd"); |
| 385 |
|
| 386 |
/+ |
| 387 |
super(Rectangle(), [cast(Window)sequencer, instable, |
| 388 |
wavetable, pulsetable, filtertable, |
| 389 |
cmdtable, chordtable], null); |
| 390 |
+/ |
| 391 |
|
| 392 |
super(Rectangle(), [cast(Window)sequencer, instable, |
| 393 |
bottomTabSwitcher]); |
| 394 |
{ |
| 395 |
int x1 = 4; |
| 396 |
int x2 = x1 + (com.fb.mode > 0 ? 64 : 48); |
| 397 |
int y1 = screen.height - 4; |
| 398 |
|
| 399 |
hotspots = [ |
| 400 |
Hotspot(Rectangle(x2 + 3, y1, 1, 30), (int b){ |
| 401 |
ui.activateDialog(UI.infobar); |
| 402 |
}), |
| 403 |
Hotspot(Rectangle(x2 + 18, y1 + 1, 1, 10), (int b){ |
| 404 |
b > 1 ? audio.player.toggleSIDModel() : audio.player.nextFP(); |
| 405 |
}), |
| 406 |
Hotspot(Rectangle(x2 + 3, y1 + 1, 1, 14), (int b) { |
| 407 |
b == 1 ? audio.player.incMultiplier() : audio.player.decMultiplier(); |
| 408 |
}) |
| 409 |
]; |
| 410 |
} |
| 411 |
refresh(); |
| 412 |
} |
| 413 |
|
| 414 |
override void clickedAt(int x, int y, int b) { |
| 415 |
foreach(idx, win; windows) { |
| 416 |
if(win.area.overlaps(x, y)) { |
| 417 |
activateWindow(idx); |
| 418 |
activeWindow.clickedAt(x, y, b); |
| 419 |
} |
| 420 |
} |
| 421 |
foreach(idx, win; bottomTabSwitcher.windows) { |
| 422 |
if(win.area.overlaps(x, y)) { |
| 423 |
bottomTabSwitcher.activateWindow(idx); |
| 424 |
bottomTabSwitcher.activeWindow.clickedAt(x, y, b); |
| 425 |
break; |
| 426 |
} |
| 427 |
} |
| 428 |
foreach(idx, spot; hotspots) { |
| 429 |
if(spot.area.overlaps(x, y)) |
| 430 |
spot.callback(b); |
| 431 |
} |
| 432 |
} |
| 433 |
|
| 434 |
override int keypress(Keyinfo key) { |
| 435 |
switch(key.unicode) { |
| 436 |
case ']': |
| 437 |
if(song.speed < 32) |
| 438 |
song.speed = song.speed + 1; |
| 439 |
return OK; |
| 440 |
case '[': |
| 441 |
if(song.speed > 0) |
| 442 |
song.speed = song.speed - 1; |
| 443 |
return OK; |
| 444 |
case '{': |
| 445 |
audio.player.setMultiplier(song.multiplier - 1); |
| 446 |
return OK; |
| 447 |
case '}': |
| 448 |
audio.player.setMultiplier(song.multiplier + 1); |
| 449 |
return OK; |
| 450 |
/+ |
| 451 |
case '(': |
| 452 |
if(octave > 0) |
| 453 |
octave--; |
| 454 |
return OK; |
| 455 |
case ')': |
| 456 |
if(octave < 6) |
| 457 |
octave++; |
| 458 |
return OK;+/ |
| 459 |
default: |
| 460 |
break; |
| 461 |
} |
| 462 |
|
| 463 |
if(key.mods & KMOD_ALT) { |
| 464 |
switch(key.raw) |
| 465 |
{ |
| 466 |
case SDLK_v: |
| 467 |
activateWindow(0); |
| 468 |
break; |
| 469 |
case SDLK_1: |
| 470 |
if(!(key.mods & KMOD_CTRL)) { |
| 471 |
activateWindow(0); |
| 472 |
sequencer.activateVoice(0); |
| 473 |
} |
| 474 |
break; |
| 475 |
case SDLK_2: |
| 476 |
if(!(key.mods & KMOD_CTRL)) { |
| 477 |
activateWindow(0); |
| 478 |
sequencer.activateVoice(1); |
| 479 |
} |
| 480 |
break; |
| 481 |
case SDLK_3: |
| 482 |
if(!(key.mods & KMOD_CTRL)) { |
| 483 |
activateWindow(0); |
| 484 |
sequencer.activateVoice(2); |
| 485 |
} |
| 486 |
break; |
| 487 |
case SDLK_4: |
| 488 |
case SDLK_i: |
| 489 |
activateWindow(1); |
| 490 |
break; |
| 491 |
case SDLK_5, SDLK_w: |
| 492 |
activateWindow(2); |
| 493 |
key.key = SDLK_w; |
| 494 |
activeWindow.keypress(key); |
| 495 |
return OK; |
| 496 |
case SDLK_6, SDLK_p: |
| 497 |
activateWindow(2); |
| 498 |
key.key = SDLK_p; |
| 499 |
activeWindow.keypress(key); |
| 500 |
return OK; |
| 501 |
case SDLK_7, SDLK_f: |
| 502 |
activateWindow(2); |
| 503 |
key.key = SDLK_f; |
| 504 |
activeWindow.keypress(key); |
| 505 |
return OK; |
| 506 |
case SDLK_8, SDLK_m: |
| 507 |
activateWindow(2); |
| 508 |
key.key = SDLK_m; |
| 509 |
activeWindow.keypress(key); |
| 510 |
return OK; |
| 511 |
case SDLK_9, SDLK_d: |
| 512 |
activateWindow(2); |
| 513 |
key.key = SDLK_d; |
| 514 |
activeWindow.keypress(key); |
| 515 |
return OK; |
| 516 |
case SDLK_t: |
| 517 |
ui.activateDialog(UI.infobar); |
| 518 |
return OK; |
| 519 |
case SDLK_KP_0: |
| 520 |
clearSeqs(); |
| 521 |
return OK; |
| 522 |
case SDLK_KP_PERIOD: |
| 523 |
optimizeSong(); |
| 524 |
return OK; |
| 525 |
case SDLK_o: |
| 526 |
if(key.mods & KMOD_CTRL) { |
| 527 |
optimizeSong(); |
| 528 |
return OK; |
| 529 |
} |
| 530 |
break; |
| 531 |
case SDLK_n: |
| 532 |
if(key.mods & KMOD_CTRL) { |
| 533 |
return OK; |
| 534 |
} |
| 535 |
break; |
| 536 |
case SDLK_c: |
| 537 |
if(key.mods & KMOD_CTRL) { |
| 538 |
clearSeqs(); |
| 539 |
return OK; |
| 540 |
} |
| 541 |
break; |
| 542 |
case SDLK_h: |
| 543 |
state.displayHelp ^= 1; |
| 544 |
UI.statusline.display("Help texts " ~ (state.displayHelp ? "enabled." : "disabled.")); |
| 545 |
break; |
| 546 |
default: |
| 547 |
break; |
| 548 |
} |
| 549 |
} |
| 550 |
else if(key.mods & KMOD_CTRL) { |
| 551 |
switch(key.raw) |
| 552 |
{ |
| 553 |
case SDLK_PLUS: |
| 554 |
case SDLK_KP_PLUS: |
| 555 |
song.speed = clamp(song.speed + 1, 0, 31); |
| 556 |
break; |
| 557 |
case SDLK_MINUS: |
| 558 |
case SDLK_KP_MINUS: |
| 559 |
song.speed = clamp(song.speed - 1, 0, 31); |
| 560 |
break; |
| 561 |
case SDLK_TAB: |
| 562 |
key.mods & KMOD_SHIFT ? activeWindowNum-- : activeWindowNum++ ; |
| 563 |
if(activeWindowNum < 0) activeWindowNum = cast(int)( windows.length - 1); |
| 564 |
if(activeWindowNum >= windows.length) |
| 565 |
activeWindowNum %= windows.length; |
| 566 |
activateWindow(); |
| 567 |
return OK; |
| 568 |
case SDLK_z: |
| 569 |
com.session.executeUndo(); |
| 570 |
return OK; |
| 571 |
case SDLK_r: |
| 572 |
com.session.executeRedo(); |
| 573 |
refresh(); |
| 574 |
return OK; |
| 575 |
default: |
| 576 |
break; |
| 577 |
} |
| 578 |
} |
| 579 |
else if(!key.mods & KMOD_SHIFT) { |
| 580 |
switch(key.raw) |
| 581 |
{ |
| 582 |
case SDLK_KP_DIVIDE: |
| 583 |
if(state.octave > 0) |
| 584 |
state.octave--; |
| 585 |
break; |
| 586 |
case SDLK_KP_MULTIPLY: |
| 587 |
if(state.octave < 6) |
| 588 |
state.octave++; |
| 589 |
break; |
| 590 |
case SDLK_PLUS: |
| 591 |
case SDLK_KP_PLUS: |
| 592 |
if(state.allowInstabNavigation) { |
| 593 |
instable.stepRow(1); |
| 594 |
state.activeInstrument = instable.row; |
| 595 |
} |
| 596 |
break; |
| 597 |
case SDLK_MINUS: |
| 598 |
case SDLK_KP_MINUS: |
| 599 |
if(state.allowInstabNavigation) { |
| 600 |
instable.stepRow(-1); |
| 601 |
state.activeInstrument = instable.row; |
| 602 |
} |
| 603 |
break; |
| 604 |
default: |
| 605 |
break; |
| 606 |
} |
| 607 |
} |
| 608 |
else if(key.mods & KMOD_SHIFT) { |
| 609 |
version(OSX) { |
| 610 |
if(key.raw == SDLK_EQUALS && state.allowInstabNavigation) { |
| 611 |
instable.stepRow(1); |
| 612 |
state.activeInstrument = instable.row; |
| 613 |
} |
| 614 |
} |
| 615 |
} |
| 616 |
if(state.keyjamStatus == true) { |
| 617 |
inputKeyjam.keypress(key); |
| 618 |
} |
| 619 |
else { |
| 620 |
int r = activeWindow.keypress(key); |
| 621 |
if(r == RETURN || r == CANCEL) { |
| 622 |
assert(0); |
| 623 |
} |
| 624 |
} |
| 625 |
return OK; |
| 626 |
} |
| 627 |
|
| 628 |
override int keyrelease(Keyinfo key) { |
| 629 |
if(state.keyjamStatus == true) { |
| 630 |
inputKeyjam.keyrelease(key); |
| 631 |
} |
| 632 |
return activeWindow.keyrelease(key); |
| 633 |
} |
| 634 |
|
| 635 |
override void refresh() { |
| 636 |
foreach(t; windows) { |
| 637 |
t.refresh(); |
| 638 |
t.update(); |
| 639 |
} |
| 640 |
bottomTabSwitcher.refresh(); |
| 641 |
// needed because 'input' might be messed by a subdialog |
| 642 |
activeWindow.activate(); |
| 643 |
} |
| 644 |
|
| 645 |
override void update() { |
| 646 |
foreach(t; windows) { |
| 647 |
t.update(); |
| 648 |
} |
| 649 |
} |
| 650 |
|
| 651 |
bool fplayEnabled() { return followplay; } |
| 652 |
|
| 653 |
void activateByCoord(int x, int y) { |
| 654 |
foreach(idx, win; windows) { |
| 655 |
if(win.area.overlaps(x, y)) { |
| 656 |
activateWindow(idx); |
| 657 |
} |
| 658 |
} |
| 659 |
foreach(idx, win; bottomTabSwitcher.windows) { |
| 660 |
if(win.area.overlaps(x, y)) { |
| 661 |
bottomTabSwitcher.activateWindow(idx); |
| 662 |
break; |
| 663 |
} |
| 664 |
} |
| 665 |
} |
| 666 |
|
| 667 |
|
| 668 |
void timerEvent() { |
| 669 |
fplay.timerEvent(); |
| 670 |
} |
| 671 |
|
| 672 |
Window windowByCoord(int x, int y) { |
| 673 |
foreach(idx, win; windows ~ bottomTabSwitcher.windows) { |
| 674 |
if(win.area.overlaps(x, y)) |
| 675 |
return win; |
| 676 |
} |
| 677 |
return null; |
| 678 |
} |
| 679 |
|
| 680 |
void playFromCursor() { |
| 681 |
Voice[] v = sequencer.getVoices(); |
| 682 |
auto d1 = v[0].activeRow; |
| 683 |
auto d2 = v[1].activeRow; |
| 684 |
auto d3 = v[2].activeRow; |
| 685 |
audio.player.start([d1.trkOffset,d2.trkOffset,d3.trkOffset], |
| 686 |
[d1.seqOffset,d2.seqOffset,d3.seqOffset]); |
| 687 |
fplay.startFromCursor(); |
| 688 |
} |
| 689 |
|
| 690 |
void reset() { |
| 691 |
sequencer.reset(); |
| 692 |
sequencer.resetMark(); |
| 693 |
} |
| 694 |
|
| 695 |
void startFp() { |
| 696 |
followplay = true; |
| 697 |
windows[0] = fplay; |
| 698 |
if(activeWindow == sequencer) |
| 699 |
activateWindow(0); |
| 700 |
} |
| 701 |
|
| 702 |
void startFp(int mode) { |
| 703 |
startFp(); |
| 704 |
if(activeWindow == fplay) |
| 705 |
fplay.start(mode); |
| 706 |
} |
| 707 |
|
| 708 |
void startPlayback(int j) { |
| 709 |
fplay.start(j); |
| 710 |
} |
| 711 |
|
| 712 |
private void stopFp() { |
| 713 |
followplay = false; |
| 714 |
windows[0] = sequencer; |
| 715 |
activateWindow(activeWindowNum); |
| 716 |
} |
| 717 |
|
| 718 |
void stopPlayback() { |
| 719 |
fplay.stop(); |
| 720 |
if(followplay) { |
| 721 |
stopFp(); |
| 722 |
followplay = false; |
| 723 |
activate(); |
| 724 |
sequencer.reset(false); |
| 725 |
} |
| 726 |
} |
| 727 |
|
| 728 |
private void optimizeSong() { |
| 729 |
if(++optimizecounter > 1) { |
| 730 |
refresh(); |
| 731 |
// TODO: VALIDATION HERE BEFORE PURGING... PurgeExpception should be useless if validate covers all errorcases |
| 732 |
try { |
| 733 |
(new Purge(song,true)).purgeAll(); |
| 734 |
} |
| 735 |
catch(PurgeException e) { |
| 736 |
UI.statusline.display(e.toString); |
| 737 |
optimizecounter = 0; |
| 738 |
return; |
| 739 |
|
| 740 |
} |
| 741 |
|
| 742 |
refresh(); |
| 743 |
UI.statusline.display("Song data optimized."); |
| 744 |
optimizecounter = 0; |
| 745 |
} |
| 746 |
else { |
| 747 |
UI.statusline.display("Press again to confirm song data optimization..."); |
| 748 |
tickcounter3 = 0; |
| 749 |
} |
| 750 |
} |
| 751 |
|
| 752 |
private void clearSong() { |
| 753 |
if(++restartcounter > 1) { |
| 754 |
//song.open(cast(ubyte[])import("player.bin")); |
| 755 |
sequencer.reset(); |
| 756 |
refresh(); |
| 757 |
clearcounter = 0; |
| 758 |
//savedialog.setFilename(""); |
| 759 |
state.filename = ""; |
| 760 |
UI.statusline.display("Editor restarted."); |
| 761 |
} |
| 762 |
else { |
| 763 |
UI.statusline.display("Press again to confirm editor cold start..."); |
| 764 |
tickcounter3 = 0; |
| 765 |
} |
| 766 |
} |
| 767 |
|
| 768 |
private void clearSeqs() { |
| 769 |
if(++clearcounter > 1) { |
| 770 |
song.clearSeqs(); |
| 771 |
sequencer.reset(); |
| 772 |
clearcounter = 0; |
| 773 |
UI.statusline.display("Sequence data cleared."); |
| 774 |
} |
| 775 |
else { |
| 776 |
UI.statusline.display("Press again to confirm sequence data clearing..."); |
| 777 |
tickcounter3 = 0; |
| 778 |
} |
| 779 |
} |
| 780 |
} |
| 781 |
|
| 782 |
final class UI { |
| 783 |
private { |
| 784 |
Window dialog = null; |
| 785 |
//bool printSIDDump = false; |
| 786 |
enum VisMode { None, Regs, Oscilloscope } |
| 787 |
int vismode; |
| 788 |
AboutDialog aboutdialog; |
| 789 |
FileSelectorDialog loaddialog, savedialog; |
| 790 |
} |
| 791 |
static Statusline statusline; |
| 792 |
static Infobar infobar; |
| 793 |
static Toplevel toplevel; |
| 794 |
bool exitRequested = false; |
| 795 |
|
| 796 |
this() { |
| 797 |
statusline = new Statusline(Rectangle(0, 2, 1)); |
| 798 |
toplevel = new Toplevel(this); |
| 799 |
|
| 800 |
infobar = new Infobar(Rectangle(4, screen.height - 4, 1, screen.width - 8)); |
| 801 |
|
| 802 |
int dialog_width = screen.width - 32; |
| 803 |
int dialog_height = screen.height - 10; |
| 804 |
int dialog_x = screen.width / 2 - dialog_width / 2; |
| 805 |
int dialog_y = screen.height / 2 - dialog_height / 2; |
| 806 |
|
| 807 |
loaddialog = new LoadFileDialog(Rectangle(dialog_x, dialog_y, dialog_height, |
| 808 |
dialog_width), &loadCallback, &importCallback); |
| 809 |
savedialog = new SaveFileDialog(Rectangle(dialog_x, dialog_y, dialog_height, |
| 810 |
dialog_width), &saveCallback); |
| 811 |
|
| 812 |
int aboutdlg_width = screen.width - 18; |
| 813 |
int aboutdlg_height = 12; |
| 814 |
int aboutdlg_x = screen.width / 2 - aboutdlg_width / 2; |
| 815 |
int aboutdlg_y = screen.height / 2 - aboutdlg_height / 2; |
| 816 |
|
| 817 |
aboutdialog = new AboutDialog(Rectangle(aboutdlg_x, aboutdlg_y, |
| 818 |
aboutdlg_height, |
| 819 |
aboutdlg_width)); |
| 820 |
|
| 821 |
audio.player.setMultiplier(song.multiplier); |
| 822 |
|
| 823 |
if(com.fb.mode > 0) |
| 824 |
state.shortTitles = false; |
| 825 |
toplevel.activate(); |
| 826 |
activateDialog(aboutdialog); |
| 827 |
update(); |
| 828 |
} |
| 829 |
|
| 830 |
@property Window activeWindow() { |
| 831 |
if(dialog) return dialog; |
| 832 |
return toplevel.activeWindow; |
| 833 |
} |
| 834 |
|
| 835 |
@property Input activeInput() { |
| 836 |
return activeWindow.input; |
| 837 |
} |
| 838 |
|
| 839 |
void timerEvent(int n) { |
| 840 |
Exception e = audio.callback.getException(); |
| 841 |
if(e !is null) { |
| 842 |
writeln("error" ~ e.toString()); |
| 843 |
audio.player.stop(); |
| 844 |
statusline.display(e.toString()); |
| 845 |
} |
| 846 |
if((tickcounter3 >= 0) && ++tickcounter3 > 20) { |
| 847 |
clearcounter = optimizecounter = escapecounter = restartcounter = 0; |
| 848 |
infobar.update(); |
| 849 |
tickcounter3 = -1; |
| 850 |
} |
| 851 |
statusline.timerEvent(); |
| 852 |
tickcounter1 += n; |
| 853 |
if(tickcounter1 >= UPDATE_RATE) { |
| 854 |
infobar.update(); |
| 855 |
if(dialog) dialog.update(); |
| 856 |
tickcounter1 = 0; |
| 857 |
toplevel.timerEvent(); |
| 858 |
|
| 859 |
if(audio.player.isPlaying || audio.player.keyjamEnabled) { |
| 860 |
if(vismode == VisMode.Regs) { |
| 861 |
int x = screen.width - 42; |
| 862 |
screen.cprint(x, 1, 15, 0, "V1:"); |
| 863 |
screen.cprint(x, 2, 15, 0, "V2:"); |
| 864 |
screen.cprint(x, 3, 15, 0, "V3:"); |
| 865 |
screen.cprint(x+26, 1, 15, 0, "$D415 16 17 18"); |
| 866 |
|
| 867 |
for(int i = 0; i < 7; i++) { |
| 868 |
screen.cprint(x+3+i*3, 1, 5,0, format("%02X", audio.audio.sidreg[i])); |
| 869 |
screen.cprint(x+3+i*3, 2, 5,0, format("%02X", audio.audio.sidreg[i+7])); |
| 870 |
screen.cprint(x+3+i*3, 3, 5,0, format("%02X", audio.audio.sidreg[i+14])); |
| 871 |
} |
| 872 |
|
| 873 |
for(int i = 0; i < 4;i++) { |
| 874 |
screen.cprint(x+8+21+i*3, 2, 5,0, format("%02X", audio.audio.sidreg[i+0x15])); |
| 875 |
} |
| 876 |
} |
| 877 |
update(); // TESTME: just do video.updateFrame() |
| 878 |
} |
| 879 |
} |
| 880 |
if(vismode == VisMode.Oscilloscope && |
| 881 |
(audio.player.isPlaying || audio.player.keyjamEnabled)) |
| 882 |
video.drawVisualizer(n); |
| 883 |
} |
| 884 |
|
| 885 |
void update() { |
| 886 |
infobar.update(); |
| 887 |
toplevel.update(); |
| 888 |
if(dialog) |
| 889 |
dialog.update(); |
| 890 |
} |
| 891 |
|
| 892 |
private void F1orF2(Keyinfo key, bool fromStart) { |
| 893 |
if(audio.player.isPlaying) { |
| 894 |
if(key.mods & KMOD_SHIFT) { // already playing, reinit tracking |
| 895 |
stop(false); |
| 896 |
toplevel.startFp(); |
| 897 |
return; |
| 898 |
} |
| 899 |
else if(toplevel.fplayEnabled()) { // drop tracking |
| 900 |
stop(false); |
| 901 |
seqPos.copyFrom(fplayPos); |
| 902 |
toplevel.stopFp(); |
| 903 |
return; |
| 904 |
} |
| 905 |
// song is playing but plain F1 pressed; restart |
| 906 |
} |
| 907 |
int m1, m2, m3; |
| 908 |
m1 = seqPos.pos[0].mark; |
| 909 |
m2 = seqPos.pos[1].mark; |
| 910 |
m3 = seqPos.pos[2].mark; |
| 911 |
stop(); |
| 912 |
if(!fromStart) { |
| 913 |
audio.player.start([m1, m2, m3], [0, 0, 0]); |
| 914 |
if(key.mods & KMOD_SHIFT) { |
| 915 |
toplevel.startFp(); |
| 916 |
} |
| 917 |
toplevel.startPlayback(Jump.toMark); |
| 918 |
} |
| 919 |
else { |
| 920 |
audio.player.start(); |
| 921 |
if(key.mods & KMOD_SHIFT) { |
| 922 |
toplevel.startFp(Jump.toBeginning); |
| 923 |
} |
| 924 |
toplevel.startPlayback(Jump.toBeginning); |
| 925 |
} |
| 926 |
} |
| 927 |
|
| 928 |
int keypress(Keyinfo key) { |
| 929 |
/+ old buggy coldstart code |
| 930 |
if(key.mods & KMOD_ALT && key.mods & KMOD_CTRL && key.raw == SDLK_KP0) { |
| 931 |
if(++restartcounter > 1) { |
| 932 |
song = new Song(); |
| 933 |
toplevel.sequencer.reset(); |
| 934 |
refresh(); |
| 935 |
clearcounter = 0; |
| 936 |
UI.statusline.display("Editor restarted."); |
| 937 |
savedialog.setFilename(""); |
| 938 |
// TODO: find out why tracklist is not erased |
| 939 |
filename = ""; |
| 940 |
} |
| 941 |
else { |
| 942 |
UI.statusline.display("Press again to confirm editor cold start..."); |
| 943 |
tickcounter3 = 0; |
| 944 |
} |
| 945 |
return OK; |
| 946 |
} |
| 947 |
else+/ |
| 948 |
|
| 949 |
bool skip_imm_keypress = false; //workaround for F11 - crapchars in savedialog |
| 950 |
if(key.mods & KMOD_ALT) { |
| 951 |
switch(key.raw) |
| 952 |
{ |
| 953 |
case SDLK_RETURN: |
| 954 |
video.toggleFullscreen(); |
| 955 |
//update(); |
| 956 |
break; |
| 957 |
case SDLK_KP_PLUS: |
| 958 |
audio.player.setMultiplier(song.multiplier + 1); |
| 959 |
break; |
| 960 |
case SDLK_KP_MINUS: |
| 961 |
audio.player.setMultiplier(song.multiplier - 1); |
| 962 |
break; |
| 963 |
case SDLK_F12: |
| 964 |
audio.player.dumpFrame(); |
| 965 |
break; |
| 966 |
default: |
| 967 |
break; |
| 968 |
} |
| 969 |
} |
| 970 |
else if(key.mods & KMOD_CTRL) { |
| 971 |
switch(key.raw) |
| 972 |
{ |
| 973 |
case SDLK_1: |
| 974 |
audio.player.toggleVoice(0); |
| 975 |
break; |
| 976 |
case SDLK_2: |
| 977 |
audio.player.toggleVoice(1); |
| 978 |
break; |
| 979 |
case SDLK_3: |
| 980 |
audio.player.toggleVoice(2); |
| 981 |
break; |
| 982 |
case SDLK_F11: |
| 983 |
string s = savedialog.filename; |
| 984 |
if(s == "") |
| 985 |
statusline.display("Cannot Quicksave; give filename first by doing a regular save."); |
| 986 |
else { |
| 987 |
saveCallback(s); |
| 988 |
statusline.display(format("Saved \"%s\".",s)); |
| 989 |
} |
| 990 |
break; |
| 991 |
case SDLK_F12: |
| 992 |
break; |
| 993 |
case SDLK_F2: |
| 994 |
audio.player.interpolate ^= 1; |
| 995 |
audio.player.init(); |
| 996 |
break; |
| 997 |
case SDLK_F3: |
| 998 |
song.sidModel ^= 1; |
| 999 |
audio.player.setSidModel(song.sidModel); |
| 1000 |
break; |
| 1001 |
/+ |
| 1002 |
case SDLK_F4, SDLK_b: |
| 1003 |
audio.player.badline ^= 1; |
| 1004 |
audio.player.init(); |
| 1005 |
break; |
| 1006 |
+/ |
| 1007 |
case SDLK_F8: |
| 1008 |
key.mods & KMOD_SHIFT ? audio.player.prevFP() : audio.player.nextFP(); |
| 1009 |
break; |
| 1010 |
case SDLK_F9: |
| 1011 |
/+ |
| 1012 |
if(printSIDDump) { |
| 1013 |
screen.clrtoeol(55, 1, 0); |
| 1014 |
screen.clrtoeol(55, 2, 0); |
| 1015 |
screen.clrtoeol(55, 3, 0); |
| 1016 |
} |
| 1017 |
printSIDDump = !printSIDDump; |
| 1018 |
+/ |
| 1019 |
vismode = umod(vismode + 1, 0, VisMode.max); |
| 1020 |
screen.clrtoeol(55, 1, 0); |
| 1021 |
screen.clrtoeol(55, 2, 0); |
| 1022 |
screen.clrtoeol(55, 3, 0); |
| 1023 |
video.clearVisualizer(); |
| 1024 |
break; |
| 1025 |
case SDLK_SPACE: |
| 1026 |
if(song.ver < 7) break; |
| 1027 |
state.keyjamStatus ^= 1; |
| 1028 |
enableKeyjamMode(state.keyjamStatus); |
| 1029 |
statusline.display("Keyjam " ~ (state.keyjamStatus ? "enabled." : "disabled.") |
| 1030 |
~ " Press Ctrl-Space to toggle."); |
| 1031 |
break; |
| 1032 |
default: |
| 1033 |
break; |
| 1034 |
} |
| 1035 |
} |
| 1036 |
else switch(key.raw) |
| 1037 |
{ |
| 1038 |
case SDLK_ESCAPE: |
| 1039 |
if(dialog || activeWindow == infobar) |
| 1040 |
break; |
| 1041 |
if(++escapecounter > 1) { |
| 1042 |
activateDialog(new ConfirmationDialog("Really exit (y/n)? ", (int param) { |
| 1043 |
if(param != 0) return; |
| 1044 |
audio.player.stop(); |
| 1045 |
exitRequested = true; |
| 1046 |
})); |
| 1047 |
return OK; |
| 1048 |
} |
| 1049 |
tickcounter3 = 0; |
| 1050 |
break; |
| 1051 |
/+ |
| 1052 |
case SDLK_PRINT: |
| 1053 |
audio.player.dumpFrame(); |
| 1054 |
break; |
| 1055 |
+/ |
| 1056 |
case SDLK_F1: |
| 1057 |
F1orF2(key, false); |
| 1058 |
break; |
| 1059 |
case SDLK_F2: |
| 1060 |
F1orF2(key, true); |
| 1061 |
break; |
| 1062 |
case SDLK_F3: |
| 1063 |
toplevel.playFromCursor(); |
| 1064 |
break; |
| 1065 |
case SDLK_SCROLLLOCK: |
| 1066 |
if(!audio.player.isPlaying) break; |
| 1067 |
if(toplevel.fplayEnabled()) { |
| 1068 |
stop(false); |
| 1069 |
seqPos.copyFrom(fplayPos); |
| 1070 |
toplevel.stopFp(); |
| 1071 |
statusline.display("Tracking off."); |
| 1072 |
} |
| 1073 |
else { |
| 1074 |
stop(false); |
| 1075 |
toplevel.startFp(); |
| 1076 |
statusline.display("Tracking on."); |
| 1077 |
} |
| 1078 |
break; |
| 1079 |
case SDLK_F4: |
| 1080 |
if(toplevel.fplayEnabled()) |
| 1081 |
seqPos.copyFrom(fplayPos); |
| 1082 |
stop(); |
| 1083 |
if(toplevel.fplayEnabled()) |
| 1084 |
toplevel.stopFp(); |
| 1085 |
break; |
| 1086 |
case SDLK_F8: |
| 1087 |
if(key.mods & KMOD_SHIFT) |
| 1088 |
audio.player.fastForward(25); |
| 1089 |
else |
| 1090 |
audio.player.fastForward(5); |
| 1091 |
break; |
| 1092 |
case SDLK_F9: |
| 1093 |
activateDialog(aboutdialog); |
| 1094 |
break; |
| 1095 |
case SDLK_F10: |
| 1096 |
activateDialog(loaddialog); |
| 1097 |
break; |
| 1098 |
case SDLK_F11: |
| 1099 |
activateDialog(savedialog); |
| 1100 |
skip_imm_keypress = true; |
| 1101 |
break; |
| 1102 |
case SDLK_F12: |
| 1103 |
int helpdlg_width = screen.width - 10; |
| 1104 |
int helpdlg_height = 36; |
| 1105 |
int helpdlg_x = screen.width / 2 - helpdlg_width / 2; |
| 1106 |
int helpdlg_y = screen.height / 2 - helpdlg_height / 2; |
| 1107 |
HelpDialog helpdialog = |
| 1108 |
new HelpDialog(Rectangle(helpdlg_x, helpdlg_y, |
| 1109 |
helpdlg_height, |
| 1110 |
helpdlg_width), activeWindow.contextHelp); |
| 1111 |
activateDialog(helpdialog); |
| 1112 |
break; |
| 1113 |
default: |
| 1114 |
break; |
| 1115 |
} |
| 1116 |
int r; |
| 1117 |
if(dialog && !skip_imm_keypress) { |
| 1118 |
if(key.mods & KMOD_ALT) return OK; |
| 1119 |
r = dialog.keypress(key); |
| 1120 |
if(r != OK) { |
| 1121 |
closeDialog(); |
| 1122 |
return r; |
| 1123 |
} |
| 1124 |
} |
| 1125 |
else { |
| 1126 |
toplevel.keypress(key); |
| 1127 |
} |
| 1128 |
return OK; |
| 1129 |
} |
| 1130 |
|
| 1131 |
int keyrelease(Keyinfo key) { |
| 1132 |
toplevel.keyrelease(key); |
| 1133 |
return OK; |
| 1134 |
} |
| 1135 |
|
| 1136 |
void clickedAt(int x, int y, int b) { |
| 1137 |
if(dialog) |
| 1138 |
dialog.clickedAt(x, y, b); |
| 1139 |
else toplevel.clickedAt(x, y, b); |
| 1140 |
} |
| 1141 |
|
| 1142 |
private void saveCallback(string s) { |
| 1143 |
try { |
| 1144 |
song.save(s); |
| 1145 |
} |
| 1146 |
catch(FileException e) { |
| 1147 |
stderr.writeln(e.toString); |
| 1148 |
statusline.display("Could not save file! Check your filename."); |
| 1149 |
return; |
| 1150 |
} |
| 1151 |
|
| 1152 |
string fn = s.strip(); |
| 1153 |
auto ind = 1 + fn.lastIndexOf(DIR_SEPARATOR); |
| 1154 |
fn = fn[ind..$]; |
| 1155 |
state.filename = fn; |
| 1156 |
|
| 1157 |
// sync load filesel to save filesel |
| 1158 |
if(loaddialog.directory != savedialog.directory) { |
| 1159 |
foreach(d; [loaddialog, savedialog]) { |
| 1160 |
d.setFilename(fn); |
| 1161 |
d.setDirectory(getcwd()); |
| 1162 |
} |
| 1163 |
loaddialog.fsel.fpos.reset(); |
| 1164 |
} |
| 1165 |
} |
| 1166 |
|
| 1167 |
void importCallback(string s) { |
| 1168 |
loadCallback(s, true); |
| 1169 |
} |
| 1170 |
|
| 1171 |
void loadCallback(string s) { |
| 1172 |
loadCallback(s, false); |
| 1173 |
} |
| 1174 |
|
| 1175 |
private void loadCallback(string s, bool doImport) { |
| 1176 |
stop(); |
| 1177 |
|
| 1178 |
if(std.file.exists(s) == 0 || std.file.isDir(s)) { |
| 1179 |
statusline.display("File not found or not accessible: " ~ s); |
| 1180 |
return; |
| 1181 |
} |
| 1182 |
try { |
| 1183 |
if(!doImport) |
| 1184 |
song.open(s); |
| 1185 |
else { |
| 1186 |
Song insong = new Song(); |
| 1187 |
insong.open(s); |
| 1188 |
song.importData(insong); |
| 1189 |
} |
| 1190 |
} |
| 1191 |
catch(Exception e) { |
| 1192 |
statusline.display("Error: " ~ e.toString); |
| 1193 |
return; |
| 1194 |
} |
| 1195 |
|
| 1196 |
refresh(); |
| 1197 |
// all voices ON |
| 1198 |
audio.player.setVoicon(0,0,0); |
| 1199 |
|
| 1200 |
string fn = s.strip(); |
| 1201 |
auto ind = 1 + fn.lastIndexOf(DIR_SEPARATOR); |
| 1202 |
fn = fn[ind .. $]; |
| 1203 |
state.filename = fn; |
| 1204 |
infobar.refresh(); |
| 1205 |
|
| 1206 |
// sync save filesel to load filesel in case dir was changed |
| 1207 |
foreach(d; [loaddialog, savedialog]) { |
| 1208 |
d.setFilename(fn); |
| 1209 |
d.setDirectory(getcwd()); |
| 1210 |
} |
| 1211 |
savedialog.fsel.fpos = loaddialog.fsel.fpos; |
| 1212 |
|
| 1213 |
// set variables |
| 1214 |
audio.player.setSidModel(song.sidModel); |
| 1215 |
audio.player.setFP(song.fppres); |
| 1216 |
audio.player.setMultiplier(song.multiplier); |
| 1217 |
|
| 1218 |
enableKeyjamMode(false); |
| 1219 |
|
| 1220 |
toplevel.reset(); |
| 1221 |
|
| 1222 |
if(doImport) { |
| 1223 |
statusline.display("Song data imported."); |
| 1224 |
} |
| 1225 |
|
| 1226 |
import com.session; |
| 1227 |
com.session.state.undoQueue.clear(); |
| 1228 |
com.session.state.redoQueue.clear(); |
| 1229 |
} |
| 1230 |
|
| 1231 |
void activateDialog(Window d) { |
| 1232 |
enableKeyjamMode(false); |
| 1233 |
closeDialog(); |
| 1234 |
dialog = d; |
| 1235 |
d.activate(); |
| 1236 |
} |
| 1237 |
|
| 1238 |
void closeDialog() { |
| 1239 |
if(dialog) dialog.deactivate(); |
| 1240 |
dialog = null; |
| 1241 |
refresh(); |
| 1242 |
} |
| 1243 |
|
| 1244 |
void enableKeyjamMode(bool doEnable) { |
| 1245 |
if(audio.player.isPlaying) return; |
| 1246 |
/+ doEnable ? com.fb.disableKeyRepeat() : |
| 1247 |
com.fb.enableKeyRepeat();+/ |
| 1248 |
state.keyjamStatus = doEnable; |
| 1249 |
} |
| 1250 |
|
| 1251 |
void activateInstrumentTable(int ins) { |
| 1252 |
UI.activateInstrument(ins); |
| 1253 |
// just hacking away..... |
| 1254 |
toplevel.activateWindow(2); |
| 1255 |
toplevel.keypress(Keyinfo(SDLK_i, KMOD_ALT, 0)); |
| 1256 |
} |
| 1257 |
|
| 1258 |
static void stop() { |
| 1259 |
stop(true); |
| 1260 |
} |
| 1261 |
|
| 1262 |
static void stop(bool doStop) { |
| 1263 |
if(doStop) { |
| 1264 |
audio.player.stop(); |
| 1265 |
} |
| 1266 |
infobar.update(); |
| 1267 |
toplevel.stopPlayback(); |
| 1268 |
} |
| 1269 |
|
| 1270 |
static void refresh() { |
| 1271 |
screen.clrscr(); |
| 1272 |
toplevel.refresh(); |
| 1273 |
UI.statusline.update(); |
| 1274 |
} |
| 1275 |
|
| 1276 |
static void activateInstrument(int ins) { |
| 1277 |
if(ins > 47) ins = 47; |
| 1278 |
if(ins < 0) ins = 0; |
| 1279 |
toplevel.instable.seekRow(ins); |
| 1280 |
state.activeInstrument = ins; |
| 1281 |
toplevel.refresh(); |
| 1282 |
} |
| 1283 |
} |