1 | import { Loop } from "./Loop.js";
|
2 | import { PatternGenerator } from "./PatternGenerator.js";
|
3 | import { optionsFromArguments } from "../core/util/Defaults.js";
|
4 | import { noOp } from "../core/util/Interface.js";
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | export class Pattern extends Loop {
|
15 | constructor() {
|
16 | const options = optionsFromArguments(Pattern.getDefaults(), arguments, [
|
17 | "callback",
|
18 | "values",
|
19 | "pattern",
|
20 | ]);
|
21 | super(options);
|
22 | this.name = "Pattern";
|
23 | this.callback = options.callback;
|
24 | this._values = options.values;
|
25 | this._pattern = PatternGenerator(options.values.length, options.pattern);
|
26 | this._type = options.pattern;
|
27 | }
|
28 | static getDefaults() {
|
29 | return Object.assign(Loop.getDefaults(), {
|
30 | pattern: "up",
|
31 | values: [],
|
32 | callback: noOp,
|
33 | });
|
34 | }
|
35 | |
36 |
|
37 |
|
38 | _tick(time) {
|
39 | const index = this._pattern.next();
|
40 | this._index = index.value;
|
41 | this._value = this._values[index.value];
|
42 | this.callback(time, this._value);
|
43 | }
|
44 | |
45 |
|
46 |
|
47 | get values() {
|
48 | return this._values;
|
49 | }
|
50 | set values(val) {
|
51 | this._values = val;
|
52 |
|
53 | this.pattern = this._type;
|
54 | }
|
55 | |
56 |
|
57 |
|
58 | get value() {
|
59 | return this._value;
|
60 | }
|
61 | |
62 |
|
63 |
|
64 | get index() {
|
65 | return this._index;
|
66 | }
|
67 | |
68 |
|
69 |
|
70 | get pattern() {
|
71 | return this._type;
|
72 | }
|
73 | set pattern(pattern) {
|
74 | this._type = pattern;
|
75 | this._pattern = PatternGenerator(this._values.length, this._type);
|
76 | }
|
77 | }
|
78 |
|
\ | No newline at end of file |