control realization(1, 1, 4); // Each column has its own rhythm on a shared eighth-note grid. let choices = [ // Statement [[c4, e4], ~], [~, ~], [d4, ~], [e4, ~], [~, ~], [g4, ~], [~, ~], [~, ~], // Answer a fifth higher, with a free upbeat in the flute. [g3, [g4, b4]], [~, ~], [~, [g4, a4]], [c4, [b4, c5]], [~, [~, c5]], [~, [d5, e5]], [d4, [~, a4]], [~, ~], // Contrast [f4, a4], [~, g4], [e4, ~], [~, ~], [d4, f4], [c4, ~], [~, ~], [~, e4], // Return the statement and stagger the second flute upbeat. [[c4, e4], ~], [~, ~], [d4, ~], [e4, ~], [~, [~, b4]], [g4, ~], [~, [~, g4]], [[c4, e4], ~], ]; def answer_at_the_fifth(rows) { at(at(rows, 0), 0) + 7 == at(at(rows, 1), 1); }; def opening_pitch_returns(rows) { let opening = at(at(rows, 0), 0); at(at(rows, 1), 0) == opening and at(at(rows, 2), 0) == opening; }; def stagger_flute_upbeats(rows) { let first = at(at(rows, 0), 1) == ~; let second = at(at(rows, 1), 1) == ~; let third = at(at(rows, 2), 1) == ~; let fourth = at(at(rows, 3), 1) == ~; first != second and third != fourth and first != third; }; def prefer_c_cadence(rows) { pi(c4, at(at(rows, 1), 0)); }; let form_rules = [ [[1, 9], answer_at_the_fifth], [[3, 11], answer_at_the_fifth], [[4, 12], answer_at_the_fifth], [[6, 14], answer_at_the_fifth], [[1, 25, 32], opening_pitch_returns], [[13, 15, 29, 31], stagger_flute_upbeats], ]; let music = solve_grid(choices, [], across=form_rules, prefer_across=[[[1, 32], prefer_c_cadence]], alternative=realization); let rule_issues = check_grid(music, [], across=form_rules); def line(column) { for (row in music) { at(row, column); }; }; score "Imitation and Return" { @tempo 104; @time_signature 4/4; timeline { part "Flute" { @clef "treble"; @midi_program 74; 1/8 line(1) mp; }; part "Clarinet" { @clef "treble"; @midi_program 72; 1/8 line(0) mp; }; }; };