mdedwards/slippery-chicken

midi-file-to-events function

mt-collins opened this issue · 2 comments

There seems to be an issue with the midi-file-to-events function at the moment where the first event in a MIDI file is always omitted from the outputted events list.

midi-tests.zip

The attached MIDI files are just two examples of several I've tried with this function -- always with the same result. test-midifile.mid is from the SC test suite and cmajor2.mid is of my own creation. Below is the first few events of what's returned for me when the latter file is passed to the function. The first event returned has start time of 0.500 and pitch D4, when the first event should be start time 0.000 and pitch C4:

(
EVENT: start-time: 0.500, end-time: NIL, 
       duration-in-tempo: 0.500, 
       compound-duration-in-tempo: 0.500, 
       amplitude: 1.000 
       bar-num: -1, marks-before: NIL, 
       tempo-change: NIL 
       instrument-change: NIL 
       display-tempo: NIL, start-time-qtrs: 1.000, 
       midi-time-sig: NIL, midi-program-changes: NIL, 
       midi-control-changes: NIL, 
       8va: 0, player: NIL
       asco-label: NIL, asco-msgs: NIL
       set-ref: NIL
       pitch-or-chord: 
PITCH: frequency: 293.665, midi-note: 62, midi-channel: 1 
       pitch-bend: 0.0 
       degree: 124, data-consistent: T, white-note: D4
       nearest-chromatic: D4
       src: 1.1224622, src-ref-pitch: C4, score-note: D4 
       qtr-sharp: NIL, qtr-flat: NIL, qtr-tone: NIL,  
       micro-tone: NIL, 
       sharp: NIL, flat: NIL, natural: T, 
       octave: 4, c5ths: 0, no-8ve: D, no-8ve-no-acc: D
       show-accidental: T, white-degree: 36, 
       accidental: N, 
       accidental-in-parentheses: NIL, marks: NIL, 
       marks-before: NIL, amplitude: NIL
LINKED-NAMED-OBJECT: previous: NIL, 
                     this: NIL, 
                     next: NIL
NAMED-OBJECT: id: D4, tag: NIL, 
data: D4
**************

       written-pitch-or-chord: NIL
RHYTHM: value: 4.000, duration: 1.000, rq: 1, is-rest: NIL, 
        is-whole-bar-rest: NIL, 
        score-rthm: 4.0, undotted-value: 4, num-flags: 0, num-dots: 0, 
        is-tied-to: NIL, is-tied-from: NIL, compound-duration: 1.000, 
        is-grace-note: NIL, needs-new-note: T, beam: NIL, bracket: NIL, 
        rqq-note: NIL, rqq-info: NIL, marks: (FFFF), marks-in-part: NIL, 
        letter-value: 4, tuplet-scaler: 1, bar-pos: -1, 
        grace-note-duration: 0.05
LINKED-NAMED-OBJECT: previous: NIL, 
                     this: NIL, 
                     next: NIL
NAMED-OBJECT: id: Q, tag: NIL, 
data: Q
**************

 
EVENT: start-time: 1.000, end-time: NIL, 
       duration-in-tempo: 0.500, 
       compound-duration-in-tempo: 0.500, 
       amplitude: 1.000 
       bar-num: -1, marks-before: NIL, 
       tempo-change: NIL 
       instrument-change: NIL 
       display-tempo: NIL, start-time-qtrs: 2.000, 
       midi-time-sig: NIL, midi-program-changes: NIL, 
       midi-control-changes: NIL, 
       8va: 0, player: NIL
       asco-label: NIL, asco-msgs: NIL
       set-ref: NIL
       pitch-or-chord: 
PITCH: frequency: 329.628, midi-note: 64, midi-channel: 1 
       pitch-bend: 0.0 
       degree: 128, data-consistent: T, white-note: E4
       nearest-chromatic: E4
       src: 1.2599212, src-ref-pitch: C4, score-note: E4 
       qtr-sharp: NIL, qtr-flat: NIL, qtr-tone: NIL,  
       micro-tone: NIL, 
       sharp: NIL, flat: NIL, natural: T, 
       octave: 4, c5ths: 0, no-8ve: E, no-8ve-no-acc: E
       show-accidental: T, white-degree: 37, 
       accidental: N, 
       accidental-in-parentheses: NIL, marks: NIL, 
       marks-before: NIL, amplitude: NIL
LINKED-NAMED-OBJECT: previous: NIL, 
                     this: NIL, 
                     next: NIL
NAMED-OBJECT: id: E4, tag: NIL, 
data: E4
**************

       written-pitch-or-chord: NIL
RHYTHM: value: 4.000, duration: 1.000, rq: 1, is-rest: NIL, 
        is-whole-bar-rest: NIL, 
        score-rthm: 4.0, undotted-value: 4, num-flags: 0, num-dots: 0, 
        is-tied-to: NIL, is-tied-from: NIL, compound-duration: 1.000, 
        is-grace-note: NIL, needs-new-note: T, beam: NIL, bracket: NIL, 
        rqq-note: NIL, rqq-info: NIL, marks: (FFFF), marks-in-part: NIL, 
        letter-value: 4, tuplet-scaler: 1, bar-pos: -1, 
        grace-note-duration: 0.05
LINKED-NAMED-OBJECT: previous: NIL, 
                     this: NIL, 
                     next: NIL
NAMED-OBJECT: id: Q, tag: NIL, 
data: Q
**************

 
EVENT: start-time: 1.500, end-time: NIL, 
       duration-in-tempo: 0.500, 
       compound-duration-in-tempo: 0.500, 
       amplitude: 1.000 
       bar-num: -1, marks-before: NIL, 
       tempo-change: NIL 
       instrument-change: NIL 
       display-tempo: NIL, start-time-qtrs: 3.000, 
       midi-time-sig: NIL, midi-program-changes: NIL, 
       midi-control-changes: NIL, 
       8va: 0, player: NIL
       asco-label: NIL, asco-msgs: NIL
       set-ref: NIL
       pitch-or-chord: 
PITCH: frequency: 349.228, midi-note: 65, midi-channel: 1 
       pitch-bend: 0.0 
       degree: 130, data-consistent: T, white-note: F4
       nearest-chromatic: F4
       src: 1.3348399, src-ref-pitch: C4, score-note: F4 
       qtr-sharp: NIL, qtr-flat: NIL, qtr-tone: NIL,  
       micro-tone: NIL, 
       sharp: NIL, flat: NIL, natural: T, 
       octave: 4, c5ths: 0, no-8ve: F, no-8ve-no-acc: F
       show-accidental: T, white-degree: 38, 
       accidental: N, 
       accidental-in-parentheses: NIL, marks: NIL, 
       marks-before: NIL, amplitude: NIL
LINKED-NAMED-OBJECT: previous: NIL, 
                     this: NIL, 
                     next: NIL
NAMED-OBJECT: id: F4, tag: NIL, 
data: F4
**************

       written-pitch-or-chord: NIL
RHYTHM: value: 4.000, duration: 1.000, rq: 1, is-rest: NIL, 
        is-whole-bar-rest: NIL, 
        score-rthm: 4.0, undotted-value: 4, num-flags: 0, num-dots: 0, 
        is-tied-to: NIL, is-tied-from: NIL, compound-duration: 1.000, 
        is-grace-note: NIL, needs-new-note: T, beam: NIL, bracket: NIL, 
        rqq-note: NIL, rqq-info: NIL, marks: (FFFF), marks-in-part: NIL, 
        letter-value: 4, tuplet-scaler: 1, bar-pos: -1, 
        grace-note-duration: 0.05
LINKED-NAMED-OBJECT: previous: NIL, 
                     this: NIL, 
                     next: NIL
NAMED-OBJECT: id: Q, tag: NIL, 
data: Q
**************

Similarly for test-midifile.mid, which has several instruments:

(
EVENT: start-time: 0.500, end-time: NIL, 
       duration-in-tempo: 0.500, 
       compound-duration-in-tempo: 0.500, 
       amplitude: 0.693 
       bar-num: -1, marks-before: NIL, 
       tempo-change: NIL 
       instrument-change: NIL 
       display-tempo: NIL, start-time-qtrs: 2.500, 
       midi-time-sig: NIL, midi-program-changes: NIL, 
       midi-control-changes: NIL, 
       8va: 0, player: NIL
       asco-label: NIL, asco-msgs: NIL
       set-ref: NIL
       pitch-or-chord: 
CHORD: auto-sort: T, marks: NIL, micro-tone: NIL, micro-tonality: 0.0
centroid: NIL, dissonance: NIL
SCLIST: sclist-length: 3, bounds-alert: T, copy: T
LINKED-NAMED-OBJECT: previous: NIL, 
                     this: NIL, 
                     next: NIL
NAMED-OBJECT: id: NIL, tag: NIL, 
data: (
PITCH: frequency: 329.628, midi-note: 64, midi-channel: 2 
       pitch-bend: 0.0 
       degree: 128, data-consistent: T, white-note: E4
       nearest-chromatic: E4
       src: 1.2599212, src-ref-pitch: C4, score-note: E4 
       qtr-sharp: NIL, qtr-flat: NIL, qtr-tone: NIL,  
       micro-tone: NIL, 
       sharp: NIL, flat: NIL, natural: T, 
       octave: 4, c5ths: 0, no-8ve: E, no-8ve-no-acc: E
       show-accidental: T, white-degree: 37, 
       accidental: N, 
       accidental-in-parentheses: NIL, marks: NIL, 
       marks-before: NIL, amplitude: NIL
LINKED-NAMED-OBJECT: previous: NIL, 
                     this: NIL, 
                     next: NIL
NAMED-OBJECT: id: E4, tag: NIL, 
data: E4
**************

       
PITCH: frequency: 391.995, midi-note: 67, midi-channel: 3 
       pitch-bend: 0.0 
       degree: 134, data-consistent: T, white-note: G4
       nearest-chromatic: G4
       src: 1.4983071, src-ref-pitch: C4, score-note: G4 
       qtr-sharp: NIL, qtr-flat: NIL, qtr-tone: NIL,  
       micro-tone: NIL, 
       sharp: NIL, flat: NIL, natural: T, 
       octave: 4, c5ths: 0, no-8ve: G, no-8ve-no-acc: G
       show-accidental: T, white-degree: 39, 
       accidental: N, 
       accidental-in-parentheses: NIL, marks: NIL, 
       marks-before: NIL, amplitude: NIL
LINKED-NAMED-OBJECT: previous: NIL, 
                     this: NIL, 
                     next: NIL
NAMED-OBJECT: id: G4, tag: NIL, 
data: G4
**************

       
PITCH: frequency: 493.883, midi-note: 71, midi-channel: 1 
       pitch-bend: 0.0 
       degree: 142, data-consistent: T, white-note: B4
       nearest-chromatic: B4
       src: 1.8877487, src-ref-pitch: C4, score-note: B4 
       qtr-sharp: NIL, qtr-flat: NIL, qtr-tone: NIL,  
       micro-tone: NIL, 
       sharp: NIL, flat: NIL, natural: T, 
       octave: 4, c5ths: 0, no-8ve: B, no-8ve-no-acc: B
       show-accidental: T, white-degree: 41, 
       accidental: N, 
       accidental-in-parentheses: NIL, marks: NIL, 
       marks-before: NIL, amplitude: NIL
LINKED-NAMED-OBJECT: previous: NIL, 
                     this: NIL, 
                     next: NIL
NAMED-OBJECT: id: B4, tag: NIL, 
data: B4
**************
)
**************

       written-pitch-or-chord: NIL
RHYTHM: value: 8.000, duration: 0.500, rq: 1/2, is-rest: NIL, 
        is-whole-bar-rest: NIL, 
        score-rthm: 8.0, undotted-value: 8, num-flags: 1, num-dots: 0, 
        is-tied-to: NIL, is-tied-from: NIL, compound-duration: 0.500, 
        is-grace-note: NIL, needs-new-note: T, beam: NIL, bracket: NIL, 
        rqq-note: NIL, rqq-info: NIL, marks: (F), marks-in-part: NIL, 
        letter-value: 8, tuplet-scaler: 1, bar-pos: -1, 
        grace-note-duration: 0.05
LINKED-NAMED-OBJECT: previous: NIL, 
                     this: NIL, 
                     next: NIL
NAMED-OBJECT: id: E, tag: NIL, 
data: E
**************

 
EVENT: start-time: 1.000, end-time: NIL, 
       duration-in-tempo: 0.500, 
       compound-duration-in-tempo: 0.500, 
       amplitude: 0.693 
       bar-num: -1, marks-before: NIL, 
       tempo-change: NIL 
       instrument-change: NIL 
       display-tempo: NIL, start-time-qtrs: 4.000, 
       midi-time-sig: NIL, midi-program-changes: NIL, 
       midi-control-changes: NIL, 
       8va: 0, player: NIL
       asco-label: NIL, asco-msgs: NIL
       set-ref: NIL
       pitch-or-chord: 
CHORD: auto-sort: T, marks: NIL, micro-tone: NIL, micro-tonality: 0.0
centroid: NIL, dissonance: NIL
SCLIST: sclist-length: 3, bounds-alert: T, copy: T
LINKED-NAMED-OBJECT: previous: NIL, 
                     this: NIL, 
                     next: NIL
NAMED-OBJECT: id: NIL, tag: NIL, 
data: (
PITCH: frequency: 261.626, midi-note: 60, midi-channel: 3 
       pitch-bend: 0.0 
       degree: 120, data-consistent: T, white-note: C4
       nearest-chromatic: C4
       src: 1.0, src-ref-pitch: C4, score-note: C4 
       qtr-sharp: NIL, qtr-flat: NIL, qtr-tone: NIL,  
       micro-tone: NIL, 
       sharp: NIL, flat: NIL, natural: T, 
       octave: 4, c5ths: 0, no-8ve: C, no-8ve-no-acc: C
       show-accidental: T, white-degree: 35, 
       accidental: N, 
       accidental-in-parentheses: NIL, marks: NIL, 
       marks-before: NIL, amplitude: NIL
LINKED-NAMED-OBJECT: previous: NIL, 
                     this: NIL, 
                     next: NIL
NAMED-OBJECT: id: C4, tag: NIL, 
data: C4
**************

       
PITCH: frequency: 293.665, midi-note: 62, midi-channel: 2 
       pitch-bend: 0.0 
       degree: 124, data-consistent: T, white-note: D4
       nearest-chromatic: D4
       src: 1.1224622, src-ref-pitch: C4, score-note: D4 
       qtr-sharp: NIL, qtr-flat: NIL, qtr-tone: NIL,  
       micro-tone: NIL, 
       sharp: NIL, flat: NIL, natural: T, 
       octave: 4, c5ths: 0, no-8ve: D, no-8ve-no-acc: D
       show-accidental: T, white-degree: 36, 
       accidental: N, 
       accidental-in-parentheses: NIL, marks: NIL, 
       marks-before: NIL, amplitude: NIL
LINKED-NAMED-OBJECT: previous: NIL, 
                     this: NIL, 
                     next: NIL
NAMED-OBJECT: id: D4, tag: NIL, 
data: D4
**************

       
PITCH: frequency: 523.251, midi-note: 72, midi-channel: 1 
       pitch-bend: 0.0 
       degree: 144, data-consistent: T, white-note: C5
       nearest-chromatic: C5
       src: 2.0, src-ref-pitch: C4, score-note: C5 
       qtr-sharp: NIL, qtr-flat: NIL, qtr-tone: NIL,  
       micro-tone: NIL, 
       sharp: NIL, flat: NIL, natural: T, 
       octave: 5, c5ths: 0, no-8ve: C, no-8ve-no-acc: C
       show-accidental: T, white-degree: 42, 
       accidental: N, 
       accidental-in-parentheses: NIL, marks: NIL, 
       marks-before: NIL, amplitude: NIL
LINKED-NAMED-OBJECT: previous: NIL, 
                     this: NIL, 
                     next: NIL
NAMED-OBJECT: id: C5, tag: NIL, 
data: C5
**************
)
**************

       written-pitch-or-chord: NIL
RHYTHM: value: 8.000, duration: 0.500, rq: 1/2, is-rest: NIL, 
        is-whole-bar-rest: NIL, 
        score-rthm: 8.0, undotted-value: 8, num-flags: 1, num-dots: 0, 
        is-tied-to: NIL, is-tied-from: NIL, compound-duration: 0.500, 
        is-grace-note: NIL, needs-new-note: T, beam: NIL, bracket: NIL, 
        rqq-note: NIL, rqq-info: NIL, marks: (F), marks-in-part: NIL, 
        letter-value: 8, tuplet-scaler: 1, bar-pos: -1, 
        grace-note-duration: 0.05
LINKED-NAMED-OBJECT: previous: NIL, 
                     this: NIL, 
                     next: NIL
NAMED-OBJECT: id: E, tag: NIL, 
data: E
**************

Hopefully I haven't missed anything obvious here!

Good catch Matt, thanks for this. I think I found it. Caused some head scratching but it turns out I'd shot myself in the foot by trying to save execution time by not reversing potentially long lists of events and instead doing all the processing in reverse. Serves me right for thinking I can run backwards. We all know what happens there. Latest source on the Michael branch should help you out here. Ping this back to me if not. Best, Michael

Thanks Michael, that's great. I think it's all working fine now!