Skip to content

Commit 79a9368

Browse files
feat(input): a selected note in its voice's colour, the above-staff ruler, re-pitch, intervals below (#123)
The differences from MuseScore's handbook left in the three input modes, each checked against [Entering notes and rests](https://handbook.musescore.org/basics/entering-notes-and-rests), [Input by duration mode](https://handbook.musescore.org/basics/input-by-duration-mode), [Alternative note input methods](https://handbook.musescore.org/basics/alternative-note-input-methods) and [Working with multiple voices](https://handbook.musescore.org/basics/working-with-multiple-voices). ## A selected note in its voice's colour The handbook: "notes and rests … will be highlighted in the color of their respective voice when you select them." - **Engraver:** the layout marks each lower voice's notes and rests with their voice (`SceneNode::set_voice` in `add_lower_voices`), and `Selectable::voice` carries it. - **View:** the selection layer draws each voice in its colour. Voice 1's is the selection colour; voices 2 to 4 are green, orange and pink unless the theme sets `chart.voice2`…`4`. - **A click on another voice's note or rest** selects that voice's element in note input too (`ChartGesture::Click::voice`, `KEYFLOW_INPUT_MOVE {voice}`). The status line ("Rest · half · voice 2 · bar 1, beat 3") and the next key act on it. Before, the click selected voice 1's note at that beat as well. - **Fixed in passing:** normal mode no longer draws a sliver of the note-input cursor at the bar's start. ## Input by duration: the above-staff ruler The handbook's preference, "Input by duration mode cursor: choose whether to show the above staff ruler or the classic note entry cursor". Its figure shows the ruler: a pin in the voice's colour over where the next note goes, and a tick each duration on to the barline. That is now input by duration's cursor; `KEYFLOW_DURATION_RULER` switches back to the box. ## Re-pitch (⇧⌘I) "The Re-pitch note input method allows you to change the pitches of a sequence of notes while leaving their durations unaltered." `KEYFLOW_REPITCH`, ⇧⌘I (Ctrl+Shift+I off a Mac): - In input by note name, a letter gives the note at the cursor that pitch, its length and ties kept, and moves on to the next note, past rests. - Not by mouse, as in MuseScore. - The status line says it's on. ## Intervals below "For intervals below the selected note, you can apply a custom shortcut of your own." `KEYFLOW_INTERVAL_BELOW_1`–`9` add a note that interval under the chord's lowest note, spelled in the key. They have no key by default and can be bound in the action list. ## Not built, and why - **Real-time input** (automatic and manual): it needs a MIDI keyboard and a metronome, and Keyflow's chart has no MIDI input. - **Insert:** it grows a bar past its time signature (MuseScore shows a "+" over the measure). A Keyflow bar's length is its meter's, so an insert would have to push notes into the next bar, which is a different operation. ## Checked in the app Isolated Architect `main` `48d3894e`: - voice 2's rest selected in green; - the ruler in input by duration; - re-pitch: E G C became A G F with lengths kept (`A:24 G:24 F:22`). Recordings of all three modes with these are on [`pr-media`](https://github.com/FastTrackStudios/keyflow/blob/pr-media/chart-selection-and-input-modes/README.md#round-7-the-input-modes-with-musescores-remaining-behaviours), in `recording/round7/`. ## Tests - **New:** - `each_note_and_rest_knows_its_voice` (engraver); - `re_pitch_changes_the_notes_pitches_and_keeps_their_rhythm`; - intervals below in `alt_number_adds_an_interval_above_the_chord_in_the_key`. - **Manifest test:** checks every key, ⇧⌘I included. Actions without a default key are left out of the keys. - **`just ci`:** passes (2,625 passed, 51 skipped). No `Cargo.lock` change.
2 parents b0b4044 + b82c34f commit 79a9368

9 files changed

Lines changed: 474 additions & 45 deletions

File tree

‎features/engraver/src/engraver/layout/chart/measure_render.rs‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -421,12 +421,14 @@ impl ChartLayoutEngine {
421421

422422
// Voices sharing the bar: voice 1's stems up and its rests raised,
423423
// so the lower voices have the space below.
424-
let lower_voices: Vec<&[super::MelodyNoteSegment]> = melody_data
424+
// Each with its voice (`voices[0]` is voice 2: 1 from 0).
425+
let lower_voices: Vec<(u8, &[super::MelodyNoteSegment])> = melody_data
425426
.map(|d| {
426427
d.voices
427428
.iter()
428-
.map(Vec::as_slice)
429-
.filter(|v| !v.is_empty())
429+
.enumerate()
430+
.filter(|(_, v)| !v.is_empty())
431+
.map(|(k, v)| (u8::try_from(k + 1).unwrap_or(u8::MAX), v.as_slice()))
430432
.collect()
431433
})
432434
.unwrap_or_default();
@@ -494,7 +496,7 @@ impl ChartLayoutEngine {
494496
&self,
495497
result: &mut MeasureScene,
496498
data: &super::MeasureMelodyData,
497-
voices: &[&[super::MelodyNoteSegment]],
499+
voices: &[(u8, &[super::MelodyNoteSegment])],
498500
config: &RhythmBuildConfig,
499501
width_spatiums: f64,
500502
id_base: u64,
@@ -516,7 +518,7 @@ impl ChartLayoutEngine {
516518
let end_x = result.width.max(last.x + last.width);
517519
positions.push((last.tick + last.ticks, end_x));
518520
}
519-
for (k, segments) in voices.iter().enumerate() {
521+
for (k, (voice_index, segments)) in voices.iter().enumerate() {
520522
let voice = super::MeasureMelodyData {
521523
segments: segments.to_vec(),
522524
total_beats: segments.iter().map(|s| s.beats).sum(),
@@ -545,7 +547,10 @@ impl ChartLayoutEngine {
545547
for spec in &rhythm.tuplet_specs {
546548
builder = builder.tuplet_group(spec.start_idx, spec.end_idx, spec.ratio);
547549
}
548-
let built = builder.build(ctx);
550+
let mut built = builder.build(ctx);
551+
// Its notes and rests are this voice's: a selection draws them
552+
// in its colour.
553+
built.scene.set_voice(*voice_index);
549554
result.scene.add_child(built.scene);
550555
}
551556
}

‎features/engraver/src/engraver/layout/chart/select.rs‎

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,14 @@ pub struct Selectable {
8585
/// root: what a highlight draws again in another colour. `None` for a
8686
/// bar, which is the layout's box, not a node.
8787
pub node: Option<Vec<usize>>,
88+
/// The voice a note or rest is in, from 0 (voice 1), when the layout
89+
/// marked it (`SceneNode::set_voice`): what it is highlighted in the
90+
/// colour of, as MuseScore does. `None` for other elements.
91+
pub voice: Option<u8>,
8892
}
8993

90-
/// One element found on the walk: its kind, bounds, span and node.
91-
type Found = (Kind, Rect, Option<TextSpan>, Option<Vec<usize>>);
94+
/// One element found on the walk: its kind, bounds, span, node and voice.
95+
type Found = (Kind, Rect, Option<TextSpan>, Option<Vec<usize>>, Option<u8>);
9296

9397
/// The metadata keys that name an element, and its kind.
9498
const MARKED: &[(&str, Kind)] = &[
@@ -145,7 +149,13 @@ pub fn kind_of(node: &SceneNode) -> Option<Kind> {
145149
#[must_use]
146150
pub fn selectables(layout: &ChartLayoutResult) -> Vec<Selectable> {
147151
let mut found: Vec<Found> = Vec::new();
148-
walk(&layout.scene, Affine::IDENTITY, &mut Vec::new(), &mut found);
152+
walk(
153+
&layout.scene,
154+
Affine::IDENTITY,
155+
&mut Vec::new(),
156+
None,
157+
&mut found,
158+
);
149159

150160
// Every bar, from the layout's own boxes: a measure that wraps is one
151161
// per system it sits on. The count-in's beats (negative ticks, their
@@ -167,9 +177,9 @@ pub fn selectables(layout: &ChartLayoutResult) -> Vec<Selectable> {
167177
);
168178
let seen = found
169179
.iter()
170-
.any(|(kind, r, _, _)| *kind == Kind::Bar && *r == rect);
180+
.any(|(kind, r, _, _, _)| *kind == Kind::Bar && *r == rect);
171181
if !seen && rect.width() > 0.0 {
172-
found.push((Kind::Bar, rect, None, None));
182+
found.push((Kind::Bar, rect, None, None, None));
173183
}
174184
}
175185

@@ -210,7 +220,7 @@ pub fn selectables(layout: &ChartLayoutResult) -> Vec<Selectable> {
210220
.collect();
211221
found
212222
.into_iter()
213-
.map(|(kind, bounds, span, node)| {
223+
.map(|(kind, bounds, span, node, voice)| {
214224
let key = if kind == Kind::Bar {
215225
let measure = bars
216226
.iter()
@@ -237,31 +247,41 @@ pub fn selectables(layout: &ChartLayoutResult) -> Vec<Selectable> {
237247
bounds,
238248
span,
239249
node,
250+
// A note or rest not marked is voice 1's.
251+
voice: matches!(kind, Kind::Note | Kind::Rest).then(|| voice.unwrap_or(0)),
240252
}
241253
})
242254
.collect()
243255
}
244256

245257
/// Collects every named element under `node`; an element inside another
246258
/// (a note in a measure's group) is one of its own.
247-
fn walk(node: &SceneNode, parent: Affine, path: &mut Vec<usize>, found: &mut Vec<Found>) {
259+
fn walk(
260+
node: &SceneNode,
261+
parent: Affine,
262+
path: &mut Vec<usize>,
263+
voice: Option<u8>,
264+
found: &mut Vec<Found>,
265+
) {
248266
if !node.visible {
249267
return;
250268
}
251269
let transform = parent * node.transform;
270+
// The voice of what is inside a node marked with one.
271+
let voice = node.get_voice().or(voice);
252272
if let Some(kind) = kind_of(node)
253273
&& let Some(bounds) = scene_ink_bounds(node, parent)
254274
{
255275
let span = node.get_json_metadata::<TextSpan>(metadata_keys::SOURCE_SPAN);
256-
found.push((kind, bounds, span, Some(path.clone())));
276+
found.push((kind, bounds, span, Some(path.clone()), voice));
257277
// A chord symbol's own parts (its quality, its bass) are it.
258278
if kind == Kind::Chord {
259279
return;
260280
}
261281
}
262282
for (i, child) in node.children.iter().enumerate() {
263283
path.push(i);
264-
walk(child, transform, path, found);
284+
walk(child, transform, path, voice, found);
265285
path.pop();
266286
}
267287
}
@@ -347,6 +367,7 @@ mod tests {
347367
bounds: Rect::new(r.0, r.1, r.2, r.3),
348368
span: None,
349369
node: None,
370+
voice: None,
350371
}
351372
}
352373

‎features/engraver/tests/input_bars.rs‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,31 @@ fn a_chord_entered_at_the_cursor_is_written_in_the_bar_the_cursor_is_drawn_in()
158158
let drawn = chord_over(&items, bar_box(&items, input.selected.unwrap().bar));
159159
assert_eq!(line_of(COUNT_IN, drawn), changed[0].0);
160160
}
161+
162+
/// A selected note or rest is drawn in its voice's colour, as MuseScore's
163+
/// are: each knows its voice, voice 1's notes from 0 and voice 2's from 1.
164+
#[test]
165+
fn each_note_and_rest_knows_its_voice() {
166+
let items =
167+
selectables("Voices\n#C 4/4\n\nVS 1\n<< C_1 ; m{ G:44 G:44 G:42 } ; m{ C:42 r2 } >>\n");
168+
let voices: Vec<(Kind, Option<u8>)> = items
169+
.iter()
170+
.filter(|s| matches!(s.kind, Kind::Note | Kind::Rest))
171+
.map(|s| (s.kind, s.voice))
172+
.collect();
173+
assert!(
174+
voices.iter().filter(|v| v.1 == Some(0)).count() >= 3,
175+
"voice 1's three notes: {voices:?}"
176+
);
177+
assert!(
178+
voices.iter().any(|v| v.1 == Some(1)),
179+
"voice 2's note and rest: {voices:?}"
180+
);
181+
// A chord symbol has no voice.
182+
assert!(
183+
items
184+
.iter()
185+
.filter(|s| s.kind == Kind::Chord)
186+
.all(|s| s.voice.is_none())
187+
);
188+
}

‎features/extension/extension.toml‎

Lines changed: 89 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,10 +411,10 @@ effect = "mutating"
411411
[[actions]]
412412
id = "KEYFLOW_INPUT_MOVE"
413413
name = "Keyflow: move the input cursor"
414-
description = "The note-input cursor to the note, rest or chord at `fraction` (0 to 1) across bar `bar` (the chart's bars from 0), selecting it: what a click on the chart does. `target` (`chords`, `notes`) says which line; `select: false` moves without selecting."
414+
description = "The note-input cursor to the note, rest or chord at `fraction` (0 to 1) across bar `bar` (the chart's bars from 0), selecting it: what a click on the chart does. `target` (`chords`, `notes`) says which line; `select: false` moves without selecting; `voice` (0 to 3), the voice of the note or rest clicked, which note input then enters into."
415415
group = "Keyflow"
416416
effect = "mutating"
417-
params = '{"type":"object","required":["bar"],"properties":{"bar":{"type":"integer","minimum":0},"fraction":{"type":"number","minimum":0,"maximum":1},"target":{"type":"string","enum":["chords","notes"]},"select":{"type":"boolean"}}}'
417+
params = '{"type":"object","required":["bar"],"properties":{"bar":{"type":"integer","minimum":0},"fraction":{"type":"number","minimum":0,"maximum":1},"target":{"type":"string","enum":["chords","notes"]},"select":{"type":"boolean"},"voice":{"type":"integer","minimum":0,"maximum":3}}}'
418418

419419
[[actions]]
420420
id = "KEYFLOW_SYNTAX_WRITE"
@@ -634,6 +634,83 @@ description = "A note a ninth above the selected note's chord (its top note) add
634634
group = "Keyflow"
635635
effect = "mutating"
636636

637+
[[actions]]
638+
id = "KEYFLOW_INTERVAL_BELOW_1"
639+
name = "Keyflow: add unison below"
640+
description = "A note a unison below the selected note's chord (its lowest note) added to it, spelled in the key: MuseScore's add interval below. No key by default; bind one in the action list."
641+
group = "Keyflow"
642+
effect = "mutating"
643+
644+
[[actions]]
645+
id = "KEYFLOW_INTERVAL_BELOW_2"
646+
name = "Keyflow: add second below"
647+
description = "A note a second below the selected note's chord (its lowest note) added to it, spelled in the key: MuseScore's add interval below. No key by default; bind one in the action list."
648+
group = "Keyflow"
649+
effect = "mutating"
650+
651+
[[actions]]
652+
id = "KEYFLOW_INTERVAL_BELOW_3"
653+
name = "Keyflow: add third below"
654+
description = "A note a third below the selected note's chord (its lowest note) added to it, spelled in the key: MuseScore's add interval below. No key by default; bind one in the action list."
655+
group = "Keyflow"
656+
effect = "mutating"
657+
658+
[[actions]]
659+
id = "KEYFLOW_INTERVAL_BELOW_4"
660+
name = "Keyflow: add fourth below"
661+
description = "A note a fourth below the selected note's chord (its lowest note) added to it, spelled in the key: MuseScore's add interval below. No key by default; bind one in the action list."
662+
group = "Keyflow"
663+
effect = "mutating"
664+
665+
[[actions]]
666+
id = "KEYFLOW_INTERVAL_BELOW_5"
667+
name = "Keyflow: add fifth below"
668+
description = "A note a fifth below the selected note's chord (its lowest note) added to it, spelled in the key: MuseScore's add interval below. No key by default; bind one in the action list."
669+
group = "Keyflow"
670+
effect = "mutating"
671+
672+
[[actions]]
673+
id = "KEYFLOW_INTERVAL_BELOW_6"
674+
name = "Keyflow: add sixth below"
675+
description = "A note a sixth below the selected note's chord (its lowest note) added to it, spelled in the key: MuseScore's add interval below. No key by default; bind one in the action list."
676+
group = "Keyflow"
677+
effect = "mutating"
678+
679+
[[actions]]
680+
id = "KEYFLOW_INTERVAL_BELOW_7"
681+
name = "Keyflow: add seventh below"
682+
description = "A note a seventh below the selected note's chord (its lowest note) added to it, spelled in the key: MuseScore's add interval below. No key by default; bind one in the action list."
683+
group = "Keyflow"
684+
effect = "mutating"
685+
686+
[[actions]]
687+
id = "KEYFLOW_INTERVAL_BELOW_8"
688+
name = "Keyflow: add octave below"
689+
description = "A note an octave below the selected note's chord (its lowest note) added to it, spelled in the key: MuseScore's add interval below. No key by default; bind one in the action list."
690+
group = "Keyflow"
691+
effect = "mutating"
692+
693+
[[actions]]
694+
id = "KEYFLOW_INTERVAL_BELOW_9"
695+
name = "Keyflow: add ninth below"
696+
description = "A note a ninth below the selected note's chord (its lowest note) added to it, spelled in the key: MuseScore's add interval below. No key by default; bind one in the action list."
697+
group = "Keyflow"
698+
effect = "mutating"
699+
700+
[[actions]]
701+
id = "KEYFLOW_REPITCH"
702+
name = "Keyflow: re-pitch"
703+
description = "MuseScore's re-pitch method, on or off (Cmd+Shift+I): in input by note name, a letter gives the note at the cursor that pitch, its length kept, and moves on to the next note, past rests."
704+
group = "Keyflow"
705+
effect = "mutating"
706+
707+
[[actions]]
708+
id = "KEYFLOW_DURATION_RULER"
709+
name = "Keyflow: input by duration cursor (ruler or box)"
710+
description = "Input by duration's cursor switched between MuseScore's above-staff ruler (a pin where the next note goes and a tick a duration on to the barline; the default) and the classic box cursor, as MuseScore's Preferences → Note input chooses."
711+
group = "Keyflow"
712+
effect = "mutating"
713+
637714
[[actions]]
638715
id = "KEYFLOW_CHORD_EDIT"
639716
name = "Keyflow: retype chord symbol"
@@ -1285,6 +1362,16 @@ chord = "⌥↓"
12851362
action = "KEYFLOW_QUALITY_DOWN"
12861363
when = "view:chart"
12871364

1365+
[[keys]]
1366+
chord = "⇧⌘I"
1367+
action = "KEYFLOW_REPITCH"
1368+
when = "view:chart"
1369+
1370+
[[keys]]
1371+
chord = "⌃⇧I"
1372+
action = "KEYFLOW_REPITCH"
1373+
when = "view:chart"
1374+
12881375
[[keys]]
12891376
chord = "J"
12901377
action = "KEYFLOW_RESPELL"

‎features/extension/src/input.rs‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ pub const OP_ACTIONS: &[OpAction] = &[
6262
op("KEYFLOW_QUALITY_UP", Op::Quality(true), "⌥↑"),
6363
op("KEYFLOW_QUALITY_DOWN", Op::Quality(false), "⌥↓"),
6464
op("KEYFLOW_RESPELL", Op::Respell, "J"),
65+
// MuseScore's re-pitch method (Cmd+Shift+I).
66+
op("KEYFLOW_REPITCH", Op::Repitch, "⇧⌘I"),
6567
// MuseScore's add interval: Alt+1–9, a unison to a ninth above.
6668
op("KEYFLOW_INTERVAL_1", Op::Interval(1), "⌥1"),
6769
op("KEYFLOW_INTERVAL_2", Op::Interval(2), "⌥2"),
@@ -72,6 +74,17 @@ pub const OP_ACTIONS: &[OpAction] = &[
7274
op("KEYFLOW_INTERVAL_7", Op::Interval(7), "⌥7"),
7375
op("KEYFLOW_INTERVAL_8", Op::Interval(8), "⌥8"),
7476
op("KEYFLOW_INTERVAL_9", Op::Interval(9), "⌥9"),
77+
// MuseScore's add interval below: no key by default; bound by the
78+
// person, as MuseScore's are.
79+
op("KEYFLOW_INTERVAL_BELOW_1", Op::Interval(-1), ""),
80+
op("KEYFLOW_INTERVAL_BELOW_2", Op::Interval(-2), ""),
81+
op("KEYFLOW_INTERVAL_BELOW_3", Op::Interval(-3), ""),
82+
op("KEYFLOW_INTERVAL_BELOW_4", Op::Interval(-4), ""),
83+
op("KEYFLOW_INTERVAL_BELOW_5", Op::Interval(-5), ""),
84+
op("KEYFLOW_INTERVAL_BELOW_6", Op::Interval(-6), ""),
85+
op("KEYFLOW_INTERVAL_BELOW_7", Op::Interval(-7), ""),
86+
op("KEYFLOW_INTERVAL_BELOW_8", Op::Interval(-8), ""),
87+
op("KEYFLOW_INTERVAL_BELOW_9", Op::Interval(-9), ""),
7588
];
7689

7790
/// The toolbar's actions that are note input's operations, and their keys
@@ -109,6 +122,7 @@ pub const CHORD_EDIT_KEY: (&str, &str) = ("KEYFLOW_CHORD_EDIT", "↵");
109122
pub fn default_keys() -> impl Iterator<Item = (&'static str, &'static str)> {
110123
OP_ACTIONS
111124
.iter()
125+
.filter(|a| !a.key.is_empty())
112126
.map(|a| (a.action, a.key))
113127
.chain(TOOL_KEYS.iter().copied())
114128
.chain(HISTORY_KEYS.iter().copied())

‎features/extension/src/keep.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ mod tests {
153153
selected: Some(Pos { bar: 11, tick: 0 }),
154154
target: Target::Notes,
155155
voice: 2,
156+
repitch: false,
156157
};
157158
let back = input_from(&input_json(&i));
158159
assert_eq!(back, i);

0 commit comments

Comments
 (0)