Skip to content

Commit

Permalink
🐛 Fix setting quantizations not working correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
leolabs committed Nov 10, 2023
1 parent 147eb5c commit cd7a6e5
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 6 deletions.
39 changes: 39 additions & 0 deletions midi-script/Song.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,37 @@
from .Scene import Scene
from .Track import Track

import Live

PLAY_QUANTIZATIONS = {
'q_8_bars': Live.Song.Quantization.q_8_bars,
'q_4_bars': Live.Song.Quantization.q_4_bars,
'q_2_bars': Live.Song.Quantization.q_2_bars,
'q_bar': Live.Song.Quantization.q_bar,
'q_half': Live.Song.Quantization.q_half,
'q_half_triplet': Live.Song.Quantization.q_half_triplet,
'q_quarter': Live.Song.Quantization.q_quarter,
'q_quarter_triplet': Live.Song.Quantization.q_quarter_triplet,
'q_eight': Live.Song.Quantization.q_eight,
'q_eight_triplet': Live.Song.Quantization.q_eight_triplet,
'q_sixtenth': Live.Song.Quantization.q_sixtenth,
'q_sixtenth_triplet': Live.Song.Quantization.q_sixtenth_triplet,
'q_thirtytwoth': Live.Song.Quantization.q_thirtytwoth,
'q_no_q': Live.Song.Quantization.q_no_q
}

REC_QUANTIZATIONS = {
'rec_q_eight': Live.Song.RecordingQuantization.rec_q_eight,
'rec_q_eight_eight_triplet': Live.Song.RecordingQuantization.rec_q_eight_eight_triplet,
'rec_q_eight_triplet': Live.Song.RecordingQuantization.rec_q_eight_triplet,
'rec_q_no_q': Live.Song.RecordingQuantization.rec_q_no_q,
'rec_q_quarter': Live.Song.RecordingQuantization.rec_q_quarter,
'rec_q_sixtenth': Live.Song.RecordingQuantization.rec_q_sixtenth,
'rec_q_sixtenth_sixtenth_triplet': Live.Song.RecordingQuantization.rec_q_sixtenth_sixtenth_triplet,
'rec_q_sixtenth_triplet': Live.Song.RecordingQuantization.rec_q_sixtenth_triplet,
'rec_q_thirtysecond': Live.Song.RecordingQuantization.rec_q_thirtysecond,
}


class Song(Interface):
def __init__(self, c_instance, socket):
Expand Down Expand Up @@ -64,6 +95,14 @@ def get_current_smpte_song_time(self, ns, timeFormat):
def set_appointed_device(self, ns, device_id):
ns.appointed_device = Interface.get_obj(device_id)

def set_clip_trigger_quantization(self, ns, name):
quantization = PLAY_QUANTIZATIONS.get(str(name), PLAY_QUANTIZATIONS['q_bar'])
ns.clip_trigger_quantization = quantization

def set_midi_recording_quantization(self, ns, name):
quantization = REC_QUANTIZATIONS.get(str(name), REC_QUANTIZATIONS['rec_q_no_q'])
ns.midi_recording_quantization = quantization

def safe_stop_playing(self, ns):
if self.song.is_playing:
self.song.stop_playing()
Expand Down
36 changes: 35 additions & 1 deletion src/ns/song.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { describe, it, expect } from "vitest";
import { withAbleton } from "../util/tests";
import { GettableProperties } from "./song";
import {
GettableProperties,
Quantization,
RecordingQuantization,
} from "./song";

const gettableProps: (keyof GettableProperties)[] = [
"arrangement_overdub",
Expand Down Expand Up @@ -72,6 +76,36 @@ describe("Song", () => {
});
});

it("should be able to change the playback quantization", async () => {
await withAbleton(async (ab) => {
const currentQuantization = await ab.song.get(
"clip_trigger_quantization",
);
for (const quantization of Object.keys(Quantization)) {
await ab.song.set(
"clip_trigger_quantization",
quantization as Quantization,
);
}
await ab.song.set("clip_trigger_quantization", currentQuantization);
});
});

it("should be able to change the recording quantization", async () => {
await withAbleton(async (ab) => {
const currentQuantization = await ab.song.get(
"midi_recording_quantization",
);
for (const quantization of Object.keys(RecordingQuantization)) {
await ab.song.set(
"midi_recording_quantization",
quantization as RecordingQuantization,
);
}
await ab.song.set("midi_recording_quantization", currentQuantization);
});
});

it("should be able to write and read large objects from the project", async () => {
await withAbleton(async (ab) => {
const largeArray: number[] = [];
Expand Down
10 changes: 5 additions & 5 deletions src/ns/song.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,20 +165,20 @@ export enum TimeFormat {
}

export enum Quantization {
q_2_bars = "q_2_bars",
q_4_bars = "q_4_bars",
q_8_bars = "q_8_bars",
q_4_bars = "q_4_bars",
q_2_bars = "q_2_bars",
q_bar = "q_bar",
q_eight = "q_eight",
q_eight_triplet = "q_eight_triplet",
q_half = "q_half",
q_half_triplet = "q_half_triplet",
q_no_q = "q_no_q",
q_quarter = "q_quarter",
q_quarter_triplet = "q_quarter_triplet",
q_eight = "q_eight",
q_eight_triplet = "q_eight_triplet",
q_sixtenth = "q_sixtenth",
q_sixtenth_triplet = "q_sixtenth_triplet",
q_thirtytwoth = "q_thirtytwoth",
q_no_q = "q_no_q",
}

export enum RecordingQuantization {
Expand Down

0 comments on commit cd7a6e5

Please sign in to comment.