| 1 |
/* |
| 2 |
CheeseCutter v2 (C) Abaddon. Licensed under GNU GPL. |
| 3 |
*/ |
| 4 |
|
| 5 |
module com.session; |
| 6 |
import ct.base; |
| 7 |
import com.fb; |
| 8 |
import com.util; |
| 9 |
import ui.ui; |
| 10 |
import seq.sequencer; |
| 11 |
import std.typecons; |
| 12 |
import com.util; |
| 13 |
|
| 14 |
interface Undoable { |
| 15 |
void undo(UndoValue); |
| 16 |
UndoValue createRedoState(UndoValue); |
| 17 |
} |
| 18 |
|
| 19 |
struct TracklistStore { |
| 20 |
Tracklist store, source; |
| 21 |
} |
| 22 |
|
| 23 |
struct UndoValue { |
| 24 |
import ct.base; |
| 25 |
|
| 26 |
alias Array = Tuple!(ubyte[], "target", ubyte[], "source"); |
| 27 |
|
| 28 |
// undo data needed by sequencer |
| 29 |
Array array; |
| 30 |
Sequence seq; |
| 31 |
// undo data needed by track editor |
| 32 |
TracklistStore[] trackLists; |
| 33 |
ushort trackValue; |
| 34 |
Track track; |
| 35 |
ubyte[][] tableData; |
| 36 |
int subtuneNum; |
| 37 |
PosDataTable posTable; |
| 38 |
bool allVoices; |
| 39 |
} |
| 40 |
|
| 41 |
struct UndoState { |
| 42 |
Undoable func; |
| 43 |
UndoValue value; |
| 44 |
} |
| 45 |
|
| 46 |
struct EditorState { |
| 47 |
__gshared Song song; |
| 48 |
PosDataTable fplayPos, seqPos; |
| 49 |
int octave = 3; |
| 50 |
int activeInstrument; |
| 51 |
bool autoinsertInstrument = true; |
| 52 |
bool shortTitles = true; |
| 53 |
bool displayHelp = true; |
| 54 |
bool keyjamStatus = false; |
| 55 |
bool allowInstabNavigation = true; |
| 56 |
string filename; |
| 57 |
auto undoQueue = Queue!UndoState(); |
| 58 |
auto redoQueue = Queue!UndoState(); |
| 59 |
} |
| 60 |
|
| 61 |
UI mainui; |
| 62 |
Video video; |
| 63 |
Screen screen; |
| 64 |
EditorState state; |
| 65 |
|
| 66 |
void insertUndo(Undoable undoable, UndoValue value) { |
| 67 |
state.undoQueue.insert(UndoState(undoable, value)); |
| 68 |
} |
| 69 |
|
| 70 |
void executeUndo() { |
| 71 |
if(state.undoQueue.empty) return; |
| 72 |
auto u = state.undoQueue.pop(); |
| 73 |
// make entry for redo (copy current state) |
| 74 |
auto redo = makeRedoOrUndo(u); |
| 75 |
state.redoQueue.insert(redo); |
| 76 |
u.func.undo(u.value); |
| 77 |
} |
| 78 |
|
| 79 |
void executeRedo() { |
| 80 |
if(state.redoQueue.empty) return; |
| 81 |
auto r = state.redoQueue.pop(); |
| 82 |
// make entry for undo (copy current state) |
| 83 |
auto undo = makeRedoOrUndo(r); |
| 84 |
state.undoQueue.insert(undo); |
| 85 |
r.func.undo(r.value); |
| 86 |
} |
| 87 |
|
| 88 |
private UndoState makeRedoOrUndo(UndoState state) { |
| 89 |
state.value = state.func.createRedoState(state.value); |
| 90 |
return state; |
| 91 |
} |
| 92 |
|
| 93 |
@property song() { |
| 94 |
return state.song; |
| 95 |
} |
| 96 |
|
| 97 |
@property seqPos() { |
| 98 |
return state.seqPos; |
| 99 |
} |
| 100 |
|
| 101 |
@property fplayPos() { |
| 102 |
return state.fplayPos; |
| 103 |
} |
| 104 |
|
| 105 |
void initSession() { |
| 106 |
state.song = new Song(); |
| 107 |
state.seqPos = new PosDataTable(); |
| 108 |
state.fplayPos = new PosDataTable(); |
| 109 |
for(int i = 0; i < 3; i++) { |
| 110 |
state.seqPos[i].tracks = song.tracks[i]; |
| 111 |
state.fplayPos[i].tracks = song.tracks[i]; |
| 112 |
} |
| 113 |
} |