Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removed unused variables, imports and mut #15

Merged
merged 1 commit into from Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/config.rs
Expand Up @@ -2,11 +2,11 @@ use bevy::prelude::Color;
use dirs::home_dir;
use serde::{Deserialize, Serialize};
use serde_yaml::{self};
use std::fs::{create_dir, create_dir_all, read_to_string, File, OpenOptions};
use std::fs::{create_dir_all, read_to_string, File, OpenOptions};
use std::io::BufWriter;
use std::{
fs::remove_file,
io::{stdout, Read, Write},
io::Write,
path::PathBuf,
};

Expand Down Expand Up @@ -136,9 +136,9 @@ pub fn write_fftargs_to_config(args: &FFTArgs) {
overwrite_non_default_args!(&mut default_args.volume, args.volume);

let cfg_path = config_path();
create_dir_all(cfg_path.as_path().parent().unwrap());
create_dir_all(cfg_path.as_path().parent().unwrap()).unwrap();

let mut config_file = OpenOptions::new()
let config_file = OpenOptions::new()
.write(true)
.create(true)
.open(&cfg_path)
Expand All @@ -153,21 +153,22 @@ pub fn write_fftargs_to_config(args: &FFTArgs) {

cfg_yaml.retain(|x| x.contains(":"));

remove_file(&cfg_path);
remove_file(&cfg_path).unwrap();

let f = File::create(&cfg_path).expect("Unable to create file");
let mut f = BufWriter::new(f);
f.write_all(cfg_yaml.join("\n").as_bytes())
.expect("Unable to write data");
}

#[allow(dead_code)]
pub fn reset_config_file() {
let default_user_config = ConfigFFTArgs::default();

let cfg_path = config_path();
create_dir_all(cfg_path.as_path().parent().unwrap());
create_dir_all(cfg_path.as_path().parent().unwrap()).unwrap();

let mut config_file = OpenOptions::new()
let config_file = OpenOptions::new()
.write(true)
.create(true)
.open(cfg_path)
Expand Down
18 changes: 3 additions & 15 deletions src/main.rs
@@ -1,5 +1,3 @@
#![allow(unused)]

mod args;
mod config;
mod fft;
Expand All @@ -12,27 +10,17 @@ use systems::egui::*;
use systems::get_keyboard_input::*;
use systems::startup::*;
use systems::update_fft::*;
use systems::update_frame_counters;
use systems::update_frame_counters::*;
use systems::update_view_settings::*;

use bevy::render::mesh::VertexAttributeValues;
use bevy::sprite::Anchor;
use bevy::{
app::AppExit,
prelude::*,
sprite::{MaterialMesh2dBundle, Mesh2dHandle},
};
use bevy_egui::egui::{Align2, Color32, Stroke};
use bevy_egui::{egui, EguiContexts, EguiPlugin};
use clap::{ArgAction, Parser};
use bevy::prelude::*;
use bevy_egui::EguiPlugin;
use rayon::iter::{IntoParallelRefMutIterator, ParallelIterator};
use rodio::{source::Source, Decoder, OutputStream};
use rodio::{Decoder, OutputStream};
use std::ffi::OsString;
use std::fs::File;
use std::io::BufReader;
use std::path::PathBuf;
use std::time::Duration;
use std::time::Instant;

// TODO: Add to other package managers
Expand Down
26 changes: 6 additions & 20 deletions src/systems/egui.rs
@@ -1,29 +1,15 @@
use crate::{
cli_args_to_fft_args, config_path, parse_cli_args, reset_config_file, write_fftargs_to_config,
cli_args_to_fft_args, config_path, parse_cli_args, write_fftargs_to_config,
AppState, FFTArgs, FFTState,
};
use bevy::render::mesh::VertexAttributeValues;
use bevy::sprite::Anchor;
use bevy::{
app::AppExit,
prelude::*,
sprite::{MaterialMesh2dBundle, Mesh2dHandle},
};
use bevy_egui::egui::{Align2, Color32, Stroke};
use bevy_egui::{egui, EguiContexts, EguiPlugin};
use clap::{ArgAction, Parser};
use rayon::iter::{IntoParallelRefMutIterator, ParallelIterator};
use rodio::{source::Source, Decoder, OutputStream};
use std::ffi::OsString;
use std::fs::File;
use std::io::BufReader;
use std::path::PathBuf;
use std::time::Duration;
use bevy::prelude::*;
use bevy_egui::egui::Align2;
use bevy_egui::{egui, EguiContexts};
use clap::Parser;

pub fn ui_example_system(
mut contexts: EguiContexts,
keyboard_input: Res<ButtonInput<KeyCode>>,
mut fft_state: ResMut<FFTState>,
fft_state: ResMut<FFTState>,
mut app_state: ResMut<AppState>,
mut args: ResMut<FFTArgs>,
) {
Expand Down
16 changes: 1 addition & 15 deletions src/systems/get_keyboard_input.rs
@@ -1,26 +1,12 @@
use crate::{AppState, FFTArgs, FFTState};
use bevy::render::mesh::VertexAttributeValues;
use bevy::sprite::Anchor;
use crate::{AppState, FFTArgs};
use bevy::{
app::AppExit,
prelude::*,
sprite::{MaterialMesh2dBundle, Mesh2dHandle},
};
use bevy_egui::egui::{Align2, Color32, Stroke};
use bevy_egui::{egui, EguiContexts, EguiPlugin};
use clap::{ArgAction, Parser};
use rayon::iter::{IntoParallelRefMutIterator, ParallelIterator};
use rodio::{source::Source, Decoder, OutputStream};
use std::ffi::OsString;
use std::fs::File;
use std::io::BufReader;
use std::path::PathBuf;
use std::time::Duration;

pub fn get_keyboard_input(
keyboard_input: Res<ButtonInput<KeyCode>>,
mut exit: EventWriter<AppExit>,
mut fft_state: ResMut<FFTState>,
mut app_state: ResMut<AppState>,
mut args: ResMut<FFTArgs>,
) {
Expand Down
13 changes: 0 additions & 13 deletions src/systems/startup.rs
@@ -1,21 +1,9 @@
use crate::{FFTArgs, FFTState};
use bevy::render::mesh::VertexAttributeValues;
use bevy::sprite::Anchor;
use bevy::{
app::AppExit,
prelude::*,
sprite::{MaterialMesh2dBundle, Mesh2dHandle},
};
use bevy_egui::egui::{Align2, Color32, Stroke};
use bevy_egui::{egui, EguiContexts, EguiPlugin};
use clap::{ArgAction, Parser};
use rayon::iter::{IntoParallelRefMutIterator, ParallelIterator};
use rodio::{source::Source, Decoder, OutputStream};
use std::ffi::OsString;
use std::fs::File;
use std::io::BufReader;
use std::path::PathBuf;
use std::time::Duration;

fn spawn_bars(
num_bars: u32,
Expand Down Expand Up @@ -75,7 +63,6 @@ pub fn startup(
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<ColorMaterial>>,
mut fft_queue: ResMut<FFTState>,
clear_color: Res<ClearColor>,
args: Res<FFTArgs>,
) {
commands.spawn(Camera2dBundle::default());
Expand Down
27 changes: 4 additions & 23 deletions src/systems/update_fft.rs
@@ -1,33 +1,14 @@
use crate::fft::time_interpolate;
use crate::*;
use bevy::render::mesh::VertexAttributeValues;
use bevy::sprite::Anchor;
use bevy::{
app::AppExit,
prelude::*,
sprite::{MaterialMesh2dBundle, Mesh2dHandle},
};
use bevy_egui::egui::{Align2, Color32, Stroke};
use bevy_egui::{egui, EguiContexts, EguiPlugin};
use clap::{ArgAction, Parser};
use rayon::iter::{IntoParallelRefMutIterator, ParallelIterator};
use rodio::{source::Source, Decoder, OutputStream};
use std::ffi::OsString;
use std::fs::File;
use std::io::BufReader;
use std::path::PathBuf;
use std::time::Duration;
use bevy::prelude::*;

pub fn update_fft(
mut commands: Commands,
mut window: Query<&mut Window>,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<ColorMaterial>>,
mut fft_state: ResMut<FFTState>,
mut app_state: ResMut<AppState>,
mut args: ResMut<FFTArgs>,
mut clear_color: ResMut<ClearColor>,
mut text_query: Query<&mut Text>,
fft_state: ResMut<FFTState>,
app_state: ResMut<AppState>,
args: ResMut<FFTArgs>,
) {
let h = window.single_mut().height();
let interval = app_state.rendering_fps / app_state.fft_fps;
Expand Down
21 changes: 2 additions & 19 deletions src/systems/update_frame_counters.rs
@@ -1,24 +1,7 @@
use crate::fft::time_interpolate;
use crate::*;
use bevy::render::mesh::VertexAttributeValues;
use bevy::sprite::Anchor;
use bevy::{
app::AppExit,
prelude::*,
sprite::{MaterialMesh2dBundle, Mesh2dHandle},
};
use bevy_egui::egui::{Align2, Color32, Stroke};
use bevy_egui::{egui, EguiContexts, EguiPlugin};
use clap::{ArgAction, Parser};
use rayon::iter::{IntoParallelRefMutIterator, ParallelIterator};
use rodio::{source::Source, Decoder, OutputStream};
use std::ffi::OsString;
use std::fs::File;
use std::io::BufReader;
use std::path::PathBuf;
use std::time::Duration;
use bevy::prelude::*;

pub fn update_frame_counters(mut fft_state: ResMut<FFTState>, mut args: ResMut<FFTArgs>) {
pub fn update_frame_counters(mut fft_state: ResMut<FFTState>) {
let elapsed_time = fft_state.fft_timer.elapsed().as_secs_f64();
fft_state.fft_frame_counter = (elapsed_time / TIME_BETWEEN_FFT_FRAMES) as usize;
fft_state.total_frame_counter = (elapsed_time / TIME_BETWEEN_FRAMES) as usize;
Expand Down
23 changes: 3 additions & 20 deletions src/systems/update_view_settings.rs
@@ -1,30 +1,13 @@
use crate::fft::time_interpolate;
use crate::*;
use bevy::render::mesh::VertexAttributeValues;
use bevy::sprite::{Anchor, Material2d};
use bevy::{
app::AppExit,
prelude::*,
sprite::{MaterialMesh2dBundle, Mesh2dHandle},
};
use bevy_egui::egui::{Align2, Color32, Stroke};
use bevy_egui::{egui, EguiContexts, EguiPlugin};
use clap::{ArgAction, Parser};
use rayon::iter::{IntoParallelRefMutIterator, ParallelIterator};
use rodio::{source::Source, Decoder, OutputStream};
use std::ffi::OsString;
use std::fs::File;
use std::io::BufReader;
use std::path::PathBuf;
use std::time::Duration;
use bevy::prelude::*;

pub fn update_view_settings(
mut commands: Commands,
mut window: Query<&mut Window>,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<ColorMaterial>>,
mut app_state: ResMut<FFTState>,
mut args: ResMut<FFTArgs>,
app_state: Res<FFTState>,
args: Res<FFTArgs>,
mut clear_color: ResMut<ClearColor>,
mut text_query: Query<(&mut Transform, &mut Text)>,
mut differencing_args_query: Query<&mut FFTArgs>,
Expand Down