| 1 |
/* |
| 2 |
CheeseCutter v2 (C) Abaddon. Licensed under GNU GPL. |
| 3 |
*/ |
| 4 |
|
| 5 |
module ui.tables; |
| 6 |
import ui.ui; |
| 7 |
import ui.dialogs; |
| 8 |
import ui.input; |
| 9 |
import ui.help; |
| 10 |
import com.session; |
| 11 |
import com.util; |
| 12 |
import ct.purge; |
| 13 |
import derelict.sdl2.sdl; |
| 14 |
import std.string; |
| 15 |
import std.stdio : stderr; |
| 16 |
import std.file; |
| 17 |
import com.fb; |
| 18 |
import std.conv, std.array; |
| 19 |
|
| 20 |
abstract class Table : Window { |
| 21 |
mixin ValueChangedHandler; |
| 22 |
const int columns, rows, visibleRows; |
| 23 |
protected { |
| 24 |
ubyte[] data; |
| 25 |
int column, row, cursorOffset, viewOffset; |
| 26 |
} |
| 27 |
|
| 28 |
this(Rectangle a, ubyte[] tbl, int c, int r) { |
| 29 |
super(a); |
| 30 |
columns = c; |
| 31 |
rows = r; |
| 32 |
data = tbl; |
| 33 |
input = new InputByte(tbl[0..1]); |
| 34 |
visibleRows = a.height - 1; |
| 35 |
} |
| 36 |
|
| 37 |
override void refresh() { |
| 38 |
update(); |
| 39 |
} |
| 40 |
|
| 41 |
protected: |
| 42 |
|
| 43 |
void adjustView(); |
| 44 |
} |
| 45 |
|
| 46 |
private class HexTable : Table, Undoable { |
| 47 |
this(Rectangle a, ubyte[] tbl, int c, int r) { |
| 48 |
super(a,tbl,c,r); |
| 49 |
(cast(InputValue)input).setValueChangedCallback(&valueChangedCallback); |
| 50 |
} |
| 51 |
|
| 52 |
void valueChangedCallback() { |
| 53 |
saveState(false); |
| 54 |
} |
| 55 |
|
| 56 |
override void activate() { |
| 57 |
initializeInput(); |
| 58 |
} |
| 59 |
|
| 60 |
void initializeInput() { |
| 61 |
input.setCoord(area.x + 3 + column * 3, area.y + cursorOffset + 1); |
| 62 |
} |
| 63 |
alias initializeInput set; |
| 64 |
|
| 65 |
override protected void adjustView() { |
| 66 |
if(column >= columns) { |
| 67 |
column -= columns; |
| 68 |
} |
| 69 |
else if(column < 0) { |
| 70 |
column += columns; |
| 71 |
} |
| 72 |
if(row >= rows) { |
| 73 |
row = row - rows; |
| 74 |
} |
| 75 |
else if(row < 0) { |
| 76 |
row = rows + row; |
| 77 |
} |
| 78 |
assert(row >= 0); |
| 79 |
if(cursorOffset >= visibleRows) { |
| 80 |
int i = cursorOffset - visibleRows + 1; |
| 81 |
viewOffset += i; |
| 82 |
if(viewOffset >= rows) { |
| 83 |
viewOffset -= rows; |
| 84 |
} |
| 85 |
cursorOffset -= i; |
| 86 |
} |
| 87 |
if(cursorOffset < 0) { |
| 88 |
int i = -cursorOffset; |
| 89 |
viewOffset -= i; |
| 90 |
if(viewOffset < 0) |
| 91 |
viewOffset += rows; |
| 92 |
cursorOffset += i; |
| 93 |
} |
| 94 |
initializeInput(); |
| 95 |
} |
| 96 |
|
| 97 |
void stepColumn(int n) { |
| 98 |
column += n; |
| 99 |
adjustView(); |
| 100 |
showByteDescription(); |
| 101 |
} |
| 102 |
|
| 103 |
void setColumn(int n) { |
| 104 |
column = n; |
| 105 |
adjustView(); |
| 106 |
} |
| 107 |
|
| 108 |
void stepColumnWrap(int n) { |
| 109 |
column += n; |
| 110 |
if(column >= columns) { |
| 111 |
stepRow(1); |
| 112 |
} |
| 113 |
adjustView(); |
| 114 |
} |
| 115 |
|
| 116 |
void stepRow(int n) { |
| 117 |
seekRow(n + row); |
| 118 |
} |
| 119 |
|
| 120 |
void setCursorOffset(int r) { |
| 121 |
row += r - cursorOffset; |
| 122 |
cursorOffset = r; |
| 123 |
adjustView(); |
| 124 |
} |
| 125 |
|
| 126 |
void seekRow(int r) { |
| 127 |
cursorOffset += r - row; |
| 128 |
row = r; |
| 129 |
adjustView(); |
| 130 |
} |
| 131 |
|
| 132 |
void seekTableEnd() { |
| 133 |
} |
| 134 |
|
| 135 |
void deleteRow() { |
| 136 |
} |
| 137 |
|
| 138 |
void insertRow() { |
| 139 |
} |
| 140 |
|
| 141 |
void seekColumn(int c) { |
| 142 |
column = c; |
| 143 |
} |
| 144 |
|
| 145 |
override int keypress(Keyinfo key) { |
| 146 |
/+ |
| 147 |
if(key.mods & KMOD_CTRL || key.mods & KMOD_ALT || |
| 148 |
key.mods & KMOD_META) return OK; |
| 149 |
+/ |
| 150 |
if(key.mods & KMOD_CTRL || key.mods & KMOD_ALT || |
| 151 |
key.mods & KMOD_GUI) return OK; |
| 152 |
|
| 153 |
switch(key.raw) |
| 154 |
{ |
| 155 |
case SDLK_LEFT: |
| 156 |
if(input.step(-1) == WRAP) { |
| 157 |
stepColumn(-1); |
| 158 |
} |
| 159 |
break; |
| 160 |
case SDLK_RIGHT: |
| 161 |
if(input.step(1) == WRAP) { |
| 162 |
stepColumn(1); |
| 163 |
} |
| 164 |
break; |
| 165 |
case SDLK_INSERT: |
| 166 |
insertRow(); |
| 167 |
break; |
| 168 |
case SDLK_DELETE: |
| 169 |
deleteRow(); |
| 170 |
break; |
| 171 |
case SDLK_DOWN: |
| 172 |
stepRow(1); |
| 173 |
break; |
| 174 |
case SDLK_UP: |
| 175 |
stepRow(-1); |
| 176 |
break; |
| 177 |
case SDLK_PAGEUP: |
| 178 |
stepRow(-PAGESTEP / 2); |
| 179 |
break; |
| 180 |
case SDLK_PAGEDOWN: |
| 181 |
stepRow(PAGESTEP / 2); |
| 182 |
break; |
| 183 |
case SDLK_HOME: |
| 184 |
if(cursorOffset > 0) |
| 185 |
setCursorOffset(0); |
| 186 |
else seekRow(0); |
| 187 |
break; |
| 188 |
case SDLK_END: |
| 189 |
if(cursorOffset < visibleRows - 1) |
| 190 |
setCursorOffset(visibleRows - 1); |
| 191 |
else seekTableEnd(); |
| 192 |
break; |
| 193 |
case SDLK_h: |
| 194 |
showByteDescription(); |
| 195 |
break; |
| 196 |
|
| 197 |
default: |
| 198 |
if(input.keypress(key) == WRAP) { |
| 199 |
stepColumnWrap(1); |
| 200 |
} |
| 201 |
break; |
| 202 |
} |
| 203 |
initializeInput(); |
| 204 |
return OK; |
| 205 |
} |
| 206 |
|
| 207 |
override void clickedAt(int x, int y, int button) { |
| 208 |
int rx = x - area.x; |
| 209 |
int ry = y - area.y; |
| 210 |
int c = (rx - 3) / 3; |
| 211 |
setCursorOffset(ry - 1); |
| 212 |
if(c >= columns) c = columns - 1; |
| 213 |
setColumn(c); |
| 214 |
} |
| 215 |
|
| 216 |
|
| 217 |
protected: |
| 218 |
|
| 219 |
override final UndoValue createRedoState(UndoValue value) { |
| 220 |
return createState(true); |
| 221 |
} |
| 222 |
|
| 223 |
override final void undo(UndoValue v) { |
| 224 |
// if array has 1 child, assume to be data for this table |
| 225 |
if(v.tableData.length == 1) { |
| 226 |
this.data[] = v.tableData[0]; |
| 227 |
} |
| 228 |
else { |
| 229 |
int idx; |
| 230 |
song.tableIterator((ct.base.Song.Table t) { |
| 231 |
t.data[0..$] = v.tableData[idx++][0..$]; |
| 232 |
}); |
| 233 |
} |
| 234 |
initializeInput(); |
| 235 |
} |
| 236 |
|
| 237 |
void showByteDescription() { |
| 238 |
} |
| 239 |
|
| 240 |
void showByteDescription(PetString pet) { |
| 241 |
if(song.ver < 9 || !state.displayHelp) return; |
| 242 |
string[] s = com.util.petscii2D(pet).splitLines(); |
| 243 |
string outstr = s[0]; |
| 244 |
if(s.length > 1) |
| 245 |
outstr ~= " `01[F12 for more]"; |
| 246 |
UI.statusline.display(format("Byte %d: %s", column + 1, outstr)); |
| 247 |
} |
| 248 |
|
| 249 |
bool highlightRow(int row) { |
| 250 |
return false; |
| 251 |
} |
| 252 |
|
| 253 |
void saveState(bool allTables) { |
| 254 |
auto v = createState(allTables); |
| 255 |
com.session.insertUndo(this, v); |
| 256 |
} |
| 257 |
|
| 258 |
private: |
| 259 |
|
| 260 |
UndoValue createState(bool allTables) { |
| 261 |
UndoValue v; |
| 262 |
if(allTables) { |
| 263 |
song.tableIterator((ct.base.Song.Table t) { |
| 264 |
v.tableData ~= t.data.dup; |
| 265 |
}); |
| 266 |
} |
| 267 |
else v.tableData = [data.dup]; |
| 268 |
return v; |
| 269 |
} |
| 270 |
|
| 271 |
} |
| 272 |
|
| 273 |
class InsValueTable : HexTable { |
| 274 |
private { |
| 275 |
static ubyte[8] instrBuffer; |
| 276 |
static char[32] instrName; |
| 277 |
int mark = -1; |
| 278 |
int width; |
| 279 |
FileSelectorDialog loadDialog; |
| 280 |
} |
| 281 |
this(Rectangle a) { |
| 282 |
width = com.fb.mode ? 32 : 16; |
| 283 |
super(a, song.instrumentTable, 8, 48); |
| 284 |
loadDialog = new FileSelectorDialog(Rectangle(), |
| 285 |
"Load Instrument", |
| 286 |
&loadCallback); |
| 287 |
} |
| 288 |
|
| 289 |
override void refresh() { |
| 290 |
data = song.instrumentTable; |
| 291 |
} |
| 292 |
|
| 293 |
override int keypress(Keyinfo key) { |
| 294 |
if(key.mods & KMOD_ALT) return OK; |
| 295 |
if(key.mods & KMOD_CTRL) { |
| 296 |
switch(key.raw) { |
| 297 |
case SDLK_c: |
| 298 |
foreach(i, ref buf; instrBuffer) { |
| 299 |
buf = data[row + i * 48]; |
| 300 |
} |
| 301 |
instrName[0..32] = insName(row)[]; |
| 302 |
UI.statusline.display("Instrument copied to buffer."); |
| 303 |
break; |
| 304 |
case SDLK_v: |
| 305 |
foreach(i, ref buf; instrBuffer) { |
| 306 |
data[i * 48 + row] = buf; |
| 307 |
} |
| 308 |
song.insLabels[row][] = instrName[]; |
| 309 |
initializeInput(); |
| 310 |
break; |
| 311 |
case SDLK_s: |
| 312 |
void delegate(string) dg = (string fn) { |
| 313 |
if(fn == "") |
| 314 |
return; |
| 315 |
if(!fnIsSane(fn)) { |
| 316 |
UI.statusline.display("Illegal characters in filename!"); |
| 317 |
return; |
| 318 |
} |
| 319 |
try { |
| 320 |
com.session.song.savePatch(fn, state.activeInstrument); |
| 321 |
} |
| 322 |
catch(UserException e) { |
| 323 |
stderr.writeln(e.toString); |
| 324 |
UI.statusline.display(e.toString); |
| 325 |
return; |
| 326 |
} |
| 327 |
UI.statusline.display(format("Saved instrument %d", state.activeInstrument)); |
| 328 |
}; |
| 329 |
string fn = fnClean(std.string.stripRight |
| 330 |
(std.conv.to!string(song.insLabels[row]))); |
| 331 |
if(fn.length == 0) |
| 332 |
fn = "unnamed"; |
| 333 |
try { |
| 334 |
chdir(loadDialog.directory); |
| 335 |
} |
| 336 |
catch(FileException e) { |
| 337 |
stderr.writeln(e); |
| 338 |
UI.statusline.display(format("Could not change to directory %40s",loadDialog.directory)); |
| 339 |
break; |
| 340 |
} |
| 341 |
|
| 342 |
mainui.activateDialog(new StringDialog("Enter filename: ", |
| 343 |
dg, |
| 344 |
fn ~ ".cti", |
| 345 |
32)); |
| 346 |
|
| 347 |
break; |
| 348 |
case SDLK_l: |
| 349 |
mainui.activateDialog(loadDialog); |
| 350 |
break; |
| 351 |
case SDLK_d: |
| 352 |
void delegate(int) dg = (int param) { |
| 353 |
if(param != 0) return; |
| 354 |
(new Purge(song)).deleteInstrument(state.activeInstrument); |
| 355 |
}; |
| 356 |
|
| 357 |
mainui.activateDialog(new ConfirmationDialog("Delete current instrument (y/n)? ", |
| 358 |
dg)); |
| 359 |
|
| 360 |
break; |
| 361 |
case SDLK_x: |
| 362 |
break; |
| 363 |
default: break; |
| 364 |
} |
| 365 |
} |
| 366 |
int r = super.keypress(key); |
| 367 |
if(r == WRAP) { |
| 368 |
stepColumn(1); |
| 369 |
} |
| 370 |
return OK; |
| 371 |
} |
| 372 |
|
| 373 |
private void loadCallback(string fn) { |
| 374 |
if(!std.file.exists(fn)) { |
| 375 |
UI.statusline.display("File does not exist or is not accessible!"); |
| 376 |
return; |
| 377 |
} |
| 378 |
if(fn.indexOf(".cti") == -1) { |
| 379 |
UI.statusline.display("Not loading; possibly not an instrument def file."); |
| 380 |
return; |
| 381 |
} |
| 382 |
try { |
| 383 |
song.insertPatch(fn, state.activeInstrument); |
| 384 |
} |
| 385 |
catch(Exception e) { |
| 386 |
stderr.writeln(e.toString); |
| 387 |
UI.statusline.display("Error in parsing instrument data!"); |
| 388 |
} |
| 389 |
} |
| 390 |
|
| 391 |
string insName(int row) { |
| 392 |
assert(row >= 0 && row < 48); |
| 393 |
return format(song.insLabels[row % 48][0..32]); |
| 394 |
} |
| 395 |
|
| 396 |
override void stepColumn(int n) { |
| 397 |
super.stepColumn(n); |
| 398 |
} |
| 399 |
|
| 400 |
override void stepColumnWrap(int n) { |
| 401 |
stepColumn(-7); |
| 402 |
adjustView(); |
| 403 |
} |
| 404 |
|
| 405 |
override void activate() { |
| 406 |
super.activate(); |
| 407 |
} |
| 408 |
|
| 409 |
override void update() { |
| 410 |
int b = 0; |
| 411 |
int i, j, ofs; |
| 412 |
int myrow = row; |
| 413 |
|
| 414 |
if(myrow > 48) myrow -= 48; |
| 415 |
screen.fprint(area.x,area.y, "`b1I`01nstruments"); |
| 416 |
for(i = 0; i < visibleRows; i++) { |
| 417 |
int p = (i + viewOffset); |
| 418 |
if(p > 47) p -= 48; |
| 419 |
assert(p >= 0 && p < 48); |
| 420 |
|
| 421 |
int c = (state.activeInstrument >= 0 && row == p) ? 15 : 12; |
| 422 |
screen.cprint(area.x,area.y + i + 1, c, 0, format("%02X:", p)); |
| 423 |
for(j=0; j<8; j++) { |
| 424 |
ofs = p + j * 48; |
| 425 |
int hl = p == mark ? 13 : 5; |
| 426 |
screen.cprint(area.x+3+j*3,area.y + i + 1,hl,0, format("%02X ", data[ofs])); |
| 427 |
} |
| 428 |
string label = insName(p)[0..width]; |
| 429 |
if(paddedStringLength(label, 32) == 0) |
| 430 |
screen.cprint(area.x + 27, area.y + 1 + i, 11, 0, |
| 431 |
format("No description" ~ std.array.replicate(" ", width-14))); |
| 432 |
else |
| 433 |
screen.cprint(area.x + 27, area.y + 1 + i, 15, 0, |
| 434 |
label); |
| 435 |
} |
| 436 |
} |
| 437 |
|
| 438 |
override void initializeInput() { |
| 439 |
super.set(); |
| 440 |
assert(row < 48); |
| 441 |
int ofs = column * 48 + row; |
| 442 |
input.setOutput(data[ofs .. ofs+1]); |
| 443 |
} |
| 444 |
|
| 445 |
override void stepRow(int n) { |
| 446 |
super.stepRow(n); |
| 447 |
UI.activateInstrument(row); |
| 448 |
} |
| 449 |
|
| 450 |
override void showByteDescription() { |
| 451 |
if(song.ver > 8) { |
| 452 |
super.showByteDescription(song.instrumentByteDescriptions[column]); |
| 453 |
} |
| 454 |
} |
| 455 |
} |
| 456 |
|
| 457 |
class InsTable : Window { |
| 458 |
private { |
| 459 |
DialogString insdesc; |
| 460 |
InsValueTable insinput; |
| 461 |
} |
| 462 |
Window active; |
| 463 |
|
| 464 |
this(Rectangle a) { |
| 465 |
super(a); |
| 466 |
insdesc = new DialogString(a, com.fb.mode ? 32 : 16); |
| 467 |
insinput = new InsValueTable(a); |
| 468 |
refresh(); |
| 469 |
activateInsValueTable(); |
| 470 |
} |
| 471 |
|
| 472 |
override const ContextHelp contextHelp() { |
| 473 |
if(song.ver > 8) |
| 474 |
return genPlayerContextHelp("Instrument table", |
| 475 |
song.instrumentByteDescriptions); |
| 476 |
return ui.help.HELPMAIN; |
| 477 |
} |
| 478 |
|
| 479 |
override void refresh() { |
| 480 |
super.refresh(); |
| 481 |
insdesc.refresh(); |
| 482 |
insinput.refresh(); |
| 483 |
} |
| 484 |
|
| 485 |
@property int row() { |
| 486 |
return insinput.row; |
| 487 |
} |
| 488 |
|
| 489 |
void stepRow(int n) { insinput.stepRow(n); } |
| 490 |
void seekRow(int r) { insinput.seekRow(r); } |
| 491 |
|
| 492 |
override void activate() { |
| 493 |
activateInsValueTable(); |
| 494 |
} |
| 495 |
|
| 496 |
override void deactivate() { |
| 497 |
if(active == insdesc) { |
| 498 |
string s = insdesc.toString(false); |
| 499 |
song.insLabels[insinput.row][0..s.length] = s; |
| 500 |
} |
| 501 |
activateInsValueTable(); |
| 502 |
active.update(); |
| 503 |
state.allowInstabNavigation = true; |
| 504 |
} |
| 505 |
|
| 506 |
void activateDescInput() { |
| 507 |
update(); |
| 508 |
active = insdesc; |
| 509 |
input = insdesc.input; |
| 510 |
input.setCoord(area.x + 9 * 3, 1 + area.y + insinput.cursorOffset); |
| 511 |
insdesc.setString(format(song.insLabels[insinput.row])); |
| 512 |
initializeInput(); |
| 513 |
state.allowInstabNavigation = false; |
| 514 |
} |
| 515 |
|
| 516 |
void activateInsValueTable() { |
| 517 |
active = insinput; |
| 518 |
input = insinput.input; |
| 519 |
active.activate(); |
| 520 |
initializeInput(); |
| 521 |
state.allowInstabNavigation = true; |
| 522 |
} |
| 523 |
|
| 524 |
override int keypress(Keyinfo key) { |
| 525 |
if(key.mods & KMOD_ALT) return OK; |
| 526 |
if(key.unicode == SDLK_RETURN || key.unicode == SDLK_TAB) { |
| 527 |
if(active == insinput) { |
| 528 |
activateDescInput(); |
| 529 |
} |
| 530 |
else { |
| 531 |
string s = insdesc.toString(true); |
| 532 |
song.insLabels[insinput.row][0..s.length] = s; |
| 533 |
activateInsValueTable(); |
| 534 |
} |
| 535 |
return OK; |
| 536 |
} |
| 537 |
int r; |
| 538 |
r = active.keypress(key); |
| 539 |
return r; |
| 540 |
} |
| 541 |
|
| 542 |
override void update() { |
| 543 |
active.update(); |
| 544 |
} |
| 545 |
|
| 546 |
void initializeInput() { |
| 547 |
if(active == insinput) insinput.initializeInput(); |
| 548 |
} |
| 549 |
alias initializeInput set; |
| 550 |
|
| 551 |
override void clickedAt(int x, int y, int button) { |
| 552 |
insinput.clickedAt(x,y,button); |
| 553 |
if((x - area.x) > 3 + 8 * 3) |
| 554 |
activateDescInput(); |
| 555 |
} |
| 556 |
} |
| 557 |
|
| 558 |
|
| 559 |
class CmdTable : HexTable { |
| 560 |
alias row position; |
| 561 |
|
| 562 |
this(Rectangle a) { |
| 563 |
super(a, song.superTable, 1, 64); |
| 564 |
input = new InputSpecial(song.superTable); |
| 565 |
} |
| 566 |
|
| 567 |
override void update() { |
| 568 |
int i; |
| 569 |
if(state.shortTitles) |
| 570 |
screen.fprint(area.x,area.y, "`01Co`b1m`01mand"); |
| 571 |
else |
| 572 |
screen.fprint(area.x,area.y, "`01Cmd (Alt-S)"); |
| 573 |
for(i = 0; i < visibleRows; i++) { |
| 574 |
int ofs = (viewOffset + i) & 0x3f; |
| 575 |
screen.fprint(area.x,area.y + i + 1, |
| 576 |
format("`0c%02X:`0d%01X-`05%02X %02X", ofs, |
| 577 |
song.superTable[ofs] & 15, |
| 578 |
song.superTable[ofs+64], |
| 579 |
song.superTable[ofs+128])); |
| 580 |
} |
| 581 |
} |
| 582 |
|
| 583 |
override int keypress(Keyinfo key) { |
| 584 |
if(key.mods & KMOD_ALT) return OK; |
| 585 |
switch(key.raw) { |
| 586 |
case SDLK_LEFT: |
| 587 |
input.step(-1); |
| 588 |
break; |
| 589 |
case SDLK_RIGHT: |
| 590 |
input.step(1); |
| 591 |
break; |
| 592 |
case SDLK_DOWN: |
| 593 |
stepRow(1); |
| 594 |
break; |
| 595 |
case SDLK_UP: |
| 596 |
stepRow(-1); |
| 597 |
break; |
| 598 |
case SDLK_PAGEUP: |
| 599 |
stepRow(-(PAGESTEP/2)); |
| 600 |
break; |
| 601 |
case SDLK_PAGEDOWN: |
| 602 |
stepRow((PAGESTEP/2)); |
| 603 |
break; |
| 604 |
case SDLK_HOME: |
| 605 |
seekRow(0); |
| 606 |
break; |
| 607 |
case SDLK_END: |
| 608 |
seekTableEnd(); |
| 609 |
break; |
| 610 |
default: |
| 611 |
break; |
| 612 |
} |
| 613 |
int r = input.keypress(key); |
| 614 |
song.superTable[position] = input.inarray[0]; |
| 615 |
song.superTable[position+64] = cast(ubyte)input.toIntRange(1, 3); |
| 616 |
song.superTable[position+128] = cast(ubyte)input.toIntRange(3, 5); |
| 617 |
if(r == WRAP) { |
| 618 |
stepRow(1); |
| 619 |
} |
| 620 |
return OK; |
| 621 |
} |
| 622 |
|
| 623 |
override void initializeInput() { |
| 624 |
super.initializeInput(); |
| 625 |
input.inarray[0] = song.superTable[position]; |
| 626 |
input.inarray[1] = song.superTable[position+64] >> 4; |
| 627 |
input.inarray[2] = song.superTable[position+64] & 15; |
| 628 |
input.inarray[3] = song.superTable[position+128] >> 4; |
| 629 |
input.inarray[4] = song.superTable[position+128] & 15; |
| 630 |
} |
| 631 |
|
| 632 |
override void seekTableEnd() { |
| 633 |
for(int i = 63; i >= 1; i--) { |
| 634 |
if(data[i-1] > 0) { |
| 635 |
seekRow(i); |
| 636 |
return; |
| 637 |
} |
| 638 |
} |
| 639 |
} |
| 640 |
|
| 641 |
override ContextHelp contextHelp() { |
| 642 |
if(song.ver > 9) |
| 643 |
return genPlayerContextHelp("Command table", |
| 644 |
song.cmdDescriptions); |
| 645 |
return ui.help.HELPMAIN; |
| 646 |
} |
| 647 |
|
| 648 |
override void showByteDescription() { |
| 649 |
if(song.ver > 9) { |
| 650 |
super.showByteDescription(song.cmdDescriptions[column]); |
| 651 |
} |
| 652 |
} |
| 653 |
|
| 654 |
} |
| 655 |
|
| 656 |
class ChordTable : HexTable { |
| 657 |
this(Rectangle a) { |
| 658 |
super(a, song.chordTable, 1, 128); |
| 659 |
} |
| 660 |
|
| 661 |
override void refresh() { |
| 662 |
super.refresh(); |
| 663 |
data = song.chordTable; |
| 664 |
} |
| 665 |
|
| 666 |
override void seekTableEnd() { |
| 667 |
for(int i = 127; i >= 1; i--) { |
| 668 |
if(data[i-1] > 0) { |
| 669 |
seekRow(i); |
| 670 |
return; |
| 671 |
} |
| 672 |
} |
| 673 |
} |
| 674 |
|
| 675 |
override void update() { |
| 676 |
int i; |
| 677 |
if(state.shortTitles) |
| 678 |
screen.fprint(area.x,area.y, "`01Chor`b1d`01"); |
| 679 |
else |
| 680 |
screen.fprint(area.x,area.y, "`01Chd (A-D)"); |
| 681 |
|
| 682 |
for(i = 0; i < visibleRows; i++) { |
| 683 |
int row = (i + viewOffset) & 0x7f; |
| 684 |
string col = "`05"; |
| 685 |
if(data[row] >= 0x80) col = "`0d"; |
| 686 |
screen.fprint(area.x, area.y + i + 1, |
| 687 |
format("`0c%02X:%s%02X", row, col, data[row])); |
| 688 |
} |
| 689 |
|
| 690 |
for(i = 0; i < visibleRows; i++) { |
| 691 |
screen.fprint(area.x + 5, area.y + i + 1, " "); |
| 692 |
} |
| 693 |
|
| 694 |
int[] chordno = getHighestChordIndex(); |
| 695 |
|
| 696 |
{ |
| 697 |
int ct; |
| 698 |
for(i = 0; i < viewOffset; i++) { |
| 699 |
if(data[i] >= 0x80) ct++; |
| 700 |
} |
| 701 |
bool doPrint = true; |
| 702 |
int row = viewOffset & 127; |
| 703 |
for(i = 0; i < visibleRows; i++,row++) { |
| 704 |
if(row > 127) { |
| 705 |
row -= 128; |
| 706 |
ct = 0; |
| 707 |
doPrint = true; |
| 708 |
} |
| 709 |
|
| 710 |
if(doPrint) { |
| 711 |
screen.fprint(area.x + 5, area.y + i + 1, format("`0c%X ", ct)); |
| 712 |
doPrint = false; |
| 713 |
} |
| 714 |
|
| 715 |
if(data[row] >= 0x80) { |
| 716 |
if(ct >= chordno[0]) break; |
| 717 |
ct++; |
| 718 |
doPrint = true; |
| 719 |
if(row >= chordno[1]) { |
| 720 |
doPrint = false; |
| 721 |
} |
| 722 |
} |
| 723 |
} |
| 724 |
} |
| 725 |
} |
| 726 |
|
| 727 |
override void initializeInput() { |
| 728 |
super.initializeInput(); |
| 729 |
input.setOutput(data[row .. row + 1]); |
| 730 |
song.generateChordIndex(); |
| 731 |
} |
| 732 |
|
| 733 |
override void insertRow() { |
| 734 |
saveState(false); |
| 735 |
ubyte[] tmp = data[row .. $-1].dup; |
| 736 |
foreach(i, c; tmp) { |
| 737 |
if(/+row > 0 && +/ c >= (0x80 + row) && ++c < 0x100) { |
| 738 |
tmp[i] = c; |
| 739 |
} |
| 740 |
} |
| 741 |
data[row+1 .. $] = tmp; |
| 742 |
data[row] = 0; |
| 743 |
initializeInput(); |
| 744 |
} |
| 745 |
|
| 746 |
override void deleteRow() { |
| 747 |
saveState(false); |
| 748 |
ubyte[] tmp = data[row + 1 .. $].dup; |
| 749 |
foreach(i, c; tmp) { |
| 750 |
if(c > (0x80 + row) && --c >= 0x80) |
| 751 |
tmp[i] = c; |
| 752 |
} |
| 753 |
data[row .. $ - 1] = tmp; |
| 754 |
data[$-1] = 0; |
| 755 |
initializeInput(); |
| 756 |
} |
| 757 |
|
| 758 |
private: |
| 759 |
|
| 760 |
// returns number of chords and the offset of the last chord |
| 761 |
int[] getHighestChordIndex() { |
| 762 |
foreach_reverse(counter, idx; song.chordIndexTable) { |
| 763 |
if(idx == 0) continue; |
| 764 |
return cast(int[])[counter, idx]; |
| 765 |
} |
| 766 |
return [-1, -1]; |
| 767 |
} |
| 768 |
} |
| 769 |
|
| 770 |
class WaveTable : HexTable { |
| 771 |
this(Rectangle a) { |
| 772 |
super(a, song.waveTable, 2, 256); |
| 773 |
} |
| 774 |
|
| 775 |
override void refresh() { |
| 776 |
super.refresh(); |
| 777 |
data = song.waveTable; |
| 778 |
} |
| 779 |
|
| 780 |
override void seekTableEnd() { |
| 781 |
for(int i = 255; i >= 1; i--) { |
| 782 |
if(data[i-1] > 0) { |
| 783 |
seekRow(i); |
| 784 |
return; |
| 785 |
} |
| 786 |
} |
| 787 |
} |
| 788 |
|
| 789 |
void seekCurWave() { |
| 790 |
seekRow(song.instrumentTable[state.activeInstrument + 7 * 48]); |
| 791 |
} |
| 792 |
|
| 793 |
override int keypress(Keyinfo key) { |
| 794 |
if(key.mods & KMOD_SHIFT) { |
| 795 |
switch(key.raw) |
| 796 |
{ |
| 797 |
case SDLK_HOME: |
| 798 |
seekRow(0); |
| 799 |
return OK; |
| 800 |
case SDLK_END: |
| 801 |
seekTableEnd(); |
| 802 |
return OK; |
| 803 |
default: |
| 804 |
break; |
| 805 |
} |
| 806 |
} |
| 807 |
else if(key.mods & KMOD_CTRL) { |
| 808 |
switch(key.raw) { |
| 809 |
case SDLK_g: |
| 810 |
seekCurWave(); |
| 811 |
return OK; |
| 812 |
default: |
| 813 |
break; |
| 814 |
} |
| 815 |
} |
| 816 |
else switch(key.raw) { |
| 817 |
case SDLK_g: |
| 818 |
seekCurWave(); |
| 819 |
return OK; |
| 820 |
case SDLK_DELETE: |
| 821 |
saveState(true); |
| 822 |
song.tWave.deleteRow(song, row); |
| 823 |
refresh(); |
| 824 |
set(); |
| 825 |
return OK; |
| 826 |
case SDLK_INSERT: |
| 827 |
saveState(true); |
| 828 |
song.tWave.insertRow(song, row); |
| 829 |
refresh(); |
| 830 |
set(); |
| 831 |
return OK; |
| 832 |
case '.': |
| 833 |
data[column ? (256 + row) : row] = 0; |
| 834 |
stepColumnWrap(1); |
| 835 |
return OK; |
| 836 |
default: |
| 837 |
break; |
| 838 |
} |
| 839 |
return super.keypress(key); |
| 840 |
} |
| 841 |
|
| 842 |
override void update() { |
| 843 |
int i; |
| 844 |
int t1, t2; |
| 845 |
if(state.shortTitles) |
| 846 |
screen.fprint(area.x,area.y, "`b1W`01ave"); |
| 847 |
else |
| 848 |
screen.fprint(area.x,area.y, "`01Wave (A-W)"); |
| 849 |
for(i = 0; i < visibleRows; i++) { |
| 850 |
int row = (i + viewOffset) & 255; |
| 851 |
t1 = data[row]; |
| 852 |
t2 = data[row+256]; |
| 853 |
int col = (t1 == 0x7e || t1 == 0x7f) ? 0x0d : 0x05; |
| 854 |
screen.fprint(area.x,area.y + i + 1, format("`0c%02X:`%02x%02X %02X", |
| 855 |
row, col, t1, t2)); |
| 856 |
|
| 857 |
} |
| 858 |
} |
| 859 |
|
| 860 |
override void initializeInput() { |
| 861 |
int offset = column ? (256 + row) : row; |
| 862 |
(cast(InputByte)input).setOutput(data[offset..offset+1]); |
| 863 |
super.set(); |
| 864 |
} |
| 865 |
|
| 866 |
override void stepColumnWrap(int n) { |
| 867 |
stepRow(1); |
| 868 |
adjustView(); |
| 869 |
} |
| 870 |
|
| 871 |
|
| 872 |
override void showByteDescription() { |
| 873 |
if(song.ver > 9) { |
| 874 |
super.showByteDescription(song.waveDescriptions[column]); |
| 875 |
} |
| 876 |
} |
| 877 |
|
| 878 |
override ContextHelp contextHelp() { |
| 879 |
if(song.ver > 9) |
| 880 |
return genPlayerContextHelp("Wave table", |
| 881 |
song.waveDescriptions); |
| 882 |
return ui.help.HELPMAIN; |
| 883 |
|
| 884 |
} |
| 885 |
} |
| 886 |
|
| 887 |
class SweepTable : HexTable { |
| 888 |
this(Rectangle a, ubyte[] d) { |
| 889 |
super(a, d, 4, 64); |
| 890 |
} |
| 891 |
|
| 892 |
override int keypress(Keyinfo key) { |
| 893 |
switch(key.raw) { |
| 894 |
case SDLK_DELETE: |
| 895 |
deleteRow(); |
| 896 |
refresh(); |
| 897 |
set(); |
| 898 |
return OK; |
| 899 |
case SDLK_INSERT: |
| 900 |
insertRow(); |
| 901 |
refresh(); |
| 902 |
set(); |
| 903 |
return OK; |
| 904 |
default: return super.keypress(key); |
| 905 |
} |
| 906 |
} |
| 907 |
|
| 908 |
override void update() { |
| 909 |
for(int i = 0; i < visibleRows; i++) { |
| 910 |
int curRow = (i + viewOffset) & 63; |
| 911 |
int p = curRow * 4; |
| 912 |
string col = "`05", col2 = "`05"; |
| 913 |
if(data[p+3] > 0) col = "`0d"; |
| 914 |
if(data[p+3] > 0x3f && data[p+3] != 0x7f) col = "`0a"; |
| 915 |
if(highlightRow(curRow)) { col2 = col = "`0d"; } |
| 916 |
screen.fprint(area.x,area.y + i + 1, |
| 917 |
format("`0c%02X:%s%02X %02X %02X %s%02X", |
| 918 |
curRow, col2, |
| 919 |
data[p], data[p+1], data[p+2], col, data[p+3])); |
| 920 |
} |
| 921 |
} |
| 922 |
|
| 923 |
override void initializeInput() { |
| 924 |
InputByte i = cast(InputByte)input; |
| 925 |
int ofs = row * 4 + column; |
| 926 |
i.setOutput(data[ofs..ofs+1]); |
| 927 |
super.initializeInput(); |
| 928 |
|
| 929 |
} |
| 930 |
|
| 931 |
override void seekTableEnd() { |
| 932 |
for(int i = 63; i >= 0; i--) { |
| 933 |
ubyte[] arr = data[i * 3 .. i * 3 + 3]; |
| 934 |
bool flag; |
| 935 |
foreach(a; arr) { |
| 936 |
if(a) { |
| 937 |
int row = i + 1; |
| 938 |
if(row > 63) row = 63; |
| 939 |
seekRow(row); |
| 940 |
return; |
| 941 |
} |
| 942 |
} |
| 943 |
} |
| 944 |
} |
| 945 |
|
| 946 |
protected bool highlightActiveFor(int startFrom, int currentRow) { |
| 947 |
if(startFrom > 0x3f || startFrom == 0) return false; |
| 948 |
|
| 949 |
if(startFrom == currentRow) |
| 950 |
return true; |
| 951 |
|
| 952 |
bool[0x40] visited; |
| 953 |
for(int row = startFrom; row < 0x40;) { |
| 954 |
if(visited[row]) break; |
| 955 |
visited[row] = true; |
| 956 |
if(row == currentRow) return true; |
| 957 |
int jumpValue = data[row * 4 + 3]; |
| 958 |
if(jumpValue > 0x3f && jumpValue != 0x7f) // if illegal, break |
| 959 |
break; |
| 960 |
if(jumpValue == 0x7f) |
| 961 |
break; // if loops or ends, break |
| 962 |
else if(jumpValue == 0) |
| 963 |
row++; |
| 964 |
else row = jumpValue; |
| 965 |
} |
| 966 |
return false; |
| 967 |
} |
| 968 |
} |
| 969 |
|
| 970 |
class PulseTable : SweepTable { |
| 971 |
this(Rectangle a) { |
| 972 |
super(a, song.pulseTable); |
| 973 |
} |
| 974 |
|
| 975 |
override void refresh() { |
| 976 |
super.refresh(); |
| 977 |
data = song.pulseTable; |
| 978 |
} |
| 979 |
|
| 980 |
override void update() { |
| 981 |
if(state.shortTitles) |
| 982 |
screen.fprint(area.x, area.y, "`b1P`01ulse"); |
| 983 |
else |
| 984 |
screen.fprint(area.x, area.y, "`01Pulse (Alt-P)"); |
| 985 |
super.update(); |
| 986 |
} |
| 987 |
|
| 988 |
override void showByteDescription() { |
| 989 |
if(song.ver > 8) { |
| 990 |
super.showByteDescription(song.pulseDescriptions[column]); |
| 991 |
} |
| 992 |
} |
| 993 |
|
| 994 |
override ContextHelp contextHelp() { |
| 995 |
if(song.ver > 8) |
| 996 |
return genPlayerContextHelp("Pulse table", |
| 997 |
song.pulseDescriptions); |
| 998 |
return ui.help.HELPMAIN; |
| 999 |
} |
| 1000 |
|
| 1001 |
override void deleteRow() { |
| 1002 |
saveState(true); |
| 1003 |
ct.purge.pulseDeleteRow(song, row); |
| 1004 |
} |
| 1005 |
|
| 1006 |
override void insertRow() { |
| 1007 |
saveState(true); |
| 1008 |
ct.purge.pulseInsertRow(song, row); |
| 1009 |
} |
| 1010 |
|
| 1011 |
override bool highlightRow(int row) { |
| 1012 |
return highlightActiveFor(song.instrumentTable[state.activeInstrument + 5 * 48], row); |
| 1013 |
} |
| 1014 |
} |
| 1015 |
|
| 1016 |
class FilterTable : SweepTable { |
| 1017 |
this(Rectangle a) { |
| 1018 |
super(a, song.filterTable); |
| 1019 |
refresh(); |
| 1020 |
} |
| 1021 |
|
| 1022 |
override void refresh() { |
| 1023 |
super.refresh(); |
| 1024 |
data = song.filterTable; |
| 1025 |
} |
| 1026 |
|
| 1027 |
override void update() { |
| 1028 |
if(state.shortTitles) |
| 1029 |
screen.fprint(area.x, area.y, "`b1F`01ilter"); |
| 1030 |
else |
| 1031 |
screen.fprint(area.x, area.y, "`01Filter (Alt-F)"); |
| 1032 |
super.update(); |
| 1033 |
} |
| 1034 |
|
| 1035 |
override ContextHelp contextHelp() { |
| 1036 |
if(song.ver > 8) |
| 1037 |
return genPlayerContextHelp("Filter table", |
| 1038 |
song.filterDescriptions); |
| 1039 |
return ui.help.HELPMAIN; |
| 1040 |
} |
| 1041 |
|
| 1042 |
override void showByteDescription() { |
| 1043 |
if(song.ver > 8) { |
| 1044 |
super.showByteDescription(song.filterDescriptions[column]); |
| 1045 |
} |
| 1046 |
} |
| 1047 |
|
| 1048 |
override void deleteRow() { |
| 1049 |
saveState(true); |
| 1050 |
ct.purge.filterDeleteRow(song, row); |
| 1051 |
} |
| 1052 |
|
| 1053 |
override void insertRow() { |
| 1054 |
saveState(true); |
| 1055 |
ct.purge.filterInsertRow(song, row); |
| 1056 |
} |
| 1057 |
|
| 1058 |
override bool highlightRow(int row) { |
| 1059 |
return highlightActiveFor(song.instrumentTable[state.activeInstrument + 4 * 48], row); |
| 1060 |
} |
| 1061 |
|
| 1062 |
} |
| 1063 |
|