1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
|
/*
* MetronomeController.cpp
*
* Created on: 2 Oct 2016
* Author: jeremy
*/
#include "MetronomeController.h"
#include <algorithm>
#include <iterator>
using namespace eXaDrumsApi;
namespace Controllers
{
MetronomeController::MetronomeController(Glib::RefPtr<Gtk::Builder> builder, std::shared_ptr<eXaDrums> drumKit)
: builder(builder), drumKit(drumKit)
{
// Get all widgets
{
this->builder->get_widget("MetronomeConfig", metronomeWindow);
this->builder->get_widget("MetronomeConfigSave", metronomeConfigSave);
this->builder->get_widget("MetronomeSoundType", clickTypes);
this->builder->get_widget("ClickTempoScale", clickTempoScale);
this->builder->get_widget("ClickVolumeScale", clickVolumeScale);
this->builder->get_widget("EnableClickButton", enableClickButton);
this->builder->get_widget("RhythmList", rhythmList);
this->builder->get_widget("BpmeasList", bpmeasList);
}
// Connect all signals
{
metronomeConfigSave->signal_clicked().connect([&] { SaveMetronomeConfig(); });
clickTempoScale->signal_value_changed().connect([&] { ChangeTempo(); });
clickVolumeScale->signal_value_changed().connect([&] { ChangeClickVolume(); });
enableClickButton->signal_clicked().connect([&] { EnableClick(); });
}
// Set tempo value
clickTempoScale->set_value(drumKit->GetTempo());
// Metronome not running by defautl
clickVolumeScale->property_sensitive() = false;
// Configure Metronome Window
{
// Append clicks to list
std::vector<std::string> clicks = drumKit->GetClicksTypes();
std::for_each(clicks.cbegin(), clicks.cend(), [this](const std::string& s){ clickTypes->append(s); });
// Get current click type
int clickTypeId = drumKit->GetClickTypeId();
// Select current click type
clickTypes->set_active(clickTypeId);
}
// Populate rhythm list
this->rhythms = drumKit->GetRhythms();
{
// Append rhythms to list
std::for_each(rhythms.cbegin(), rhythms.cend(), [this](int x) { rhythmList->append(std::to_string(x)); });
// Get current rhythm index in vector
auto it = std::find(rhythms.cbegin(), rhythms.cend(), this->drumKit->GetRhythm());
int index = std::distance(rhythms.cbegin(), it);
// Select current rhythm
rhythmList->set_active(index);
}
// Populate beats per measure list
this->bpmeasValues = drumKit->GetBpms();
{
// Append values to list
std::for_each(bpmeasValues.cbegin(), bpmeasValues.cend(), [this](int x) { bpmeasList->append(std::to_string(x));});
// Get current nb of beats per measure's index in vector
auto it = std::find(bpmeasValues.cbegin(), bpmeasValues.cend(), this->drumKit->GetBpmeas());
int index = std::distance(bpmeasValues.cbegin(), it);
// Select current number of beats per measure
bpmeasList->set_active(index);
}
return;
}
MetronomeController::~MetronomeController()
{
// Delete all windows and dialogs
delete metronomeWindow;
return;
}
// Private methods
void MetronomeController::EnableClick() const
{
bool enable = enableClickButton->get_active();
drumKit->EnableMetronome(enable);
clickVolumeScale->property_sensitive() = enable;
clickVolumeScale->set_value(drumKit->GetClickVolume());
return;
}
void MetronomeController::ChangeTempo() const
{
int tempo = (int) this->clickTempoScale->get_value();
drumKit->ChangeTempo(tempo);
return;
}
void MetronomeController::ChangeClickVolume() const
{
int volume = (int) this->clickVolumeScale->get_value();
drumKit->ChangeClickVolume(volume);
clickVolumeScale->property_sensitive() = true;
return;
}
void MetronomeController::ShowMetronomePrefs()
{
metronomeWindow->show();
return;
}
void MetronomeController::SaveMetronomeConfig()
{
// Set new parameters values
drumKit->SetClickType(clickTypes->get_active_row_number());
drumKit->SetRhythm(rhythms[rhythmList->get_active_row_number()]);
drumKit->SetBpmeas(bpmeasValues[bpmeasList->get_active_row_number()]);
drumKit->RestartMetronome();
drumKit->SaveMetronomeConfig();
metronomeWindow->hide();
return;
}
} /* namespace Gui */
|