Ability to change text encoding post-parse
See original GitHub issueSo right now if you need to try and handle multiple midi files of various text encodings at runtime you are somewhat out of luck and would need to continuously re-parse the whole midi until the correct encoding is found.
Going from this:
public string Text { get; set; }
protected sealed override void ReadContent(MidiReader reader, ReadingSettings settings, int size)
{
ThrowIfArgument.IsNegative(nameof(size), size,
"Text event cannot be read since the size is negative number.");
if (size == 0)
return;
textData = reader.ReadBytes(size);
var encoding = settings.TextEncoding ?? SmfUtilities.DefaultEncoding;
Text = encoding.GetString(bytes);
}
to something like this (this isnt 100% working code but just something to get an idea of what i’m saying here)
protected byte[] _textData = null;
protected string _textEncoded;
public string Text
{
get
{
if (_textData != null)
{
var encoding = settings.TextEncoding ?? SmfUtilities.DefaultEncoding;
_textEncoded = encoding.GetString(_textData);
return _textEncoded;
}
else
{
return _textEncoded;
}
}
set => _textEncoded = value;
}
protected sealed override void ReadContent(MidiReader reader, ReadingSettings settings, int size)
{
ThrowIfArgument.IsNegative(nameof(size), size, "Text event cannot be read since the size is negative number.");
if (size == 0)
return;
_textData = reader.ReadBytes(size);
}
It would need some other api changes perhaps with how settings and/or encodings are handled.
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
How do I correct the character encoding of a file?
1- Copy the original text · 2- In Notepad++, open new file, change Encoding -> pick an encoding you think the original text...
Read more >Choose text encoding when you open and save files
In the File Conversion dialog box, select Other encoding, and then select the encoding standard that you want from the list.
Read more >How do I change the character encoding for a webpage ...
Manual encoding switching may be able to be done by use of Chrome extensions. Marked as best answer by Kameron M - Community...
Read more >Problem with special character encoding (Possibly Latin1)
Solved: Hi there, So, I got a database that possibly has a Latin1 encoding for the text fields. I say possibly because it's...
Read more >Change character encoding after a file has been opened
Being able to change character encoding after a file has been loaded or a new buffer created. (Have to work with a lot...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I’ve added
DecodeTextCallbackproperty toReadingSettings.@mdsitton So is it good to have text parsing callback?