Use existing track names from midi file instead of overwriting them with "InitializedTrack" #2903
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi Aure
I tried to use AppleSequencer to read a midi file, find a specific track by name, make some changes on that track and then write the result back to the file with
sequencer.genData()!.write(to: fileUrl!)
.While doing that, I run into two issues of AppleSequencer midi file handling:
This pull request fixes these two issues as following:
init(musicTrack: MusicTrack, name: String = "Unnamed")
inMusicTrackManager
now reads the track name from existing meta event, if the name parameter is an empty string. If no track name meta event is found, no name is set by intention (to not change midi file when writing back).init(musicTrack: MusicTrack, name: String = "Unnamed")
inMusicTrackManager
first removes existing track name meta event before adding a new one.initTracks()
inAppleSequencer
initializes MusicTrackManager with empty name to request track names from midi fileaddMetaEvent()
that is also internally used to write the track name meta eventclearMetaEvent(_ metaEventType: MIDIByte)
that is also internally used to delete existing track name meta event.Regards, Matthias