| 1 |
/* |
| 2 |
CheeseCutter v2 (C) Abaddon. Licensed under GNU GPL. |
| 3 |
*/ |
| 4 |
|
| 5 |
module seq.trackmap; |
| 6 |
import main; |
| 7 |
import com.fb; |
| 8 |
import com.session; |
| 9 |
import ui.ui; |
| 10 |
import seq.sequencer; |
| 11 |
import seq.tracktable; |
| 12 |
import ui.input; |
| 13 |
import derelict.sdl2.sdl; |
| 14 |
import std.string : format; |
| 15 |
import ct.base; |
| 16 |
import std.array; |
| 17 |
|
| 18 |
|
| 19 |
class TrackmapVoice : TrackVoice { |
| 20 |
this(VoiceInitParams v) { |
| 21 |
super(v); |
| 22 |
} |
| 23 |
|
| 24 |
override void update() { |
| 25 |
RowData wseq, cseq; |
| 26 |
int h = area.y + area.h + 1; |
| 27 |
int y,i; |
| 28 |
int trkofs = pos.trkOffset; |
| 29 |
int lasttrk = tracks.trackLength; |
| 30 |
int counter; |
| 31 |
int scry = area.y + 1; |
| 32 |
|
| 33 |
void printEmpty() { |
| 34 |
screen.cprint(area.x - 1, scry, 1, 0, |
| 35 |
std.array.replicate(" ", 16)); |
| 36 |
} |
| 37 |
|
| 38 |
void printTrack() { |
| 39 |
int fpCounter = fplayPos.rowCounter; |
| 40 |
int delta = fpCounter - counter; |
| 41 |
int fgcol = (delta >= 0 && delta < wseq.seq.rows) ? 13 : 5; |
| 42 |
int trk = wseq.trk.smashedValue; |
| 43 |
int rows = wseq.seq.rows; |
| 44 |
int c = counter; |
| 45 |
if(scry == area.y + 1 + anchor) fgcol = 1; |
| 46 |
if(wseq.trk.trans >= 0xf0) { |
| 47 |
rows = 0; |
| 48 |
c = 0; |
| 49 |
} |
| 50 |
screen.fprint(area.x-1, scry, |
| 51 |
format(" `01%s `0%x%02X %04X ", |
| 52 |
formatTrackValue(trk), fgcol, |
| 53 |
rows, c)); |
| 54 |
if(trkofs == pos.mark) { |
| 55 |
for(int i = 0; i < 13; i++) { |
| 56 |
int xpos = area.x + i; |
| 57 |
if(screen.getbg(xpos, scry) == 0) |
| 58 |
screen.setbg(xpos, scry, playbackBarColor); |
| 59 |
} |
| 60 |
} |
| 61 |
if(trkofs == tracks.wrapOffset) { |
| 62 |
for(int i = 0; i < 15; i++) { |
| 63 |
int xpos = area.x + i - 1; |
| 64 |
if(screen.getbg(xpos, scry) == 0) |
| 65 |
screen.setbg(xpos, scry, wrapBarColor); |
| 66 |
} |
| 67 |
} |
| 68 |
} |
| 69 |
trkofs -= seq.sequencer.anchor; |
| 70 |
counter = getRowcounter(trkofs); |
| 71 |
|
| 72 |
if(trkofs >= 0) |
| 73 |
wseq = getRowData(trkofs); |
| 74 |
y = area.y + 1; |
| 75 |
|
| 76 |
while(scry <= area.y + area.height) { |
| 77 |
if(trkofs < 0) { |
| 78 |
printEmpty(); |
| 79 |
scry++; |
| 80 |
} |
| 81 |
else if(trkofs >= lasttrk+1) { |
| 82 |
printEmpty(); |
| 83 |
scry++; trkofs++; |
| 84 |
continue; |
| 85 |
} |
| 86 |
else { |
| 87 |
printTrack(); |
| 88 |
counter += wseq.seq.rows; |
| 89 |
scry++; |
| 90 |
} |
| 91 |
trkofs++; |
| 92 |
if(trkofs >= 0 && trkofs <= lasttrk) { |
| 93 |
wseq = getRowData(trkofs, 0); |
| 94 |
} |
| 95 |
} |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
class TrackmapTable : BaseTrackTable { |
| 100 |
this(Rectangle a, PosDataTable pi) { |
| 101 |
int x = 5 + com.fb.border + a.x; |
| 102 |
for(int v=0;v<3;v++) { |
| 103 |
Rectangle na = Rectangle(x, a.y, a.height, 13 + com.fb.border); |
| 104 |
x += 13 + com.fb.border; |
| 105 |
voices[v] = new TrackmapVoice(VoiceInitParams(song.tracks[v], |
| 106 |
na, pi.pos[v], this)); |
| 107 |
} |
| 108 |
super(a, pi); |
| 109 |
} |
| 110 |
|
| 111 |
override void activate() { |
| 112 |
super.activate(); |
| 113 |
// FIX: scroll the screen to center, don't just set the offset vars |
| 114 |
centralize(); |
| 115 |
} |
| 116 |
|
| 117 |
override int keypress(Keyinfo key) { |
| 118 |
switch(key.raw) |
| 119 |
{ |
| 120 |
case SDLK_z: |
| 121 |
mainui.activateDialog(queryClip); |
| 122 |
return OK; |
| 123 |
case SDLK_i: |
| 124 |
pasteCallback(true); |
| 125 |
return OK; |
| 126 |
default: |
| 127 |
return super.keypress(key); |
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
// centerTo() & jump() (?) do not work with this! |
| 133 |
override void step(int st) { step(st,0); } |
| 134 |
override void step(int st, int extra) { |
| 135 |
int steps, rows; |
| 136 |
RowData s; |
| 137 |
activeVoice.trackFlush(posTable.pointerOffset); |
| 138 |
if(st > 0) { |
| 139 |
if(activeVoice.atEnd()) return; |
| 140 |
rows = activeVoice.activeRow.seq.rows; |
| 141 |
foreach(v; voices) { |
| 142 |
v.scroll(rows, true); |
| 143 |
} |
| 144 |
} |
| 145 |
else if(st < 0) { |
| 146 |
int t = activeVoice.pos.trkOffset-1; |
| 147 |
if(t < 0) t = activeVoice.tracks.trackLength-1; |
| 148 |
|
| 149 |
s = activeVoice.getRowData(t,0); |
| 150 |
rows = s.seq.rows; |
| 151 |
foreach(v; voices) { |
| 152 |
v.scroll(-rows); |
| 153 |
} |
| 154 |
} |
| 155 |
super.refresh(); |
| 156 |
} |
| 157 |
override void toSeqStart() { return; } |
| 158 |
} |
| 159 |
|