13
0

Sanitize MIDI track names, remove unprintable chars #9553

This commit is contained in:
Robin Gareus 2023-11-28 00:29:19 +01:00
parent 02d91a7ff0
commit 1306a698a7
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04

View File

@ -534,6 +534,11 @@ SMF::round_to_file_precision (double val) const
return round (val * div) / div; return round (val * div) / div;
} }
static bool invalid_char (unsigned char c)
{
return !isprint (c) && c != '\n';
}
void void
SMF::track_names(vector<string>& names) const SMF::track_names(vector<string>& names) const
{ {
@ -551,7 +556,9 @@ SMF::track_names(vector<string>& names) const
names.push_back (string()); names.push_back (string());
} else { } else {
if (trk->name) { if (trk->name) {
names.push_back (Glib::convert_with_fallback (trk->name, "UTF-8", "ISO-8859-1", "_")); std::string name (Glib::convert_with_fallback (trk->name, "UTF-8", "ISO-8859-1", "_"));
name.erase (std::remove_if (name.begin(), name.end(), invalid_char), name.end());
names.push_back (name);
} else { } else {
char buf[32]; char buf[32];
sprintf(buf, "t%d", n+1); sprintf(buf, "t%d", n+1);
@ -578,7 +585,9 @@ SMF::instrument_names(vector<string>& names) const
names.push_back (string()); names.push_back (string());
} else { } else {
if (trk->instrument) { if (trk->instrument) {
names.push_back (trk->instrument); std::string name (Glib::convert_with_fallback (trk->instrument, "UTF-8", "ISO-8859-1", "_"));
name.erase (std::remove_if (name.begin(), name.end(), invalid_char), name.end());
names.push_back (name);
} else { } else {
char buf[32]; char buf[32];
sprintf(buf, "i%d", n+1); sprintf(buf, "i%d", n+1);