Skip to content

Commit f59a024

Browse files
committed
wip
1 parent a5d8a54 commit f59a024

File tree

15 files changed

+209
-61
lines changed

15 files changed

+209
-61
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/notation_kb/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,3 @@ dev = [
2222

2323
[dependencies]
2424
notation_bevy = { path = "../../crates/notation_bevy" }
25-
notation_tab = { path = "../../crates/notation_tab" }

apps/notation_kb/src/index_panel.rs

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use notation_bevy::bevy::prelude::*;
22
use notation_bevy::bevy_egui::{egui, EguiContext};
3-
use notation_bevy::prelude::{StereoStream, ProtoTab};
3+
use notation_bevy::prelude::{StereoStream, ProtoTab, NotationSettings, Control, MidiState, PlayControlEvent, MidiControl};
44

55
use notation_bevy::prelude::{MarkDownAsset, KbPageId, KbPage, KbContent, KbPanel, DockSide, EasyLinkEvent};
66
use notation_bevy::prelude::{NotationState, NotationAssets, NotationTheme};
@@ -56,6 +56,8 @@ impl IndexPanel {
5656
pub const LINK_SOUND: &'static str = ":kb:sound";
5757
pub const LINK_SCALE: &'static str = ":kb:scale";
5858
pub const LINK_SOUND_SINGLE_STRING: &'static str = ":kb:sound:single_string";
59+
60+
pub const LINK_MIDI_PLAY: &'static str = ":midi:play";
5961
}
6062

6163
impl KbPanel for IndexPanel {
@@ -85,6 +87,46 @@ impl KbPanel for IndexPanel {
8587
}
8688

8789
impl IndexPanel {
90+
pub fn check_reload(
91+
mut state: ResMut<NotationState>,
92+
mut theme: ResMut<NotationTheme>,
93+
index: Res<IndexPanel>,
94+
) {
95+
if let Some(tab) = state.tab.as_ref() {
96+
let need_reload = match index.current_page_id {
97+
Self::SCALE => {
98+
index.scale.check_reload(&tab)
99+
},
100+
_ => false,
101+
};
102+
if need_reload {
103+
Control::reload_tab(&mut state, &mut theme);
104+
}
105+
}
106+
}
107+
pub fn hack_settings(
108+
state: Res<NotationState>,
109+
theme: Res<NotationTheme>,
110+
mut settings: ResMut<NotationSettings>,
111+
) {
112+
settings.hide_mini_map = true;
113+
settings.hide_bar_number = true;
114+
settings.layout.focus_bar_ease_ms = 0;
115+
if state.window_width > 0.0 && state.window_height > 0.0 {
116+
if state.window_width > state.window_height {
117+
let width = state.window_width / 3.0 + theme.sizes.layout.page_margin;
118+
settings.hide_guitar_view = false;
119+
settings.override_guitar_width = Some(width);
120+
settings.hide_chords_view = true;
121+
} else {
122+
settings.hide_guitar_view = true;
123+
settings.hide_chords_view = false;
124+
settings.override_guitar_width = None;
125+
let height = state.window_height / 3.0;
126+
settings.override_chord_size = Some(height);
127+
}
128+
}
129+
}
88130
pub fn index_ui(
89131
egui_ctx: Res<EguiContext>,
90132
texts: Res<Assets<MarkDownAsset>>,
@@ -98,15 +140,12 @@ impl IndexPanel {
98140
index.skip_frames -= 1;
99141
return;
100142
}
101-
102143
if state.window_width > state.window_height {
103-
let min_width = state.window_width / 3.0;
104-
let max_width = state.window_width * 2.0 / 3.0;
105-
(&mut index).side_ui(&egui_ctx, &texts, &assets, &mut state, &theme, &mut link_evts, DockSide::Left, (min_width, max_width));
144+
let width = state.window_width / 3.0;
145+
(&mut index).side_ui(&egui_ctx, &texts, &assets, &mut state, &theme, &mut link_evts, DockSide::Left, (width, width));
106146
} else {
107-
let min_height = state.window_height / 3.0;
108-
let max_height = state.window_height * 2.0 / 3.0;
109-
(&mut index).side_ui(&egui_ctx, &texts, &assets, &mut state, &theme, &mut link_evts, DockSide::Top, (min_height, max_height));
147+
let height = state.window_height / 3.0;
148+
(&mut index).side_ui(&egui_ctx, &texts, &assets, &mut state, &theme, &mut link_evts, DockSide::Top, (height, height));
110149
}
111150
(&mut index).content_ui(&egui_ctx, &texts, &assets, &state, &theme, &mut link_evts);
112151
}
@@ -135,15 +174,19 @@ impl IndexPanel {
135174
}
136175
}
137176
pub fn handle_link_evts(
177+
mut midi_state: ResMut<MidiState>,
178+
mut play_control_evts: EventWriter<PlayControlEvent>,
138179
mut index: ResMut<IndexPanel>,
139180
mut evts: EventReader<EasyLinkEvent>,
140181
) {
141182
for evt in evts.iter() {
142-
(&mut index).handle_link_evt(evt);
183+
(&mut index).handle_link_evt(&mut midi_state, &mut play_control_evts, evt);
143184
}
144185
}
145186
fn handle_link_evt(
146187
&mut self,
188+
midi_state: &mut MidiState,
189+
play_control_evts: &mut EventWriter<PlayControlEvent>,
147190
evt: &EasyLinkEvent,
148191
) {
149192
println!("handle_link_evt {:?}", evt);
@@ -158,6 +201,9 @@ impl IndexPanel {
158201
self.current_page_id = Self::SOUND;
159202
self.sound.section = SoundSection::SingleString(Default::default());
160203
}
204+
Self::LINK_MIDI_PLAY => {
205+
MidiControl::play(midi_state, play_control_evts)
206+
}
161207
_ => (),
162208
}
163209
}

apps/notation_kb/src/kb.rs

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,26 @@ pub struct NotationKnowledgeBase();
1414
impl NotationKnowledgeBase {
1515
fn extra(app: &mut AppBuilder) {
1616
app.init_resource::<IndexPanel>();
17-
app.add_startup_system(Self::setup.system());
17+
app.add_startup_system(Self::setup_state.system());
1818
TabPlugin::setup_mouse_input(app);
1919
app.add_system_set(
2020
SystemSet::on_update(NotationAssetsStates::Loaded)
21+
.with_system(IndexPanel::hack_settings.system())
22+
.with_system(IndexPanel::check_reload.system())
2123
.with_system(IndexPanel::index_ui.system())
2224
.with_system(IndexPanel::index_audio.system())
2325
.with_system(IndexPanel::handle_link_evts.system())
2426
.with_system(Self::load_tab.system())
27+
.with_system(Self::on_window_resized.system())
2528
);
2629
}
2730
pub fn run() {
2831
notation_bevy::prelude::NotationApp::run_with_extra::<NotationKnowledgeBaseAssets, _>(vec![], Self::extra);
2932
}
30-
fn setup(
33+
fn setup_state(
3134
mut state: ResMut<NotationState>,
32-
mut settings: ResMut<NotationSettings>,
3335
) {
3436
state.show_kb = true;
35-
settings.hide_guitar_view = true;
36-
settings.hide_chords_view = true;
37-
settings.hide_mini_map = true;
3837
}
3938
fn load_tab(
4039
mut commands: Commands,
@@ -51,5 +50,26 @@ impl NotationKnowledgeBase {
5150
index.make_tab(tab_path)
5251
})
5352
}
53+
fn on_window_resized(
54+
mut state: ResMut<NotationState>,
55+
mut theme: ResMut<NotationTheme>,
56+
mut window_resized_evts: EventReader<WindowResizedEvent>,
57+
) {
58+
let mut need_reload = false;
59+
for evt in window_resized_evts.iter() {
60+
if state.window_width > state.window_height {
61+
if evt.last_width <= evt.last_height {
62+
need_reload = true;
63+
}
64+
} else {
65+
if evt.last_width > evt.last_height {
66+
need_reload = true;
67+
}
68+
}
69+
}
70+
if need_reload {
71+
Control::reload_tab(&mut state, &mut theme);
72+
}
73+
}
5474
}
5575

apps/notation_kb/src/theory/scale.rs

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
use notation_bevy::bevy::prelude::*;
22
use notation_bevy::bevy_egui::egui::{self, *};
33

4-
use notation_tab::prelude::{track, Context};
5-
64
use notation_bevy::kb::markdown_page::MarkDownPage;
75
use notation_bevy::kb::notes_page::NotesPage;
8-
use notation_bevy::prelude::{NotationState, NotationAssets, NotationTheme, MarkDownAsset, KbPage, KbContent, EasyLinkEvent, Scale, Key, ProtoTab, TabMeta, Signature, Tempo};
6+
use notation_bevy::prelude::*;
7+
8+
use crate::index_panel::IndexPanel;
99

1010
#[derive(Copy, Clone, Debug)]
1111
pub struct ScalePage {
1212
pub path: &'static str,
1313
pub scale: Scale,
14-
pub key: Key,
14+
pub key: notation_bevy::prelude::Key,
1515
}
1616

1717
impl KbPage for ScalePage {
@@ -34,7 +34,7 @@ impl KbPage for ScalePage {
3434
.width(64.0)
3535
.selected_text(key.to_string())
3636
.show_ui(ui, |ui| {
37-
for k in Key::ALL.iter() {
37+
for k in notation_bevy::prelude::Key::ALL.iter() {
3838
if ui.selectable_label(*k == key, k.to_string()).clicked() {
3939
self.key = k.clone();
4040
}
@@ -54,6 +54,12 @@ impl KbPage for ScalePage {
5454
});
5555
ui.separator();
5656
NotesPage::notes_ui(ui, texts, assets, state, theme, link_evts, self.scale, self.key);
57+
ui.separator();
58+
ui.horizontal(|ui| {
59+
if ui.button("play").clicked() {
60+
link_evts.send(EasyLinkEvent::from(IndexPanel::LINK_MIDI_PLAY));
61+
}
62+
});
5763
}
5864
}
5965

@@ -83,18 +89,41 @@ impl ScalePage {
8389
self.key.clone(), self.scale.clone(),
8490
Signature::_4_4, Tempo::Bpm(60),
8591
);
86-
Context::set_scale(self.scale);
87-
Context::set_key(self.key);
88-
Context::set_duration(Duration::_1_4);
89-
let track = track! {vocal Vocal [
90-
]};
91-
let section = Section::new();
92+
let mut entries = vec![];
93+
let duration = Duration::_1_4;
94+
for syllable in self.scale.get_syllables().iter() {
95+
let note = Note::from(Semitones::from(Octave::CENTER) + Semitones::from(self.scale.calc_syllable_for_sort(syllable)));
96+
entries.push(ProtoEntry::from(CoreEntry::from((Tone::from(note), duration))));
97+
}
98+
let note = Note::from(Semitones(12) + Semitones::from(Octave::CENTER) + Semitones::from(self.scale.calc_syllable_for_sort(&self.scale.calc_root_syllable())));
99+
entries.push(ProtoEntry::from(CoreEntry::from((Tone::from(note), duration))));
100+
let track = ProtoTrack::new("notes".to_owned(), TrackKind::Vocal, entries);
101+
let bars = vec![
102+
ProtoBar::new(
103+
vec![
104+
ProtoBarLayer::new("notes".to_owned(), vec![
105+
Slice::new(SliceBegin::Index(0), SliceEnd::Count(4), None),
106+
])
107+
],
108+
),
109+
ProtoBar::new(
110+
vec![
111+
ProtoBarLayer::new("notes".to_owned(), vec![
112+
Slice::new(SliceBegin::Index(4), SliceEnd::Count(4), None),
113+
])
114+
]
115+
),
116+
];
117+
let section = ProtoSection::new("notes".to_owned(), SectionKind::Rest, bars);
92118
ProtoTab::new(
93119
ProtoTab::new_uuid().as_str(),
94120
meta,
95121
vec![track],
96122
vec![section],
97-
Form{ sections: vec!["section"]},
123+
ProtoForm{ sections: vec!["notes".to_owned()]},
98124
)
99125
}
126+
pub fn check_reload(&self, tab: &Tab) -> bool {
127+
self.scale != tab.meta.scale || self.key != tab.meta.key
128+
}
100129
}

crates/notation_bevy/src/notation/app.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,13 @@ impl NotationApp {
206206
"on_window_resized(): {} {} -> {} {} ",
207207
window.width, window.height, evt.width, evt.height
208208
);
209+
let resized_evt = WindowResizedEvent::new(&app_state);
209210
window.width = evt.width;
210211
window.height = evt.height;
211212
app_state.window_width = evt.width;
212213
app_state.window_height = evt.height;
213214
app_state.scale_factor_override = window.scale_factor_override;
214-
window_resized_evts.send(WindowResizedEvent());
215+
window_resized_evts.send(resized_evt);
215216
}
216217
}
217218
}

0 commit comments

Comments
 (0)