Added a crude UI mockup
This commit is contained in:
parent
5795a75251
commit
da0c5081e9
File diff suppressed because it is too large
Load Diff
|
@ -6,3 +6,5 @@ authors = ["Sebastian <sebastian@sebastians-site.de>"]
|
||||||
[dependencies]
|
[dependencies]
|
||||||
hound = "*"
|
hound = "*"
|
||||||
image = "*"
|
image = "*"
|
||||||
|
eframe = "0.16.0"
|
||||||
|
rfd = "0.7.0"
|
||||||
|
|
268
src/main.rs
268
src/main.rs
|
@ -1,44 +1,262 @@
|
||||||
|
extern crate eframe;
|
||||||
extern crate hound;
|
extern crate hound;
|
||||||
extern crate image;
|
extern crate image;
|
||||||
|
extern crate rfd;
|
||||||
|
|
||||||
mod utils;
|
|
||||||
mod firfilter;
|
|
||||||
mod resamplers;
|
|
||||||
mod amdemod;
|
mod amdemod;
|
||||||
mod aptsyncer;
|
mod aptsyncer;
|
||||||
|
mod firfilter;
|
||||||
|
mod resamplers;
|
||||||
|
mod utils;
|
||||||
|
|
||||||
use std::io::prelude::*;
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
|
use std::io::prelude::*;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
use std::sync::{Arc, Mutex};
|
||||||
|
use std::time;
|
||||||
|
|
||||||
use utils::float_sample_iterator;
|
|
||||||
use firfilter::FIRFilter;
|
|
||||||
use amdemod::SquaringAMDemodulator;
|
use amdemod::SquaringAMDemodulator;
|
||||||
use resamplers::{Upsampler, Downsampler};
|
|
||||||
use aptsyncer::{APTSyncer, SyncedSample};
|
use aptsyncer::{APTSyncer, SyncedSample};
|
||||||
|
use firfilter::FIRFilter;
|
||||||
|
use resamplers::{Downsampler, Upsampler};
|
||||||
|
use utils::float_sample_iterator;
|
||||||
|
|
||||||
const LINES_PER_SECOND: u32 = 2;
|
const LINES_PER_SECOND: u32 = 2;
|
||||||
const PIXELS_PER_LINE: u32 = 2080;
|
const PIXELS_PER_LINE: u32 = 2080;
|
||||||
|
|
||||||
const LOWPASS_COEFFS : [f32; 63] = [ -7.383784e-03,
|
const LOWPASS_COEFFS: [f32; 63] = [
|
||||||
-3.183046e-03, 2.255039e-03, 7.461166e-03, 1.091908e-02,
|
-7.383784e-03,
|
||||||
1.149109e-02, 8.769802e-03, 3.252932e-03, -3.720606e-03,
|
-3.183046e-03,
|
||||||
-1.027446e-02, -1.447403e-02, -1.486427e-02, -1.092423e-02,
|
2.255039e-03,
|
||||||
-3.307958e-03, 6.212477e-03, 1.511364e-02, 2.072873e-02,
|
7.461166e-03,
|
||||||
2.096037e-02, 1.492345e-02, 3.347624e-03, -1.138407e-02,
|
1.091908e-02,
|
||||||
-2.560252e-02, -3.507114e-02, -3.591225e-02, -2.553830e-02,
|
1.149109e-02,
|
||||||
-3.371569e-03, 2.882645e-02, 6.711368e-02, 1.060042e-01,
|
8.769802e-03,
|
||||||
1.394643e-01, 1.620650e-01, 1.700462e-01, 1.620650e-01,
|
3.252932e-03,
|
||||||
1.394643e-01, 1.060042e-01, 6.711368e-02, 2.882645e-02,
|
-3.720606e-03,
|
||||||
-3.371569e-03, -2.553830e-02, -3.591225e-02, -3.507114e-02,
|
-1.027446e-02,
|
||||||
-2.560252e-02, -1.138407e-02, 3.347624e-03, 1.492345e-02,
|
-1.447403e-02,
|
||||||
2.096037e-02, 2.072873e-02, 1.511364e-02, 6.212477e-03,
|
-1.486427e-02,
|
||||||
-3.307958e-03, -1.092423e-02, -1.486427e-02, -1.447403e-02,
|
-1.092423e-02,
|
||||||
-1.027446e-02, -3.720606e-03, 3.252932e-03, 8.769802e-03,
|
-3.307958e-03,
|
||||||
1.149109e-02, 1.091908e-02, 7.461166e-03, 2.255039e-03,
|
6.212477e-03,
|
||||||
-3.183046e-03, -7.383784e-03];
|
1.511364e-02,
|
||||||
|
2.072873e-02,
|
||||||
|
2.096037e-02,
|
||||||
|
1.492345e-02,
|
||||||
|
3.347624e-03,
|
||||||
|
-1.138407e-02,
|
||||||
|
-2.560252e-02,
|
||||||
|
-3.507114e-02,
|
||||||
|
-3.591225e-02,
|
||||||
|
-2.553830e-02,
|
||||||
|
-3.371569e-03,
|
||||||
|
2.882645e-02,
|
||||||
|
6.711368e-02,
|
||||||
|
1.060042e-01,
|
||||||
|
1.394643e-01,
|
||||||
|
1.620650e-01,
|
||||||
|
1.700462e-01,
|
||||||
|
1.620650e-01,
|
||||||
|
1.394643e-01,
|
||||||
|
1.060042e-01,
|
||||||
|
6.711368e-02,
|
||||||
|
2.882645e-02,
|
||||||
|
-3.371569e-03,
|
||||||
|
-2.553830e-02,
|
||||||
|
-3.591225e-02,
|
||||||
|
-3.507114e-02,
|
||||||
|
-2.560252e-02,
|
||||||
|
-1.138407e-02,
|
||||||
|
3.347624e-03,
|
||||||
|
1.492345e-02,
|
||||||
|
2.096037e-02,
|
||||||
|
2.072873e-02,
|
||||||
|
1.511364e-02,
|
||||||
|
6.212477e-03,
|
||||||
|
-3.307958e-03,
|
||||||
|
-1.092423e-02,
|
||||||
|
-1.486427e-02,
|
||||||
|
-1.447403e-02,
|
||||||
|
-1.027446e-02,
|
||||||
|
-3.720606e-03,
|
||||||
|
3.252932e-03,
|
||||||
|
8.769802e-03,
|
||||||
|
1.149109e-02,
|
||||||
|
1.091908e-02,
|
||||||
|
7.461166e-03,
|
||||||
|
2.255039e-03,
|
||||||
|
-3.183046e-03,
|
||||||
|
-7.383784e-03,
|
||||||
|
];
|
||||||
|
|
||||||
|
use eframe::egui::text_edit::TextEdit;
|
||||||
|
use eframe::egui::widgets::{Button, ProgressBar};
|
||||||
|
use eframe::egui::{Color32, RichText};
|
||||||
|
use eframe::{egui, epi};
|
||||||
|
|
||||||
|
#[derive(PartialEq)]
|
||||||
|
enum DecoderRunState {
|
||||||
|
RUNNING,
|
||||||
|
CANCELED,
|
||||||
|
DONE,
|
||||||
|
}
|
||||||
|
|
||||||
|
struct DecoderJobState {
|
||||||
|
progress: f32,
|
||||||
|
run_state: DecoderRunState,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DecoderJobState {
|
||||||
|
fn is_running(&self) -> bool {
|
||||||
|
self.run_state == DecoderRunState::RUNNING
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for DecoderJobState {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
progress: 0.0,
|
||||||
|
run_state: DecoderRunState::DONE,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct DecoderApp {
|
||||||
|
input_path: String,
|
||||||
|
output_path: String,
|
||||||
|
decoding_state: Arc<Mutex<DecoderJobState>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for DecoderApp {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
// Example stuff:
|
||||||
|
input_path: "input.wav".to_owned(),
|
||||||
|
output_path: "output.png".to_owned(),
|
||||||
|
decoding_state: Arc::new(Mutex::new(DecoderJobState::default())),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl epi::App for DecoderApp {
|
||||||
|
fn name(&self) -> &str {
|
||||||
|
"eframe template"
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Called once before the first frame.
|
||||||
|
fn setup(
|
||||||
|
&mut self,
|
||||||
|
_ctx: &egui::CtxRef,
|
||||||
|
_frame: &epi::Frame,
|
||||||
|
_storage: Option<&dyn epi::Storage>,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Called each time the UI needs repainting, which may be many times per second.
|
||||||
|
/// Put your widgets into a `SidePanel`, `TopPanel`, `CentralPanel`, `Window` or `Area`.
|
||||||
|
fn update(&mut self, ctx: &egui::CtxRef, frame: &epi::Frame) {
|
||||||
|
let Self {
|
||||||
|
input_path,
|
||||||
|
output_path,
|
||||||
|
decoding_state,
|
||||||
|
} = self;
|
||||||
|
|
||||||
|
{
|
||||||
|
let mut state = decoding_state.lock().unwrap();
|
||||||
|
|
||||||
|
if !ctx.input().raw.dropped_files.is_empty() && !state.is_running() {
|
||||||
|
if let Some(path) = ctx.input().raw.dropped_files[0].clone().path {
|
||||||
|
*input_path = path.display().to_string();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
egui::CentralPanel::default().show(ctx, |ui| {
|
||||||
|
ui.heading("APT-Decoder");
|
||||||
|
|
||||||
|
egui::Grid::new("form_grid").num_columns(3).show(ui, |ui| {
|
||||||
|
ui.label("Input Wav File:");
|
||||||
|
ui.add_sized([300.0, 20.0], TextEdit::singleline(input_path));
|
||||||
|
|
||||||
|
if ui
|
||||||
|
.add_enabled(!state.is_running(), Button::new("Open"))
|
||||||
|
.clicked()
|
||||||
|
{
|
||||||
|
if let Some(path) = rfd::FileDialog::new().pick_file() {
|
||||||
|
*input_path = path.display().to_string();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
ui.end_row();
|
||||||
|
|
||||||
|
ui.label("Output PNG File:");
|
||||||
|
ui.add_sized([300.0, 20.0], TextEdit::singleline(output_path));
|
||||||
|
if ui
|
||||||
|
.add_enabled(!state.is_running(), Button::new("Save"))
|
||||||
|
.clicked()
|
||||||
|
{
|
||||||
|
if let Some(path) = rfd::FileDialog::new().save_file() {
|
||||||
|
*output_path = path.display().to_string();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
ui.end_row();
|
||||||
|
});
|
||||||
|
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
if ui
|
||||||
|
.add_enabled(!state.is_running(), Button::new("Decode"))
|
||||||
|
.clicked()
|
||||||
|
{
|
||||||
|
let frame = frame.clone();
|
||||||
|
let decoding_state = decoding_state.clone();
|
||||||
|
state.run_state = DecoderRunState::RUNNING;
|
||||||
|
let thread = std::thread::spawn(move || {
|
||||||
|
for i in 0..101 {
|
||||||
|
{
|
||||||
|
let mut state = decoding_state.lock().unwrap();
|
||||||
|
if state.run_state == DecoderRunState::CANCELED {
|
||||||
|
frame.request_repaint();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
state.progress = (i as f32) / 100.0;
|
||||||
|
}
|
||||||
|
frame.request_repaint();
|
||||||
|
|
||||||
|
std::thread::sleep(time::Duration::from_millis(200));
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
let mut state = decoding_state.lock().unwrap();
|
||||||
|
state.progress = 100.0;
|
||||||
|
state.run_state = DecoderRunState::DONE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if ui
|
||||||
|
.add_enabled(
|
||||||
|
state.is_running(),
|
||||||
|
Button::new(RichText::new("Cancel").color(Color32::RED)),
|
||||||
|
)
|
||||||
|
.clicked()
|
||||||
|
{
|
||||||
|
state.run_state = DecoderRunState::CANCELED;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let progressbar = ProgressBar::new(state.progress).show_percentage();
|
||||||
|
ui.add(progressbar);
|
||||||
|
|
||||||
|
ui.separator();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
let app = DecoderApp::default();
|
||||||
|
let native_options = eframe::NativeOptions::default();
|
||||||
|
eframe::run_native(Box::new(app), native_options);
|
||||||
|
|
||||||
|
/*
|
||||||
let args : Vec<String> = std::env::args().collect();
|
let args : Vec<String> = std::env::args().collect();
|
||||||
|
|
||||||
if args.len() != 3 {
|
if args.len() != 3 {
|
||||||
|
@ -148,6 +366,6 @@ fn main() {
|
||||||
};
|
};
|
||||||
|
|
||||||
image::ImageLuma8(img).save(fout, image::PNG).unwrap();
|
image::ImageLuma8(img).save(fout, image::PNG).unwrap();
|
||||||
|
*/
|
||||||
println!("Done !");
|
println!("Done !");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue