Skip to content

Commit f784eda

Browse files
committed
Move track editor keyboard handling code into SongEditor.ts.
1 parent d6c21cd commit f784eda

File tree

3 files changed

+91
-91
lines changed

3 files changed

+91
-91
lines changed

editor/Selection.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ export class Selection {
6969
}
7070

7171
public nextDigit(digit: string): void {
72+
if (this.digits.length > 0 && this.digits != String(this._doc.song.channels[this.boxSelectionChannel].bars[this.boxSelectionBar])) {
73+
this.digits = "";
74+
}
75+
7276
this.digits += digit;
7377
let parsed: number = parseInt(this.digits);
7478
if (parsed <= this._doc.song.patternsPerChannel) {

editor/SongEditor.ts

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,8 @@ import {ChangeTempo, ChangeReverb, ChangeVolume, ChangePan, ChangeFilterCutoff,
829829
}
830830

831831
private _tempoStepperCaptureNumberKeys = (event: KeyboardEvent): void => {
832+
// When the number input is in focus, allow some keyboard events to
833+
// edit the input without accidentally editing the song otherwise.
832834
switch (event.keyCode) {
833835
case 8: // backspace/delete
834836
case 13: // enter/return
@@ -860,7 +862,6 @@ import {ChangeTempo, ChangeReverb, ChangeVolume, ChangePan, ChangeFilterCutoff,
860862
return;
861863
}
862864

863-
this._trackEditor.onKeyPressed(event);
864865
switch (event.keyCode) {
865866
case 32: // space
866867
this._togglePlay();
@@ -961,6 +962,91 @@ import {ChangeTempo, ChangeReverb, ChangeVolume, ChangePan, ChangeFilterCutoff,
961962
this._doc.selection.transpose(true, event.shiftKey);
962963
event.preventDefault();
963964
break;
965+
case 38: // up
966+
if (event.shiftKey) {
967+
this._doc.selection.boxSelectionY1 = Math.max(0, this._doc.selection.boxSelectionY1 - 1);
968+
this._doc.selection.selectionUpdated();
969+
} else {
970+
this._doc.selection.setChannelBar((this._doc.channel - 1 + this._doc.song.getChannelCount()) % this._doc.song.getChannelCount(), this._doc.bar);
971+
this._doc.selection.resetBoxSelection();
972+
}
973+
event.preventDefault();
974+
break;
975+
case 40: // down
976+
if (event.shiftKey) {
977+
this._doc.selection.boxSelectionY1 = Math.min(this._doc.song.getChannelCount() - 1, this._doc.selection.boxSelectionY1 + 1);
978+
this._doc.selection.selectionUpdated();
979+
} else {
980+
this._doc.selection.setChannelBar((this._doc.channel + 1) % this._doc.song.getChannelCount(), this._doc.bar);
981+
this._doc.selection.resetBoxSelection();
982+
}
983+
event.preventDefault();
984+
break;
985+
case 37: // left
986+
if (event.shiftKey) {
987+
this._doc.selection.boxSelectionX1 = Math.max(0, this._doc.selection.boxSelectionX1 - 1);
988+
this._doc.selection.scrollToSelection();
989+
this._doc.selection.selectionUpdated();
990+
} else {
991+
this._doc.selection.setChannelBar(this._doc.channel, (this._doc.bar + this._doc.song.barCount - 1) % this._doc.song.barCount);
992+
this._doc.selection.resetBoxSelection();
993+
}
994+
event.preventDefault();
995+
break;
996+
case 39: // right
997+
if (event.shiftKey) {
998+
this._doc.selection.boxSelectionX1 = Math.min(this._doc.song.barCount - 1, this._doc.selection.boxSelectionX1 + 1);
999+
this._doc.selection.scrollToSelection();
1000+
this._doc.selection.selectionUpdated();
1001+
} else {
1002+
this._doc.selection.setChannelBar(this._doc.channel, (this._doc.bar + 1) % this._doc.song.barCount);
1003+
this._doc.selection.resetBoxSelection();
1004+
}
1005+
event.preventDefault();
1006+
break;
1007+
case 48: // 0
1008+
this._doc.selection.nextDigit("0");
1009+
event.preventDefault();
1010+
break;
1011+
case 49: // 1
1012+
this._doc.selection.nextDigit("1");
1013+
event.preventDefault();
1014+
break;
1015+
case 50: // 2
1016+
this._doc.selection.nextDigit("2");
1017+
event.preventDefault();
1018+
break;
1019+
case 51: // 3
1020+
this._doc.selection.nextDigit("3");
1021+
event.preventDefault();
1022+
break;
1023+
case 52: // 4
1024+
this._doc.selection.nextDigit("4");
1025+
event.preventDefault();
1026+
break;
1027+
case 53: // 5
1028+
this._doc.selection.nextDigit("5");
1029+
event.preventDefault();
1030+
break;
1031+
case 54: // 6
1032+
this._doc.selection.nextDigit("6");
1033+
event.preventDefault();
1034+
break;
1035+
case 55: // 7
1036+
this._doc.selection.nextDigit("7");
1037+
event.preventDefault();
1038+
break;
1039+
case 56: // 8
1040+
this._doc.selection.nextDigit("8");
1041+
event.preventDefault();
1042+
break;
1043+
case 57: // 9
1044+
this._doc.selection.nextDigit("9");
1045+
event.preventDefault();
1046+
break;
1047+
default:
1048+
this._doc.selection.digits = "";
1049+
break;
9641050
}
9651051
}
9661052

editor/TrackEditor.ts

Lines changed: 0 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -146,96 +146,6 @@ import {HTML, SVG} from "imperative-html/dist/esm/elements-strict";
146146
window.requestAnimationFrame(this._animatePlayhead);
147147
}
148148

149-
public onKeyPressed(event: KeyboardEvent): void {
150-
switch (event.keyCode) {
151-
case 38: // up
152-
if (event.shiftKey) {
153-
this._doc.selection.boxSelectionY1 = Math.max(0, this._doc.selection.boxSelectionY1 - 1);
154-
this._doc.selection.selectionUpdated();
155-
} else {
156-
this._doc.selection.setChannelBar((this._doc.channel - 1 + this._doc.song.getChannelCount()) % this._doc.song.getChannelCount(), this._doc.bar);
157-
this._doc.selection.resetBoxSelection();
158-
}
159-
event.preventDefault();
160-
break;
161-
case 40: // down
162-
if (event.shiftKey) {
163-
this._doc.selection.boxSelectionY1 = Math.min(this._doc.song.getChannelCount() - 1, this._doc.selection.boxSelectionY1 + 1);
164-
this._doc.selection.selectionUpdated();
165-
} else {
166-
this._doc.selection.setChannelBar((this._doc.channel + 1) % this._doc.song.getChannelCount(), this._doc.bar);
167-
this._doc.selection.resetBoxSelection();
168-
}
169-
event.preventDefault();
170-
break;
171-
case 37: // left
172-
if (event.shiftKey) {
173-
this._doc.selection.boxSelectionX1 = Math.max(0, this._doc.selection.boxSelectionX1 - 1);
174-
this._doc.selection.scrollToSelection();
175-
this._doc.selection.selectionUpdated();
176-
} else {
177-
this._doc.selection.setChannelBar(this._doc.channel, (this._doc.bar + this._doc.song.barCount - 1) % this._doc.song.barCount);
178-
this._doc.selection.resetBoxSelection();
179-
}
180-
event.preventDefault();
181-
break;
182-
case 39: // right
183-
if (event.shiftKey) {
184-
this._doc.selection.boxSelectionX1 = Math.min(this._doc.song.barCount - 1, this._doc.selection.boxSelectionX1 + 1);
185-
this._doc.selection.scrollToSelection();
186-
this._doc.selection.selectionUpdated();
187-
} else {
188-
this._doc.selection.setChannelBar(this._doc.channel, (this._doc.bar + 1) % this._doc.song.barCount);
189-
this._doc.selection.resetBoxSelection();
190-
}
191-
event.preventDefault();
192-
break;
193-
case 48: // 0
194-
this._doc.selection.nextDigit("0");
195-
event.preventDefault();
196-
break;
197-
case 49: // 1
198-
this._doc.selection.nextDigit("1");
199-
event.preventDefault();
200-
break;
201-
case 50: // 2
202-
this._doc.selection.nextDigit("2");
203-
event.preventDefault();
204-
break;
205-
case 51: // 3
206-
this._doc.selection.nextDigit("3");
207-
event.preventDefault();
208-
break;
209-
case 52: // 4
210-
this._doc.selection.nextDigit("4");
211-
event.preventDefault();
212-
break;
213-
case 53: // 5
214-
this._doc.selection.nextDigit("5");
215-
event.preventDefault();
216-
break;
217-
case 54: // 6
218-
this._doc.selection.nextDigit("6");
219-
event.preventDefault();
220-
break;
221-
case 55: // 7
222-
this._doc.selection.nextDigit("7");
223-
event.preventDefault();
224-
break;
225-
case 56: // 8
226-
this._doc.selection.nextDigit("8");
227-
event.preventDefault();
228-
break;
229-
case 57: // 9
230-
this._doc.selection.nextDigit("9");
231-
event.preventDefault();
232-
break;
233-
default:
234-
this._doc.selection.digits = "";
235-
break;
236-
}
237-
}
238-
239149
private _dragBoxSelection(): void {
240150
this._doc.selection.boxSelectionX1 = this._mouseBar;
241151
this._doc.selection.boxSelectionY1 = this._mouseChannel;

0 commit comments

Comments
 (0)