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 33d17e4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
30 changes: 20 additions & 10 deletions desktop/sources/scripts/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 }
Expand Down Expand Up @@ -190,15 +195,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 Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions desktop/sources/scripts/clock.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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}`
}
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 33d17e4

Please sign in to comment.