sugarlabs / musicblocks

Music Blocks -- A musical microworld
https://musicblocks.sugarlabs.org/
GNU Affero General Public License v3.0
558 stars 757 forks source link

Smarter Clef Choices over time, within a single voice. #837

Closed pikurasa closed 1 year ago

pikurasa commented 6 years ago

It would be nice to change clef if a particular voice changes register drastically (over time or suddenly).

The following example (output from a MB project) should be bass clef until about measure 10 or 11, then should have ottava (the "play an octave up" symbol) from about measure 20:

\version "2.18.2"

% ****************************************************************
% 
% WHAT IS THIS? -- This is a LilyPond file generated from Music
% Blocks software (Read about it at www.musicblocks.net).
% 
% DOWNLOAD LILYPOND -- In order to create notation with this file,
% you will need to download and install LilyPond software onto your
% computer (http://lilypond.org/download.html). Frescobaldi
% software is also handy for editing LilyPond files
% (http://frescobaldi.org/download).
% 
% LILYPOND INSTRUCTIONS -- For instructions on how to further
% manipulate musical notation using LilyPond software, please
% read the Introduction (http://lilypond.org/text-input.html) and
% the Manual
% (http://lilypond.org/doc/v2.18/Documentation/learning/index.html).
% 
% GLOSSARY -- A glossary with helpful examples may be found here
% (http://www.lilypond.org/doc/v2.19/Documentation/music-glossary/).
% 
% MUTOPIA -- You may also benefit from studying scores from the
% Mutopia Project website, which has freely sharable music notation
% generated with LilyPond (http://www.mutopiaproject.org/).
% 
% LILYBIN -- You can explore your Lilypond output in a web browser at
% (http://lilybin.com/).
% 
% COMMENTS -- Some of the code below is commented out. You can
% enable it by deleting the % that precedes the text or, in the
% case of a commented section, deleting the %{ and %} that surrounds
% the section.
% 
% ****************************************************************

% Please add your own name, the title of your musical creation,
% and the intended copyright below.
% The copyright is great for sharing (and re-sharing)!
% Read more about it here (http://creativecommons.org/licenses/by-sa/4.0/).
% Of course, you can use any copyright you like -- you made it!
\header {
   dedication = \markup {
      \abs-fontsize #8 \sans "Made with LilyPond and Music Blocks" \with-url #"http://walterbender.github.io/musicblocks/" {
         \abs-fontsize #8 \sans "(http://walterbender.github.io/musicblocks/)"
      }
   }
   title = "My Music Blocks Creation"
%   subtitle = "Subtitle"
%   instrument = "Instrument"
   composer = "Mr. Mouse"
%   arranger = "Arranger"
   copyright = "Mr. Mouse (c) 2017 -- CC-BY-SA"
   tagline = "Made from Music Blocks v.2.0"
   footer = \markup {
      \with-url #"http://walterbender.github.io/musicblocks/" "Made with Music Blocks Software v.2.0." Engraved on \simple #(strftime "%Y-%m-%d" (localtime (current-time)))
   }
   currentYear = \markup {
      \simple #(strftime "%Y" (localtime (current-time)))
   }
   copyTag =  " free to distribute, modify, and perform"
   copyType = \markup {
      \with-url #"http://creativecommons.org/licenses/by-sa/3.0/" "Creative Commons Attribution ShareAlike 3.0 (Unported) License "
   }
   copyright = \markup {
      \override #'(baseline-skip . 0 ) \right-column {
         \sans \bold \with-url #"http://musicblocks.net" {
            \abs-fontsize #9  "Music " \concat {
               \abs-fontsize #12 \with-color #white \char ##x01C0 \abs-fontsize #9 "Blocks "
            }
         }
      }
      \override #'(baseline-skip . 0 ) \center-column {
         \abs-fontsize #11.9 \with-color #grey \bold {
            \char ##x01C0 \char ##x01C0
         }
      }
      \override #'(baseline-skip . 0 ) \column {
         \abs-fontsize #8 \sans \concat {
            " Typeset using " \with-url #"http://www.lilypond.org" "LilyPond software " \char ##x00A9 " " \currentYear " by " \composer " " \char ##x2014 " " \footer
         }
         \concat {
            \concat {
               \abs-fontsize #8 \sans {
                  " " \copyType \char ##x2014 \copyTag
               }
            }
            \abs-fontsize #13 \with-color #white \char ##x01C0
         }
      }
   }
   tagline = ##f
}

% To change the meter make adjustments in the following section.
% You must also delete the % before \meter everywhere it appears below.
meter = {
%   \time 3/4
%   \key c \minor
   \numericTimeSignature
%   \partial 4 
%   \tempo "Andante" 4=90
}

% You can change the MIDI instruments below to anything on logo list:
% (http://lilypond.org/doc/v2.18/documentation/notation/midi-instruments)

brown_rat = {
\meter
2  2  2  2  
2  2  2  2  
2  2  2  2  
2  2  2  2  
2  2  2  2  
2  2  2  2  
2  2  2  2  
2  2  2  2  
2  2  2  2  
2  2  2  2  
2  2  2  2  
2  2  2  2   \bar "|."
}

brown_ratVoice = \new Staff \with {
   \clef "treble"
   instrumentName = "brown_rat"
   shortInstrumentName = "br"
   midiInstrument = "acoustic grand"

} { \clef "treble" \brown_rat }

\score {
   <<
      \brown_ratVoice

% GUITAR TAB SECTION
% Delete the %{ and %} below to include guitar tablature output.
%{
      \new TabStaff = "guitar tab" 
      <<
         \clef moderntab
         \context TabVoice = "brown_rat" \brown_rat
      >>
%}

   >>
   \layout {}

% MIDI SECTION
% Delete the %{ and %} below to include MIDI output.
%{
\midi {
   \tempo 4=90
}
%}

}

% MUSIC BLOCKS CODE
% Below is the code for the Music Blocks project that generated logo Lilypond file.
%{

[[0,["start",{"collapsed":false,"xcor":0,"ycor":0,"heading":0,"color":10,"shade":50,"pensize":5,"grey":100}],145.41666666666663,145.41666666666666,[null,17,null]],
[1,["newnote",{}],449.75,185.91666666666666,[24,2,5,6]],
[2,["divide",{}],545.97119140625,185.91666666666666,[1,3,4]],
[3,["number",{"value":1}],631.47119140625,185.91666666666666,[2]],
[4,["number",{"value":2}],631.47119140625,217.41666666666666,[2]],
[5,["vspace",{}],463.25,217.41666666666666,[1,30]],
[6,["hidden",{}],449.75,406.41666666666663,[1,7]],
[7,["newnote",{}],449.75,406.41666666666663,[6,8,11,12]],
[8,["divide",{}],545.97119140625,406.41666666666663,[7,9,10]],
[9,["number",{"value":1}],631.47119140625,406.41666666666663,[8]],
[10,["number",{"value":2}],631.47119140625,437.91666666666663,[8]],
[11,["vspace",{}],463.25,437.91666666666663,[7,32]],
[12,["hidden",{}],449.75,626.9166666666666,[7,null]],
[13,["scaledegree",{}],476.75,280.41666666666663,[30,20,14,null]],
[14,["number",{"value":3}],591.14111328125,311.91666666666663,[13]],
[15,["scaledegree",{}],476.75,500.91666666666663,[32,21,16,null]],
[16,["number",{"value":3}],591.14111328125,532.4166666666666,[15]],
[17,["storein",{}],158.91666666666663,185.91666666666666,[0,18,19,26]],
[18,["text",{"value":"box"}],236.60611979166663,185.91666666666666,[17]],
[19,["number",{"value":1}],236.60611979166663,217.41666666666666,[17]],
[20,["namedbox",{"value":"box"}],591.14111328125,280.41666666666663,[13]],
[21,["namedbox",{"value":"box"}],591.14111328125,500.91666666666663,[15]],
[22,["action",{"collapsed":false}],436.25,145.41666666666666,[null,23,24,null]],
[23,["text",{"value":"5-6"}],530.75,154.41666666666666,[22]],
[24,["hidden",{}],449.75,185.91666666666666,[22,1]],
[25,["nameddo",{"value":"5-6"}],172.41666666666663,280.41666666666663,[26,28]],
[26,["repeat",{}],158.91666666666663,248.91666666666666,[17,27,25,null]],
[27,["number",{"value":24}],230.91666666666663,248.91666666666666,[26]],
[28,["incrementOne",{}],172.41666666666663,311.91666666666663,[25,29,null]],
[29,["namedbox",{"value":"box"}],255.13053385416663,311.91666666666663,[28]],
[30,["interval",{}],463.25,248.91666666666666,[5,31,13,34]],
[31,["number",{"value":5}],591.12646484375,248.91666666666666,[30]],
[32,["interval",{}],463.25,469.41666666666663,[11,33,15,35]],
[33,["number",{"value":6}],591.12646484375,469.41666666666663,[32]],
[34,["hidden",{}],463.25,374.91666666666663,[30,null]],
[35,["hidden",{}],463.25,595.4166666666666,[32,null]],
[36,1,[0,"notes","C3",1.3333333333333333,"default",null,null]],
[37,1,[0,"notes","G3",1.3333333333333333,"default",null,null]],
[38,1,[1.3333333333333333,"notes","C3",1.3333333333333333,"default",null,null]],
[39,1,[1.3333333333333333,"notes","A3",1.3333333333333333,"default",null,null]],
[40,1,[2.6666666666666665,"notes","D3",1.3333333333333333,"default",null,null]],
[41,1,[2.6666666666666665,"notes","A3",1.3333333333333333,"default",null,null]],
[42,1,[4,"notes","D3",1.3333333333333333,"default",null,null]],
[43,1,[4,"notes","B3",1.3333333333333333,"default",null,null]],
[44,1,[5.333333333333333,"notes","E3",1.3333333333333333,"default",null,null]],
[45,1,[5.333333333333333,"notes","B3",1.3333333333333333,"default",null,null]],
[46,1,[6.666666666666666,"notes","E3",1.3333333333333333,"default",null,null]],
[47,1,[6.666666666666666,"notes","C4",1.3333333333333333,"default",null,null]],
[48,1,[7.999999999999999,"notes","F3",1.3333333333333333,"default",null,null]],
[49,1,[7.999999999999999,"notes","C4",1.3333333333333333,"default",null,null]],
[50,1,[9.333333333333332,"notes","F3",1.3333333333333333,"default",null,null]],
[51,1,[9.333333333333332,"notes","D4",1.3333333333333333,"default",null,null]],
[52,1,[10.666666666666666,"notes","G3",1.3333333333333333,"default",null,null]],
[53,1,[10.666666666666666,"notes","D4",1.3333333333333333,"default",null,null]],
[54,1,[12,"notes","G3",1.3333333333333333,"default",null,null]],
[55,1,[12,"notes","E4",1.3333333333333333,"default",null,null]],
[56,1,[13.333333333333334,"notes","A3",1.3333333333333333,"default",null,null]],
[57,1,[13.333333333333334,"notes","E4",1.3333333333333333,"default",null,null]],
[58,1,[14.666666666666668,"notes","A3",1.3333333333333333,"default",null,null]],
[59,1,[14.666666666666668,"notes","F4",1.3333333333333333,"default",null,null]],
[60,1,[16,"notes","B3",1.3333333333333333,"default",null,null]],
[61,1,[16,"notes","F4",1.3333333333333333,"default",null,null]],
[62,1,[17.333333333333332,"notes","B3",1.3333333333333333,"default",null,null]],
[63,1,[17.333333333333332,"notes","G4",1.3333333333333333,"default",null,null]],
[64,1,[18.666666666666664,"notes","C4",1.3333333333333333,"default",null,null]],
[65,1,[18.666666666666664,"notes","G4",1.3333333333333333,"default",null,null]],
[66,1,[19.999999999999996,"notes","C4",1.3333333333333333,"default",null,null]],
[67,1,[19.999999999999996,"notes","A4",1.3333333333333333,"default",null,null]],
[68,1,[21.33333333333333,"notes","D4",1.3333333333333333,"default",null,null]],
[69,1,[21.33333333333333,"notes","A4",1.3333333333333333,"default",null,null]],
[70,1,[22.66666666666666,"notes","D4",1.3333333333333333,"default",null,null]],
[71,1,[22.66666666666666,"notes","B4",1.3333333333333333,"default",null,null]],
[72,1,[23.999999999999993,"notes","E4",1.3333333333333333,"default",null,null]],
[73,1,[23.999999999999993,"notes","B4",1.3333333333333333,"default",null,null]],
[74,1,[25.333333333333325,"notes","E4",1.3333333333333333,"default",null,null]],
[75,1,[25.333333333333325,"notes","C5",1.3333333333333333,"default",null,null]],
[76,1,[26.666666666666657,"notes","F4",1.3333333333333333,"default",null,null]],
[77,1,[26.666666666666657,"notes","C5",1.3333333333333333,"default",null,null]],
[78,1,[27.99999999999999,"notes","F4",1.3333333333333333,"default",null,null]],
[79,1,[27.99999999999999,"notes","D5",1.3333333333333333,"default",null,null]],
[80,1,[29.33333333333332,"notes","G4",1.3333333333333333,"default",null,null]],
[81,1,[29.33333333333332,"notes","D5",1.3333333333333333,"default",null,null]],
[82,1,[30.666666666666654,"notes","G4",1.3333333333333333,"default",null,null]],
[83,1,[30.666666666666654,"notes","E5",1.3333333333333333,"default",null,null]],
[84,1,[31.999999999999986,"notes","A4",1.3333333333333333,"default",null,null]],
[85,1,[31.999999999999986,"notes","E5",1.3333333333333333,"default",null,null]],
[86,1,[33.33333333333332,"notes","A4",1.3333333333333333,"default",null,null]],
[87,1,[33.33333333333332,"notes","F5",1.3333333333333333,"default",null,null]],
[88,1,[34.66666666666666,"notes","B4",1.3333333333333333,"default",null,null]],
[89,1,[34.66666666666666,"notes","F5",1.3333333333333333,"default",null,null]],
[90,1,[35.99999999999999,"notes","B4",1.3333333333333333,"default",null,null]],
[91,1,[35.99999999999999,"notes","G5",1.3333333333333333,"default",null,null]],
[92,1,[37.33333333333333,"notes","C5",1.3333333333333333,"default",null,null]],
[93,1,[37.33333333333333,"notes","G5",1.3333333333333333,"default",null,null]],
[94,1,[38.666666666666664,"notes","C5",1.3333333333333333,"default",null,null]],
[95,1,[38.666666666666664,"notes","A5",1.3333333333333333,"default",null,null]],
[96,1,[40,"notes","D5",1.3333333333333333,"default",null,null]],
[97,1,[40,"notes","A5",1.3333333333333333,"default",null,null]],
[98,1,[41.333333333333336,"notes","D5",1.3333333333333333,"default",null,null]],
[99,1,[41.333333333333336,"notes","B5",1.3333333333333333,"default",null,null]],
[100,1,[42.66666666666667,"notes","E5",1.3333333333333333,"default",null,null]],
[101,1,[42.66666666666667,"notes","B5",1.3333333333333333,"default",null,null]],
[102,1,[44.00000000000001,"notes","E5",1.3333333333333333,"default",null,null]],
[103,1,[44.00000000000001,"notes","C6",1.3333333333333333,"default",null,null]],
[104,1,[45.33333333333334,"notes","F5",1.3333333333333333,"default",null,null]],
[105,1,[45.33333333333334,"notes","C6",1.3333333333333333,"default",null,null]],
[106,1,[46.66666666666668,"notes","F5",1.3333333333333333,"default",null,null]],
[107,1,[46.66666666666668,"notes","D6",1.3333333333333333,"default",null,null]],
[108,1,[48.000000000000014,"notes","G5",1.3333333333333333,"default",null,null]],
[109,1,[48.000000000000014,"notes","D6",1.3333333333333333,"default",null,null]],
[110,1,[49.33333333333335,"notes","G5",1.3333333333333333,"default",null,null]],
[111,1,[49.33333333333335,"notes","E6",1.3333333333333333,"default",null,null]],
[112,1,[50.666666666666686,"notes","A5",1.3333333333333333,"default",null,null]],
[113,1,[50.666666666666686,"notes","E6",1.3333333333333333,"default",null,null]],
[114,1,[52.00000000000002,"notes","A5",1.3333333333333333,"default",null,null]],
[115,1,[52.00000000000002,"notes","F6",1.3333333333333333,"default",null,null]],
[116,1,[53.33333333333336,"notes","B5",1.3333333333333333,"default",null,null]],
[117,1,[53.33333333333336,"notes","F6",1.3333333333333333,"default",null,null]],
[118,1,[54.66666666666669,"notes","B5",1.3333333333333333,"default",null,null]],
[119,1,[54.66666666666669,"notes","G6",1.3333333333333333,"default",null,null]],
[120,1,[56.00000000000003,"notes","C6",1.3333333333333333,"default",null,null]],
[121,1,[56.00000000000003,"notes","G6",1.3333333333333333,"default",null,null]],
[122,1,[57.333333333333364,"notes","C6",1.3333333333333333,"default",null,null]],
[123,1,[57.333333333333364,"notes","A6",1.3333333333333333,"default",null,null]],
[124,1,[58.6666666666667,"notes","D6",1.3333333333333333,"default",null,null]],
[125,1,[58.6666666666667,"notes","A6",1.3333333333333333,"default",null,null]],
[126,1,[60.000000000000036,"notes","D6",1.3333333333333333,"default",null,null]],
[127,1,[60.000000000000036,"notes","B6",1.3333333333333333,"default",null,null]],
[128,1,[61.33333333333337,"notes","E6",1.3333333333333333,"default",null,null]],
[129,1,[61.33333333333337,"notes","B6",1.3333333333333333,"default",null,null]],
[130,1,[62.66666666666671,"notes","E6",1.3333333333333333,"default",null,null]],
[131,1,[62.66666666666671,"notes","C7",1.3333333333333333,"default",null,null]]]
%}

Lilypond code for ottava is:

\ottava

walterbender commented 6 years ago

Can you generate a lilypond example where the clef changes? I can use that as a basis for implementing this change. Also, any constraints on how we apply this? e.g., do we change clef for even one note?

pikurasa commented 6 years ago

Can you generate a lilypond example where the clef changes? I can use that as a basis for implementing this change. Also, any constraints on how we apply this? e.g., do we change clef for even one note?

Rules for this can get complicated and have been well-thought out and documented, so I would like to find a book/reference and work from there as to avoid the inevitable corner cases that will arise.