From d4f74b6c45ad346d0e6765cc3e42fe6bb006dcf5 Mon Sep 17 00:00:00 2001 From: Harry van Haaren Date: Sat, 30 Aug 2014 16:44:09 +0100 Subject: [PATCH] Fixed #86, metronome volume. Use right-click --- src/event.cxx | 2 ++ src/event.hxx | 13 +++++++++++ src/eventhandlerdsp.cxx | 8 +++++++ src/gmastertrack.cxx | 52 +++++++++++++++++++++++++++++++++++++---- src/metronome.cxx | 11 +++++++-- src/metronome.hxx | 3 +++ 6 files changed, 83 insertions(+), 6 deletions(-) diff --git a/src/event.cxx b/src/event.cxx index 94ca6b7..e0337f8 100644 --- a/src/event.cxx +++ b/src/event.cxx @@ -33,6 +33,7 @@ const char* EventTrackRecordArm::prettyName = "track:record_arm"; const char* EventTimeBPM::prettyName = "tempo_bpm"; const char* EventTimeTempoTap::prettyName = "tempo_tap"; const char* EventMetronomeActive::prettyName = "metronome:active"; +const char* EventMetronomeVolume::prettyName = "metronome:volume"; const char* EventGridEvent::prettyName = "grid:event"; const char* EventGridLaunchScene::prettyName = "grid:launch_scene"; @@ -75,6 +76,7 @@ const char* Event::getPrettyName( int type ) case GRID_LAUNCH_SCENE:{ return EventGridLaunchScene::prettyName; } case METRONOME_ACTIVE:{ return EventMetronomeActive::prettyName; } + case METRONOME_VOLUME:{ return EventMetronomeVolume::prettyName; } default: return 0; } diff --git a/src/event.hxx b/src/event.hxx index 20634a2..74d08ca 100644 --- a/src/event.hxx +++ b/src/event.hxx @@ -100,6 +100,7 @@ namespace Event /// Transport etc METRONOME_ACTIVE, + METRONOME_VOLUME, TRANSPORT, /// rolling or stopped TIME_BPM, @@ -566,6 +567,18 @@ class EventMetronomeActive : public EventBase EventMetronomeActive(bool a = false) : active(a) {} }; +class EventMetronomeVolume : public EventBase +{ + public: + int type() { return int(METRONOME_VOLUME); } + uint32_t size() { return sizeof(EventMetronomeVolume); } + static const char* prettyName; + const char* name(){ return prettyName; } + + float vol; + EventMetronomeVolume(float v = 0.f) : vol(v){} +}; + class EventTimeBPM : public EventBase { public: diff --git a/src/eventhandlerdsp.cxx b/src/eventhandlerdsp.cxx index c2463d3..2cd6a0d 100644 --- a/src/eventhandlerdsp.cxx +++ b/src/eventhandlerdsp.cxx @@ -31,6 +31,7 @@ #include "controller/controller.hxx" #include "controller/genericmidi.hxx" #include "eventhandler.hxx" +#include "metronome.hxx" #include "logic.hxx" #include "state/state.hxx" @@ -204,6 +205,13 @@ void handleDspEvents() jack_ringbuffer_read( rbToDsp, (char*)&ev, sizeof(EventMetronomeActive) ); jack->getLogic()->metronomeEnable(ev.active); } break; } + case Event::METRONOME_VOLUME: { + if ( availableRead >= sizeof(EventMetronomeVolume) ) { + EventMetronomeVolume ev(false); + jack_ringbuffer_read( rbToDsp, (char*)&ev, sizeof(EventMetronomeVolume) ); + LUPPP_NOTE("EventDSP: MetroVol %f", ev.vol ); + jack->getMetronome()->setVolume(ev.vol); + } break; } case Event::LOOPER_STATE: { if ( availableRead >= sizeof(EventLooperState) ) { EventLooperState ev; diff --git a/src/gmastertrack.cxx b/src/gmastertrack.cxx index 14f2f78..5c77682 100644 --- a/src/gmastertrack.cxx +++ b/src/gmastertrack.cxx @@ -18,6 +18,8 @@ #include "gmastertrack.hxx" +#include + static void gmastertrack_tempoDial_callback(Fl_Widget *w, void *data) { Avtk::Dial* b = (Avtk::Dial*)w; @@ -131,10 +133,52 @@ static void gmastertrack_button_callback(Fl_Widget *w, void *data) { if ( strcmp( w->label(), "Metro" ) == 0 ) { - Avtk::LightButton* b = (Avtk::LightButton*)w; - b->value( !b->value() ); - EventMetronomeActive e = EventMetronomeActive( b->value() ); - writeToDspRingbuffer( &e ); + if ( Fl::event_button() == FL_RIGHT_MOUSE ) + { + // popup volume menu: 10 "steps of volume" + Fl_Menu_Item rclick_menu[] = + { + { "Vol 100%" }, + { "Vol 75%" }, + { "Vol 50%" }, + { "Vol 25%"}, + { 0 } + }; + + Fl_Menu_Item *m = (Fl_Menu_Item*) rclick_menu->popup( Fl::event_x(), Fl::event_y(), 0, 0, 0); + + float v = 0.f; + if ( !m ) + { + return; + } + else if ( strcmp(m->label(), "Vol 100%") == 0 ) { + v = 1; + } + else if ( strcmp(m->label(), "Vol 75%") == 0 ) { + v = 0.75; + } + else if ( strcmp(m->label(), "Vol 50%") == 0 ) { + v = 0.5; + } + else + v = 0.25; + + LUPPP_NOTE("metro vol = %f", v ); + + EventMetronomeVolume e( v ); + writeToDspRingbuffer( &e ); + } + else + { + Avtk::LightButton* b = (Avtk::LightButton*)w; + b->value( !b->value() ); + EventMetronomeActive e = EventMetronomeActive( b->value() ); + writeToDspRingbuffer( &e ); + } + + + } else if ( strcmp( w->label(), "Tap" ) == 0 ) { diff --git a/src/metronome.cxx b/src/metronome.cxx index 6736787..e0b2e4a 100644 --- a/src/metronome.cxx +++ b/src/metronome.cxx @@ -33,7 +33,8 @@ Metronome::Metronome() : TimeObserver(), playBar (false), active (false), - playPoint (0) + playPoint (0), + vol (1) { // create beat and bar samples endPoint = ( jack->getSamplerate() / 441 ); @@ -57,6 +58,12 @@ void Metronome::setActive(bool a) playPoint = endPoint + 1; } +void Metronome::setVolume( float v ) +{ + vol = v; + printf(" vol = %f \n", vol ); +} + void Metronome::bar() { playPoint = 0; @@ -94,7 +101,7 @@ void Metronome::process(int nframes, Buffers* buffers) { if ( playPoint < endPoint ) { - out[i] += sample[playPoint]; + out[i] += sample[playPoint] * vol; playPoint++; } } diff --git a/src/metronome.hxx b/src/metronome.hxx index 89c5ad1..baacb44 100644 --- a/src/metronome.hxx +++ b/src/metronome.hxx @@ -40,12 +40,15 @@ class Metronome : public TimeObserver void beat(); void setFpb(int f); + void setVolume( float v ); + void process(int nframes, Buffers* buffers); private: int fpb; bool playBar; bool active; + float vol; int playPoint, endPoint; float barSample[44100];