From 33d17e4c880e4eb909cad346cddcc0b85cd5be75 Mon Sep 17 00:00:00 2001 From: Manuel Cartagena Date: Wed, 7 Oct 2020 18:18:04 -0300 Subject: [PATCH] fix(setSpeed): fix setSpeed bug when changing tempo through bpm command --- desktop/sources/scripts/client.js | 30 ++++++++++++++++++---------- desktop/sources/scripts/clock.js | 3 +-- desktop/sources/scripts/commander.js | 6 +++++- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/desktop/sources/scripts/client.js b/desktop/sources/scripts/client.js index 51568cc5..86126892 100644 --- a/desktop/sources/scripts/client.js +++ b/desktop/sources/scripts/client.js @@ -14,7 +14,7 @@ const AbletonLink = require("abletonlink-addon") function Client () { - this.version = 176 + this.version = 177 this.library = library this.theme = new Theme(this) @@ -29,28 +29,33 @@ function Client () { this.clock = new Clock(this) // Ableton Link - this.link = new AbletonLink(); + this.link = new AbletonLink() + this.numPeers = 0 this.link.setTempoCallback((newTempo) => { newTempo = this.link.getTempo(true) if (this.clock.isLinkEnabled && this.clock.speed.value != newTempo) { - this.clock.setSpeed(newTempo, newTempo, true) - this.clock.setFrame(0) - this.update() + this.clock.setSpeed(newTempo, newTempo, this.link.isPlaying()) }; }); this.link.setStartStopCallback((startStopState) => { - console.log("startstop: " + startStopState); + console.log('ABLETON LINK', startStopState ? 'Start' : 'Stop') if (startStopState && this.clock.isPaused) { - this.clock.play(false, true, true) + this.clock.play(false, false, true) } else if (!startStopState && !this.clock.isPaused) { - this.clock.stop(false, true, false) + this.clock.stop(false, false, false) this.clock.setFrame(0) this.update() } }); + this.link.setNumPeersCallback((newNumPeers) => { + console.log('ABLETON LINK', 'NumPeers: ' + newNumPeers) + this.numPeers = newNumPeers + this.update() + }); + // Settings this.scale = window.devicePixelRatio this.grid = { w: 8, h: 8 } @@ -190,6 +195,7 @@ function Client () { if (this.clock.isLinkEnabled) { this.link.disable() this.link.disableStartStopSync() + this.clock.isLinkEnabled = false } else { this.link.enable() this.link.enableStartStopSync() @@ -197,8 +203,8 @@ function Client () { if (!this.link.isPlaying()) { this.clock.stop(false, true) } + this.clock.isLinkEnabled = true } - this.clock.isLinkEnabled = !this.clock.isLinkEnabled } this.update = () => { @@ -370,7 +376,11 @@ function Client () { if (this.commander.isActive === true) { this.write(`${this.commander.query}${this.orca.f % 2 === 0 ? '_' : ''}`, this.grid.w * 0, this.orca.h + 1, this.grid.w * 4) } else { - this.write(this.orca.f < 25 ? `ver${this.version}` : `${Object.keys(this.source.cache).length} mods`, this.grid.w * 0, this.orca.h + 1, this.grid.w) + if (this.clock.isLinkEnabled) { + this.write(`${this.numPeers} links`, this.grid.w * 0, this.orca.h + 1, this.grid.w) + } else { + this.write(this.orca.f < 25 ? `ver${this.version}` : `${Object.keys(this.source.cache).length} mods`, this.grid.w * 0, this.orca.h + 1, this.grid.w) + } this.write(`${this.orca.w}x${this.orca.h}`, this.grid.w * 1, this.orca.h + 1, this.grid.w) this.write(`${this.grid.w}/${this.grid.h}${this.tile.w !== 10 ? ' ' + (this.tile.w / 10).toFixed(1) : ''}`, this.grid.w * 2, this.orca.h + 1, this.grid.w) this.write(`${this.clock}`, this.grid.w * 3, this.orca.h + 1, this.grid.w, this.clock.isPuppet ? 3 : this.io.midi.isClock ? 11 : this.clock.isPaused ? 20 : 2) diff --git a/desktop/sources/scripts/clock.js b/desktop/sources/scripts/clock.js index 4bfdaa62..085caa1c 100644 --- a/desktop/sources/scripts/clock.js +++ b/desktop/sources/scripts/clock.js @@ -91,7 +91,6 @@ function Clock (client) { this.stop = function (msg = false, linkStop = false) { console.log('Clock', 'Stop') - console.log(this.isLinkEnabled, this.isPaused, linkStop) if (this.isLinkEnabled && !this.isPaused && !linkStop) { this.isPaused = true this.clearTimer() @@ -186,7 +185,7 @@ function Clock (client) { this.getUIMessage = function (offset) { if (this.isLinkEnabled) { - return `link${this.speed.value}${offset}` + return `link${this.speed.value}` } else { return this.isPuppet === true ? 'midi' : `${this.speed.value}${offset}` } diff --git a/desktop/sources/scripts/commander.js b/desktop/sources/scripts/commander.js index a06bfb3c..6d1ded14 100644 --- a/desktop/sources/scripts/commander.js +++ b/desktop/sources/scripts/commander.js @@ -55,7 +55,11 @@ function Commander (client) { }, bpm: (p) => { if (client.clock.isLinkEnabled) { - client.clock.setSpeed(p.int, p.int, true) + if (client.link.isPlaying()) { + client.clock.setSpeed(p.int, p.int, true) + } else { + client.clock.setSpeed(p.int, p.int, false) + } client.clock.setSpeedLink(p.int) } else { client.clock.setSpeed(p.int, p.int, true)