Composition Blog 1

This composition is a continuation of the strings example from the orchestration tutorial. It documents incremental updates, additions and improvements while building a larger piece. The tutorial example started like this.

function Main()
{
  @span = 20;
  @octave = 3;
  @tutti = true;
  @articulation = Articulations.Vibrato;

  @Tempo(measures: 4); //by default @beats are 4
  @timpaniHit = Meter.Quarter(@tempo) / 8; //corresponds to a 32nd note

  @Split(4).Then(i => @sentence = i);
  @harmony = (@sentence % 2 == 0) ? 0 : -2;
  @Slice(
    Contrabass
    ,Cello
    ,Viola
    ,Violin
    ,Timpani
  );
  var colors = ["#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00", "#CC79A7"];
  @color = colors[(colors.Length * 10 + @harmony + @degree) % colors.Length];
}

function Contrabass()
{
  @instrument = "contrabass";
  if (@sentence % 2 == 0) @articulation = Articulations.Tremolo;
}

function Cello()
{
  @instrument = "cello";
  @degree = 4;
  @melody = (@sentence % 2 == 0) ? [0, -1] : [0, -1, 1];
  @rhythm = (@sentence % 2 == 0) ? [1.0, 1, 1, 1] : [2.0, 1, 1, 2, 1, 1];
  @Split(@rhythm).Then(i => @degree += @melody[i % @melody.Length]);
}

function Viola()
{
  @instrument = "viola";
  @degree = 7;
  var melody = [0, 1, 2, 1];
  if (@sentence >= 2) @articulation = Articulations.Pizzicato;
  @Split(melody.Length * 2).Then(i => {
      if (@sentence >= 2 && (i % 4) == 3) @Rest();
      @degree += melody[i % melody.Length];
  });
}

function Violin()
{
  @instrument = "violin";
  @degree = 14;
  @chord += 2;
  @melody = (@sentence % 2 == 0) ? [0, -1, 0, 1, 2, 3, 2] : [0, 2, 5, 4, 3, 2, 1];
  @Split(4, 1, 1, 1, 1, 2, 2).Then(i => @degree += @melody[i % @melody.Length]);
  if (@span <= 1) { @octave += 2; @degree -= 12; @chord = Chord.Base; }
  @Slice(); //just to get the colors right
}

function Timpani()
{
    @instrument = "timpani";
    @time -= @timpaniHit; //shift it backwards in time so that the first hit occures before the beat
    @tmpSpan = @span; //remember the span
    @span = @timpaniHit * 2;
    @motive = (@sentence % 2 == 0) ? [-3, 0] : [2, 0];
    //there is a shortcut for the following construct, see intermediate tutorials
    @Split(@motive.Length).Then(i => {
      @degree = @motive[i];
      @velocity = 0.8 + i * 0.05;
    });
    @span = @tmpSpan * 0.7; //set back the span to avoid cutting away the resonance
}
22.48 s
Search for something