aboutsummaryrefslogtreecommitdiffhomepage
path: root/desktop/sources
diff options
context:
space:
mode:
authorDevine Lu Linvega <[email protected]>2019-04-12 10:20:04 +0900
committerDevine Lu Linvega <[email protected]>2019-04-12 10:20:04 +0900
commit98fe367aba7def1280fc67dbbbf79275883dc1df (patch)
treef5a9d06ffa94473390f6c4cc7886a264aba5634a /desktop/sources
parent0c88dfe73029ce23a17b56c7e40e0e318813d14a (diff)
downloadOrca-MidiClock.tar.gz
Orca-MidiClock.zip
Cleaned up the clockMidiClock
Diffstat (limited to 'desktop/sources')
-rw-r--r--desktop/sources/index.html8
-rw-r--r--desktop/sources/scripts/clock.js52
-rw-r--r--desktop/sources/scripts/keyboard.js4
3 files changed, 31 insertions, 33 deletions
diff --git a/desktop/sources/index.html b/desktop/sources/index.html
index 59eae2f..50a88f6 100644
--- a/desktop/sources/index.html
+++ b/desktop/sources/index.html
@@ -50,10 +50,10 @@
terminal.controller.add("default","Clock","Play/Pause",() => { terminal.clock.togglePlay() },"Space")
terminal.controller.add("default","Clock","Reset Frame",() => { terminal.clock.resetFrame() },"CmdOrCtrl+Shift+N")
- terminal.controller.add("default","Clock","Incr. Speed",() => { terminal.clock.modSpeed(1) },">")
- terminal.controller.add("default","Clock","Decr. Speed",() => { terminal.clock.modSpeed(-1) },"<")
- terminal.controller.add("default","Clock","Incr. Speed(10x)",() => { terminal.clock.modSpeed(10,true) },"cmdOrCtrl+>")
- terminal.controller.add("default","Clock","Decr. Speed(10x)",() => { terminal.clock.modSpeed(-10,true) },"cmdOrCtrl+<")
+ 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","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 b53db1f..52d0af4 100644
--- a/desktop/sources/scripts/clock.js
+++ b/desktop/sources/scripts/clock.js
@@ -12,17 +12,31 @@ function Clock (terminal) {
}
this.update = function () {
- if (this.speed.target === this.speed.value) { return }
+ this.animate()
+ }
- this.setTimer(this.speed.value)
+ this.set = function (value, target = null, setTimer = false) {
+ if (value) { this.speed.value = clamp(value, 60, 300) }
+ if (target) { this.speed.target = clamp(target, 60, 300) }
+ if (setTimer === true) { this.setTimer(this.speed.value) }
+ }
- if (this.speed.value < this.speed.target) { this.speed.value++ }
- if (this.speed.value > this.speed.target) { this.speed.value-- }
+ this.mod = function (mod = 0, animate = false) {
+ if (animate === true) {
+ this.set(null, this.speed.target + mod)
+ } else {
+ this.set(this.speed.value + mod, this.speed.value + mod, true)
+ terminal.update()
+ }
+ }
- this.speed.value = clamp(this.speed.value, 60, 300)
- this.speed.target = clamp(this.speed.target, 60, 300)
+ this.animate = function () {
+ if (this.speed.target === this.speed.value) { return }
+ this.set(this.speed.value + (this.speed.value < this.speed.target ? 1 : -1), null, true)
}
+ // Controls
+
this.togglePlay = function () {
if (this.isPaused === true) {
this.play()
@@ -35,7 +49,7 @@ function Clock (terminal) {
if (!this.isPaused) { console.warn('Already playing'); return }
console.log('Play')
this.isPaused = false
- this.setTimer(this.speed.target)
+ this.set(this.speed.target, this.speed.target, true)
}
this.stop = function () {
@@ -46,6 +60,8 @@ function Clock (terminal) {
this.clearTimer()
}
+ // Timer
+
this.clearTimer = function () {
if (this.timer) {
clearInterval(this.timer)
@@ -53,34 +69,16 @@ function Clock (terminal) {
}
this.setTimer = function (bpm) {
- this.speed.value = bpm
this.clearTimer()
this.timer = setInterval(() => { terminal.run(); this.update() }, (60000 / bpm) / 4)
}
- this.setSpeed = function (bpm, animate = false) {
- if (animate === true) {
- this.speed.target = bpm
- } else {
- this.speed.target = bpm
- this.setTimer(bpm)
- }
- }
-
- this.modSpeed = function (mod = 0, animate = false) {
- if (animate === true) {
- this.speed.target += mod
- } else {
- this.setTimer(this.speed.value + mod)
- this.speed.target = this.speed.value
- terminal.update()
- }
- }
-
this.resetFrame = function () {
terminal.orca.f = 0
}
+ // UI
+
this.toString = function () {
const diff = this.speed.target - this.speed.value
const _offset = diff > 0 ? `+${diff}` : diff < 0 ? diff : ''
diff --git a/desktop/sources/scripts/keyboard.js b/desktop/sources/scripts/keyboard.js
index 90a6139..45cc773 100644
--- a/desktop/sources/scripts/keyboard.js
+++ b/desktop/sources/scripts/keyboard.js
@@ -36,8 +36,8 @@ function Keyboard (terminal) {
if (event.key === '[') { terminal.modGrid(-1, 0); event.preventDefault(); return }
if (event.key === '}') { terminal.modGrid(0, 1); event.preventDefault(); return }
if (event.key === '{') { terminal.modGrid(0, -1); event.preventDefault(); return }
- if (event.key === '>') { terminal.clock.modSpeed(1); event.preventDefault(); return }
- if (event.key === '<') { terminal.clock.modSpeed(-1); event.preventDefault(); return }
+ if (event.key === '>') { terminal.clock.mod(1); event.preventDefault(); return }
+ if (event.key === '<') { terminal.clock.mod(-1); event.preventDefault(); return }
if (event.key.length === 1) {
terminal.cursor.write(event.key)