Add method to format set of MIDI channels

eg. channels 1,2,3,5,6
will be formatted as "1-3, 5, 6"
This commit is contained in:
Robin Gareus 2022-02-05 00:12:38 +01:00
parent 12e8235193
commit ef8904210e
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
2 changed files with 47 additions and 0 deletions

View File

@ -801,6 +801,51 @@ ARDOUR_UI_UTILS::samples_as_time_string (samplecnt_t s, float rate, bool show_sa
return buf;
}
string
ARDOUR_UI_UTILS::midi_channels_as_string (std::set<uint8_t> const& channels)
{
if (channels.empty ()) {
return _("none");
}
string rv;
auto i = channels.begin ();
uint8_t next = *i;
uint8_t prev = next;
rv += to_string<int> (next + 1);
do {
if (*i == next) {
++i;
++next;
if (i != channels.end ()) {
continue;
}
}
if (next - prev > 2) {
rv += "-";
rv += to_string<int> (next);
} else if (next - prev > 1) {
rv += ", ";
rv += to_string<int> (next);
}
if (i == channels.end ()) {
break;
}
rv += ", ";
rv += to_string<int> (*i + 1);
prev = *i;
next = prev + 1;
++i;
} while (i != channels.end ());
return rv;
}
bool
ARDOUR_UI_UTILS::windows_overlap (Gtk::Window *a, Gtk::Window *b)
{

View File

@ -103,6 +103,8 @@ Gdk::Color unique_random_color (std::list<Gdk::Color> &);
std::string rate_as_string (float r);
std::string samples_as_time_string (ARDOUR::samplecnt_t s, float r, bool show_samples = false);
std::string midi_channels_as_string (std::set<uint8_t> const&);
bool windows_overlap (Gtk::Window *a, Gtk::Window *b);
bool overwrite_file_dialog (Gtk::Window& parent, std::string title, std::string text);