From c3cf05372d13f5ddec1a844421a71a4c41ba756b Mon Sep 17 00:00:00 2001 From: Leonard Ritter Date: Wed, 22 Sep 2010 21:40:35 +0200 Subject: [PATCH] ability to mute individual patterns --- jsong.cpp | 2 ++ model.cpp | 1 + model.hpp | 1 + player.cpp | 2 ++ songview.cpp | 33 ++++++++++++++++++++++++++++----- songview.hpp | 1 + 6 files changed, 35 insertions(+), 5 deletions(-) diff --git a/jsong.cpp b/jsong.cpp index a1104e0..3ae1572 100644 --- a/jsong.cpp +++ b/jsong.cpp @@ -47,6 +47,7 @@ void JSongWriter::collect(Json::Value &root, Song::Event &event) { return; root["frame"] = event.frame; root["track"] = event.track; + root["mute"] = event.mute; root["pattern"] = iter->second; } @@ -191,6 +192,7 @@ void JSongReader::build(const Json::Value &root, Pattern &pattern) { bool JSongReader::build(const Json::Value &root, Song::Event &event) { extract(root["frame"], event.frame); extract(root["track"], event.track); + extract(root["mute"], event.mute); int pattern_index = -1; if (!extract(root["pattern"], pattern_index)) return false; diff --git a/model.cpp b/model.cpp index 56103f9..9ff4382 100644 --- a/model.cpp +++ b/model.cpp @@ -268,6 +268,7 @@ SongEvent::SongEvent() { frame = ValueNone; pattern = NULL; track = 0; + mute = false; } SongEvent::SongEvent(int frame, int track, Pattern &pattern) { diff --git a/model.hpp b/model.hpp index 81c4f0c..f23c5b8 100644 --- a/model.hpp +++ b/model.hpp @@ -173,6 +173,7 @@ protected: struct SongEvent { int frame; int track; + bool mute; Pattern *pattern; SongEvent(); diff --git a/player.cpp b/player.cpp index 6b07ffd..4c33747 100644 --- a/player.cpp +++ b/player.cpp @@ -278,6 +278,8 @@ void Player::mix_frame(MessageQueue &queue) { Song::Event &event = (*iter)->second; Pattern &pattern = *event.pattern; + if (event.mute) + continue; // ignore event if (model->tracks[event.track].mute) continue; // ignore event diff --git a/songview.cpp b/songview.cpp index 3b888f9..1971287 100644 --- a/songview.cpp +++ b/songview.cpp @@ -13,6 +13,7 @@ enum { ColorBackground, ColorTrack, ColorGhost, + ColorMuted, ColorCount, }; @@ -89,6 +90,7 @@ SongView::SongView(BaseObjectType* cobject, colors[ColorBackground].set("#e0e0e0"); colors[ColorTrack].set("#ffffff"); colors[ColorGhost].set("#606060"); + colors[ColorMuted].set("#A0A0A0"); play_position = 0; cursor_x = 0; cursor_y = 0; @@ -183,8 +185,15 @@ void SongView::render_event(Song::iterator event) { bool selected = is_event_selected(event); int x,y,w,h; get_event_rect(event, x, y, w, h); + + bool mute = event->second.mute; + Gdk::Color color; - if (event->second.pattern->refcount > 1) { + if (mute) { + x += 1; + y += 1; + color = colors[ColorMuted]; + } else if (event->second.pattern->refcount > 1) { color = colors[ColorGhost]; } else { color = colors[ColorBlack]; @@ -192,10 +201,12 @@ void SongView::render_event(Song::iterator event) { // main border gc->set_foreground(color); window->draw_rectangle(gc, false, x, y+1, w, h-3); - // bottom shadow - window->draw_rectangle(gc, true, x+1, y+h-1, w, 1); - // right shadow - window->draw_rectangle(gc, true, x+w+1, y+2, 1, h-2); + if (!mute) { + // bottom shadow + window->draw_rectangle(gc, true, x+1, y+h-1, w, 1); + // right shadow + window->draw_rectangle(gc, true, x+w+1, y+2, 1, h-2); + } pango_layout->set_width((w-4)*Pango::SCALE); pango_layout->set_text(event->second.pattern->name.c_str()); if (selected) { @@ -676,6 +687,17 @@ void SongView::apply_move() { do_move(ofs_frame, ofs_track); } +void SongView::toggle_mute_selection() { + for (Song::IterList::iterator iter = selection.begin(); + iter != selection.end(); ++iter) { + Song::Event &event = (*iter)->second; + event.mute = !event.mute; + } + + invalidate(); +} + + void SongView::do_resize(int ofs_frame) { // verify that we can move for (Song::IterList::iterator iter = selection.begin(); @@ -982,6 +1004,7 @@ bool SongView::on_key_press_event(GdkEventKey* event) { return true; } break; case GDK_p: seek_to_mouse_cursor(); return true; + case GDK_m: toggle_mute_selection(); return true; case GDK_Left: navigate(-1,0); return true; case GDK_Right: navigate(1,0); return true; case GDK_Up: navigate(0,-1); return true; diff --git a/songview.hpp b/songview.hpp index ef025d4..34e691d 100644 --- a/songview.hpp +++ b/songview.hpp @@ -182,6 +182,7 @@ protected: void clone_selection(bool references=false); void join_selection(); + void toggle_mute_selection(); void show_selection();