-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathscroll.ts
More file actions
45 lines (36 loc) · 1.03 KB
/
scroll.ts
File metadata and controls
45 lines (36 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import assert from "assert";
import { Beat, BeatTime } from "../../charting";
import { RootStore } from "../../store";
import { Action } from "../action";
/**
* Arguments for the ScrollAction.
*/
export interface ScrollArgs {
by?: { beat?: number; time?: number };
to?: Partial<BeatTime>;
}
/**
* Action for scrolling the notefield by beat/time.
*/
export class ScrollAction implements Action {
args: ScrollArgs;
oldScroll!: Beat;
store: RootStore;
constructor(store: RootStore, args: ScrollArgs) {
assert(args.to || args.by, "both scroll arguments are undefined");
this.args = args;
this.store = store;
}
run(): void {
const args = this.args;
this.oldScroll = this.store.notefield.data.scroll.beat;
if (args.by) {
this.store.notefield.scrollBy(args.by);
} else if (args.to) {
this.store.notefield.setScroll(args.to);
}
}
undo(): void {
this.store.notefield.setScroll({ beat: this.oldScroll });
}
}