Skip to content

Commit

Permalink
fix(setSpeed): fix setSpeed bug when changing tempo through bpm command
Browse files Browse the repository at this point in the history
  • Loading branch information
mcartagenah committed Oct 7, 2020
1 parent 4af0b12 commit 4c123de
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
14 changes: 9 additions & 5 deletions desktop/sources/scripts/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,21 @@ function Client () {
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)
if (this.link.isPlaying()) {
this.clock.setSpeed(newTempo, newTempo, true)
} else {
this.clock.setSpeed(newTempo, newTempo, false)
}
this.update()
};
});

this.link.setStartStopCallback((startStopState) => {
console.log("startstop: " + startStopState);
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()
}
Expand Down Expand Up @@ -190,15 +193,16 @@ function Client () {
if (this.clock.isLinkEnabled) {
this.link.disable()
this.link.disableStartStopSync()
this.clock.isLinkEnabled = false
} else {
this.link.enable()
this.link.enableStartStopSync()
this.clock.setSpeed(this.link.getTempo(true), this.link.getTempo(true), true)
if (!this.link.isPlaying()) {
this.clock.stop(false, true)
}
this.clock.isLinkEnabled = true
}
this.clock.isLinkEnabled = !this.clock.isLinkEnabled
}

this.update = () => {
Expand Down
4 changes: 3 additions & 1 deletion desktop/sources/scripts/clock.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ function Clock (client) {
this.play = function (msg = false, midiStart = false, linkStart = false) {
console.log('Clock', 'Play', msg, midiStart, linkStart)
if (this.isLinkEnabled && this.isPaused && !linkStart) {
console.warn('Clock', 'Ableton Link')
this.isPaused = false
this.setSpeed(this.speed.target, this.speed.target, true)
client.link.play()
Expand All @@ -93,6 +94,7 @@ function Clock (client) {
console.log('Clock', 'Stop')
console.log(this.isLinkEnabled, this.isPaused, linkStop)
if (this.isLinkEnabled && !this.isPaused && !linkStop) {
console.warn('Clock', 'Ableton Link')
this.isPaused = true
this.clearTimer()
client.link.stop()
Expand Down Expand Up @@ -186,7 +188,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}`
}
Expand Down
6 changes: 5 additions & 1 deletion desktop/sources/scripts/commander.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 4c123de

Please sign in to comment.