melanchall / drywetmidi

.NET library to read, write, process MIDI files and to work with MIDI devices
https://melanchall.github.io/drywetmidi
MIT License
540 stars 75 forks source link

Non-ASCII encoding is not supported by text-based meta events #2

Closed melanchall closed 7 years ago

melanchall commented 7 years ago

From discussion in #1:

@nicowitteman

Hi Max, I switched to framework, and I think the library is very useful. Now I have this issue: In a MIDI file bwv227.zip there is a track named "Ténor". In SequenceTrackNameEvent.Text it is represented as "T?nor". That is a pity, because I want to write the tracks away as files with their trackname. This one fails. Any suggestions? Nico

@melanchall

Hi Nico,

It is because the Text of any text-based meta event is processed in ASCII encoding. Obviously the é symbol doesn't belong this encoding. I'm planning to add other encodings support later. Maybe as a first iteration I will introduce kind of TextEncoding property in ReadingSettings/WritingSettings so you will be able to specify desired encoding for strings serialization/deserialization. Yes, sounds like a plan.

Thank you for your feedback and for remebering me about non-ASCII encodings in text-based meta events. I'll try to provide a solution in the next release which should be at the beginning of August.

Max

@nicowitteman

Thanks Max, I will await the update. Nico

melanchall commented 7 years ago

OK, I've added TextEncoding property to ReadingSettings and WritingSettings. These changes will be available in the next release of the DryWetMIDI.

To write the text of text-based meta events, for example, in Unicode you will be able to specify desired encoding via WritingSettings:

midiFile.Write("output.mid",
               settings: new WritingSettings { TextEncoding = Encoding.Unicode });

and then you can read this file using the same encoding via ReadingSettings:

var midiFile = MidiFile.Read("input.mid",
                             settings: new ReadingSettings { TextEncoding = Encoding.Unicode });
melanchall commented 7 years ago

DryWetMIDI 1.2.0 has been released. This release contains a fix for this bug as described in the post above.

nicowitteman commented 7 years ago

Max, Thanks for this. For the text fields (that are represented as 8-bit ASCII, not Unicode), the value "TextEncoding = Encoding.GetEncoding(28591)" works for me in this specific case (28591 is ISO 8859-1, aka Latin-1). Kind regards, Nico

melanchall commented 7 years ago

Nico,

Sounds good, glad to hear that you've solved your problem :)

Max