Skip to content

Commit 8991144

Browse files
committed
wip
1 parent f59a024 commit 8991144

File tree

5 files changed

+81
-54
lines changed

5 files changed

+81
-54
lines changed

apps/notation_kb/src/index_panel.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ impl IndexPanel {
5858
pub const LINK_SOUND_SINGLE_STRING: &'static str = ":kb:sound:single_string";
5959

6060
pub const LINK_MIDI_PLAY: &'static str = ":midi:play";
61+
pub const LINK_MIDI_STOP: &'static str = ":midi:stop";
6162
}
6263

6364
impl KbPanel for IndexPanel {
@@ -106,9 +107,11 @@ impl IndexPanel {
106107
}
107108
pub fn hack_settings(
108109
state: Res<NotationState>,
109-
theme: Res<NotationTheme>,
110+
mut theme: ResMut<NotationTheme>,
110111
mut settings: ResMut<NotationSettings>,
111112
) {
113+
theme.sizes.melody.note_height = 8.0;
114+
theme.sizes.melody.semitone_height = 8.0;
112115
settings.hide_mini_map = true;
113116
settings.hide_bar_number = true;
114117
settings.layout.focus_bar_ease_ms = 0;
@@ -200,10 +203,13 @@ impl IndexPanel {
200203
Self::LINK_SOUND_SINGLE_STRING => {
201204
self.current_page_id = Self::SOUND;
202205
self.sound.section = SoundSection::SingleString(Default::default());
203-
}
206+
},
204207
Self::LINK_MIDI_PLAY => {
205208
MidiControl::play(midi_state, play_control_evts)
206-
}
209+
},
210+
Self::LINK_MIDI_STOP => {
211+
MidiControl::stop(midi_state, play_control_evts)
212+
},
207213
_ => (),
208214
}
209215
}

apps/notation_kb/src/theory/scale.rs

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub struct ScalePage {
1212
pub path: &'static str,
1313
pub scale: Scale,
1414
pub key: notation_bevy::prelude::Key,
15+
pub transpose: i8,
1516
}
1617

1718
impl KbPage for ScalePage {
@@ -53,12 +54,15 @@ impl KbPage for ScalePage {
5354
});
5455
});
5556
ui.separator();
56-
NotesPage::notes_ui(ui, texts, assets, state, theme, link_evts, self.scale, self.key);
57+
NotesPage::notes_ui(ui, texts, assets, state, theme, link_evts, self.scale, self.key, self.transpose);
5758
ui.separator();
5859
ui.horizontal(|ui| {
5960
if ui.button("play").clicked() {
6061
link_evts.send(EasyLinkEvent::from(IndexPanel::LINK_MIDI_PLAY));
6162
}
63+
if ui.button("stop").clicked() {
64+
link_evts.send(EasyLinkEvent::from(IndexPanel::LINK_MIDI_STOP));
65+
}
6266
});
6367
}
6468
}
@@ -82,6 +86,7 @@ impl ScalePage {
8286
path,
8387
scale: Default::default(),
8488
key: Default::default(),
89+
transpose: 0,
8590
}
8691
}
8792
pub fn make_tab(&self) -> ProtoTab {
@@ -91,28 +96,40 @@ impl ScalePage {
9196
);
9297
let mut entries = vec![];
9398
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)));
99+
let mut add_note = |syllable: &Syllable, semitones: Option<Semitones>| {
100+
let note = Note::from(
101+
Semitones::from(Octave::CENTER)
102+
+ Semitones::from(self.key.clone())
103+
+ Semitones::from(self.scale.calc_syllable_for_sort(syllable))
104+
+ semitones.unwrap_or(Semitones(0))
105+
);
96106
entries.push(ProtoEntry::from(CoreEntry::from((Tone::from(note), duration))));
107+
};
108+
let mut syllables = self.scale.get_syllables();
109+
for syllable in syllables.iter() {
110+
add_note(syllable, None);
97111
}
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![
112+
add_note(&self.scale.calc_root_syllable(), Some(Semitones(12)));
113+
add_note(&self.scale.calc_root_syllable(), Some(Semitones(12)));
114+
syllables.reverse();
115+
for syllable in syllables.iter() {
116+
add_note(syllable, None);
117+
}
118+
let new_bar = |index: usize| {
102119
ProtoBar::new(
103120
vec![
104121
ProtoBarLayer::new("notes".to_owned(), vec![
105-
Slice::new(SliceBegin::Index(0), SliceEnd::Count(4), None),
122+
Slice::new(SliceBegin::Index(index), SliceEnd::Count(4), None),
106123
])
107124
],
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-
),
125+
)
126+
};
127+
let track = ProtoTrack::new("notes".to_owned(), TrackKind::Vocal, entries);
128+
let bars = vec![
129+
new_bar(0),
130+
new_bar(4),
131+
new_bar(8),
132+
new_bar(12),
116133
];
117134
let section = ProtoSection::new("notes".to_owned(), SectionKind::Rest, bars);
118135
ProtoTab::new(

crates/notation_bevy/src/kb/notes_page.rs

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,13 @@ impl KbPage for NotesPage {
3535
.unwrap_or_default();
3636
PageHelper::add_key_scale(ui, &key, &scale);
3737
ui.separator();
38-
Self::notes_ui(ui, texts, assets, state, theme, link_evts, scale, key);
38+
39+
let capo = state.tab.as_ref().and_then(|tab| {
40+
tab.get_track_of_kind(TrackKind::Guitar)
41+
.and_then(|x| x.get_fretboard6())
42+
}).map(|x| x.capo).unwrap_or(0);
43+
let transpose = capo as i8;
44+
Self::notes_ui(ui, texts, assets, state, theme, link_evts, scale, key, transpose);
3945
}
4046
}
4147

@@ -44,11 +50,12 @@ impl NotesPage {
4450
ui: &mut Ui,
4551
_texts: &Assets<MarkDownAsset>,
4652
_assets: &NotationAssets,
47-
state: &NotationState,
53+
_state: &NotationState,
4854
theme: &NotationTheme,
4955
_link_evts: &mut EventWriter<EasyLinkEvent>,
5056
scale: Scale,
5157
key: Key,
58+
transpose: i8,
5259
) {
5360
let strong_style = EasyMarkStyle {
5461
strong: true,
@@ -72,36 +79,31 @@ impl NotesPage {
7279
PageHelper::add_syllable_pitch(ui, theme, &scale, &key, syllable, index == 0);
7380
}
7481
ui.end_row();
75-
if let Some(fretboard) = state.tab.as_ref().and_then(|tab| {
76-
tab.get_track_of_kind(TrackKind::Guitar)
77-
.and_then(|x| x.get_fretboard6())
78-
}) {
79-
if fretboard.capo > 0 {
80-
ui.separator();
81-
ui.add(label_from_style("guitar", &strong_style));
82-
ui.add(label_from_style("capo", &strong_style));
83-
ui.add(label_from_style("at", &strong_style));
84-
ui.add(label_from_style(
85-
fretboard.capo.to_string().as_str(),
86-
&strong_style,
87-
));
88-
let frets = if fretboard.capo == 1 { "fret" } else { "frets" };
89-
ui.add(label_from_style(frets, &strong_style));
90-
ui.separator();
91-
ui.end_row();
92-
for (index, syllable) in syllables.iter().enumerate() {
93-
PageHelper::add_syllable_pitch_with_capo(
94-
ui,
95-
theme,
96-
fretboard.capo,
97-
&scale,
98-
&key,
99-
syllable,
100-
index == 0,
101-
);
102-
}
103-
ui.end_row();
82+
if transpose != 0 {
83+
ui.separator();
84+
ui.add(label_from_style("guitar", &strong_style));
85+
ui.add(label_from_style("capo", &strong_style));
86+
ui.add(label_from_style("at", &strong_style));
87+
ui.add(label_from_style(
88+
transpose.to_string().as_str(),
89+
&strong_style,
90+
));
91+
let frets = if transpose == 1 { "fret" } else { "frets" };
92+
ui.add(label_from_style(frets, &strong_style));
93+
ui.separator();
94+
ui.end_row();
95+
for (index, syllable) in syllables.iter().enumerate() {
96+
PageHelper::add_syllable_pitch_with_transpose(
97+
ui,
98+
theme,
99+
transpose,
100+
&scale,
101+
&key,
102+
syllable,
103+
index == 0,
104+
);
104105
}
106+
ui.end_row();
105107
}
106108
});
107109
}

crates/notation_bevy/src/kb/page_helper.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,17 @@ impl PageHelper {
6666
let text = pitch.to_string();
6767
Self::add_maybe_strong_text(ui, strong, &text);
6868
}
69-
pub fn add_syllable_pitch_with_capo(
69+
pub fn add_syllable_pitch_with_transpose(
7070
ui: &mut Ui,
7171
_theme: &NotationTheme,
72-
capo: u8,
72+
transpose: i8,
7373
scale: &Scale,
7474
key: &Key,
7575
syllable: &Syllable,
7676
strong: bool,
7777
) {
7878
let pitch = scale.calc_pitch(&key, &syllable);
79-
let pitch = Pitch::from(Semitones::from(pitch) - Semitones(capo as i8));
79+
let pitch = Pitch::from(Semitones::from(pitch) - Semitones(transpose));
8080
let text = pitch.to_string();
8181
Self::add_maybe_strong_text(ui, strong, &text);
8282
}

crates/notation_midi/src/midi_state.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,9 @@ impl MidiState {
351351
self.tab = Some(tab.clone());
352352
self.reset_channels();
353353
let mut index: usize = 0;
354-
self.create_click_channel(settings, hub, &tab, &mut index);
354+
if tab.sections.len() > 1 {
355+
self.create_click_channel(settings, hub, &tab, &mut index);
356+
}
355357
for track in tab.tracks.iter() {
356358
if index >= self.channels.len() {
357359
return;

0 commit comments

Comments
 (0)