inline font & font_render () { static font * sp_font_renderer = nullptr; if (is_nullptr(sp_font_renderer)) { sp_font_renderer = new font; if (not_nullptr(sp_font_renderer)) { // sp_font_renderer->init(m_window) } else { errprint("could not create the application font object, crash!"); } } return *sp_font_renderer; }
void mastermidibus::dump_midi_input (event ev) { for (size_t i = 0; i < m_vector_sequence.size(); ++i) { if (is_nullptr(m_vector_sequence[i])) // error check { break; } else if (m_vector_sequence[i]->stream_event(ev)) { /* * Did we find a match to the sequence channel? Then don't bother * with the remaining sequences. */ break; } } }
bool variant::can_convert(const type& target_type) const { if (!is_valid()) return false; type source_type = get_type(); source_type = (source_type.is_wrapper() && !target_type.is_wrapper()) ? source_type.get_wrapped_type() : source_type; if (source_type == target_type) return true; if (source_type.get_pointer_dimension() == 1 && target_type.get_pointer_dimension() == 1) { if (type::apply_offset(get_raw_ptr(), source_type, target_type)) return true; } if (!source_type.is_wrapper() && target_type.is_wrapper()) { if (target_type.get_wrapped_type() == source_type && target_type.m_type_data->create_wrapper) return true; } if (source_type.get_type_converter(target_type)) return true; if (target_type == type::get<std::nullptr_t>() && is_nullptr()) return true; const bool source_is_arithmetic = source_type.is_arithmetic(); const bool target_is_arithmetic = target_type.is_arithmetic(); const bool target_is_enumeration = target_type.is_enumeration(); const type string_type = type::get<std::string>(); return ((source_is_arithmetic && target_is_arithmetic) || (source_is_arithmetic && target_type == string_type) || (source_type == string_type && target_is_arithmetic) || (source_type.is_enumeration() && target_is_arithmetic) || (source_is_arithmetic && target_is_enumeration) || (source_type == string_type && target_is_enumeration)); }
perfedit::perfedit ( perform & p, bool second_perfedit, int ppqn ) : gui_window_gtk2 (p, 750, 500), m_peer_perfedit (nullptr), m_table (manage(new Gtk::Table(6, 3, false))), m_vadjust (manage(new Gtk::Adjustment(0, 0, 1, 1, 1, 1))), m_hadjust (manage(new Gtk::Adjustment(0, 0, 1, 1, 1, 1))), m_vscroll (manage(new Gtk::VScrollbar(*m_vadjust))), m_hscroll (manage(new Gtk::HScrollbar(*m_hadjust))), m_perfnames (manage(new perfnames(perf(), *this, *m_vadjust))), m_perfroll ( manage(new perfroll(perf(), *this, *m_hadjust, *m_vadjust, ppqn)) ), m_perftime (manage(new perftime(perf(), *this, *m_hadjust))), m_menu_snap (manage(new Gtk::Menu())), #ifdef SEQ64_STAZED_TRANSPOSE m_menu_xpose (manage(new Gtk::Menu())), m_button_xpose (manage(new Gtk::Button())), m_entry_xpose (manage(new Gtk::Entry())), #endif m_image_play (manage(new PIXBUF_IMAGE(play2_xpm))), m_button_snap (manage(new Gtk::Button())), m_entry_snap (manage(new Gtk::Entry())), m_button_stop (manage(new Gtk::Button())), m_button_play (manage(new Gtk::Button())), m_button_loop (manage(new Gtk::ToggleButton())), m_button_expand (manage(new Gtk::Button())), m_button_collapse (manage(new Gtk::Button())), m_button_copy (manage(new Gtk::Button())), m_button_grow (manage(new Gtk::Button())), m_button_undo (manage(new Gtk::Button())), m_button_redo (manage(new Gtk::Button())), // stazed #ifdef SEQ64_STAZED_JACK_SUPPORT m_button_jack (manage(new Gtk::ToggleButton())), m_button_follow (manage(new Gtk::ToggleButton())), #endif m_button_bpm (manage(new Gtk::Button())), m_entry_bpm (manage(new Gtk::Entry())), m_button_bw (manage(new Gtk::Button())), m_entry_bw (manage(new Gtk::Entry())), m_hbox (manage(new Gtk::HBox(false, 2))), m_hlbox (manage(new Gtk::HBox(false, 2))), m_tooltips (manage(new Gtk::Tooltips())), // valgrind complains! m_menu_bpm (manage(new Gtk::Menu())), m_menu_bw (manage(new Gtk::Menu())), m_snap (0), m_bpm (0), m_bw (0), m_ppqn (0), #ifdef SEQ64_PAUSE_SUPPORT m_is_running (false), #endif m_standard_bpm (SEQ64_DEFAULT_LINES_PER_MEASURE) /* 4 */ { std::string title = "Sequencer64 - Song Editor"; if (second_perfedit) title += " 2"; m_ppqn = choose_ppqn(ppqn); set_icon(Gdk::Pixbuf::create_from_xpm_data(perfedit_xpm)); set_title(title); /* caption bar */ m_table->set_border_width(2); m_hlbox->set_border_width(2); m_button_grow->add ( *manage(new Gtk::Arrow(Gtk::ARROW_RIGHT, Gtk::SHADOW_OUT)) ); m_button_grow->signal_clicked().connect(mem_fun(*this, &perfedit::grow)); add_tooltip(m_button_grow, "Increase size of grid."); /* * Fill the table */ m_table->attach(*m_hlbox, 0, 3, 0, 1, Gtk::FILL, Gtk::SHRINK, 2, 0); m_table->attach(*m_perfnames, 0, 1, 2, 3, Gtk::SHRINK, Gtk::FILL); m_table->attach(*m_perftime, 1, 2, 1, 2, Gtk::FILL, Gtk::SHRINK); m_table->attach ( *m_perfroll, 1, 2, 2, 3, Gtk::FILL | Gtk::SHRINK, Gtk::FILL | Gtk::SHRINK ); m_table->attach(*m_vscroll, 2, 3, 2, 3, Gtk::SHRINK, Gtk::FILL | Gtk::EXPAND); m_table->attach(*m_hbox, 0, 1, 3, 4, Gtk::FILL, Gtk::SHRINK, 0, 2); m_table->attach(*m_hscroll, 1, 2, 3, 4, Gtk::FILL | Gtk::EXPAND, Gtk::SHRINK); m_table->attach(*m_button_grow, 2, 3, 3, 4, Gtk::SHRINK, Gtk::SHRINK); /* * To reduce the amount of written code, we now use a static array to * initialize some of the menu entries. We use the same list for the snap * menu and for the beat-width menu. This adds a beat-width of 32 to the * beat-width menu. A new feature! :-D */ #define SET_SNAP mem_fun(*this, &perfedit::set_snap) #define SET_BW mem_fun(*this, &perfedit::set_beat_width) static const int s_width_items [] = { 1, 2, 4, 8, 16, 32, 0, 3, 6, 12, 24, #ifdef USE_STAZED_EXTRA_SNAPS 0, 5, 10, 20, 40, 0, 7, 9, 11, 13, 14, 15 #endif }; static const int s_width_count = sizeof(s_width_items) / sizeof(int); for (int si = 0; si < s_width_count; ++si) { int item = s_width_items[si]; char fmt[8]; bool use_separator = false; if (item > 1) snprintf(fmt, sizeof fmt, "1/%d", item); else if (item == 0) use_separator = true; else snprintf(fmt, sizeof fmt, "%d", item); if (use_separator) { m_menu_snap->items().push_back(SeparatorElem()); } else { m_menu_snap->items().push_back ( MenuElem(fmt, sigc::bind(SET_SNAP, item)) ); snprintf(fmt, sizeof fmt, "%d", item); m_menu_bw->items().push_back(MenuElem(fmt, sigc::bind(SET_BW, item))); } } #define SET_POPUP mem_fun(*this, &perfedit::popup_menu) m_button_snap->add(*manage(new PIXBUF_IMAGE(snap_xpm))); m_button_snap->signal_clicked().connect ( sigc::bind<Gtk::Menu *>(SET_POPUP, m_menu_snap) ); add_tooltip(m_button_snap, "Grid snap (fraction of measure length)."); m_entry_snap->set_size_request(40, -1); m_entry_snap->set_editable(false); #ifdef SEQ64_STAZED_TRANSPOSE char num[12]; for (int i = -SEQ64_OCTAVE_SIZE; i <= SEQ64_OCTAVE_SIZE; ++i) { if (i != 0) snprintf(num, sizeof num, "%+d [%s]", i, c_interval_text[abs(i)]); else snprintf(num, sizeof num, "0 [normal]"); m_menu_xpose->items().push_front ( MenuElem ( num, sigc::bind ( mem_fun(*this, &perfedit::transpose_button_callback), i ) ) ); } m_button_xpose->add ( *manage(new Gtk::Image(Gdk::Pixbuf::create_from_xpm_data(transpose_xpm))) ); m_button_xpose->signal_clicked().connect ( sigc::bind<Gtk::Menu *> ( mem_fun(*this, &perfedit::popup_menu), m_menu_xpose ) ); add_tooltip(m_button_xpose, "Song-transpose all transposable sequences."); m_entry_xpose->set_size_request(30, -1); m_entry_xpose->set_editable(false); #endif // SEQ64_STAZED_TRANSPOSE #define SET_BPB mem_fun(*this, &perfedit::set_beats_per_bar) char b[4]; for (int i = 0; i < 16; ++i) { snprintf(b, sizeof b, "%d", i + 1); m_menu_bpm->items().push_back(MenuElem(b, sigc::bind(SET_BPB, i + 1))); } m_button_bpm->add(*manage(new PIXBUF_IMAGE(down_xpm))); m_button_bpm->signal_clicked().connect ( sigc::bind<Gtk::Menu *>(SET_POPUP, m_menu_bpm) ); add_tooltip ( m_button_bpm, "Time signature: beats per measure or bar." ); m_entry_bpm->set_width_chars(2); m_entry_bpm->set_editable(false); m_button_bw->add(*manage(new PIXBUF_IMAGE(down_xpm))); /* beat width */ m_button_bw->signal_clicked().connect ( sigc::bind<Gtk::Menu *>(SET_POPUP, m_menu_bw) ); add_tooltip(m_button_bw, "Time signature: length of measure or bar."); m_entry_bw->set_width_chars(2); m_entry_bw->set_editable(false); m_button_undo->add(*manage(new PIXBUF_IMAGE(undo_xpm))); m_button_undo->signal_clicked().connect(mem_fun(*this, &perfedit::undo)); add_tooltip(m_button_undo, "Undo the last action (Ctrl-Z)."); m_button_redo->add(*manage(new PIXBUF_IMAGE(redo_xpm))); m_button_redo->signal_clicked().connect(mem_fun(*this, &perfedit::redo)); add_tooltip(m_button_redo, "Redo the last undone action (Ctrl-R)."); m_button_expand->add(*manage(new PIXBUF_IMAGE(expand_xpm))); m_button_expand->signal_clicked().connect(mem_fun(*this, &perfedit::expand)); add_tooltip(m_button_expand, "Expand space between L and R markers."); m_button_collapse->add(*manage(new PIXBUF_IMAGE(collapse_xpm))); m_button_collapse->signal_clicked().connect ( mem_fun(*this, &perfedit::collapse) ); add_tooltip(m_button_collapse, "Collapse pattern between L and R markers."); m_button_copy->add(*manage(new PIXBUF_IMAGE(copy_xpm))); /* expand+copy */ m_button_copy->signal_clicked().connect(mem_fun(*this, &perfedit::copy)); add_tooltip(m_button_copy, "Expand and copy between the L and R markers."); m_button_loop->add(*manage(new PIXBUF_IMAGE(loop_xpm))); m_button_loop->signal_toggled().connect ( mem_fun(*this, &perfedit::set_looped) ); add_tooltip(m_button_loop, "Playback looped between the L and R markers."); m_button_stop->set_focus_on_click(false); m_button_stop->add(*manage(new PIXBUF_IMAGE(stop_xpm))); m_button_stop->signal_clicked().connect ( mem_fun(*this, &perfedit::stop_playing) ); add_tooltip(m_button_stop, "Stop playback."); m_button_stop->set_sensitive(true); m_button_play->set_focus_on_click(false); m_button_play->set_image(*m_image_play); m_button_play->signal_clicked().connect ( mem_fun(*this, &perfedit::start_playing) ); add_tooltip(m_button_play, "Begin playback at the L marker."); m_button_play->set_sensitive(true); #ifdef SEQ64_STAZED_JACK_SUPPORT m_button_jack->add(*manage(new PIXBUF_IMAGE(jack_black_xpm))); m_button_jack->signal_clicked().connect ( mem_fun(*this, &perfedit::set_jack_mode) ); add_tooltip(m_button_jack, "Toggle JACK sync connection."); if (rc().with_jack_transport()) m_button_jack->set_active(true); m_button_follow->add(*manage(new PIXBUF_IMAGE(transport_follow_xpm))); m_button_follow->signal_clicked().connect ( mem_fun(*this, &perfedit::set_follow_transport) ); add_tooltip(m_button_follow, "Toggle the following of JACK transport."); m_button_follow->set_active(true); #endif m_hlbox->pack_end(*m_button_copy , false, false); m_hlbox->pack_end(*m_button_expand , false, false); m_hlbox->pack_end(*m_button_collapse , false, false); m_hlbox->pack_end(*m_button_undo , false, false); m_hlbox->pack_end(*m_button_redo , false, false); // stazed m_hlbox->pack_start(*m_button_stop , false, false); m_hlbox->pack_start(*m_button_play , false, false); m_hlbox->pack_start(*m_button_loop , false, false); m_hlbox->pack_start(*m_button_bpm , false, false); m_hlbox->pack_start(*m_entry_bpm , false, false); m_hlbox->pack_start(*(manage(new Gtk::Label("/"))), false, false, 4); m_hlbox->pack_start(*m_button_bw , false, false); m_hlbox->pack_start(*m_entry_bw , false, false); m_hlbox->pack_start(*(manage(new Gtk::Label("x"))), false, false, 4); m_hlbox->pack_start(*m_button_snap , false, false); m_hlbox->pack_start(*m_entry_snap , false, false); #ifdef SEQ64_STAZED_TRANSPOSE m_hlbox->pack_start(*m_button_xpose , false, false); m_hlbox->pack_start(*m_entry_xpose , false, false); #endif #ifdef SEQ64_STAZED_JACK_SUPPORT m_hlbox->pack_start(*m_button_jack, false, false); m_hlbox->pack_start(*m_button_follow, false, false); #endif add(*m_table); /* * Here, the set_snap call depends on the others being done first. These * calls also depend upon the values being set to bogus (0) values in the * initializer list, otherwise no change will occur, and the items won't * be displayed. */ set_beats_per_bar(SEQ64_DEFAULT_BEATS_PER_MEASURE); /* time-sig numerator */ set_beat_width(SEQ64_DEFAULT_BEAT_WIDTH); /* time-sig denominator */ set_snap(SEQ64_DEFAULT_PERFEDIT_SNAP); #ifdef SEQ64_STAZED_TRANSPOSE set_transpose(0); #endif /* * Log the pointer to the appropriate perfedit object, if not already * done. */ if (second_perfedit) { if (is_nullptr(gs_perfedit_pointer_1)) gs_perfedit_pointer_1 = this; } else { if (is_nullptr(gs_perfedit_pointer_0)) gs_perfedit_pointer_0 = this; } }
bool variant::convert(const type& target_type, variant& target_var) const { if (!is_valid()) return false; bool ok = false; const type source_type = get_type(); const bool source_is_arithmetic = source_type.is_arithmetic(); const bool target_is_arithmetic = target_type.is_arithmetic(); const type string_type = type::get<std::string>(); if (target_type == source_type) { target_var = *this; return true; // the current variant is already the target type, we don't need to do anything } else if (!source_type.is_wrapper() && target_type.is_wrapper() && target_type.get_wrapped_type() == source_type) { target_var = create_wrapped_value(target_type); ok = target_var.is_valid(); } else if (source_type.is_wrapper() && !target_type.is_wrapper()) { variant var = extract_wrapped_value(); ok = var.convert(target_type); target_var = var; } else if ((source_is_arithmetic && target_is_arithmetic) || (source_is_arithmetic && target_type == string_type) || (source_type == string_type && target_is_arithmetic) || (source_type.is_enumeration() && target_is_arithmetic) || (source_type.is_enumeration() && target_type == string_type)) { if (target_type == type::get<bool>()) { bool value; if ((ok = try_basic_type_conversion(value)) == true) target_var = value; } else if (target_type == type::get<char>()) { char value; if ((ok = try_basic_type_conversion(value)) == true) target_var = value; } else if (target_type == type::get<int8_t>()) { int8_t value; if ((ok = try_basic_type_conversion(value)) == true) target_var = value; } else if (target_type == type::get<int16_t>()) { int16_t value; if ((ok = try_basic_type_conversion(value)) == true) target_var = value; } else if (target_type == type::get<int32_t>()) { int32_t value; if ((ok = try_basic_type_conversion(value)) == true) target_var = value; } else if (target_type == type::get<int64_t>()) { int64_t value; if ((ok = try_basic_type_conversion(value)) == true) target_var = value; } else if (target_type == type::get<uint8_t>()) { uint8_t value; if ((ok = try_basic_type_conversion(value)) == true) target_var = value; } else if (target_type == type::get<uint16_t>()) { uint16_t value; if ((ok = try_basic_type_conversion(value)) == true) target_var = value; } else if (target_type == type::get<uint32_t>()) { uint32_t value; if ((ok = try_basic_type_conversion(value)) == true) target_var = value; } else if (target_type == type::get<uint64_t>()) { uint64_t value; if ((ok = try_basic_type_conversion(value)) == true) target_var = value; } else if (target_type == type::get<float>()) { float value; if ((ok = try_basic_type_conversion(value)) == true) target_var = value; } else if (target_type == type::get<double>()) { double value; if ((ok = try_basic_type_conversion(value)) == true) target_var = value; } else if (target_type == string_type) { std::string value; if ((ok = try_basic_type_conversion(value)) == true) target_var = std::move(value); } } else if ((source_is_arithmetic || source_type == string_type) && target_type.is_enumeration()) { variant var = target_type; auto wrapper = std::ref(var); if ((ok = try_basic_type_conversion(wrapper)) == true) target_var = std::move(var); } else { if (const auto& converter = source_type.get_type_converter(target_type)) { void* ptr = get_ptr(); target_var = converter->to_variant(ptr, ok); } else if (target_type == type::get<std::nullptr_t>() && is_nullptr()) { target_var = nullptr; ok = true; } else if (source_type.is_pointer() && (source_type.get_pointer_dimension() == 1 && target_type.get_pointer_dimension() == 1)) { void* raw_ptr = get_raw_ptr(); if (void* casted_ptr = type::apply_offset(raw_ptr, source_type, target_type)) { // although we forward a void* to create a variant, // it will create a variant for the specific class type target_var = target_type.create_variant(casted_ptr); if (target_var.is_valid()) ok = true; } } } return ok; }