1 // Licensed GNU LGPL v3 or later: http://www.gnu.org/licenses/lgpl.html
2
3 #include "smmorphplancontrol.hh"
4 #include "smfixedgrid.hh"
5 #include "smlabel.hh"
6 #include "smtimer.hh"
7 #include "smproject.hh"
8
9 using namespace SpectMorph;
10
11 using std::string;
12
MorphPlanControl(Widget * parent,MorphPlanPtr plan)13 MorphPlanControl::MorphPlanControl (Widget *parent, MorphPlanPtr plan) :
14 Frame (parent),
15 morph_plan (plan)
16 {
17 FixedGrid grid;
18
19 Label *title_label = new Label (this, "Global Instrument Settings");
20 title_label->set_align (TextAlign::CENTER);
21 title_label->set_bold (true);
22
23 grid.add_widget (title_label, 0, 0, 43, 4);
24
25 int voffset = 4;
26
27 volume_slider = new Slider (this, 0);
28 volume_value_label = new Label (this, "");
29 midi_led = new Led (this, false);
30
31 connect (volume_slider->signal_value_changed, this, &MorphPlanControl::on_volume_changed);
32
33 grid.add_widget (new Label (this, "Volume"), 2, voffset, 7, 2);
34 grid.add_widget (volume_slider, 8, voffset, 23, 2);
35 grid.add_widget (volume_value_label, 32, voffset, 7, 2);
36 grid.add_widget (midi_led, 39, voffset, 2, 2);
37
38 // initial value
39 set_volume (plan->project()->volume());
40
41 voffset += 2;
42
43 inst_status = new Label (this, "");
44 grid.add_widget (inst_status, 2, voffset, 40, 2);
45
46 voffset += 2;
47 m_view_height = voffset + 1;
48
49 connect (plan->signal_index_changed, this, &MorphPlanControl::on_index_changed);
50 connect (plan->project()->signal_volume_changed, this, &MorphPlanControl::on_project_volume_changed);
51
52 /* --- update led each time process_events() is called: --- */
53 Timer *led_timer = new Timer (this);
54 connect (led_timer->signal_timeout, this, &MorphPlanControl::on_update_led);
55 led_timer->start (0);
56
57
58 on_index_changed();
59 }
60
61 void
set_volume(double v_db)62 MorphPlanControl::set_volume (double v_db)
63 {
64 volume_slider->set_value ((v_db + 48) / 60); // map [-48:12] -> [0:1]
65 update_volume_label (v_db);
66 }
67
68 void
on_project_volume_changed(double new_volume)69 MorphPlanControl::on_project_volume_changed (double new_volume)
70 {
71 // Project volume changed (relevant: load)
72 set_volume (new_volume);
73 }
74
75 void
on_volume_changed(double new_volume)76 MorphPlanControl::on_volume_changed (double new_volume)
77 {
78 // Gui slider changed
79 double new_volume_f = new_volume * 60 - 48; // map [0:1] -> [-48:12]
80 update_volume_label (new_volume_f);
81
82 morph_plan->project()->set_volume (new_volume_f);
83 }
84
85 void
update_volume_label(double volume)86 MorphPlanControl::update_volume_label (double volume)
87 {
88 volume_value_label->set_text (string_locale_printf ("%.1f dB", volume));
89 }
90
91 void
on_update_led()92 MorphPlanControl::on_update_led()
93 {
94 midi_led->set_on (morph_plan->project()->voices_active());
95 }
96
97 void
on_index_changed()98 MorphPlanControl::on_index_changed()
99 {
100 string text;
101 bool red = false;
102
103 if (morph_plan->index()->type() == INDEX_INSTRUMENTS_DIR)
104 {
105 if (morph_plan->index()->load_ok())
106 {
107 text = string_printf ("Loaded '%s' Instrument Set.", morph_plan->index()->dir().c_str());
108 }
109 else
110 {
111 red = true;
112 text = string_printf ("Instrument Set '%s' NOT FOUND.", morph_plan->index()->dir().c_str());
113 }
114 #if 0
115 inst_status->setToolTip (QString ("Instrument Set is \"%1\".\nThis Instrument Set filename is \"%2\".") .
116 arg (morph_plan->index()->dir().c_str()) .
117 arg (morph_plan->index()->expanded_filename().c_str()));
118 #endif
119 }
120 if (morph_plan->index()->type() == INDEX_FILENAME)
121 {
122 if (morph_plan->index()->load_ok())
123 {
124 text = string_printf ("Loaded Custom Instrument Set.");
125 }
126 else
127 {
128 red = true;
129 text = string_printf ("Custom Instrument Set NOT FOUND.");
130 }
131 #if 0
132 inst_status->setToolTip (QString ("Custom Instrument Set is \"%1\".").arg (morph_plan->index()->filename().c_str()));
133 #endif
134 }
135 if (morph_plan->index()->type() == INDEX_NOT_DEFINED)
136 {
137 red = true;
138 text = string_printf ("NEED TO LOAD Instrument Set.");
139 #if 0
140 inst_status->setToolTip ("Instrument Set is empty.");
141 #endif
142 }
143 if (red)
144 inst_status->set_color (Color (1.0, 0.0, 0.0));
145 else
146 inst_status->set_color (ThemeColor::TEXT);
147 inst_status->set_text (text);
148 }
149
150 double
view_height()151 MorphPlanControl::view_height()
152 {
153 return m_view_height;
154 }
155