diff options
author | Devine Lu Linvega <[email protected]> | 2019-04-15 10:04:50 +0900 |
---|---|---|
committer | Devine Lu Linvega <[email protected]> | 2019-04-15 10:04:50 +0900 |
commit | 6ad8e1279d900c9817aead2e0e2f0846cf01af62 (patch) | |
tree | 02bc08c019a258ded757a4e185bcf70221e581d6 | |
parent | 19283ec5a65e97c86920ebfb539a8e29426fb9c2 (diff) | |
download | Orca-6ad8e1279d900c9817aead2e0e2f0846cf01af62.tar.gz Orca-6ad8e1279d900c9817aead2e0e2f0846cf01af62.zip |
Clock In is working :)
-rw-r--r-- | desktop/core/io/midi.js | 6 | ||||
-rw-r--r-- | desktop/sources/index.html | 5 | ||||
-rw-r--r-- | desktop/sources/scripts/clock.js | 18 |
3 files changed, 24 insertions, 5 deletions
diff --git a/desktop/core/io/midi.js b/desktop/core/io/midi.js index 3c831b4..a9f3608 100644 --- a/desktop/core/io/midi.js +++ b/desktop/core/io/midi.js @@ -117,7 +117,9 @@ function Midi (terminal) { switch (msg.data[0]) { case 0xF8: this.count = (this.count + 1) % 6 - terminal.clock.tap() + if (this.count % 4 === 0) { + terminal.clock.tap() + } break case 0xFA: console.log('Midi', 'Clock start.') @@ -179,7 +181,7 @@ function Midi (terminal) { for (let i = inputs.next(); i && !i.done; i = inputs.next()) { terminal.io.midi.inputs.push(i.value) } - terminal.io.midi.selectInput(0) + terminal.io.midi.selectInput(-1) } // UI diff --git a/desktop/sources/index.html b/desktop/sources/index.html index e3532e1..9b84e40 100644 --- a/desktop/sources/index.html +++ b/desktop/sources/index.html @@ -48,8 +48,9 @@ terminal.controller.add("default","Clock","Reset Frame",() => { terminal.clock.resetFrame() },"CmdOrCtrl+Shift+N") terminal.controller.add("default","Clock","Incr. Speed",() => { terminal.clock.mod(1) },">") terminal.controller.add("default","Clock","Decr. Speed",() => { terminal.clock.mod(-1) },"<") - terminal.controller.add("default","Clock","Incr. Speed(10x)",() => { terminal.clock.mod(10,true) },"cmdOrCtrl+>") - terminal.controller.add("default","Clock","Decr. Speed(10x)",() => { terminal.clock.mod(-10,true) },"cmdOrCtrl+<") + terminal.controller.add("default","Clock","Incr. Speed(10x)",() => { terminal.clock.mod(10,true) },"CmdOrCtrl+>") + terminal.controller.add("default","Clock","Decr. Speed(10x)",() => { terminal.clock.mod(-10,true) },"CmdOrCtrl+<") + terminal.controller.add("default","Clock","Tap",() => { terminal.clock.tap() },"CmdOrCtrl+T") terminal.controller.add("default","View","Zoom In",() => { terminal.modZoom(0.25) },"CmdOrCtrl+=") terminal.controller.add("default","View","Zoom Out",() => { terminal.modZoom(-0.25) },"CmdOrCtrl+-") diff --git a/desktop/sources/scripts/clock.js b/desktop/sources/scripts/clock.js index 6607fcf..ccdf1d7 100644 --- a/desktop/sources/scripts/clock.js +++ b/desktop/sources/scripts/clock.js @@ -60,8 +60,24 @@ function Clock (terminal) { this.clearTimer() } + this.intervals = [] + this.lastTap = 0 + this.tap = function () { - console.log('Clock', 'Tapped..') + if (this.intervals.length > 8) { + this.intervals.shift() + } + if (this.intervals.length === 8) { + const sum = this.intervals.reduce((sum, interval) => { return sum + interval }) + const bpm = parseInt((1000 / sum) * 60) + if (Math.abs(bpm - this.speed.target) > 3) { + this.speed.target = bpm + } + } + + const now = performance.now() + this.intervals.push(now - this.lastTap) + this.lastTap = now } // Timer |