// Punch a recording in and out on a monotonic sample clock and retain the captured duration. use std::cli; pub fn take_punch_start() -> vector { [0, 0, 0] } pub fn take_punch_step(snapshot: vector, event: str, value: f64) -> vector { if len(snapshot) != 3 { return []; } let phase = at(snapshot, 0); let saved = at(snapshot, 1); let previous = at(snapshot, 2); if !(phase >= 0.0 && phase < 5.0 && phase % 1.0 == 0.0 && previous >= 0.0 && previous < 6.0 && previous % 1.0 == 0.0 && saved >= 0.0 && saved <= 9007199254740991.0 && saved % 1.0 == 0.0) { return []; } if !(value >= 0.0 && value <= 1000000000.0 && value % 1.0 == 0.0) { return [phase, saved, 0]; } // idle if phase == 0.0 { if event == "cue" { return [1, value, 1]; // remember_marker } } // cued if phase == 1.0 { if event == "punch" && value>=saved { return [2, value, 2]; // start_capture } } // recording if phase == 2.0 { if event == "out" && value>saved { return [3, value-saved, 3]; // stop_capture } } // captured if phase == 3.0 { if event == "discard" { return [0, 0.0, 4]; // drop_take } if event == "keep" { return [4, saved, 5]; // catalog_take } } [phase, saved, 0] } pub fn take_punch_command(snapshot: vector) -> str { if len(snapshot) != 3 { return "invalid"; } let action = at(snapshot, 2); if action == 0.0 { return "reject"; } if action == 1.0 { return "remember_marker"; } if action == 2.0 { return "start_capture"; } if action == 3.0 { return "stop_capture"; } if action == 4.0 { return "drop_take"; } if action == 5.0 { return "catalog_take"; } "invalid" } // Stop at the first rejected event. No host effects run during replay. pub fn take_punch_replay(events: arglist, values: vector) -> vector { if args_len(events) != len(values) { return []; } let mut state = take_punch_start(); let mut i = 0; while i < len(values) { state = take_punch_step(state, args_at(events, i), at(values, i)); if at(state, 2) == 0.0 { return []; } i += 1; } state }