Commit 07278356 authored by René Rössler's avatar René Rössler 😍
Browse files

lots of code changes after some clippy::pedantic

parent e1a7dfda
Pipeline #104662219 passed with stage
in 10 minutes and 7 seconds
......@@ -105,7 +105,7 @@ fn cycle_render_group(
fn animate(
config: &Arc<RwLock<RendererConfig>>,
context: &Context,
size: Size,
size: &Size,
main_progress: f64,
live: bool,
) {
......@@ -129,10 +129,7 @@ fn animate(
}
/// Iterate over all measurement points in currently selected render group and read its color from the given image
fn get_colors(
image_live: &mut Image,
measurement_points: &MeasurementPoints,
) -> Option<()> {
fn get_colors(image_live: &mut Image, measurement_points: &MeasurementPoints) -> Option<()> {
let master_dimmer = {
let state = STATE.read().unwrap();
state.master_dimmer
......@@ -165,7 +162,7 @@ fn get_colors(
}
/// Plit svg on Cairo context
fn plit_svg(context: &Context, image_svg: Arc<Mutex<Option<Image>>>) {
fn plit_svg(context: &Context, image_svg: &Arc<Mutex<Option<Image>>>) {
let (elapsed, _) = measure_time(|| {
if let Some(image_svg) = image_svg.lock().unwrap().as_mut() {
image_svg.with_surface(|image_svg| {
......@@ -221,7 +218,7 @@ pub fn spawn(renderer: &Renderer) {
if !STATE.read().unwrap().blackout {
let (elapsed, _) = measure_time(|| {
animate(&config, &context, size, main_progress, true);
animate(&config, &context, &size, main_progress, true);
});
debug!("Animation: {:?}", elapsed);
}
......@@ -242,7 +239,7 @@ pub fn spawn(renderer: &Renderer) {
context.set_source_surface(&image_live, 0., 0.);
context.paint();
plit_svg(&context, image_svg);
plit_svg(&context, &image_svg);
context.set_source_rgb(0., 0., 0.);
});
}
......@@ -275,12 +272,12 @@ pub fn spawn(renderer: &Renderer) {
context.save();
let (elapsed, _) = measure_time(|| {
animate(&config, &context, size, main_progress, false);
animate(&config, &context, &size, main_progress, false);
});
debug!("Animation: {:?}", elapsed);
context.restore();
plit_svg(&context, image_svg);
plit_svg(&context, &image_svg);
context.set_source_rgb(0., 0., 0.);
}));
......
......@@ -33,7 +33,7 @@ pub enum Animation {
impl Default for Animation {
fn default() -> Self {
Animation::Test(test::Animation {})
Self::Test(test::Animation {})
}
}
......
......@@ -26,7 +26,7 @@ pub struct Animation {
impl Default for Animation {
fn default() -> Self {
Animation {
Self {
thickness: Arc::new(RwLock::new(10.)),
direction: Arc::new(RwLock::new(0)),
}
......
......@@ -26,7 +26,7 @@ pub struct Animation {
impl Default for Animation {
fn default() -> Self {
Animation {
Self {
thickness: Arc::new(RwLock::new(10.)),
orientation: Arc::new(RwLock::new(0)),
}
......
......@@ -24,7 +24,7 @@ pub struct Animation {
impl Default for Animation {
fn default() -> Self {
Animation {
Self {
file: Arc::new(RwLock::new(None)),
zoom: Arc::new(RwLock::new(1.)),
image: Arc::new(Mutex::new(None)),
......
......@@ -28,7 +28,7 @@ pub struct Animation {
impl Default for Animation {
fn default() -> Self {
Animation {
Self {
thickness: Arc::new(RwLock::new(10.)),
direction: Arc::new(RwLock::new(0)),
}
......
......@@ -97,7 +97,7 @@ pub struct Animation {
impl Default for Animation {
fn default() -> Self {
Animation {
Self {
min_size: Arc::new(RwLock::new(0.)),
max_size: Arc::new(RwLock::new(0.1)),
min_count: Arc::new(RwLock::new(0.)),
......
......@@ -18,7 +18,7 @@ enum Direction {
}
impl Direction {
fn opposite(self) -> Direction {
fn opposite(self) -> Self {
match self {
Self::Up => Self::Down,
Self::Down => Self::Up,
......@@ -78,8 +78,8 @@ impl Snake {
direction: Direction::random(),
point_type: DirectionPointType::Normal,
};
Snake {
color_index: rng.gen_range(0, std::usize::MAX),
Self {
color_index: rng.gen_range(0, usize::max_value()),
points: vec![dp.clone(), dp],
last_progress: 0.,
}
......@@ -294,7 +294,7 @@ pub struct Animation {
impl Default for Animation {
fn default() -> Self {
Animation {
Self {
count: Arc::new(RwLock::new(1.)),
thickness: Arc::new(RwLock::new(30.)),
speed: Arc::new(RwLock::new(100.)),
......
......@@ -26,7 +26,7 @@ pub struct Animation {
impl Default for Animation {
fn default() -> Self {
Animation {
Self {
thickness: Arc::new(RwLock::new(10.)),
direction: Arc::new(RwLock::new(0)),
}
......
......@@ -23,13 +23,13 @@ pub struct Circle {
}
impl Circle {
fn new() -> Circle {
fn new() -> Self {
let mut rng = thread_rng();
let start_radius = rng.gen_range(0.1, 0.9);
let start_perimeter = rng.gen_range(0.6, 0.8);
Circle {
Self {
alpha: rng.gen_range(0.3, 0.8),
start_radius,
middle_radius: start_radius + rng.gen_range(-0.1, 0.1),
......@@ -94,7 +94,7 @@ pub struct Animation {
impl Default for Animation {
fn default() -> Self {
Animation {
Self {
thickness: Arc::new(RwLock::new(10.)),
count: Arc::new(RwLock::new(5.)),
circles: Arc::new(Mutex::new(vec![])),
......
......@@ -19,8 +19,8 @@ use std::{
/// Determine data for all leds which are affected by the selected render group based on their fixture. Currently only `RGB` is supported.
fn prepare_data(
universes: &mut HashMap<u16, Vec<u8>>,
measurement_points: MeasurementPoints,
config: Arc<RwLock<RendererConfig>>,
measurement_points: &MeasurementPoints,
config: &Arc<RwLock<RendererConfig>>,
) {
let measurement_points = measurement_points.read().unwrap();
let config = config.read().unwrap();
......@@ -102,8 +102,8 @@ pub fn spawn() {
let renderer = renderer.read().unwrap();
prepare_data(
&mut universes,
renderer.measurement_points.clone(),
renderer.config.clone(),
&renderer.measurement_points,
&renderer.config,
);
});
}
......@@ -120,7 +120,7 @@ pub fn spawn() {
})
.ok()
.as_mut()
.and_then(|addr| addr.next())
.and_then(std::iter::Iterator::next)
} {
send_data(&universes, &socket, addr);
}
......
......@@ -125,11 +125,11 @@ pub fn has_unsaved_changes() -> bool {
pub fn has_ui_changes() -> bool {
let mut ui_hash = UI_HASH.lock().unwrap();
let hash = Some(STATE.read().unwrap().hash());
if *ui_hash != hash {
if *ui_hash == hash {
false
} else {
*ui_hash = hash;
true
} else {
false
}
}
......
......@@ -28,22 +28,32 @@ fn read_svg_file(file_path: &Path) -> String {
/// Recursivly traverse nodes and read parameters
fn traverse_node(
parameters: &mut HashMap<String, Parameter>,
node: Node,
node: &Node,
start: u32,
parents: HashSet<String>,
parents: &HashSet<String>,
) {
node.children()
.svg()
.filter(|(id, _child)| *id != ElementId::Desc)
.map(|(_id, child)| child)
.filter_map(|(id, child)| {
if id == ElementId::Desc {
None
} else {
Some(child)
}
})
.for_each(|node| {
let mut start = start;
let mut parents = parents.clone();
if let Some(mut parameter) = node
.children()
.svg()
.filter(|(id, _child)| *id == ElementId::Desc)
.map(|(_id, child)| child)
.filter_map(|(id, child)| {
if id == ElementId::Desc {
Some(child)
} else {
None
}
})
.nth(0)
.and_then(|child| child.children().nth(0))
.and_then(|child| {
......@@ -66,7 +76,7 @@ fn traverse_node(
parameters.insert(node.id().clone(), parameter);
}
traverse_node(parameters, node, start, parents);
traverse_node(parameters, &node, start, &parents);
});
}
......@@ -85,7 +95,7 @@ pub fn tree(file_path: &PathBuf) -> (HashMap<String, Parameter>, Tree) {
let doc = Document::from_str(&svg_data).expect("Could not parse file");
let mut parameters = HashMap::new();
traverse_node(&mut parameters, doc.root(), 0, HashSet::new());
traverse_node(&mut parameters, &doc.root(), 0, &HashSet::new());
let opt = resvg::usvg::Options {
keep_named_groups: true,
..Default::default()
......
......@@ -27,7 +27,7 @@ pub enum Timing {
impl Default for Timing {
fn default() -> Self {
Timing::Forward
Self::Forward
}
}
......
//! Animation settings for the user interface:
//! * File
//! * Range
//! * Selection
//! * SelectionClosure: Call a closure when the selection changed
//! * `File`
//! * `Range`
//! * `Selection`
//! * `SelectionClosure`: Call a closure when the selection changed
use std::{
path::PathBuf,
......
......@@ -12,7 +12,7 @@ pub struct AutoCycle {
impl Default for AutoCycle {
fn default() -> Self {
AutoCycle {
Self {
duration: Duration::from_secs(5),
on: false,
random: true,
......
......@@ -11,7 +11,7 @@ pub struct Configuration {
impl Default for Configuration {
fn default() -> Self {
Configuration {
Self {
fps: 60,
artnet_broadcast: "192.168.100.255".to_owned(),
}
......
......@@ -13,7 +13,7 @@ pub struct Image {
impl Image {
// Creates a new, black image
pub fn new(width: usize, height: usize) -> Self {
Image {
Self {
data: Some(vec![0; 4 * width * height].into()),
width,
height,
......
......@@ -52,7 +52,7 @@ impl Parameter {
impl Default for Parameter {
fn default() -> Self {
Parameter {
Self {
fixture: "rgb".to_owned(),
render_groups: vec![],
start: 0,
......
......@@ -11,7 +11,7 @@ pub struct Point {
impl Point {
pub fn new(x: f64, y: f64) -> Self {
Point { x, y }
Self { x, y }
}
pub fn shift(&mut self, delta_x: f64, delta_y: f64) {
......@@ -22,7 +22,7 @@ impl Point {
impl From<(f64, f64)> for Point {
fn from(v: (f64, f64)) -> Self {
Point::new(v.0, v.1)
Self::new(v.0, v.1)
}
}
......
......@@ -61,7 +61,7 @@ pub struct Renderer {
impl Default for Renderer {
fn default() -> Self {
Renderer {
Self {
config: Arc::new(RwLock::new(RendererConfig {
..Default::default()
})),
......@@ -94,7 +94,7 @@ impl Renderer {
}
/// Plit a rendererd animation onto a given context
pub fn render_on_context(&self, context: &Context, size: Size, live: bool) {
pub fn render_on_context(&self, context: &Context, size: &Size, live: bool) {
let scaling_factor = {
let config = self.config.read().unwrap();
let sx = size.width as f64 / config.size.width as f64;
......
......@@ -10,7 +10,7 @@ pub struct Size {
impl Default for Size {
fn default() -> Self {
Size {
Self {
width: 500,
height: 500,
}
......
//! State of gled
//! * list of renderers
//! * main configuration
//! * current bpm (duration_milliseconds)
//! * current bpm (`duration_milliseconds`)
//! * master dimmer
//! * blackout state
......@@ -44,7 +44,7 @@ pub struct State {
impl Default for State {
fn default() -> Self {
State {
Self {
config: Configuration {
..Default::default()
},
......
......@@ -12,18 +12,20 @@ use structopt::StructOpt;
#[cfg(feature = "installer")]
fn install(opts: &Opts) {
if opts.install {
match installer::install() {
Err(err) => println!("Error installing gled: {:?}", err),
Ok(_) => println!("Successfully installed gled"),
if let Err(err) = installer::install() {
println!("Error installing gled: {:?}", err)
} else {
println!("Successfully installed gled")
};
std::process::exit(0);
}
if opts.uninstall {
match installer::uninstall() {
Err(err) => println!("Error uninstalling gled: {:?}", err),
Ok(_) => println!("Successfully uninstalled gled"),
if let Err(err) = installer::uninstall() {
println!("Error uninstalling gled: {:?}", err)
} else {
println!("Successfully uninstalled gled")
};
std::process::exit(0);
......@@ -39,7 +41,7 @@ fn main() {
install(&opts);
gled::init();
let application = if !opts.noui { Some(ui::init()) } else { None };
let application = if opts.noui { None } else { Some(ui::init()) };
if let Some(file) = opts.file.as_ref() {
gled::load_state(file.to_path_buf()).expect("Could not open project");
......
......@@ -41,7 +41,7 @@ pub struct Dirty {
palettes: AtomicBool,
}
fn create_window(renderer: Arc<RwLock<Renderer>>, application: &Application) {
fn create_window(renderer: &Arc<RwLock<Renderer>>, application: &Application) {
let ignore_signals = Arc::new(AtomicBool::new(true));
let dirty = Arc::new(Dirty {
presets: AtomicBool::new(true),
......@@ -64,44 +64,27 @@ fn create_window(renderer: Arc<RwLock<Renderer>>, application: &Application) {
update_ui.clone(),
ignore_signals.clone(),
);
drawing_area::init(&builder, renderer.clone(), true);
drawing_area::init(&builder, renderer.clone(), false);
drawing_area::init(&builder, &renderer, true);
drawing_area::init(&builder, &renderer, false);
file_menu::init(&builder, renderer.clone(), application);
frozen::init(&builder, renderer.clone());
icon::init(&builder);
master_dimmer::init(&builder, ignore_signals.clone());
palettes::init(
&builder,
renderer.clone(),
update_ui.clone(),
ignore_signals.clone(),
dirty.clone(),
);
preferences::init(&builder, renderer.clone(), ignore_signals.clone());
presets::init(
&builder,
renderer.clone(),
update_ui.clone(),
ignore_signals.clone(),
dirty.clone(),
);
palettes::init(&builder, &renderer, &update_ui, &ignore_signals, &dirty);
preferences::init(&builder, renderer.clone(), &ignore_signals);
presets::init(&builder, &renderer, &update_ui, &ignore_signals, &dirty);
preview_to_live::init(&builder, renderer.clone(), update_ui.clone(), dirty);
render_groups::init(
&builder,
renderer.clone(),
update_ui.clone(),
ignore_signals.clone(),
);
render_groups::init(&builder, &renderer, &update_ui, &ignore_signals);
tap::init(&builder);
update_fps::init(&builder, renderer.clone());
window::init(&builder, renderer.clone(), application);
let _ = update_ui.send(UpdateUiConfig::default());
show(&builder, renderer);
show(&builder, &renderer);
ignore_signals.store(false, Ordering::Relaxed);
}
fn show(builder: &Builder, renderer: Arc<RwLock<Renderer>>) {
fn show(builder: &Builder, renderer: &Arc<RwLock<Renderer>>) {
info!("It's show time");
let window = builder.get_object::<Window>("window").unwrap();
window.show_all();
......@@ -139,7 +122,7 @@ pub fn open_windows(application: &Application) {
};
renderers
.iter()
.for_each(|renderer| create_window(renderer.clone(), application));
.for_each(|renderer| create_window(&renderer, application));
}
pub fn add_recent(path: &Path) {
......@@ -152,7 +135,7 @@ pub fn add_recent(path: &Path) {
if let (Some(recent_manager), Some(path), Some(file_name)) = (
RecentManager::get_default(),
path.to_str(),
path.file_name().and_then(|file_name| file_name.to_str()),
path.file_name().and_then(std::ffi::OsStr::to_str),
) {
let item = &format!("file://{}", path);
if recent_manager.add_full(
......
......@@ -6,7 +6,7 @@ use std::{
thread,
};
pub fn init(builder: &Builder, renderer: Arc<RwLock<Renderer>>, live: bool) {
pub fn init(builder: &Builder, renderer: &Arc<RwLock<Renderer>>, live: bool) {
let drawing_area: gtk::DrawingArea = builder
.get_object(if live {
"drawing_area"
......@@ -25,7 +25,7 @@ pub fn init(builder: &Builder, renderer: Arc<RwLock<Renderer>>, live: bool) {
};
let renderer = renderer.read().unwrap();
renderer.render_on_context(context, size, live);
renderer.render_on_context(context, &size, live);
Inhibit(false)
}));
......
......@@ -14,10 +14,10 @@ use std::{
pub fn init(
builder: &Builder,
renderer: Arc<RwLock<Renderer>>,
update_ui: Sender<UpdateUiConfig>,
ignore_signals: Arc<AtomicBool>,
dirty: Arc<Dirty>,
renderer: &Arc<RwLock<Renderer>>,
update_ui: &Sender<UpdateUiConfig>,
ignore_signals: &Arc<AtomicBool>,
dirty: &Arc<Dirty>,
) {
let palettes = builder.get_object::<TreeView>("palettes").unwrap();
let palettes_model = builder.get_object::<ListStore>("palettes_model").unwrap();
......@@ -236,7 +236,7 @@ pub fn init(
palettes_cycle_duration.connect_format_value(|_, value| format!("{:.0} s", value));
}
pub fn update_ui(builder: &Builder, renderer: &Renderer, dirty: Arc<Dirty>) {
pub fn update_ui(builder: &Builder, renderer: &Renderer, dirty: &Arc<Dirty>) {
let palettes = builder.get_object::<TreeView>("palettes").unwrap();
let palettes_model = builder.get_object::<ListStore>("palettes_model").unwrap();
let palettes_cycle_label = builder.get_object::<Label>("palettes_cycle_label").unwrap();
......@@ -255,13 +255,12 @@ pub fn update_ui(builder: &Builder, renderer: &Renderer, dirty: Arc<Dirty>) {
let is_dirty = dirty.palettes.load(Relaxed)
|| palettes_model
.get_iter(&TreePath::new_from_indicesv(&[config.live_palette as i32]))
.map(|iter| {
.map_or(false, |iter| {
!palettes_model
.get_value(&iter, 2)
.get::<bool>()
.expect("Couldn't get bool value")
})
.unwrap_or(false);
});
if is_dirty {
dirty.palettes.store(false, Relaxed);
palettes_model.clear();
......