Skip to content

Commit e1bbc40

Browse files
committed
fixes #99, show only partial fretboard
1 parent 99dba4c commit e1bbc40

35 files changed

+284
-207
lines changed

apps/notation_tool/src/tab/songs/misc/scarborough_fair.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub fn new_tab() -> Tab {
99
{chord Chord [
1010
$duration = D_1_2
1111
"2sus4_7" Chord ( 2: 4 5 7- )
12-
"5_9_11" Chord ( 5: 3 9 11 )
12+
"2sus4_7/4" Chord ( 2: 4 5 7- /4 )
1313
"1/4" Chord ( 1: 3 5 /4 )
1414
"1" Chord ( 1: 3 5 )
1515
"2sus2" Chord ( 2: 2 5 )
@@ -30,7 +30,7 @@ pub fn new_tab() -> Tab {
3030
Fretboard capo: 7
3131
$duration = D_1_2
3232
"Asus4" Shape ( 0 0 4 0 3 0 )
33-
"Dadd11" Shape ( 0 5 4 0 3 0 )
33+
"Asus4/D" Shape ( 0 5 4 0 3 0 )
3434
"G/C" Shape ( _ 3 0 0 0 _ )
3535
"Asus2" Shape ( _ 0 2 2 0 0 )
3636
"G'" Shape ( 3 _ 0 0 0 _ )
@@ -155,8 +155,8 @@ pub fn new_tab() -> Tab {
155155
chord [ "2sus4_7" 1 ]
156156
guitar [ "Asus4" 1 ; "i" | ]
157157
} {
158-
chord [ "5_9_11" 1 ]
159-
guitar [ "Dadd11" 1 ; "i" | ]
158+
chord [ "2sus4_7/4" 1 ]
159+
guitar [ "Asus4/D" 1 ; "i" | ]
160160
} {
161161
chord [ "1/4" 1 ]
162162
guitar [ "G/C" 1 ; "i:3" | ]
@@ -315,8 +315,8 @@ pub fn new_tab() -> Tab {
315315
chord [ "2sus4_7" 1 ]
316316
guitar [ "Asus4" 1 ; "i" | ]
317317
} {
318-
chord [ "2_9_11" 1 ]
319-
guitar [ "Dadd11" 1 ; "i" | ]
318+
chord [ "2sus4_7/4" 1 ]
319+
guitar [ "Asus4/D" 1 ; "i" | ]
320320
} {
321321
chord [ "1/4" 1 ]
322322
guitar [ "G/C" 1 ; "i:3" | ]
120 KB
Loading

apps/notation_viewer/assets/songs/misc/scarborough_fair.ron

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@
3131
),
3232
Dotted(Half),
3333
)),// [2]
34-
Mark("5_9_11"),// [3]
34+
Mark("2sus4_7/4"),// [3]
3535
Core(Chord(
3636
(
37-
root: So,
37+
root: Re,
3838
intervals: Tetrad(
39-
Major3nd,
40-
Major2nd,
4139
Perfect4th,
40+
Perfect5th,
41+
Minor7th,
4242
),
43-
base: None,
43+
base: Some(Perfect4th),
4444
),
4545
Dotted(Half),
4646
)),// [4]
@@ -255,7 +255,7 @@
255255
),
256256
Dotted(Half),
257257
)),// [3]
258-
Mark("Dadd11"),// [4]
258+
Mark("Asus4/D"),// [4]
259259
Fretted6(Shape(
260260
(
261261
frets: (
@@ -2968,7 +2968,7 @@
29682968
track: "chord",
29692969
slices: [
29702970
(
2971-
begin: Mark("5_9_11"),
2971+
begin: Mark("2sus4_7/4"),
29722972
end: Count(1),
29732973
rounds: None,
29742974
),
@@ -2978,7 +2978,7 @@
29782978
track: "guitar",
29792979
slices: [
29802980
(
2981-
begin: Mark("Dadd11"),
2981+
begin: Mark("Asus4/D"),
29822982
end: Count(1),
29832983
rounds: None,
29842984
),// [0]
@@ -4625,7 +4625,7 @@
46254625
track: "chord",
46264626
slices: [
46274627
(
4628-
begin: Mark("2_9_11"),
4628+
begin: Mark("2sus4_7/4"),
46294629
end: Count(1),
46304630
rounds: None,
46314631
),
@@ -4635,7 +4635,7 @@
46354635
track: "guitar",
46364636
slices: [
46374637
(
4638-
begin: Mark("Dadd11"),
4638+
begin: Mark("Asus4/D"),
46394639
end: Count(1),
46404640
rounds: None,
46414641
),// [0]

crates/notation_bevy/src/chord/interval_dot.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ impl IntervalDotData {
4141
}
4242
fn offset(&self, theme: &NotationTheme) -> Vec3 {
4343
if self.total == 0 || self.note_radius <= 0.0 {
44-
return Vec3::ZERO;
44+
return Vec3::new(0.0, 0.0, 1.0);
4545
}
4646
if self.index == 0 {
4747
if self.total == 1 || self.total == 5 || self.total == 7 {
48-
return Vec3::ZERO;
48+
return Vec3::new(0.0, 0.0, 1.0);
4949
}
5050
}
5151
if self.total != 6 {

crates/notation_bevy/src/data/bar_data.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ impl<T: Send + Sync + 'static> BarData<T> {
3232
}
3333
pub fn tab_position(&self) -> TabPosition {
3434
TabPosition::new(Units(
35-
(self.bar_props.bar_ordinal - 1) as f32 * self.bar_props.bar_units.0,
35+
self.bar_props.bar_ordinal as f32 * self.bar_props.bar_units.0,
3636
))
3737
}
3838
}

crates/notation_bevy/src/guitar/fret_finger.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ impl FretFingerData {
7272
self.value.interval = Interval::from((chord.root, syllable_note.syllable));
7373
self.value.extra.in_chord = false;
7474
}
75+
//println!("set_chord_note {}, {} -> {} {}", chord, note, self.value.interval, self.value.extra.in_chord);
7576
}
7677
fn set_note(&mut self, meta: &TabMeta, note: &Note) {
7778
self.value.extra.visible = true;

crates/notation_bevy/src/guitar/guitar_capo.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ use crate::prelude::{NotationTheme};
77
#[derive(Clone, Debug)]
88
pub struct GuitarCapoData {
99
pub capo: u8,
10+
pub view_size: LayoutSize,
1011
pub guitar_size: LayoutSize,
1112
}
1213

1314
impl GuitarCapoData {
1415
pub fn new(capo: u8) -> Self {
1516
Self {
1617
capo,
18+
view_size: LayoutSize::ZERO,
1719
guitar_size: LayoutSize::ZERO,
1820
}
1921
}

crates/notation_bevy/src/guitar/guitar_string.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ impl ShapeOp<NotationTheme, OutlineRectangle> for GuitarStringData {
137137
let end_y = if self.upper {
138138
self.guitar_size.height * theme.guitar.string_y_factor
139139
} else {
140-
-self.guitar_size.height / 2.0 - 10.0
140+
-self.guitar_size.height / 2.0
141141
};
142142
let width = self.width(theme);
143143
let height = (end_y - fret_y).abs();

crates/notation_bevy/src/guitar/guitar_view.rs

Lines changed: 53 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
use std::fmt::Display;
22
use std::sync::Arc;
3+
use float_eq::float_ne;
34

45
use bevy::prelude::*;
5-
use notation_bevy_utils::prelude::{BevyUtil, ColorBackground, DockPanel, DockSide, LayoutAnchor, LayoutChangedQuery, LayoutConstraint, LayoutSize, ShapeOp, View, ViewBundle};
6+
use notation_bevy_utils::prelude::{BevyUtil, ColorBackground, LayoutAnchor, LayoutChangedQuery, LayoutSize, ShapeOp, View, ViewBundle};
67
use notation_midi::prelude::MidiState;
78
use notation_model::prelude::{
89
Duration, Entry, HandShape6, Interval, LaneEntry, LaneKind, ModelEntryProps, Pick, Syllable,
910
Tab, Units,
1011
};
1112

12-
use crate::prelude::{EntryPlaying, NotationAssets, NotationTheme};
13+
use crate::prelude::{EntryPlaying, NotationAssets, NotationTheme, NotationSettings};
1314
use crate::ui::layout::NotationLayout;
1415

1516
use super::fret_finger::{FretFingerData};
@@ -32,20 +33,9 @@ impl Display for GuitarView {
3233
}
3334
}
3435

35-
impl<'a> DockPanel<NotationLayout<'a>> for GuitarView {
36-
fn dock_side(&self, _engine: &NotationLayout<'a>, _size: LayoutSize) -> DockSide {
37-
DockSide::Left
38-
}
39-
}
40-
4136
impl<'a> View<NotationLayout<'a>> for GuitarView {
4237
fn pivot(&self) -> LayoutAnchor {
43-
LayoutAnchor::CENTER
44-
}
45-
fn calc_size(&self, engine: &NotationLayout, constraint: LayoutConstraint) -> LayoutSize {
46-
let width = constraint.max.height / engine.theme.guitar.image_size.1
47-
* engine.theme.guitar.image_size.0;
48-
LayoutSize::new(width, constraint.max.height)
38+
LayoutAnchor::TOP
4939
}
5040
}
5141

@@ -146,6 +136,8 @@ impl GuitarView {
146136
mut finger_query: Query<(&Parent, Entity, &mut FretFingerData), With<FretFingerData>>,
147137
) {
148138
for (entity, _view, layout) in query.iter() {
139+
let guitar_height = layout.size.width * theme.guitar.image_size.1 / theme.guitar.image_size.0;
140+
let guitar_size = LayoutSize::new(layout.size.width, guitar_height);
149141
for (parent, mut transform) in sprite_query.iter_mut() {
150142
if parent.0 == entity {
151143
let scale = layout.size.width / theme.guitar.image_size.0;
@@ -155,20 +147,21 @@ impl GuitarView {
155147
}
156148
for (parent, string_entity, mut string_data) in string_query.iter_mut() {
157149
if parent.0 == entity {
158-
string_data.guitar_size = layout.size;
150+
string_data.guitar_size = guitar_size;
159151
string_data.update(&mut commands, &theme, string_entity);
160152
}
161153
}
162-
for (parent, capo_entity, mut capo_data) in capo_query.iter_mut() {
154+
for (parent, finger_entity, mut finger_data) in finger_query.iter_mut() {
163155
if parent.0 == entity {
164-
capo_data.guitar_size = layout.size;
165-
capo_data.update(&mut commands, &theme, capo_entity);
156+
finger_data.value.extra.guitar_size = guitar_size;
157+
finger_data.update(&mut commands, &theme, finger_entity);
166158
}
167159
}
168-
for (parent, finger_entity, mut finger_data) in finger_query.iter_mut() {
160+
for (parent, capo_entity, mut capo_data) in capo_query.iter_mut() {
169161
if parent.0 == entity {
170-
finger_data.value.extra.guitar_size = layout.size;
171-
finger_data.update(&mut commands, &theme, finger_entity);
162+
capo_data.view_size = layout.size;
163+
capo_data.guitar_size = guitar_size;
164+
capo_data.update(&mut commands, &theme, capo_entity);
172165
}
173166
}
174167
}
@@ -289,8 +282,8 @@ impl GuitarView {
289282
string_data.update_value(shape, fretboard, pick, meta.clone());
290283
string_data.update(&mut commands, &theme, string_entity);
291284
}
292-
if let Some(fretboard) = fretboard {
293-
for (capo_entity, mut capo_data) in capo_query.iter_mut() {
285+
for (capo_entity, mut capo_data) in capo_query.iter_mut() {
286+
if let Some(fretboard) = fretboard {
294287
if fretboard.capo != capo_data.capo {
295288
capo_data.capo = fretboard.capo;
296289
capo_data.update(&mut commands, &theme, capo_entity);
@@ -299,4 +292,41 @@ impl GuitarView {
299292
}
300293
}
301294
}
295+
pub fn update_y(
296+
guitar_view_query: &mut Query<&mut Transform, With<Arc<GuitarView>>>,
297+
y: f32,
298+
) {
299+
if let Ok(mut transform) = guitar_view_query.single_mut() {
300+
let trans = transform.translation;
301+
println!("GuitarView::update_y {} -> {}", trans.y, y);
302+
if float_ne!(trans.y, y, abs <= 0.01) {
303+
*transform = Transform::from_xyz(trans.x, y, trans.z);
304+
}
305+
}
306+
}
307+
pub fn adjust_y_by_capo(
308+
theme: Res<NotationTheme>,
309+
settings: Res<NotationSettings>,
310+
capo_query: Query<&GuitarCapoData, Changed<GuitarCapoData>>,
311+
mut guitar_view_query: Query<&mut Transform, With<Arc<GuitarView>>>,
312+
) {
313+
if settings.override_guitar_y.is_some() {
314+
return;
315+
}
316+
for capo_data in capo_query.iter() {
317+
if capo_data.view_size.height <= 0.0 {
318+
return;
319+
}
320+
let y = if capo_data.view_size.height > capo_data.guitar_size.height {
321+
-capo_data.guitar_size.height / 2.0
322+
} else {
323+
let capo_y = theme
324+
.guitar
325+
.calc_fret_y(capo_data.capo, capo_data.guitar_size.height);
326+
-(capo_y + capo_data.guitar_size.height * theme.guitar.capo_height_factor)
327+
};
328+
println!("adjust_y_by_capo {} {} {} -> {}", capo_data.guitar_size, capo_data.view_size, capo_data.capo, y);
329+
Self::update_y(&mut guitar_view_query, y);
330+
}
331+
}
302332
}

crates/notation_bevy/src/mini/mini_bar.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,15 @@ impl ShapeOp<NotationTheme, OutlineRectangle> for MiniBarData {
5555
let color = theme
5656
.colors
5757
.of_option_syllable(self.value.syllable);
58-
let outline_color = theme
58+
let outline_color = if self.value.playing_state.is_current() {
59+
theme
5960
.colors
6061
.mini_map
6162
.bar_outline
62-
.of_state(&self.value.playing_state);
63+
.of_state(&self.value.playing_state)
64+
} else {
65+
theme.colors.of_section(self.bar_props.section_ordinal)
66+
};
6367
let mut z = theme.core.mini_bar_z;
6468
if self.value.playing_state.is_current() {
6569
z += 1.0;
@@ -106,7 +110,7 @@ impl MiniBar {
106110
commands
107111
.entity(shape_entity)
108112
.insert(BarPlaying::new(bar, PlayingState::Idle));
109-
if bar.props.bar_index == 0 {
113+
if bar.props.bar_index == 0 && bar.props.section_ordinal > 0 {
110114
let section_separator_data =
111115
MiniSectionSeparatorData::new(bar, MiniSectionSeparatorValue::new(0.0));
112116
section_separator_data.create(commands, theme, bar_entity);

0 commit comments

Comments
 (0)