hopefully last refactor of editor widget reference stuff

main
aprzn 2 years ago
parent f36303b1f7
commit 674285de46

156
Cargo.lock generated

@ -835,15 +835,6 @@ dependencies = [
"bytemuck", "bytemuck",
] ]
[[package]]
name = "encoding_rs"
version = "0.8.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "071a31f4ee85403370b58aca746f01041ede6f0da2730960ad001edc2b71b394"
dependencies = [
"cfg-if",
]
[[package]] [[package]]
name = "enumset" name = "enumset"
version = "1.0.12" version = "1.0.12"
@ -1781,7 +1772,6 @@ dependencies = [
"home", "home",
"ordered-float", "ordered-float",
"rodio", "rodio",
"symphonia",
] ]
[[package]] [[package]]
@ -2182,152 +2172,6 @@ version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "symphonia"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3671dd6f64f4f9d5c87179525054cfc1f60de23ba1f193bd6ceab812737403f1"
dependencies = [
"lazy_static",
"symphonia-bundle-flac",
"symphonia-bundle-mp3",
"symphonia-codec-adpcm",
"symphonia-codec-pcm",
"symphonia-codec-vorbis",
"symphonia-core",
"symphonia-format-mkv",
"symphonia-format-ogg",
"symphonia-format-wav",
"symphonia-metadata",
]
[[package]]
name = "symphonia-bundle-flac"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3dc2deed3204967871ba60f913378f95820cb47a2fe9b2eef5a9eedb417dfdc8"
dependencies = [
"log",
"symphonia-core",
"symphonia-metadata",
"symphonia-utils-xiph",
]
[[package]]
name = "symphonia-bundle-mp3"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55a0846e7a2c9a8081ff799fc83a975170417ad2a143f644a77ec2e3e82a2b73"
dependencies = [
"bitflags",
"lazy_static",
"log",
"symphonia-core",
"symphonia-metadata",
]
[[package]]
name = "symphonia-codec-adpcm"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2a5cfb8d4405e26eb9593157dc45b05e102b8d774b38ed2a95946d6bb9e26e3e"
dependencies = [
"log",
"symphonia-core",
]
[[package]]
name = "symphonia-codec-pcm"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8cb9a9f0b9991cccf3217b74644af412d5d082a4815e5e2943f26e0ecabdf3c9"
dependencies = [
"log",
"symphonia-core",
]
[[package]]
name = "symphonia-codec-vorbis"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7dfed6f7b6bfa21d7cef1acefc8eae5db80df1608a1aca91871b07cbd28d7b74"
dependencies = [
"log",
"symphonia-core",
"symphonia-utils-xiph",
]
[[package]]
name = "symphonia-core"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6b9567e2d8a5f866b2f94f5d366d811e0c6826babcff6d37de9e1a6690d38869"
dependencies = [
"arrayvec 0.7.2",
"bitflags",
"bytemuck",
"lazy_static",
"log",
]
[[package]]
name = "symphonia-format-mkv"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1bd22f2def8c8f078495ad66111648bfc7d5222ee33774f2077cb665588f3119"
dependencies = [
"lazy_static",
"log",
"symphonia-core",
"symphonia-metadata",
"symphonia-utils-xiph",
]
[[package]]
name = "symphonia-format-ogg"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "474df6e86b871dcb56913130bada1440245f483057c4a2d8a2981455494c4439"
dependencies = [
"log",
"symphonia-core",
"symphonia-metadata",
"symphonia-utils-xiph",
]
[[package]]
name = "symphonia-format-wav"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06679bd5646b3037300f88891dfc8a6e1cc4e1133206cc17a98e5d7c22f88296"
dependencies = [
"log",
"symphonia-core",
"symphonia-metadata",
]
[[package]]
name = "symphonia-metadata"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "acd35c263223ef6161000be79b124a75de3e065eea563bf3ef169b3e94c7bb2e"
dependencies = [
"encoding_rs",
"lazy_static",
"log",
"symphonia-core",
]
[[package]]
name = "symphonia-utils-xiph"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce340a6c33ac06cb42de01220308ec056e8a2a3d5cc664aaf34567392557136b"
dependencies = [
"symphonia-core",
"symphonia-metadata",
]
[[package]] [[package]]
name = "syn" name = "syn"
version = "1.0.107" version = "1.0.107"

@ -5,8 +5,6 @@ use eframe;
use eframe::egui; use eframe::egui;
use std::boxed::Box; use std::boxed::Box;
use std::collections::VecDeque; use std::collections::VecDeque;
use std::marker::PhantomData;
use symphonia::core::io::{MediaSource, MediaSourceStream};
struct PipeDash { struct PipeDash {
msg_queue: VecDeque<Message>, msg_queue: VecDeque<Message>,
@ -29,10 +27,14 @@ enum Message {
} }
struct Editor { struct Editor {
state: EditorState,
data: GdlData,
}
struct EditorState {
scroll_pos: f32, scroll_pos: f32,
pts_per_second: f32, pts_per_second: f32, // zoom level
subdivisions: f32, subdivisions: f32,
data: GdlData,
} }
struct GdlData { struct GdlData {
@ -46,20 +48,30 @@ struct GdlData {
struct Song { struct Song {
name: String, name: String,
id: u32, id: u32,
stream: MediaSourceStream,
} }
struct Orange; struct BeatRateWidget<'a> {
struct Yellow; state: &'a mut EditorState,
struct Green; beat_rate: &'a mut music::BeatRate,
}
struct BeatRateWidget<'a>(&'a mut Editor); struct TimeSignatureWidget<'a> {
struct TimeSignatureWidget<'a>(&'a mut Editor); state: &'a mut EditorState,
struct LinesWidget<'a, C: WithColor>(&'a mut Editor, PhantomData<C>); time_signatures: &'a mut music::TimeSignature,
struct WaveformWidget<'a>(&'a mut Editor); }
struct LinesWidget<'a> {
state: &'a mut EditorState,
lines: &'a mut music::Lines,
color: Color,
}
struct WaveformWidget<'a> {
state: &'a mut EditorState,
song: &'a Song,
}
trait WithColor { fn allocate_editor_space(ui: &mut egui::Ui) -> (egui::Rect, egui::Response) {
const COLOR: Color; let max_rect = ui.max_rect();
let preferred_size = egui::Vec2::new(max_rect.size().x, 60.0);
ui.allocate_exact_size(preferred_size, egui::Sense::click_and_drag())
} }
impl From<Color> for eframe::epaint::Color32 { impl From<Color> for eframe::epaint::Color32 {
@ -72,43 +84,46 @@ impl From<Color> for eframe::epaint::Color32 {
} }
} }
impl WithColor for Orange {
const COLOR: Color = Color::Orange;
}
impl WithColor for Yellow {
const COLOR: Color = Color::Yellow;
}
impl WithColor for Green {
const COLOR: Color = Color::Green;
}
impl Editor { impl Editor {
pub fn beat_rate_widget(&mut self) -> BeatRateWidget { pub fn beat_rate_widget(&mut self) -> BeatRateWidget {
BeatRateWidget(self) BeatRateWidget {
state: &mut self.state,
beat_rate: &mut self.data.beat_rate,
}
} }
pub fn time_signature_widget(&mut self) -> TimeSignatureWidget { pub fn time_signature_widget(&mut self) -> TimeSignatureWidget {
TimeSignatureWidget(self) TimeSignatureWidget {
state: &mut self.state,
time_signatures: &mut self.data.time_signatures,
}
} }
pub fn lines_widget<C: WithColor>(&mut self) -> LinesWidget<C> { pub fn lines_widget(&mut self, col: Color) -> LinesWidget {
LinesWidget(self, Default::default()) LinesWidget {
state: &mut self.state,
lines: match col {
Color::Green => &mut self.data.green_lines,
Color::Yellow => &mut self.data.yellow_lines,
Color::Orange => &mut self.data.orange_lines,
},
color: col,
}
} }
pub fn waveform_widget(&mut self) -> WaveformWidget { pub fn waveform_widget<'a>(&'a mut self, song: &'a Song) -> WaveformWidget {
WaveformWidget(self) WaveformWidget {
state: &mut self.state,
song,
}
} }
} }
impl<'a> egui::Widget for BeatRateWidget<'a> { impl<'a> egui::Widget for BeatRateWidget<'a> {
fn ui(self, ui: &mut egui::Ui) -> egui::Response { fn ui(self, ui: &mut egui::Ui) -> egui::Response {
// 1. choose size let (rect, res) = allocate_editor_space(ui);
let max_rect = ui.max_rect(); // handle interactions
let preferred_size = egui::Vec2::new(max_rect.size().x, 60.0); // draw widget
// 2. allocate space
let (rect, res) = ui.allocate_exact_size(preferred_size, egui::Sense::click_and_drag());
// 3. handle interactions
// 4. draw widget
if ui.is_rect_visible(rect) { if ui.is_rect_visible(rect) {
ui.painter() ui.painter()
.rect_filled(rect, 0f32, eframe::epaint::Color32::from_gray(0)); .rect_filled(rect, 0f32, eframe::epaint::Color32::from_gray(0));
@ -134,7 +149,7 @@ impl<'a> egui::Widget for TimeSignatureWidget<'a> {
} }
} }
impl<'a, C: WithColor> egui::Widget for LinesWidget<'a, C> { impl<'a> egui::Widget for LinesWidget<'a> {
fn ui(self, ui: &mut egui::Ui) -> egui::Response { fn ui(self, ui: &mut egui::Ui) -> egui::Response {
// 1. choose size // 1. choose size
let max_rect = ui.max_rect(); let max_rect = ui.max_rect();
@ -176,9 +191,11 @@ impl PipeDash {
level_list: gd::OuterLevel::load_all(), level_list: gd::OuterLevel::load_all(),
loaded_song: None, loaded_song: None,
editor: Editor { editor: Editor {
scroll_pos: 0f32, state: EditorState {
pts_per_second: 5f32, scroll_pos: 0f32,
subdivisions: 4.0, pts_per_second: 5f32,
subdivisions: 4.0,
},
data: GdlData { data: GdlData {
beat_rate: music::StaticBeatRate::from_bpm(120f32).into(), beat_rate: music::StaticBeatRate::from_bpm(120f32).into(),
time_signatures: music::StaticTimeSignature::new(4, 4).into(), time_signatures: music::StaticTimeSignature::new(4, 4).into(),
@ -233,12 +250,14 @@ impl PipeDash {
.size(20.0), .size(20.0),
); );
ui.add(self.editor.time_signature_widget()); if let Some(song) = &self.loaded_song {
ui.add(self.editor.beat_rate_widget()); ui.add(self.editor.time_signature_widget());
ui.add(self.editor.lines_widget::<Green>()); ui.add(self.editor.beat_rate_widget());
ui.add(self.editor.lines_widget::<Yellow>()); ui.add(self.editor.lines_widget(Color::Green));
ui.add(self.editor.lines_widget::<Orange>()); ui.add(self.editor.lines_widget(Color::Orange));
ui.add(self.editor.waveform_widget()); ui.add(self.editor.lines_widget(Color::Yellow));
ui.add(self.editor.waveform_widget(&song));
}
}); });
}); });
} }

Loading…
Cancel
Save