head_music 23.0.0 → 24.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -1
  3. data/.rspec_parallel +2 -0
  4. data/CHANGELOG.md +44 -0
  5. data/CLAUDE.md +5 -4
  6. data/Gemfile +1 -0
  7. data/Gemfile.lock +13 -10
  8. data/MUSIC_THEORY.md +1 -1
  9. data/Rakefile +55 -4
  10. data/bin/validate +1 -1
  11. data/lib/head_music/content/flow/staff_system_values.rb +2 -6
  12. data/lib/head_music/content/staff.rb +6 -2
  13. data/lib/head_music/instruments/alternate_tuning.rb +1 -1
  14. data/lib/head_music/instruments/alternate_tunings.yml +7 -4
  15. data/lib/head_music/instruments/instrument.rb +5 -2
  16. data/lib/head_music/instruments/instrument_family.rb +4 -0
  17. data/lib/head_music/instruments/instruments.yml +8 -0
  18. data/lib/head_music/instruments/stringings.yml +14 -0
  19. data/lib/head_music/locales/de.yml +8 -0
  20. data/lib/head_music/locales/en.yml +59 -0
  21. data/lib/head_music/locales/en_GB.yml +10 -0
  22. data/lib/head_music/locales/es.yml +8 -0
  23. data/lib/head_music/locales/fr.yml +8 -0
  24. data/lib/head_music/locales/it.yml +8 -0
  25. data/lib/head_music/locales/ru.yml +8 -0
  26. data/lib/head_music/midi/instrument_map.rb +2 -1
  27. data/lib/head_music/named.rb +11 -1
  28. data/lib/head_music/notation/concert_transposition.rb +8 -0
  29. data/lib/head_music/notation/instrument_names.rb +62 -0
  30. data/lib/head_music/notation/lily_pond/context_reader.rb +13 -3
  31. data/lib/head_music/notation/lily_pond/document.rb +25 -0
  32. data/lib/head_music/notation/lily_pond/flow_builder.rb +2 -0
  33. data/lib/head_music/notation/lily_pond/grace_reader.rb +38 -9
  34. data/lib/head_music/notation/lily_pond/part_layout.rb +26 -8
  35. data/lib/head_music/notation/lily_pond/render_plan.rb +21 -0
  36. data/lib/head_music/notation/lily_pond/setting_reader.rb +19 -2
  37. data/lib/head_music/notation/lily_pond/transposition_walk.rb +141 -0
  38. data/lib/head_music/notation/lily_pond/voice_context.rb +4 -2
  39. data/lib/head_music/notation/lily_pond/voice_item_reader.rb +2 -1
  40. data/lib/head_music/notation/lily_pond/voice_stream.rb +50 -14
  41. data/lib/head_music/notation/lily_pond/voice_writer.rb +18 -10
  42. data/lib/head_music/notation/lily_pond/writer.rb +3 -3
  43. data/lib/head_music/notation/music_xml/identity_reader.rb +54 -4
  44. data/lib/head_music/notation/music_xml/instrument_sounds.rb +15 -2
  45. data/lib/head_music/notation/music_xml/instrument_sounds.yml +3 -0
  46. data/lib/head_music/notation/music_xml/note_writer.rb +13 -3
  47. data/lib/head_music/notation/music_xml/part_reader.rb +36 -5
  48. data/lib/head_music/notation/music_xml/part_roster.rb +18 -1
  49. data/lib/head_music/notation/music_xml/part_writer.rb +20 -2
  50. data/lib/head_music/notation/music_xml/score_instruments.rb +20 -0
  51. data/lib/head_music/notation/music_xml/shared_instrument_sounds.yml +22 -0
  52. data/lib/head_music/notation/music_xml/writer.rb +10 -11
  53. data/lib/head_music/notation/notation_styles.yml +8 -0
  54. data/lib/head_music/notation.rb +1 -0
  55. data/lib/head_music/rudiment/clef.rb +8 -2
  56. data/lib/head_music/style/guide.rb +5 -2
  57. data/lib/head_music/style/guideline/bar_texture.rb +79 -0
  58. data/lib/head_music/style/guideline/dissonance_figures.rb +88 -0
  59. data/lib/head_music/style/guideline/harmonic_context.rb +1 -1
  60. data/lib/head_music/style/guideline/restruck_suspensions.rb +38 -0
  61. data/lib/head_music/style/guideline/voice_context.rb +34 -3
  62. data/lib/head_music/style/guidelines/allow_free_species_rhythmic_values.rb +80 -0
  63. data/lib/head_music/style/guidelines/always_move.rb +14 -3
  64. data/lib/head_music/style/guidelines/bar_count.rb +103 -0
  65. data/lib/head_music/style/guidelines/clausula_vera.rb +147 -0
  66. data/lib/head_music/style/guidelines/consonant_downbeats.rb +9 -6
  67. data/lib/head_music/style/guidelines/dissonance_figure_detection.rb +12 -70
  68. data/lib/head_music/style/guidelines/embellished_suspension_treatment.rb +2 -4
  69. data/lib/head_music/style/guidelines/free_dissonance_treatment.rb +157 -0
  70. data/lib/head_music/style/guidelines/independent_textures.rb +49 -0
  71. data/lib/head_music/style/guidelines/mix_species_textures.rb +4 -46
  72. data/lib/head_music/style/guidelines/no_parallel_perfect_across_barline.rb +2 -2
  73. data/lib/head_music/style/guides/composite_guide.rb +35 -4
  74. data/lib/head_music/style/guides/free_species_harmony.rb +29 -0
  75. data/lib/head_music/style/guides/free_species_melody.rb +27 -0
  76. data/lib/head_music/version.rb +1 -1
  77. data/lib/head_music.rb +10 -0
  78. data/user-stories/backlog/eighteenth-century-two-voice-counterpoint-guide.md +46 -0
  79. data/user-stories/backlog/fifth-species-published-examples.md +60 -0
  80. data/user-stories/backlog/free-species-translations.md +35 -0
  81. data/user-stories/backlog/free-species-with-imitation-guide.md +79 -0
  82. data/user-stories/backlog/free-species-with-sequence-guide.md +83 -0
  83. data/user-stories/done/banjo-notation-transpositions.md +369 -0
  84. data/user-stories/done/faster-test-suite.md +289 -0
  85. data/user-stories/done/free-species-guide.md +254 -0
  86. data/user-stories/done/lilypond-transposition-round-trip.md +330 -0
  87. data/user-stories/done/musicxml-instrument-fallback.md +468 -0
  88. data/user-stories/index.html +40 -0
  89. metadata +27 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 157433aaffa6dc30444fe1d12511bbf3dbc1877a8384a19fb82b30b99037174d
4
- data.tar.gz: 3168adc5bd7500b9b4e07e3b10f718e421ec5ff2419cb647e814ffe6e41d1561
3
+ metadata.gz: d001cb01522c5a296bbe9a862733d7a3853423ca4d4f085261ce0e67759052a0
4
+ data.tar.gz: 91d9579f89543fce994b751bcd20f55ac2aed98053e3a09d024e82e379bf0916
5
5
  SHA512:
6
- metadata.gz: 63e33e764528684fdff03cd3473653f64c61d136eebff7a30fe408cceabb190e13594e96d55a33e991757547ce0ab4955c1b64bc24f2b6e02407009cdac57d82
7
- data.tar.gz: 42e936c6dc431e27ebd16a6af38bc4fc1545a599bdd84bfa3c01ac204cb7b1bbedbe639f370f93a0abf1ef33d77a5bf95c9a1f3468aa5df7a812d77ce9fa303b
6
+ metadata.gz: 138dc1746d0a60782141fc7dffa392ec067ffe74c57e1f64136cff4860e891460ff97b8aa45864f7b7c4134960d090e971a729fefdba9e203054a143e7f07908
7
+ data.tar.gz: ff1aaf0b30fb201a65fca261979b2653c031913cb333ea58faa3f023eafc61d4f314b8ce5d120b906f7b9be532dde048cfc55bdba59a479faebef11d611ea13c
data/.gitignore CHANGED
@@ -6,7 +6,7 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
- /spec/examples.txt
9
+ /spec/examples*.txt
10
10
  *.gem
11
11
  .DS_Store
12
12
 
data/.rspec_parallel ADDED
@@ -0,0 +1,2 @@
1
+ --format progress
2
+ --format ParallelTests::RSpec::RuntimeLogger --out tmp/parallel_runtime_rspec.log
data/CHANGELOG.md CHANGED
@@ -7,6 +7,50 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [24.0.0] - 2026-11-16
11
+
12
+ Free species arrives: `Guide.get("free_species")` grades two voices composed together with no cantus firmus, with the guidelines it needs, and a composite guide can now be configured as a whole. MusicXML and LilyPond keep a part's instruments and their transpositions through a write and a read, the tenor and Irish tenor banjos join the catalog, and the banjo's alternate tunings sound the pitches they name.
13
+
14
+ **This is a major release**, because LilyPond reads several voices on one `\new Staff` as one part, where it read a part per voice. A consumer reading such staves gets one part with a role for each voice, taken from its `\new Voice` name, and the staff's `instrumentName` as the player's name. Counterpoint graded against a florid cantus firmus may also grade differently, since a downbeat now comes from the meter. Other consumers upgrade by upgrading.
15
+
16
+ ### Added
17
+
18
+ - The banjo has a `c_tuning` alternate tuning (gCGBD), the tuning of the classic banjo.
19
+ - The tenor banjo (C3 G3 D4 A4) and the Irish tenor banjo (G2 D3 A3 E4) join the banjo family as instruments of their own. Both are written in treble clef an octave above sounding, like the five-string banjo. MusicXML's `pluck.banjo.tenor` reads as the tenor banjo, and as the Irish tenor banjo when the part names it.
20
+ - **Free species.** `Guide.get("free_species")` grades two voices composed together in species technique with no cantus firmus: either voice, neither marked `cantus_firmus?`, against the other. It is a composite of `free_species_melody` and `free_species_harmony`, as `fifth_species` is, and a fifth-species exercise is valid free species, its cantus firmus a voice that keeps to whole notes. Its strings are in English, with British note values; other locales fall back to English for now, except the note values, which are translated.
21
+ - `ConsonantDownbeats.with(restruck_suspensions: true)` and `AlwaysMove.with(restruck_suspensions: true)`, used by the free species guide, excuse a suspension struck again rather than tied: the pitch repeated on a stronger beat, dissonant with the other voice. `AlwaysMove` still marks a consonant repetition.
22
+ - `FreeDissonanceTreatment`: fifth species' dissonance treatment, with either voice able to explain a dissonance by a figure in its own line. Only the downbeat forbids an attacked dissonance. A note held into a strong beat from a weaker one, or struck again there, is a suspension: prepared as a consonance and resolved down by step to a consonance by the second strong beat after it, with decoration between. A passing or neighbor figure runs from consonance to consonance, so two lines stepping in parallel sevenths explain nothing. An unexplained dissonance marks every voice that attacked into it.
23
+ - `ClausulaVera`: the two-part cadence, the leading tone and the second degree stepping in contrary motion to the tonic in an octave or unison, either voice carrying either. The two sound a minor third (or tenth) or a major sixth just before the final, so one of them moves by half step: the leading tone, or in Phrygian the second degree. `.with(forms:)` names any form it does not yet support.
24
+ - `IndependentTextures`: marks runs of more than two bars where both voices share one species texture. Each voice may keep one texture as long as it likes.
25
+ - `AllowFreeSpeciesRhythmicValues`: fifth species' note values with a whole note in any bar, and with `dotted_rhythms: true`, a dotted half or whole and a dotted quarter followed by an eighth that steps on.
26
+ - `BarCount.with(range)`: a passage's length in bars, from the first entry of either voice, as an Integer or any Range.
27
+ - `CompositeGuide#with` configures a composite as a whole, routing each option to the member that takes it: `Guide.get("free_species").with(dotted_rhythms: true, bars: 8..12)`. A configured composite keeps the registered guide's display name and instruction but has no `key`, as a configured guide has none, so store the options beside the registered key and configure again when grading.
28
+
29
+ ### Changed
30
+
31
+ - Counterpoint guidelines read a downbeat from the meter, as the first beat of the bar, where they took it from wherever the cantus firmus attacked. No species counterpoint grades differently, since a species cantus firmus attacks every downbeat; a cantus firmus graded against a florid line does, since every attack of the florid line used to count as its downbeat. `ConsonantDownbeats` excuses a suspension held over the barline in either voice, not only the graded one.
32
+ - **Breaking.** LilyPond reads several voices on one `\new Staff` as one part, where it read each as a part of its own, every voice taking the staff's `instrumentName` as its role. Each now takes its own `\new Voice = "…"` name as its role, or none, and the writer names each voice of a several-voice staff for its role, as it did on grouped staves, so a two-voice part round-trips as one part with its roles. The staff's `instrumentName` is now the part's player's name, as a MusicXML part name is, so a name such as "Melody" is kept and written back. A staff's only voice keeps the staff's name as its role, and voices outside any staff are still a part each. A `\new Dynamics` beside such a staff places its dynamics once.
33
+ - LilyPond names the instrument of a several-voice staff's part from its `instrumentName`, in the same forms MusicXML part names are read ("Clarinet in A", "A Clarinet", "Violin 1"), with its opening `\transposition` choosing among the instrument's key variants: a staff named "Clarinet" holding `\transposition a` reads as the clarinet in A. A name the catalog does not know names no instrument, but still names the player. LilyPond still reads no instrument for a single-voice staff, and no instrument changes.
34
+ - MusicXML keeps a part's instrument changes. The writer writes a `<score-instrument>` for each instrument a part plays, an `<instrument id>` on each of its notes, and a `<sound><instrument-change>` where it changes, as MuseScore 4 does; a change used to be written as its `<transpose>` alone and read back as a change of transposition. The reader takes a change from either a note's `<instrument>` or an `<instrument-change>`, from the downbeat of the bar it comes in. A part with several `<score-instrument>`s no longer takes its instrument from its part name. MuseScore 4 now reads the gem's instrument changes, and plays a transposed render's at each instrument's transposition.
35
+ - MusicXML keeps every catalog instrument through a write and a read, with its transposition. The 23 instruments without a standard sound of their own, such as the clarinet in C, the trumpet in E♭, the Irish tenor banjo, the ukuleles, and the toms, used to be written with no `<score-instrument>` and read back with no instrument.
36
+ - The writer writes a `<score-instrument>` with an `<instrument-name>` for every instrument. An instrument without a sound of its own writes the nearest standard one, as MuseScore and Dorico do: `wind.reed.clarinet` for the clarinet in C, `pluck.banjo.tenor` for the Irish tenor banjo. Only the synthesizer writes no sound.
37
+ - The soprillo writes and reads `wind.reed.saxophone.sopranissimo`, and the maracas `rattle.maraca`.
38
+ - The reader takes the instrument from `<instrument-name>`, then `<part-name>`, then `<virtual-name>`, where the name is in the same family as `<instrument-sound>` or there is no sound, and from the sound otherwise. So a part named "Irish tenor banjo" with `pluck.banjo.tenor` reads as the Irish tenor banjo, and a part named "Soprano" with a soprano saxophone's sound reads as the saxophone. A general sound outside the table, such as `wind.reed.saxophone`, still holds the name to its family, so "Soprano" with it reads as no instrument.
39
+ - Names are read in the forms other programs write: "C Clarinet", "Trumpet in Bb", "Trumpet in B-flat", "Horn in F", "English Horn in F", "Violin 1".
40
+ - Where the instrument read has variants, as the clarinet does, the part's first `<transpose>` picks among them, so a part named "Clarinet", or with only `wind.reed.clarinet`, transposing a minor third down reads as the clarinet in A. A name with a key, such as "clarinet in C", keeps its instrument.
41
+ - A part with no `<score-instrument>` still reads with no instrument, whatever its part name. None of the MusicXML fixtures in the specs reads differently.
42
+
43
+ ### Fixed
44
+
45
+ - LilyPond reads `\transposition`. Every transposed part the writer wrote raised `UnsupportedFeatureError` on reading. The reader now reads the notes, chords, grace notes, and keys after it at concert pitch, a key written just before it on the same downbeat too. Its pitch is absolute even inside `\relative`, as in LilyPond. Since it sets a Staff property, one in any voice of a staff reaches the staff's other voices from the moment it is made, and a staff's `\transposition` reaches the voices inside it. It is read among grace notes, holding from the grace note after it, and between the halves of a tied note, which holds its first pitch. One in a `\new Dynamics` is read for its syntax alone. A concert key needing more than seven sharps or flats raises `UnsupportedFeatureError`.
46
+ - The LilyPond writer restates `\transposition` where a part's instrument changes its transposition, with `\transposition c'` for an instrument in C. It wrote one only at the part's opening, so a transposed part read back, and played in LilyPond's MIDI, at the wrong pitch from the change on. A staff nobody is written on now restates the transposition and the key there too, where it used to keep printing the old key.
47
+ - MusicXML reads a written key and a `<transpose>` on the same downbeat together, whichever comes first. MuseScore 4 writes a bar's key in an `<attributes>` before the one holding its new `<transpose>`, so the key was read under the old transposition: an A clarinet's E♭ major after a B♭ clarinet read as D♭ major rather than C major.
48
+ - `Clef.get` answers nil for a name no clef answers to, as the other catalogs do, instead of raising `NoMethodError`. A `Content::Staff` given an unknown clef, opening or as a change, raises `ArgumentError` naming it.
49
+ - A serialized staff with the neutral (percussion) clef deserializes. It was refused as an unknown clef, since the check took a clef with no pitch for none at all.
50
+ - An instrument or instrument family looked up by a name that matches nothing is no longer kept, so reading files with many unrecognized part names does not grow the lookup cache.
51
+ - `Instrument.all` lists each catalog instrument once. It listed every instance looked up before its first call, so a lookup by alias or translated name added a duplicate, and a lookup of an unknown name added an instrument with no `name_key`.
52
+ - The banjo's alternate tunings sound the pitches they name. Their offsets were wrong, so `double_c` tuned to F4 C3 G3 A3 D4 instead of G4 C3 G3 C4 D4, `sawmill` to F4 C3 G3 B3 C4 instead of G4 D3 G3 C4 D4, and `open_d` to D4 C3 F3 A♯3 C4 instead of F♯4 D3 F♯3 A3 D4.
53
+
10
54
  ## [23.0.0] - 2026-10-30
11
55
 
12
56
  Eighteen stories since 22.0.0, most of them about getting music in and out. head_music now reads and writes MusicXML, MEI, MIDI, and Humdrum **kern beside ABC and LilyPond, infers a key and respells pitches for formats that carry none, and a flow holds the articulations, ornaments, dynamics, hairpins, bar markings, spans, tuplets, grace notes, tempo and meter changes, and lyric extenders those formats write. Underneath, a voice's contents are now voice events, notes and rests of their own classes, and a tied length is a `RhythmicDuration` rather than a chain hung off a `RhythmicValue`.
data/CLAUDE.md CHANGED
@@ -13,9 +13,10 @@ HeadMusic is a Ruby gem for Western music theory. It provides a comprehensive to
13
13
  `rake -T` lists the custom tasks.
14
14
 
15
15
  ```bash
16
- bundle exec rake validate # tests with coverage, linting, security audit, code quality
17
- bundle exec rake # tests WITH coverage (the default task, same as `rake spec`)
18
- bundle exec rspec # tests WITHOUT coverage, so a single file can run on its own
16
+ bundle exec rake validate # parallel tests without coverage, linting, security audit, code quality
17
+ bundle exec rake # parallel tests WITH coverage (the default task, same as `rake spec`)
18
+ bundle exec rake spec:without_coverage # parallel tests alone, as `rake validate` runs them
19
+ bundle exec rspec # serial tests WITHOUT coverage, so a single file can run on its own
19
20
  bundle exec rake coverage # opens the last coverage report
20
21
  bundle exec rake oracles # only the specs checked against outside tools and files, each missing one saying how to set it up
21
22
  ```
@@ -42,7 +43,7 @@ Do not use an assignment inside a condition.
42
43
 
43
44
  ### Testing
44
45
 
45
- Tests are written in RSpec and located in the `/spec` directory, mirroring the `/lib` structure. The project requires 90% code coverage minimum. Coverage is opt-in: `rake spec` sets `COVERAGE=true`, and `spec_helper.rb` starts SimpleCov only then.
46
+ Tests are written in RSpec and located in the `/spec` directory, mirroring the `/lib` structure. The project requires 90% code coverage minimum. Coverage is opt-in: `rake spec` sets `COVERAGE=true`, and `spec_helper.rb` starts SimpleCov only then. `rake spec` and `rake validate` run the specs with `parallel_rspec`, one process per core, and SimpleCov merges the processes before checking the minimum. Both take `SPEC=path` to narrow the run. Each process writes its own status file, and the task folds them back into `spec/examples.txt`, so `rspec --only-failures` works after a parallel run. `rake validate` skips coverage to save time; run `rake spec` occasionally to check it. CI checks it on pushes to `main` and on pull requests.
46
47
 
47
48
  ## Architecture
48
49
 
data/Gemfile CHANGED
@@ -14,6 +14,7 @@ gem "activesupport", "~> #{activesupport_version}.0" unless activesupport_versio
14
14
  gem "standard", require: false
15
15
 
16
16
  group :test do
17
+ gem "parallel_tests", require: false
17
18
  # rubocop is not listed directly: standard pins it (~> 1.91.0) and must
18
19
  # lead. Listing it here let Dependabot bump it past standard, which the
19
20
  # resolver "fixed" by downgrading standard 1.56 -> 1.35.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- head_music (23.0.0)
4
+ head_music (24.0.0)
5
5
  activesupport (>= 7.0, < 10)
6
6
  humanize (>= 2, < 4)
7
7
  i18n (~> 1.8)
@@ -10,7 +10,7 @@ PATH
10
10
  GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
- activesupport (8.1.4)
13
+ activesupport (8.1.4.1)
14
14
  base64
15
15
  bigdecimal
16
16
  concurrent-ruby (~> 1.0, >= 1.3.1)
@@ -23,7 +23,7 @@ GEM
23
23
  securerandom (>= 0.3)
24
24
  tzinfo (~> 2.0, >= 2.0.5)
25
25
  uri (>= 0.13.1)
26
- addressable (2.9.0)
26
+ addressable (2.9.2)
27
27
  public_suffix (>= 2.0.2, < 8.0)
28
28
  ast (2.4.3)
29
29
  axiom-types (0.1.1)
@@ -98,12 +98,14 @@ GEM
98
98
  logger (~> 1.6)
99
99
  lint_roller (1.1.0)
100
100
  logger (1.7.0)
101
- minitest (6.0.6)
101
+ minitest (6.1.0)
102
102
  drb (~> 2.0)
103
- prism (~> 1.5)
103
+ prism (>= 1.5, < 3)
104
104
  ostruct (0.6.3)
105
105
  parallel (2.3.0)
106
- parser (3.3.12.0)
106
+ parallel_tests (5.9.0)
107
+ parallel
108
+ parser (3.3.13.0)
107
109
  ast (~> 2.4.1)
108
110
  racc
109
111
  path_expander (2.0.1)
@@ -124,18 +126,18 @@ GEM
124
126
  rspec-core (~> 3.13.0)
125
127
  rspec-expectations (~> 3.13.0)
126
128
  rspec-mocks (~> 3.13.0)
127
- rspec-core (3.13.6)
129
+ rspec-core (3.13.7)
128
130
  rspec-support (~> 3.13.0)
129
- rspec-expectations (3.13.5)
131
+ rspec-expectations (3.13.6)
130
132
  diff-lcs (>= 1.2.0, < 2.0)
131
133
  rspec-support (~> 3.13.0)
132
134
  rspec-its (2.0.0)
133
135
  rspec-core (>= 3.13.0)
134
136
  rspec-expectations (>= 3.13.0)
135
- rspec-mocks (3.13.8)
137
+ rspec-mocks (3.13.9)
136
138
  diff-lcs (>= 1.2.0, < 2.0)
137
139
  rspec-support (~> 3.13.0)
138
- rspec-support (3.13.7)
140
+ rspec-support (3.13.8)
139
141
  rubocop (1.91.0)
140
142
  json (>= 2.3)
141
143
  language_server-protocol (~> 3.17.0.2)
@@ -220,6 +222,7 @@ DEPENDENCIES
220
222
  bundler-audit (~> 0.9, >= 0)
221
223
  head_music!
222
224
  kramdown
225
+ parallel_tests
223
226
  rake (~> 13.0)
224
227
  rspec (~> 3.0)
225
228
  rspec-its (~> 2.0)
data/MUSIC_THEORY.md CHANGED
@@ -58,7 +58,7 @@ unpitched note
58
58
  - a sounded rhythmic value without a specific pitch
59
59
 
60
60
  tied duration
61
- - combines multiple rhythmic values into one longer note
61
+ - combines multiple rhythmic values into one longer duration
62
62
  - ties allow rhythmic values to be combined across barlines or strong beats
63
63
 
64
64
  articulation
data/Rakefile CHANGED
@@ -4,8 +4,59 @@ require "rubocop/rake_task"
4
4
 
5
5
  RuboCop::RakeTask.new
6
6
 
7
- # The block runs when the task does, just before rspec is launched.
8
- RSpec::Core::RakeTask.new(:spec) { ENV["COVERAGE"] = "true" }
7
+ # One process per core. parallel_tests places each file by its runtime in
8
+ # tmp/parallel_runtime_rspec.log, or by its size when that log covers too few
9
+ # files, and SimpleCov merges the processes' coverage.
10
+ module ParallelSpecs
11
+ extend Rake::FileUtilsExt
12
+
13
+ STATUS_FILE = "spec/examples.txt"
14
+ PROCESS_STATUS_FILES = "spec/examples[0-9]*.txt"
15
+ RUNTIME_LOG = "tmp/parallel_runtime_rspec.log"
16
+
17
+ def self.run(coverage:)
18
+ narrowed = ENV.key?("SPEC")
19
+ runtimes = narrowed ? runtimes_logged : {}
20
+ rm_f Dir[PROCESS_STATUS_FILES]
21
+ # SimpleCov would merge a serial result from the last ten minutes into the total.
22
+ rm_f %w[coverage/.resultset.json coverage/.resultset.json.lock] if coverage
23
+ # --first-is-1 gives every process a numbered status file to fold back in.
24
+ sh({"COVERAGE" => (coverage ? "true" : nil)}, "bundle exec parallel_rspec --first-is-1 #{ENV.fetch("SPEC", "spec")}")
25
+ ensure
26
+ fold_statuses
27
+ # A narrowed run logs only its own files, which would leave the next full run to group by size.
28
+ write_runtimes(runtimes.merge(runtimes_logged)) if narrowed
29
+ end
30
+
31
+ def self.runtimes_logged
32
+ return {} unless File.exist?(RUNTIME_LOG)
33
+
34
+ File.readlines(RUNTIME_LOG, chomp: true).to_h { |line| line.rpartition(":").values_at(0, 2) }
35
+ end
36
+
37
+ def self.write_runtimes(runtimes)
38
+ File.write(RUNTIME_LOG, runtimes.map { |file, time| "#{file}:#{time}\n" }.join)
39
+ end
40
+
41
+ # Keeps `rspec --only-failures` whole after a parallel run.
42
+ def self.fold_statuses
43
+ require "rspec/core"
44
+ files = Dir[PROCESS_STATUS_FILES]
45
+ this_run = files.flat_map { |file| RSpec::Core::ExampleStatusPersister.load_from(file) }
46
+ return if this_run.empty?
47
+
48
+ merged = RSpec::Core::ExampleStatusMerger.merge(this_run, RSpec::Core::ExampleStatusPersister.load_from(STATUS_FILE))
49
+ File.write(STATUS_FILE, RSpec::Core::ExampleStatusDumper.dump(merged))
50
+ rm_f files
51
+ end
52
+ end
53
+
54
+ desc "Run the specs in parallel with coverage (SPEC=path narrows the run)"
55
+ task(:spec) { ParallelSpecs.run(coverage: true) }
56
+
57
+ # Coverage slows a run considerably, so validation leaves it to `rake spec` and CI.
58
+ desc "Run the specs in parallel without coverage (SPEC=path narrows the run)"
59
+ task("spec:without_coverage") { ParallelSpecs.run(coverage: false) }
9
60
 
10
61
  begin
11
62
  require "yard"
@@ -46,8 +97,8 @@ end
46
97
 
47
98
  task default: :spec
48
99
 
49
- desc "Run all validation checks (tests, linting, security audit, code quality)"
50
- task validate: [:spec, :rubocop, "bundle:audit:check", :rubycritic]
100
+ desc "Run all validation checks (tests without coverage, linting, security audit, code quality)"
101
+ task validate: ["spec:without_coverage", :rubocop, "bundle:audit:check", :rubycritic]
51
102
 
52
103
  desc "Open an irb session preloaded with this library"
53
104
  task :console do
data/bin/validate CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env bash
2
- # Runs the full validation: specs with coverage, Standard, the audit, and RubyCritic.
2
+ # Runs the full validation: specs without coverage, Standard, the audit, and RubyCritic.
3
3
  set -euo pipefail
4
4
  cd "$(dirname "$0")/.."
5
5
  exec bundle exec rake validate "$@"
@@ -48,12 +48,8 @@ class HeadMusic::Content::Flow
48
48
  def clef(value, path)
49
49
  return nil if value.nil?
50
50
 
51
- clef = begin
52
- HeadMusic::Rudiment::Clef.get(value)
53
- rescue
54
- nil
55
- end
56
- raise ArgumentError, "#{path}: unknown clef #{value.inspect}" if clef&.pitch.nil?
51
+ clef = HeadMusic::Rudiment::Clef.get(value)
52
+ raise ArgumentError, "#{path}: unknown clef #{value.inspect}" unless clef
57
53
 
58
54
  clef
59
55
  end
@@ -21,7 +21,7 @@ class HeadMusic::Content::Staff
21
21
  def initialize(clef: nil, line_count: DEFAULT_LINE_COUNT, instruments_staff: nil)
22
22
  @line_count = line_count
23
23
  @instruments_staff = instruments_staff
24
- @clef_map = HeadMusic::Time::EventMap.new(default: clef && HeadMusic::Rudiment::Clef.get(clef))
24
+ @clef_map = HeadMusic::Time::EventMap.new(default: clef && known_clef(clef))
25
25
  end
26
26
 
27
27
  # The clef in force at a bar, or nil where none was authored.
@@ -38,7 +38,7 @@ class HeadMusic::Content::Staff
38
38
  end
39
39
 
40
40
  def change_clef(bar_number, clef)
41
- @clef_map.add(downbeat_of(bar_number), HeadMusic::Rudiment::Clef.get(clef)).value
41
+ @clef_map.add(downbeat_of(bar_number), known_clef(clef)).value
42
42
  end
43
43
 
44
44
  def clef_changes
@@ -65,6 +65,10 @@ class HeadMusic::Content::Staff
65
65
 
66
66
  private
67
67
 
68
+ def known_clef(clef)
69
+ HeadMusic::Rudiment::Clef.get(clef) || raise(ArgumentError, "Unknown clef #{clef.inspect}")
70
+ end
71
+
68
72
  def downbeat_of(bar_number)
69
73
  HeadMusic::Time::MusicalPosition.new(bar_number, HeadMusic::Time::MusicalPosition::FIRST_COUNT, 0, 0)
70
74
  end
@@ -10,7 +10,7 @@ module HeadMusic::Instruments; end
10
10
  # drop_d.semitones # => [-2, 0, 0, 0, 0, 0]
11
11
  #
12
12
  # When applying a tuning:
13
- # - First element applies to the lowest course
13
+ # - First element applies to the first course in the stringing
14
14
  # - Missing elements are treated as 0 (no change)
15
15
  # - Extra elements are ignored
16
16
  class HeadMusic::Instruments::AlternateTuning
@@ -1,7 +1,8 @@
1
1
  # Alternate tunings for stringed instruments.
2
2
  #
3
3
  # Each tuning is defined as semitone adjustments from standard tuning.
4
- # - First element = lowest course
4
+ # - First element = first course in the stringing (for most instruments, the lowest;
5
+ # the banjo lists its short fifth string first)
5
6
  # - Missing elements = 0 (no change)
6
7
  # - Extra elements = ignored
7
8
 
@@ -51,11 +52,13 @@ banjo:
51
52
  open_g:
52
53
  semitones: [0, 0, 0, 0, 0]
53
54
  double_c:
54
- semitones: [-2, -2, 0, -2, 0]
55
+ semitones: [0, -2, 0, 1, 0]
55
56
  sawmill:
56
- semitones: [-2, -2, 0, 0, -2]
57
+ semitones: [0, 0, 0, 1, 0]
57
58
  open_d:
58
- semitones: [-5, -2, -2, -1, -2]
59
+ semitones: [-1, 0, -1, -2, 0]
60
+ c_tuning:
61
+ semitones: [0, -2, 0, 0, 0]
59
62
 
60
63
  ukulele:
61
64
  low_g:
@@ -41,6 +41,10 @@ class HeadMusic::Instruments::Instrument
41
41
  find_valid_instrument(name_str) || find_valid_instrument(normalize_variant_name(name_str))
42
42
  end
43
43
 
44
+ def recognized?(instrument)
45
+ !instrument.name_key.nil?
46
+ end
47
+
44
48
  def find_valid_instrument(name)
45
49
  instrument = get_by_name(name)
46
50
  instrument&.name_key ? instrument : nil
@@ -48,8 +52,7 @@ class HeadMusic::Instruments::Instrument
48
52
 
49
53
  def all
50
54
  HeadMusic::Instruments::InstrumentFamily.all # Ensure families are loaded first
51
- INSTRUMENTS.map { |key, _data| get(key) }
52
- @all ||= @instances.values.compact.sort_by { |instrument| instrument.name.downcase }
55
+ @all ||= INSTRUMENTS.keys.map { |key| get(key) }.sort_by { |instrument| instrument.name.downcase }
53
56
  end
54
57
 
55
58
  private
@@ -30,6 +30,10 @@ class HeadMusic::Instruments::InstrumentFamily
30
30
  result || new(name)
31
31
  end
32
32
 
33
+ def self.recognized?(family)
34
+ !family.name_key.nil?
35
+ end
36
+
33
37
  def self.all
34
38
  INSTRUMENT_FAMILIES.map { |key, _data| get(key) }
35
39
  @all ||= @instances.values.compact.sort_by(&:name)
@@ -396,6 +396,9 @@ high_tom:
396
396
  - small_tom
397
397
  - rack_tom_1
398
398
  gm_percussion_key: 50
399
+ irish_tenor_banjo:
400
+ family_key: banjo
401
+ gm_program: 106
399
402
  lute:
400
403
  family_key: lute
401
404
  gm_program: 25
@@ -597,6 +600,11 @@ tambourine:
597
600
  temple_blocks:
598
601
  family_key: woodblock
599
602
  gm_percussion_key: 76
603
+ tenor_banjo:
604
+ family_key: banjo
605
+ range_categories:
606
+ - tenor
607
+ gm_program: 106
600
608
  tenor_drum:
601
609
  family_key: tenor_drum
602
610
  gm_percussion_key: 45
@@ -112,6 +112,20 @@ banjo:
112
112
  - pitch: B3
113
113
  - pitch: D4
114
114
 
115
+ tenor_banjo:
116
+ courses:
117
+ - pitch: C3
118
+ - pitch: G3
119
+ - pitch: D4
120
+ - pitch: A4
121
+
122
+ irish_tenor_banjo:
123
+ courses:
124
+ - pitch: G2
125
+ - pitch: D3
126
+ - pitch: A3
127
+ - pitch: E4
128
+
115
129
  violin:
116
130
  courses:
117
131
  - pitch: G3
@@ -196,6 +196,7 @@ de:
196
196
  hi-hat: Hi-Hat
197
197
  high_tom: High-Tom
198
198
  horn: Horn
199
+ irish_tenor_banjo: irisches Tenorbanjo
199
200
  kettledrum: Pauke
200
201
  kick_drum: Große Trommel
201
202
  lute: Laute
@@ -258,6 +259,7 @@ de:
258
259
  tam_tam: Tamtam
259
260
  temple_blocks: Tempelblock
260
261
  tenor: Tenor
262
+ tenor_banjo: Tenorbanjo
261
263
  tenor_drum: Tenortrommel
262
264
  tenor_recorder: Tenorblockflöte
263
265
  tenor_saxophone: Tenorsaxophon
@@ -491,6 +493,12 @@ de:
491
493
  # guidelines.*.name klein.
492
494
  style:
493
495
  guidelines:
496
+ allow_free_species_rhythmic_values:
497
+ instruction: "In Ganzen, Halben, Vierteln und paarweise schrittweisen Achteln auf leichten Zählzeiten schreiben."
498
+ instruction_with_dotted_rhythms: "In Ganzen, Halben, Vierteln und paarweise schrittweisen Achteln auf leichten Zählzeiten schreiben; Halbe und Ganze dürfen punktiert sein, und auf eine punktierte Viertel darf eine einzelne Achtel folgen, die schrittweise weitergeht."
499
+ violations:
500
+ default: "Nur Ganze, Halbe, Viertel und paarweise schrittweise Achtel auf leichten Zählzeiten verwenden."
501
+ with_dotted_rhythms: "Nur Ganze, Halbe, Viertel und paarweise schrittweise Achtel auf leichten Zählzeiten verwenden, dazu punktierte Halbe und Ganze und eine punktierte Viertel mit einer einzelnen, schrittweise weitergehenden Achtel."
494
502
  allow_fifth_species_rhythmic_values:
495
503
  instruction: "In Halben, Vierteln und paarweise schrittweisen Achteln auf leichten Zählzeiten schreiben und die Ganze für den Schlusstakt aufsparen."
496
504
  violations:
@@ -316,6 +316,7 @@ en:
316
316
  hi-hat: hi-hat
317
317
  high_tom: high tom
318
318
  horn: horn
319
+ irish_tenor_banjo: Irish tenor banjo
319
320
  kettledrum: kettledrum
320
321
  kick_drum: kick drum
321
322
  lute: lute
@@ -384,6 +385,7 @@ en:
384
385
  tambourine: tambourine
385
386
  temple_blocks: temple blocks
386
387
  tenor: tenor
388
+ tenor_banjo: tenor banjo
387
389
  tenor_drum: tenor drum
388
390
  tenor_recorder: tenor recorder
389
391
  tenor_saxophone: tenor saxophone
@@ -661,6 +663,11 @@ en:
661
663
  "8": "an octave"
662
664
  "10": "a tenth"
663
665
  guidelines:
666
+ independent_textures:
667
+ name: "Independent textures"
668
+ instruction: "Give the voices different textures; let them share one species texture for no more than two bars."
669
+ violations:
670
+ default: "Give the voices different textures; they may share one species texture for no more than two bars."
664
671
  large_leaps:
665
672
  name: "Leap recovery"
666
673
  instruction: "Follow each large leap with a step, a repeated note, a change of direction, or the rest of a triad."
@@ -759,6 +766,13 @@ en:
759
766
  default:
760
767
  one: "Write at least %{number} note."
761
768
  other: "Write at least %{number} notes."
769
+ allow_free_species_rhythmic_values:
770
+ name: "Free species note values"
771
+ instruction: "Write in whole notes, half notes, quarter notes, and paired stepwise eighth notes on weak beats."
772
+ instruction_with_dotted_rhythms: "Write in whole notes, half notes, quarter notes, and paired stepwise eighth notes on weak beats; dot a half or whole note, or follow a dotted quarter with one eighth that steps on."
773
+ violations:
774
+ default: "Use only whole notes, half notes, quarter notes, and paired stepwise eighth notes on weak beats."
775
+ with_dotted_rhythms: "Use only whole notes, half notes, quarter notes, and paired stepwise eighth notes on weak beats, dotted halves and wholes, and a dotted quarter followed by one eighth that steps on."
762
776
  allow_fifth_species_rhythmic_values:
763
777
  name: "Fifth species note values"
764
778
  instruction: "Write in half notes, quarter notes, and paired stepwise eighth notes on weak beats, saving the whole note for the final bar."
@@ -772,8 +786,10 @@ en:
772
786
  always_move:
773
787
  name: "No repeated notes"
774
788
  instruction: "Move to a different note each time rather than repeating one."
789
+ instruction_with_restruck_suspensions: "Move to a different note each time rather than repeating one, except to strike a suspension again."
775
790
  violations:
776
791
  default: "Always move to a different note."
792
+ with_restruck_suspensions: "Always move to a different note, except to strike a suspension again."
777
793
  approach_perfection_contrarily:
778
794
  name: "Contrary approach to perfect consonances"
779
795
  instruction: "Approach every perfect consonance by contrary motion."
@@ -789,6 +805,36 @@ en:
789
805
  instruction: "Keep every note on your own side of the notes next to it in the other voice."
790
806
  violations:
791
807
  default: "Avoid overlapping voices. Maintain the high-low relationship between voices even for adjacent notes."
808
+ bar_count:
809
+ name: "Length in bars"
810
+ instruction:
811
+ exact:
812
+ one: "Write %{number} bar."
813
+ other: "Write %{number} bars."
814
+ at_least:
815
+ one: "Write at least %{number} bar."
816
+ other: "Write at least %{number} bars."
817
+ at_most:
818
+ one: "Write no more than %{number} bar."
819
+ other: "Write no more than %{number} bars."
820
+ between: "Write between %{minimum} and %{maximum} bars."
821
+ violations:
822
+ exact:
823
+ one: "Write %{number} bar."
824
+ other: "Write %{number} bars."
825
+ at_least:
826
+ one: "Write at least %{number} bar."
827
+ other: "Write at least %{number} bars."
828
+ at_most:
829
+ one: "Write no more than %{number} bar."
830
+ other: "Write no more than %{number} bars."
831
+ between: "Write between %{minimum} and %{maximum} bars."
832
+ clausula_vera:
833
+ name: "Clausula vera"
834
+ instruction: "Close on the tonic in an octave or unison, one voice stepping up from the leading tone as the other steps down from the second degree."
835
+ violations:
836
+ default: "Close with the clausula vera: the leading tone and the second degree, a minor third or major sixth apart, stepping in contrary motion to the tonic in an octave or unison."
837
+ unraised: "Raise the leading tone so it rises a half step into the final."
792
838
  consonant_climax:
793
839
  name: "Single consonant climax"
794
840
  instruction: "Give the line one clear peak, consonant with the tonic, sounded once or twice with a step between."
@@ -798,8 +844,10 @@ en:
798
844
  consonant_downbeats:
799
845
  name: "Consonant downbeats"
800
846
  instruction: "Sound a consonance on every downbeat, except where a tie suspends one."
847
+ instruction_with_restruck_suspensions: "Sound a consonance on every downbeat, except where a suspension, tied or struck again, makes it dissonant."
801
848
  violations:
802
849
  default: "Use consonant harmonic intervals on every downbeat (unless a tied suspension)."
850
+ with_restruck_suspensions: "Use consonant harmonic intervals on every downbeat (unless a suspension, tied or struck again)."
803
851
  diatonic:
804
852
  name: "Diatonic notes only"
805
853
  instruction: "Write using only the notes of the key signature."
@@ -845,6 +893,11 @@ en:
845
893
  instruction: "Reach every dissonance as a passing tone, cambiata, or double neighbor on a weak beat."
846
894
  violations:
847
895
  default: "Treat each dissonance as a passing tone, cambiata, or double neighbor on a weak beat."
896
+ free_dissonance_treatment:
897
+ name: "Free dissonance treatment"
898
+ instruction: "Explain every dissonance between the two voices: as a passing tone, neighbor tone, cambiata, or double neighbor in either voice, or as a suspension prepared and resolved down by step. Attack no dissonance on a downbeat."
899
+ violations:
900
+ default: "Explain each dissonance as a figure in either voice or as a prepared suspension resolving down by step; attack no dissonance on a downbeat."
848
901
  frequent_direction_changes:
849
902
  name: "Frequent changes of direction"
850
903
  instruction: "Turn the line around often."
@@ -1010,6 +1063,8 @@ en:
1010
1063
  # "first_species" to "First Species" without help.
1011
1064
  fifth_species:
1012
1065
  instruction: "Write florid counterpoint against the cantus firmus, mixing note values and ties as the line requires and treating every dissonance as its figure demands."
1066
+ free_species:
1067
+ instruction: "Compose two voices together in the techniques of the species. No cantus firmus is given: where species counterpoint sets a line against a fixed song, here you write both lines, mixing note values freely and treating every dissonance between them as its figure demands. (\"Free species\" is this guide's own name.)"
1013
1068
  first_species:
1014
1069
  instruction: "Write one whole note against each note of the cantus firmus, consonant with it and moving mostly in contrary motion."
1015
1070
  first_three_species:
@@ -1066,6 +1121,10 @@ en:
1066
1121
  instruction: "Write florid counterpoint: mix note values and ties as the line requires."
1067
1122
  fifth_species_harmony:
1068
1123
  instruction: "Write florid counterpoint against the cantus firmus, treating every dissonance as its figure demands."
1124
+ free_species_melody:
1125
+ instruction: "Write each line in the species' note values, any of them in any bar, closing by step on the tonic."
1126
+ free_species_harmony:
1127
+ instruction: "Write two lines together with no cantus firmus, explaining every dissonance between them, keeping their textures apart, and closing with the clausula vera."
1069
1128
  arch_contour_melody:
1070
1129
  instruction: "Write a melody that rises to a single peak and falls back."
1071
1130
  ascending_contour_melody:
@@ -95,6 +95,12 @@ en_GB:
95
95
  # sentence changes shape, not only vocabulary.
96
96
  style:
97
97
  guidelines:
98
+ allow_free_species_rhythmic_values:
99
+ instruction: "Write in semibreves, minims, crotchets, and paired stepwise quavers on weak beats."
100
+ instruction_with_dotted_rhythms: "Write in semibreves, minims, crotchets, and paired stepwise quavers on weak beats; dot a minim or semibreve, or follow a dotted crotchet with one quaver that steps on."
101
+ violations:
102
+ default: "Use only semibreves, minims, crotchets, and paired stepwise quavers on weak beats."
103
+ with_dotted_rhythms: "Use only semibreves, minims, crotchets, and paired stepwise quavers on weak beats, dotted minims and semibreves, and a dotted crotchet followed by one quaver that steps on."
98
104
  allow_fifth_species_rhythmic_values:
99
105
  instruction: "Write in minims, crotchets, and paired stepwise quavers on weak beats, saving the semibreve for the final bar."
100
106
  violations:
@@ -123,6 +129,10 @@ en_GB:
123
129
  instruction: "Reach every dissonance as a passing tone, cambiata, or double neighbour on a weak beat."
124
130
  violations:
125
131
  default: "Treat each dissonance as a passing tone, cambiata, or double neighbour on a weak beat."
132
+ free_dissonance_treatment:
133
+ instruction: "Explain every dissonance between the two voices: as a passing tone, neighbour tone, cambiata, or double neighbour in either voice, or as a suspension prepared and resolved down by step. Attack no dissonance on a downbeat."
134
+ violations:
135
+ default: "Explain each dissonance as a figure in either voice or as a prepared suspension resolving down by step; attack no dissonance on a downbeat."
126
136
  no_rests:
127
137
  instruction: "Sound a note in every bar."
128
138
  violations: