Skip to content

Commit

Permalink
Merge pull request #29 from zWolfrost/master
Browse files Browse the repository at this point in the history
added config file & remember window position & gradual audio decrease
  • Loading branch information
Aurailus authored Apr 15, 2024
2 parents 90992c4 + e859a67 commit d75efa7
Show file tree
Hide file tree
Showing 7 changed files with 194 additions and 57 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use shared::Shared;

fn main() {
let pulse = Shared::new(Pulse::new());

let app = gtk::Application::new(Some("com.aurailus.myxer"), Default::default())
.expect("Failed to initialize GTK application.");

Expand Down
36 changes: 17 additions & 19 deletions src/meter/sink_meter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ pub struct SinkMeter {
widgets: MeterWidgets,
pulse: Shared<Pulse>,

split: bool,
peak: Option<u32>,
pub split: bool,
pub peak: Option<u32>,

l_id: Option<glib::signal::SignalHandlerId>,
s_id: Option<glib::signal::SignalHandlerId>,
Expand Down Expand Up @@ -228,24 +228,22 @@ impl Meter for SinkMeter {
}

fn set_peak(&mut self, peak: Option<u32>) {
if self.peak != peak {
self.peak = peak;

if self.peak.is_some() {
for (i, s) in self.widgets.scales_inner.get_children().iter().enumerate() {
let s = s.clone().downcast::<gtk::Scale>().expect("Scales box has non-scale children.");
let peak_scaled = self.peak.unwrap() as f64 * (self.data.volume.get()[i].0 as f64 / MAX_SCALE_VOL as f64);
s.set_fill_level(peak_scaled as f64);
s.set_show_fill_level(!self.data.muted && peak_scaled > 0.5);
s.get_style_context().add_class("visualizer");
}
self.peak = peak;

if self.peak.is_some() {
for (i, s) in self.widgets.scales_inner.get_children().iter().enumerate() {
let s = s.clone().downcast::<gtk::Scale>().expect("Scales box has non-scale children.");
let peak_scaled = self.peak.unwrap() as f64 * (self.data.volume.get()[i].0 as f64 / MAX_SCALE_VOL as f64);
s.set_fill_level(peak_scaled as f64);
s.set_show_fill_level(!self.data.muted && peak_scaled > 0.5);
s.get_style_context().add_class("visualizer");
}
else {
for s in &self.widgets.scales_inner.get_children() {
let s = s.clone().downcast::<gtk::Scale>().expect("Scales box has non-scale children.");
s.set_show_fill_level(false);
s.get_style_context().remove_class("visualizer");
}
}
else {
for s in &self.widgets.scales_inner.get_children() {
let s = s.clone().downcast::<gtk::Scale>().expect("Scales box has non-scale children.");
s.set_show_fill_level(false);
s.get_style_context().remove_class("visualizer");
}
}
}
Expand Down
36 changes: 17 additions & 19 deletions src/meter/stream_meter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ pub struct StreamMeter {
widgets: MeterWidgets,
pulse: Shared<Pulse>,

split: bool,
peak: Option<u32>,
pub split: bool,
pub peak: Option<u32>,

b_id: Option<glib::signal::SignalHandlerId>,
}
Expand Down Expand Up @@ -151,24 +151,22 @@ impl Meter for StreamMeter {
}

fn set_peak(&mut self, peak: Option<u32>) {
if self.peak != peak {
self.peak = peak;

if self.peak.is_some() {
for (i, s) in self.widgets.scales_inner.get_children().iter().enumerate() {
let s = s.clone().downcast::<gtk::Scale>().expect("Scales box has non-scale children.");
let peak_scaled = self.peak.unwrap() as f64 * (self.data.volume.get()[i].0 as f64 / MAX_SCALE_VOL as f64);
s.set_fill_level(peak_scaled as f64);
s.set_show_fill_level(!self.data.muted && peak_scaled > 0.5);
s.get_style_context().add_class("visualizer");
}
self.peak = peak;

if self.peak.is_some() {
for (i, s) in self.widgets.scales_inner.get_children().iter().enumerate() {
let s = s.clone().downcast::<gtk::Scale>().expect("Scales box has non-scale children.");
let peak_scaled = self.peak.unwrap() as f64 * (self.data.volume.get()[i].0 as f64 / MAX_SCALE_VOL as f64);
s.set_fill_level(peak_scaled as f64);
s.set_show_fill_level(!self.data.muted && peak_scaled > 0.5);
s.get_style_context().add_class("visualizer");
}
else {
for s in &self.widgets.scales_inner.get_children() {
let s = s.clone().downcast::<gtk::Scale>().expect("Scales box has non-scale children.");
s.set_show_fill_level(false);
s.get_style_context().remove_class("visualizer");
}
}
else {
for s in &self.widgets.scales_inner.get_children() {
let s = s.clone().downcast::<gtk::Scale>().expect("Scales box has non-scale children.");
s.set_show_fill_level(false);
s.get_style_context().remove_class("visualizer");
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/pulse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ pub struct StreamData {
pub data: MeterData,

pub peak: u32,
pub repetitions: u32,
pub monitor_index: u32,
pub monitor: Shared<Stream>
}
Expand Down Expand Up @@ -599,7 +600,7 @@ impl Pulse {
else {
let source_str = stream.monitor_index.to_string();
let monitor = self.create_monitor_stream(t, if t == StreamType::SinkInput { None } else { Some(&source_str) }, index);
let data = StreamData { data, peak: 0, monitor, monitor_index: stream.monitor_index };
let data = StreamData { data, peak: 0, repetitions: 0, monitor, monitor_index: stream.monitor_index };
match t {
StreamType::Sink => self.sinks.insert(index, data),
StreamType::SinkInput => self.sink_inputs.insert(index, data),
Expand Down
1 change: 1 addition & 0 deletions src/window/about.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub fn about() {
about.set_copyright(Some("© 2021 Auri Collings"));
about.set_license_type(gtk::License::Gpl30);
about.add_credit_section("Created by", &[ "Auri Collings" ]);
about.add_credit_section("With the help of", &[ "zWolfrost" ]);
about.add_credit_section("libpulse-binding by", &[ "Lyndon Brown" ]);

about.connect_response(|about, _| about.close());
Expand Down
Loading

0 comments on commit d75efa7

Please sign in to comment.