-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Add support for the Track View class
- Loading branch information
Showing
7 changed files
with
125 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from __future__ import absolute_import | ||
from .Interface import Interface | ||
from .Device import Device | ||
|
||
import Live | ||
|
||
INSERT_MODES = {'default': Live.Track.DeviceInsertMode.default, | ||
'left': Live.Track.DeviceInsertMode.selected_left, | ||
'right': Live.Track.DeviceInsertMode.selected_right} | ||
|
||
|
||
class TrackView(Interface): | ||
def __init__(self, c_instance, socket): | ||
super(TrackView, self).__init__(c_instance, socket) | ||
|
||
def get_ns(self, nsid): | ||
return Interface.obj_ids[nsid].view | ||
|
||
def get_selected_device(self, ns): | ||
return Device.serialize_device(ns.selected_device) | ||
|
||
def set_device_insert_mode(self, ns, name): | ||
mode = INSERT_MODES.get(str(name), INSERT_MODES['default']) | ||
ns.device_insert_mode = mode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { describe, it } from "vitest"; | ||
import { withAbleton } from "../util/tests"; | ||
import { DeviceInsertMode, GettableProperties } from "./track-view"; | ||
|
||
const gettableProps: (keyof GettableProperties)[] = [ | ||
"is_collapsed", | ||
"selected_device", | ||
]; | ||
|
||
describe("Track View", () => { | ||
it("should be able to read all properties without erroring", async () => { | ||
await withAbleton(async (ab) => { | ||
const tracks = await ab.song.get("tracks"); | ||
const res = await Promise.all( | ||
gettableProps.map((p) => tracks[0].view.get(p)), | ||
); | ||
console.log(res); | ||
}); | ||
}); | ||
|
||
it("should be able to set the device insert mode", async () => { | ||
await withAbleton(async (ab) => { | ||
const tracks = await ab.song.get("tracks"); | ||
await tracks[0].view.set("device_insert_mode", DeviceInsertMode.Left); | ||
}); | ||
}); | ||
|
||
it("should select the instrument device", async () => { | ||
await withAbleton(async (ab) => { | ||
const tracks = await ab.song.get("tracks"); | ||
await tracks[0].view.selectInstrument(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { Ableton } from ".."; | ||
import { Namespace } from "."; | ||
import { Device, RawDevice } from "./device"; | ||
import { Track, RawTrack } from "./track"; | ||
import { Scene, RawScene } from "./scene"; | ||
import { RawDeviceParameter, DeviceParameter } from "./device-parameter"; | ||
import { ClipSlot, RawClipSlot } from "./clip-slot"; | ||
|
||
export enum DeviceInsertMode { | ||
Default = "default", | ||
Left = "left", | ||
Right = "right", | ||
} | ||
|
||
export interface GettableProperties { | ||
// device_insert_mode: DeviceInsertMode; – for some reason, Live returns a boolean here | ||
is_collapsed: boolean; | ||
selected_device: RawDevice; | ||
} | ||
|
||
export interface TransformedProperties { | ||
selected_device: Device; | ||
} | ||
|
||
export interface SettableProperties { | ||
device_insert_mode: DeviceInsertMode; | ||
is_collapsed: boolean; | ||
} | ||
|
||
export interface ObservableProperties { | ||
// device_insert_mode: DeviceInsertMode; | ||
is_collapsed: boolean; | ||
selected_device: RawDevice; | ||
} | ||
|
||
export class TrackView extends Namespace< | ||
GettableProperties, | ||
TransformedProperties, | ||
SettableProperties, | ||
ObservableProperties | ||
> { | ||
constructor(ableton: Ableton, nsid: string) { | ||
super(ableton, "track-view", nsid); | ||
|
||
this.transformers = { | ||
selected_device: (device) => new Device(ableton, device), | ||
}; | ||
|
||
this.cachedProps = { | ||
selected_device: true, | ||
}; | ||
} | ||
|
||
/** | ||
* Selects the track's instrument if it has one. | ||
*/ | ||
async selectInstrument() { | ||
return this.sendCommand("select_instrument"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters