Skip to content

Commit e3553f5

Browse files
committed
fixes #152, add grid line for tones
1 parent bb20693 commit e3553f5

File tree

11 files changed

+166
-20
lines changed

11 files changed

+166
-20
lines changed

crates/notation_bevy/src/entry/entry_plugin.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use notation_bevy_utils::prelude::ShapeOp;
55
use notation_model::lane_kind::LaneKind;
66

77
use crate::chord::chord_view::ChordView;
8+
use crate::tone::tone_line::ToneLineData;
89
use crate::lane::lane_layout::LaneLayoutData;
910
use crate::prelude::{
1011
BevyUtil, ChordBundle, EntryBundle, LyricsPlugin, NotationAssets, NotationAssetsStates,
@@ -150,6 +151,7 @@ fn on_tab_bars_resized(
150151
settings: Res<NotationSettings>,
151152
theme: Res<NotationTheme>,
152153
mut tone_note_query: Query<(Entity, &mut ToneNoteData), With<ToneNoteData>>,
154+
mut tone_line_query: Query<(Entity, &mut ToneLineData), With<ToneLineData>>,
153155
mut pick_note_query: Query<(Entity, &mut PickNoteData), With<PickNoteData>>,
154156
mut single_string_query: Query<(Entity, &mut SingleStringData), With<SingleStringData>>,
155157
mut word_text_query: Query<(Entity, &mut WordTextData), With<WordTextData>>,
@@ -169,6 +171,14 @@ fn on_tab_bars_resized(
169171
}
170172
}
171173
}
174+
for (entity, mut data) in tone_line_query.iter_mut() {
175+
for (view, layout) in bars.iter() {
176+
if data.bar_props.bar_ordinal == view.bar_props.bar_ordinal {
177+
data.value.bar_size = layout.size.width;
178+
data.update(&mut commands, &theme, entity);
179+
}
180+
}
181+
}
172182
for (entity, mut data) in word_text_query.iter_mut() {
173183
for (view, layout) in bars.iter() {
174184
if data.bar_props.bar_ordinal == view.bar_props.bar_ordinal {
Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,41 @@
11
use bevy::prelude::*;
2+
use notation_bevy_utils::prelude::ShapeOp;
23

3-
use std::sync::Arc;
4+
use crate::{prelude::{NotationTheme, NotationSettings}, tone::tone_mode::ToneMode};
5+
use notation_model::{bar_lane::BarLane, prelude::{Note, Semitones}};
46

5-
use crate::prelude::NotationTheme;
6-
use notation_model::prelude::TabBar;
7+
use crate::tone::tone_line::{ToneLineValue, ToneLineData};
78

89
#[derive(Debug, Default, Component)]
910
pub struct HarmonyGrid();
1011

1112
impl HarmonyGrid {
12-
pub fn add_octave(
13+
pub fn add_lines(
1314
&self,
14-
_commands: &mut Commands,
15-
_theme: &NotationTheme,
16-
_entity: Entity,
17-
_tab_bar: &Arc<TabBar>,
15+
commands: &mut Commands,
16+
theme: &NotationTheme,
17+
_settings: &NotationSettings,
18+
entity: Entity,
19+
lane: &BarLane,
1820
) {
19-
//TODO
21+
if let Some(bar) = lane.bar() {
22+
let scale = bar.tab_meta().scale;
23+
let key = bar.tab_meta().key;
24+
let syllables = scale.get_syllables();
25+
for semitones in theme.sizes.harmony.lowest.0 ..= theme.sizes.harmony.highest.0 {
26+
let note = Note::from(Semitones(semitones));
27+
let syllable_note = scale.calc_syllable_note(&key, &note);
28+
if syllables.contains(&syllable_note.syllable) {
29+
let data = ToneLineData::new(lane, ToneLineValue {
30+
mode: ToneMode::Harmony,
31+
is_root: syllables[0] == syllable_note.syllable,
32+
note,
33+
syllable_note,
34+
bar_size: 0.0,
35+
});
36+
data.create(commands, theme, entity);
37+
}
38+
}
39+
}
2040
}
2141
}

crates/notation_bevy/src/harmony/harmony_plugin.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,38 @@
11
use bevy::ecs::system::EntityCommands;
22
use bevy::prelude::*;
3+
use notation_bevy_utils::prelude::SingleData;
34

5+
use crate::notation::assets::NotationAssetsStates;
46
use crate::prelude::HarmonyGrid;
7+
use crate::settings::notation_settings::NotationSettings;
8+
use crate::theme::notation_theme::NotationTheme;
59
use notation_model::prelude::BarLane;
610

711
pub struct HarmonyPlugin;
812

913
impl Plugin for HarmonyPlugin {
10-
fn build(&self, _app: &mut App) {}
14+
fn build(&self, app: &mut App) {
15+
app.add_system_set(
16+
SystemSet::on_update(NotationAssetsStates::Loaded)
17+
.with_system(HarmonyPlugin::on_add_harmony_grid)
18+
);
19+
}
1120
}
1221

1322
impl HarmonyPlugin {
23+
pub fn on_add_harmony_grid(
24+
mut commands: Commands,
25+
theme: Res<NotationTheme>,
26+
settings: Res<NotationSettings>,
27+
query: Query<(Entity, &SingleData<BarLane>, &HarmonyGrid), Added<HarmonyGrid>>,
28+
) {
29+
if theme._bypass_systems {
30+
return;
31+
}
32+
for (entity, lane, grid) in query.iter() {
33+
grid.add_lines(&mut commands, &theme, &settings, entity, &lane.0);
34+
}
35+
}
1436
pub fn insert_lane_extra(commands: &mut EntityCommands, _lane: &BarLane) {
1537
commands.insert(HarmonyGrid::default());
1638
}
Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,41 @@
11
use bevy::prelude::*;
2+
use notation_bevy_utils::prelude::ShapeOp;
23

34
use std::sync::Arc;
45

5-
use crate::prelude::NotationTheme;
6-
use notation_model::prelude::TabBar;
6+
use crate::{prelude::NotationTheme, settings::notation_settings::NotationSettings, tone::{tone_line::{ToneLineData, ToneLineValue}, tone_mode::ToneMode}};
7+
use notation_model::{prelude::{TabBar, Note, Semitones}, bar_lane::BarLane};
78

89
#[derive(Debug, Default, Component)]
910
pub struct MelodyGrid();
1011

1112
impl MelodyGrid {
12-
pub fn add_octave(
13+
pub fn add_lines(
1314
&self,
14-
_commands: &mut Commands,
15-
_theme: &NotationTheme,
16-
_entity: Entity,
17-
_tab_bar: &Arc<TabBar>,
15+
commands: &mut Commands,
16+
theme: &NotationTheme,
17+
_settings: &NotationSettings,
18+
entity: Entity,
19+
lane: &BarLane,
1820
) {
19-
//TODO
21+
if let Some(bar) = lane.bar() {
22+
let scale = bar.tab_meta().scale;
23+
let key = bar.tab_meta().key;
24+
let root = scale.get_syllables()[0];
25+
for semitones in theme.sizes.melody.lowest.0 ..= theme.sizes.melody.highest.0 {
26+
let note = Note::from(Semitones(semitones));
27+
let syllable_note = scale.calc_syllable_note(&key, &note);
28+
if root == syllable_note.syllable {
29+
let data = ToneLineData::new(lane, ToneLineValue {
30+
mode: ToneMode::Melody,
31+
is_root: false,
32+
note,
33+
syllable_note,
34+
bar_size: 0.0,
35+
});
36+
data.create(commands, theme, entity);
37+
}
38+
}
39+
}
2040
}
2141
}

crates/notation_bevy/src/melody/melody_plugin.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,39 @@
11
use bevy::ecs::system::EntityCommands;
22
use bevy::prelude::*;
3+
use notation_bevy_utils::prelude::SingleData;
34

5+
use crate::notation::assets::NotationAssetsStates;
46
use crate::prelude::MelodyGrid;
7+
use crate::settings::notation_settings::NotationSettings;
8+
use crate::theme::notation_theme::NotationTheme;
59
use notation_model::prelude::BarLane;
610

711
pub struct MelodyPlugin;
812

913
impl Plugin for MelodyPlugin {
10-
fn build(&self, _app: &mut App) {}
14+
fn build(&self, app: &mut App) {
15+
app.add_system_set(
16+
SystemSet::on_update(NotationAssetsStates::Loaded)
17+
.with_system(MelodyPlugin::on_add_melody_grid)
18+
);
19+
20+
}
1121
}
1222

1323
impl MelodyPlugin {
24+
pub fn on_add_melody_grid(
25+
mut commands: Commands,
26+
theme: Res<NotationTheme>,
27+
settings: Res<NotationSettings>,
28+
query: Query<(Entity, &SingleData<BarLane>, &MelodyGrid), Added<MelodyGrid>>,
29+
) {
30+
if theme._bypass_systems {
31+
return;
32+
}
33+
for (entity, lane, grid) in query.iter() {
34+
grid.add_lines(&mut commands, &theme, &settings, entity, &lane.0);
35+
}
36+
}
1437
pub fn insert_lane_extra(commands: &mut EntityCommands, _lane: &BarLane) {
1538
commands.insert(MelodyGrid::default());
1639
}

crates/notation_bevy/src/notation/app.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ impl PluginGroup for NotationPlugins {
2424
group.add(MelodyPlugin);
2525
group.add(LyricsPlugin);
2626
group.add(BarPlugin);
27+
group.add(MelodyPlugin);
28+
group.add(HarmonyPlugin);
2729
group.add(StringsPlugin);
2830
group.add(ShapesPlugin);
2931
group.add(MiniPlugin);

crates/notation_bevy/src/theme/theme_colors.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,19 +144,21 @@ pub struct BarColors {
144144
pub beat_color1: Color,
145145
pub beat_color2: Color,
146146
pub pos_indicator_color: Color,
147+
pub grid_color: Color,
147148
}
148149
impl Default for BarColors {
149150
fn default() -> Self {
150151
Self {
151152
bar_indicator: hex_linear("000000AA"),
152153
bar_separator_color: ThemeColors::hex_linear("D3B59C"),
153154
selected_beat_color0: ThemeColors::hex_linear("FFFFFF88"),
154-
selected_beat_color1: ThemeColors::hex_linear("FFFFFF44"),
155+
selected_beat_color1: ThemeColors::hex_linear("00000010"),
155156
selected_beat_color2: ThemeColors::hex_linear("FFFFFF88"),
156157
beat_color0: ThemeColors::hex_linear("00000000"),
157158
beat_color1: ThemeColors::hex_linear("00000010"),
158159
beat_color2: ThemeColors::hex_linear("00000000"),
159160
pos_indicator_color: ThemeColors::hex_linear("00000077"),
161+
grid_color: ThemeColors::hex_linear("D3B59C88"),
160162
}
161163
}
162164
}

crates/notation_bevy/src/theme/theme_sizes.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ pub struct BarSizes {
7171
pub pos_indicator_size: f32,
7272
pub pos_indicator_outline: f32,
7373
pub pos_indicator_extra: f32,
74+
pub grid_line_width: f32,
75+
pub grid_root_line_width: f32,
7476
}
7577
impl Default for BarSizes {
7678
fn default() -> Self {
@@ -82,6 +84,8 @@ impl Default for BarSizes {
8284
pos_indicator_size: 2.0,
8385
pos_indicator_outline: 0.5,
8486
pos_indicator_extra: 8.0,
87+
grid_line_width: 0.5,
88+
grid_root_line_width: 2.0,
8589
}
8690
}
8791
}

crates/notation_bevy/src/theme/theme_z.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use bevy_inspector_egui::Inspectable;
77
#[cfg_attr(feature = "inspector", derive(Inspectable))]
88
pub struct ThemeZ {
99
pub beat: f32,
10+
pub grid: f32,
1011
pub string: f32,
1112
pub tone: f32,
1213
pub word: f32,
@@ -34,6 +35,7 @@ impl Default for ThemeZ {
3435
fn default() -> Self {
3536
Self {
3637
beat: 0.0,
38+
grid: 1.0,
3739
string: 1.0,
3840
tone: 8.0,
3941
word: 9.0,

crates/notation_bevy/src/tone/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ pub mod tone_bundle;
22
pub mod tone_mode;
33
pub mod tone_note;
44
pub mod tone_systems;
5+
pub mod tone_line;

0 commit comments

Comments
 (0)