Skip to content

ManageTempoMap fails on empty MidiFile #321

@FireFox2000000

Description

@FireFox2000000

Hello, currently I am trying to generate a tempo map that starts at certain tempo map values, and then after a certain amount of ticks change to a new tempo and time signature. Using the ManageTempoMap api this work fine, except in the cases where the initial tempo and time signature are standard values (120bpm @ 4/4), which results in an exception being thrown.

---
System.ArgumentException : Collection of EventsCollection is empty.
Parameter name: eventsCollections
---
at Melanchall.DryWetMidi.Common.ThrowIfArgument.IsEmptyCollection[T] (System.String parameterName, System.Collections.Generic.IEnumerable`1[T] collection, System.String message) [0x00008] in <6afb839a39da48d6bfc3946fb9a5d8af>:0 
  at Melanchall.DryWetMidi.Interaction.TempoMapManager..ctor (Melanchall.DryWetMidi.Core.TimeDivision timeDivision, System.Collections.Generic.IEnumerable`1[T] eventsCollections) [0x0001c] in <6afb839a39da48d6bfc3946fb9a5d8af>:0 
  at Melanchall.DryWetMidi.Interaction.TempoMapManagingUtilities.ManageTempoMap (System.Collections.Generic.IEnumerable`1[T] eventsCollections, Melanchall.DryWetMidi.Core.TimeDivision timeDivision) [0x00016] in <6afb839a39da48d6bfc3946fb9a5d8af>:0 
  at Melanchall.DryWetMidi.Interaction.TempoMapManagingUtilities.ManageTempoMap (System.Collections.Generic.IEnumerable`1[T] trackChunks, Melanchall.DryWetMidi.Core.TimeDivision timeDivision) [0x0003b] in <6afb839a39da48d6bfc3946fb9a5d8af>:0 
  at Melanchall.DryWetMidi.Interaction.TempoMapManagingUtilities.ManageTempoMap (Melanchall.DryWetMidi.Core.MidiFile file) [0x00017] in <6afb839a39da48d6bfc3946fb9a5d8af>:0 

This can be reproduced in the following ways-

Melanchall.DryWetMidi.Core.MidiFile midiFile = new();
var timeDivision = new Melanchall.DryWetMidi.Core.TicksPerQuarterNoteTimeDivision(192);
midiFile.TimeDivision = timeDivision;
midiFile.ReplaceTempoMap(TempoMap.Create(timeDivision, Tempo.FromBeatsPerMinute(120)));
using (var tempoMapManager = midiFile.ManageTempoMap())
{ ... }

or via

Melanchall.DryWetMidi.Core.MidiFile midiFile = new();
var timeDivision = new Melanchall.DryWetMidi.Core.TicksPerQuarterNoteTimeDivision(192);
midiFile.TimeDivision = timeDivision;
midiFile.ReplaceTempoMap(TempoMap.Create(timeDivision, new TimeSignature(4, 4)));
using (var tempoMapManager = midiFile.ManageTempoMap())
{ ... }

This does not occur if the tempo is not 120 (i.e. 121 or 119 are fine) or the time signature is not standard (i.e does not throw on anything other than 4/4).
midiFile.ReplaceTempoMap(TempoMap.Create(timeDivision, Tempo.FromBeatsPerMinute(121)));
midiFile.ReplaceTempoMap(TempoMap.Create(timeDivision, new TimeSignature(6, 4)));

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugBug in the library

    Projects

    Status

    Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions