Skip to content

Commit 6d150ea

Browse files
committed
Added some extra options: max gain, and reset buttons
1 parent 64f0f6b commit 6d150ea

File tree

1 file changed

+37
-4
lines changed

1 file changed

+37
-4
lines changed

src/main.rs

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ struct FslcMix {
137137
master: MixChannel,
138138
normalize: bool,
139139
ui_size: egui::Vec2,
140+
max_gain: f32,
140141
}
141142

142143
impl FslcMix {
@@ -155,6 +156,7 @@ impl FslcMix {
155156
normalize: false,
156157
ui_size: egui::Vec2::new(400.0, 330.0), // This size doesn't matter since it's
157158
// overritten
159+
max_gain: 1.25,
158160
}
159161
}
160162

@@ -213,7 +215,27 @@ impl FslcMix {
213215
ui.vertical(|ui| {
214216
ui.horizontal(|ui| {
215217
// ui.label("Licensed under the GPLv3.");
218+
ui.label("Max Gain:");
219+
let slider = ui.add(egui::DragValue::new(&mut self.max_gain).range(1.1..=2.0));
220+
if slider.changed() {
221+
self.update_max_gain();
222+
}
223+
let btn = ui.button("Reset");
224+
if btn.clicked() {
225+
self.max_gain = 1.2;
226+
self.update_max_gain();
227+
}
216228
ui.toggle_value(&mut self.normalize, "Normalize");
229+
if ui.add(egui::Button::new("All Unmute").frame(false)).clicked() {
230+
for channel in &mut self.channels {
231+
channel.mute = false;
232+
}
233+
}
234+
if ui.add(egui::Button::new("All Unsolo").frame(false)).clicked() {
235+
for channel in &mut self.channels {
236+
channel.solo = false;
237+
}
238+
}
217239
});
218240
});
219241
ui.horizontal(|ui| {
@@ -232,6 +254,15 @@ impl FslcMix {
232254
// frame.set_window_size(window_size);
233255
// frame.request_repaint();
234256
}
257+
258+
fn update_max_gain(&mut self) {
259+
// update max gain for all channels
260+
for channel in &mut self.channels {
261+
channel.max_gain = self.max_gain;
262+
}
263+
self.master.max_gain = self.max_gain;
264+
265+
}
235266
}
236267

237268
struct MixChannel {
@@ -247,6 +278,7 @@ struct MixChannel {
247278
solo: bool,
248279
others_solo: bool,
249280
show_rms: bool,
281+
max_gain: f32,
250282
}
251283

252284
impl MixChannel {
@@ -304,7 +336,7 @@ impl MixChannel {
304336
});
305337
ui.horizontal(|ui| {
306338
ui.spacing_mut().slider_width = 175.0;
307-
ui.add(egui::Slider::new(&mut self.gain, 0.0..=1.2)
339+
ui.add(egui::Slider::new(&mut self.gain, 0.0..=self.max_gain)
308340
//.text("Gain")
309341
.vertical()
310342
.max_decimals(2));
@@ -342,7 +374,7 @@ impl MixChannel {
342374
};
343375
let (rect, response) = ui.allocate_exact_size(vec2(10.0, 190.0), egui::Sense::hover());
344376
let painter = ui.painter();
345-
let filled_height = (rect.height() * val / 1.2).min(rect.height()); // Show a bit over max amplitude
377+
let filled_height = (rect.height() * val / self.max_gain).min(rect.height()); // Show a bit over max amplitude
346378
// let filled_rect = Rect::from_min_max(rect.min, rect.min + vec2(rect.width(), filled_height));
347379
// let remaining_rect = Rect::from_min_max(filled_rect.max, rect.max);
348380
let filled_rect = Rect::from_min_max(rect.max - vec2(rect.width(), filled_height), rect.max);
@@ -351,15 +383,15 @@ impl MixChannel {
351383
let color_saturation = if self.mute || (!self.solo && self.others_solo) { 50 } else { 200 };
352384
let color = if val < 1.0 {
353385
Color32::from_rgb(0, color_saturation, 0)
354-
} else if val < 1.2 {
386+
} else if val < self.max_gain {
355387
Color32::from_rgb(color_saturation, color_saturation, 0)
356388
} else {
357389
Color32::from_rgb(color_saturation, 0, 0)
358390
};
359391
painter.rect_filled(filled_rect, 0.0, color);
360392
painter.rect_stroke(rect, 0.0, (1.0, Color32::DARK_GRAY));
361393
// Draw scale numbers
362-
let num_steps = 12;
394+
let num_steps = (self.max_gain * 10.0) as u16;
363395
let step_size = rect.height() / num_steps as f32;
364396
for i in 0..=num_steps {
365397
let y_pos = rect.top() + i as f32 * step_size;
@@ -415,6 +447,7 @@ impl Default for MixChannel {
415447
solo: false,
416448
others_solo: false,
417449
show_rms: false,
450+
max_gain: 1.25,
418451
}
419452
}
420453
}

0 commit comments

Comments
 (0)