diff --git a/crates/engine/src/cmd/event_more.rs b/crates/engine/src/cmd/event_more.rs index 223ecb5a..858ca246 100644 --- a/crates/engine/src/cmd/event_more.rs +++ b/crates/engine/src/cmd/event_more.rs @@ -349,6 +349,9 @@ fn select_split(e: &mut Engine, p: &Value) -> Result { }; let mut nc = c.clone(); nc.id = s.new_clip_id(); + // Note-split has always copied only the matching notes, not controllers. SysEx is the same + // default now that Sequence has that field: packets stay on the source clip. Full SysEx + // split/trim/heal is storytold/soundcraft#1618. nc.content = ClipContent::Midi { sequence: soundcraft_midi::Sequence { notes: hit, ctrls: Vec::new(), sysex: Vec::new() } }; crate::edit::place_clip(s, nt, nc); } @@ -961,6 +964,44 @@ mod tests { } } + /// Note-split copies only the notes in the pitch range. SysEx already on the clip stays there; + /// the new clip's sysex list is empty (storytold/soundcraft#1618 owns split/trim of packets). + #[test] + fn note_split_leaves_sysex_on_the_source_clip() { + let (mut e, t) = midi_engine(); + let r = e + .execute( + "event.retrospective_record", + &json!({"track": t.0, "notes": [{"pitch": 36, "start_ticks": 0}, {"pitch": 72, "start_ticks": 0}]}), + ) + .unwrap(); + let cid = r["clip"].as_u64().unwrap(); + let packet = soundcraft_midi::SysExEvent { tick: 0, status: 0xF0, data: vec![0x43, 0x10, 0x4C, 0x00, 0x00, 0x7E, 0x00, 0xF7] }; + if let Some(c) = e.session_mut().find_clip_mut(ClipId(cid)) + && let ClipContent::Midi { sequence } = &mut c.content + { + sequence.sysex.push(packet.clone()); + } + e.execute("edit.select", &json!({"clips": [cid]})).unwrap(); + e.execute("event.select_split_notes", &json!({"pitch_from": 60, "pitch_to": 127, "action": "split"})).unwrap(); + let source = e.session().find_clip(ClipId(cid)).map(|(_, c)| c.clone()).unwrap(); + match &source.content { + ClipContent::Midi { sequence } => { + assert_eq!(sequence.notes.iter().map(|n| n.pitch).collect::>(), vec![36]); + assert_eq!(sequence.sysex, vec![packet]); + } + _ => panic!(), + } + let nt = e.session().tracks.iter().find(|x| x.id != t).unwrap(); + match &nt.clips()[0].content { + ClipContent::Midi { sequence } => { + assert_eq!(sequence.notes[0].pitch, 72); + assert!(sequence.sysex.is_empty()); + } + _ => panic!(), + } + } + #[test] fn chords_from_demo_become_markers() { let mut e = crate::demo::demo_engine(); diff --git a/crates/midi/src/lib.rs b/crates/midi/src/lib.rs index aff14495..f6635c73 100644 --- a/crates/midi/src/lib.rs +++ b/crates/midi/src/lib.rs @@ -1,6 +1,6 @@ //! SoundCraft MIDI. //! -//! - [`Note`], [`CtrlEvent`] and [`Sequence`]: the MIDI content of a region / track, in ticks at +//! - [`Note`], [`CtrlEvent`], [`SysExEvent`] and [`Sequence`]: the MIDI content of a region / track, in ticks at //! [`PPQ`] (960) ticks per quarter note; [`read_smf`] / [`write_smf`]: Standard MIDI File import //! and export, and [`read_smf_lenient`] for files that are slightly damaged. These come from //! `craft-midi` in craft-libs, shared with the other Craft apps, and are re-exported so the rest @@ -14,7 +14,8 @@ pub mod ops; mod rng; pub use craft_midi::{ - CtrlEvent, CtrlKind, LenientRead, MAX_EVENTS, MAX_TRACKS, MidiError, Note, PPQ, Sequence, Smf, SmfTrack, read_smf, read_smf_lenient, write_smf, + CtrlEvent, CtrlKind, LenientRead, MAX_EVENTS, MAX_TRACKS, MidiError, Note, PPQ, Sequence, Smf, SmfTrack, SysExEvent, read_smf, read_smf_lenient, + write_smf, }; pub use names::{gm_drum_name, gm_program_name, note_name}; pub use rng::XorShift;