Strasheela Tutorial (by Torsten Anders)

Torsten Anders

?? Introduction

brief..

full installation assumed...

First Steps / The OPI

how to start OPI

most important OPI commands: demonstrate with tiny musical examples (call existing Strasheela functionality)

pointers to Oz tutorial + manual

pointer to Emacs doc

Constraint Programming in Oz

NB: no Oz tutorial, but some guided tour on Oz constraint programming features

;; see /home/t/texte/PhD/Viva/Demo/StrasheelaDemo.oz

pointers to Oz doc [Strasheela-doc Ozdoc page]

The Strasheela Music Representation

;; ... see /home/t/texte/PhD/Viva/Demo/StrasheelaDemo.oz

score objects, hierarchic nesting, ADT interface (pointer to Strasheela API doc)

Constraining a Score

score information can be unknown: musical CSP

when to use plain Oz data structures and when Strasheela

pointers to Thesis

Rule Applicators

motivation [point to Thesis]

using predefined applicators

defining applicators

?? Pattern Constraints

Demonstrate usage by examples

User-defined pattern constraint: show to simple example is defined

Music Representation Extensions

Harmony Model: demonstrate usage by examples

?? Motif Model [pointer to paper]

User-defined extensions of the music representation ?? example: trumpet line [suggested by Kilian Sprotte]

Defining Distribution Strategies

motivation [point to Thesis]

using distribution strategies in plain Oz

using score distribution strategies

defining distribution strategies

Techniques for Organising Complex CSPs

CSPs consisting of Sub-CSPs [see L-system example..]

Memoization

..

Strasheela Output

controlling output formats — explain interfaces

defining new output formats: explain, e.g., how interface to Fomus is defined

Interfacing Other Systems

OzServer

Using Oz from Lisp / Common Music


!! This contains unfinished material !!

Extend the previous example to simple two-voice counterpoint

declare local

MIDI pitch domain reduction: only 'wite keys' (c major) proc {InCMajor MyNote} {List.forAll [1 3 6 8 10] list of 'black' pitch classes (c=0) proc {$ BlackKey} {FD.modI {MyNote getPitch($)} 12} \=: BlackKey end} end Determine the pitch of the first and last note of MyVoice proc {StartAndEndWithFundamental MyVoice} Notes = {MyVoice getItems($)} in {Notes.1 getPitch($)} = 60 {{List.last Notes} getPitch($)} = 60 end voice leading: only intervals up to a fifth, no pitch repetition proc {NoBigJump Pitch1 Pitch2} all intervals between minor second and fourth are allowed {FD.distance Pitch1 Pitch2 '>=:' 1} {FD.distance Pitch1 Pitch2 '<:' 5} end harmony: only consonants proc {NoDissonance [Note1 Note2]} Consonance {FD.int [3 4 7 8 9 12 15 16]} in Note1 is bass note {Note1 getPitch($)} + Consonance : {Note2 getPitch($)} end in proc {SimpleCounterpoint MyScore} N 9 Voice1 Voice2 in MyScore = {Score.makeScore sim(items: {LUtils.collectN 2 fun {$} seq(items: {LUtils.collectN N fun {$} note(duration: 1 pitch: {FD.int 53#72} amplitude: 80) end}) end} startTime: 0 timeUnit:beats) unit} Voice1 = {MyScore getItems($)}.1 Voice2 = {Nth {MyScore getItems($)} 2}

Apply compositional rules:

rule on single notes {MyScore forAll(test: isNote InCMajor)} rule on pitch pair {Pattern.for2Neighbours {Voice1 mapItems($ getPitch)} NoBigJump} {Pattern.for2Neighbours {Voice2 mapItems($ getPitch)} NoBigJump} rule on notes of Voice1 and their simultaneous notes

NB: SMapping.forContexts only works for a predetermined context (here, the context of simultaneous notes is determined because the rhythmic structure is determined in the CSP def.) {SMapping.forContexts {Voice1 getItems($)}
fun {$ X} X {X getSimultaneousItems($ test:isNote)} end
NoDissonance} rule on first (bass) voice {StartAndEndWithFundamental Voice1} end end

{SDistro.exploreOne SimpleCounterpoint

unit(order:size value:random)}

simple rhythmic rule:

predefine allowed rythmic values: 4, 2, 1

Either repeat duration or double or halve it.

Start and end are predefined to be max. duration (4)

NB: most rule definitions in the following examples apply a different 'style': instead of called the rules with a rule context (i.e. the set of score objects the rule constraints) — see rules NoDissonance and NoBigJump and their application above — the context is partly accessed within the rule definition (e.g. by accessing the simultaneous or precedessing note).

simple monophonic and purely rhythmic example

declare local

proc {StartAndEndWithLongest Note} C = {Note getTemporalAspect($)} in if {Note isFirstItem($ C)} orelse {Note isLastItem($ C)} then {Note getDuration($)} = 4 end end proc {SlowRhythmChanges Note} C = {Note getTemporalAspect($)} in if {Note hasPredecessor($ C)} then Dur1 = {{Note getPredecessor($ C)} getDuration($)} Dur2 = {Note getDuration($)} HalveDur1 in {FD.decl HalveDur1} {FD.times HalveDur1 2 Dur1} {FD.times HalveDur1 {FD.int [1 2 4]} Dur2} end end in proc {SmoothRhythm MyScore} N = 9 in MyScore = {Score.makeScore seq(items: {LUtils.collectN N fun {$} note(duration: {FD.int [1 2 4]} pitch: 60 amplitude: 80) end} startTime: 0 timeUnit:beats) unit}

Apply compositional rules:

{MyScore forAll(test: isNote proc {$ Note} {StartAndEndWithLongest Note} {SlowRhythmChanges Note} end)} search strategy (i.e. distribution strategy) {FD.distribute {SDistro.makeFDDistribution unit(order:size value:random)} {MyScore collect($ test:isParameter)}} end end

{ExploreOne SmoothRhythm}

Two parallel rhythmic sequences

declare local

Durations = [1 2 4] proc {StartAndEndWithLongest Note} C = {Note getTemporalAspect($)} in if {Note isFirstItem($ C)} orelse {Note isLastItem($ C)} then {Note getDuration($)} = {List.last Durations} end end proc {SlowRhythmChanges Note} C = {Note getTemporalAspect($)} in if {Note hasPredecessor($ C)} then Dur1 = {{Note getPredecessor($ C)} getDuration($)} Dur2 = {Note getDuration($)} HalveDur1 in {FD.decl HalveDur1} {FD.times HalveDur1 2 Dur1} {FD.times HalveDur1 {FD.int [1 2 4]} Dur2} end end in proc {SmoothRhythm2 MyScore} N = 17 EndTime in {FD.decl EndTime} MyScore = {Score.makeScore sim(items: [seq(items: {LUtils.collectN N fun {$} note(duration: {FD.int Durations} pitch: 48 amplitude: 80) end} offsetTime:0 endTime:EndTime) seq(items: {LUtils.collectN N fun {$} note(duration: {FD.int Durations} pitch: 70 amplitude: 80) end} offsetTime:{List.last Durations} endTime:EndTime)] startTime:0 timeUnit:beats) unit}

Apply compositional rules:

{MyScore forAll(test: isNote proc {$ Note} {StartAndEndWithLongest Note} {SlowRhythmChanges Note} end)} search strategy (i.e. distribution strategy) {FD.distribute {SDistro.makeFDDistribution unit(order:size value:random)} {MyScore collect($ test:isParameter)}} end end

{ExploreOne SmoothRhythm2}

To define IsSimultaneous with free rhythmic structure in an efficient and sound way, I need to go into reified constraints

declare local

Durations = [1 2 4] proc {StartAndEndWithLongest Note} C = {Note getTemporalAspect($)} in if {Note isFirstItem($ C)} orelse {Note isLastItem($ C)} then {Note getDuration($)} = {List.last Durations} end end proc {SlowRhythmChanges Note} C = {Note getTemporalAspect($)} in if {Note hasPredecessor($ C)} then Dur1 = {{Note getPredecessor($ C)} getDuration($)} Dur2 = {Note getDuration($)} HalveDur1 in {FD.decl HalveDur1} {FD.times HalveDur1 2 Dur1} {FD.times HalveDur1 {FD.int [1 2 4]} Dur2} end end MIDI pitch domain reduction: only 'wite keys' (c major) proc {InCMajor Note} {List.forAll [1 3 6 8 10] list of 'black' pitch classes (c=0) proc {$ BlackKey} {FD.modI {Note getPitch($)} 12} \=: BlackKey end} end proc {StartAndEndWithFundamental Note} C = {Note getTemporalAspect($)} in if {Note isFirstItem($ C)} orelse {Note isLastItem($ C)} then {Note getPitch($)} = 60 end end voice leading: only intervals up to a fifth, no pitch repetition (context dependent constraint — getPredecessor — but this context is predetermined by predetermined hierarchic structure) proc {NoBigJump Note} C = {Note getTemporalAspect($)} in if {Note hasPredecessor($ C)} then Pitch1 = {{Note getPredecessor($ C)} getPitch($)} Pitch2 = {Note getPitch($)} in all intervals between minor second and fourth are allowed {FD.distance Pitch1 Pitch2 '>:' 0} {FD.distance Pitch1 Pitch2 '<:' 6} end end harmony: only consonants proc {NoDissonance Note1} OtherVoiceNotes = {{Note1 find($ fun {$ X} {X hasThisInfo($ voice2)} end mode:graph)} getItems($)} Pitch1 = {Note1 getPitch($)} in {ForAll OtherVoiceNotes proc {$ Note2} Pitch2 = {Note2 getPitch($)} Consonance in !! Consonance does not necessarily get determined: the solution diamond in the explorer are light green Consonance = {FD.int [3 4 7 8 9 12 15 16]} {FD.impl {Note1 isSimultaneousItemR($ Note2)} ( Pitch1 + Consonance =: Pitch2 ) 1} end} end in proc {RhythmicCounterpoint MyScore} N=17 EndTime in MyScore = {Score.makeScore sim(items: [seq(info:voice1 items: {LUtils.collectN N fun {$} note(duration: {FD.int Durations} pitch: {FD.int 53#72} amplitude: 80) end} offsetTime:0 endTime:EndTime) seq(info:voice2 items: {LUtils.collectN N fun {$} note(duration: {FD.int Durations} pitch: {FD.int 53#72} amplitude: 80) end} offsetTime:{List.last Durations} endTime:EndTime)] startTime: 0 timeUnit:beats) unit}

Apply compositional rules:

rules for al notes {MyScore forAll(test: isNote proc {$ Note} {InCMajor Note} {NoBigJump Note} {StartAndEndWithLongest Note} {SlowRhythmChanges Note} end)} rules for notes of first voice {{MyScore find($ fun {$ X} {X hasThisInfo($ voice1)} end)} forAll(test: isNote proc {$ Note} {StartAndEndWithFundamental Note} {NoDissonance Note} end)} search strategy (i.e. distribution strategy) {FD.distribute {SDistro.makeFDDistribution unit(order:startTime value:random)} {MyScore collect($ test:fun {$ X} {X isParameter($)} andthen {Not {X isTimePoint($)}} andthen {Not {{X getItem($)} isContainer($)}} end)}} end end

{ExploreOne RhythmicCounterpoint}

Canon

declare local

Durations = [1 2 4] proc {StartAndEndWithLongest Note} C = {Note getTemporalAspect($)} in if {Note isFirstItem($ C)} orelse {Note isLastItem($ C)} then {Note getDuration($)} = {List.last Durations} end end proc {SlowRhythmChanges Note} C = {Note getTemporalAspect($)} in if {Note hasPredecessor($ C)} then Dur1 = {{Note getPredecessor($ C)} getDuration($)} Dur2 = {Note getDuration($)} HalveDur1 in {FD.decl HalveDur1} {FD.times HalveDur1 2 Dur1} {FD.times HalveDur1 {FD.int [1 2 4]} Dur2} end end MIDI pitch domain reduction: only 'wite keys' (c major) proc {InCMajor Note} {List.forAll [1 3 6 8 10] list of 'black' pitch classes (c=0) proc {$ BlackKey} {FD.modI {Note getPitch($)} 12} \=: BlackKey end} end proc {StartAndEndWithFundamental Note} C = {Note getTemporalAspect($)} in if {Note isFirstItem($ C)} orelse {Note isLastItem($ C)} then {Note getPitch($)} = 60 end end voice leading: only intervals up to a fifth, no pitch repetition (context dependent constraint — getPredecessor — but this context is predetermined by predetermined hierarchic structure) proc {NoBigJump Note} C = {Note getTemporalAspect($)} in if {Note hasPredecessor($ C)} then Pitch1 = {{Note getPredecessor($ C)} getPitch($)} Pitch2 = {Note getPitch($)} in all intervals between minor second and fourth are allowed {FD.distance Pitch1 Pitch2 '>:' 0} {FD.distance Pitch1 Pitch2 '<:' 6} end end harmony: only consonants proc {NoDissonance Note1 Voice2} Voice2Notes = {Voice2 getItems($)} Pitch1 = {Note1 getPitch($)} in {ForAll Voice2Notes proc {$ Note2} Pitch2 = {Note2 getPitch($)} Consonance in !! Consonance does not necessarily get determined: the solution diamond in the explorer are light green Consonance = {FD.int [3 4 7 8 9 12 15 16]} {FD.impl {Note1 isSimultaneousItemR($ Note2)} ( Pitch1 + Consonance : Pitch2 ) 1} end} end in proc {SimpleCanon MyScore} fun {GetVoice MyScore ScoreName} {MyScore find($ fun {$ X} {X hasThisInfo($ ScoreName)} end)} end EndTime Voice1 Voice2 in MyScore {Score.makeScore sim(items: [seq(info:voice1 items: {LUtils.collectN 17 fun {$} note(duration: {FD.int Durations} pitch: {FD.int 53#67} amplitude: 80) end} offsetTime:0 endTime:EndTime) seq(info:voice2 items: {LUtils.collectN 15 fun {$} note(duration: {FD.int Durations} pitch: {FD.int 53#72} amplitude: 80) end} offsetTime:{List.last Durations}*2 endTime:EndTime)] startTime: 0 timeUnit:beats) unit} Voice1 = {GetVoice MyScore voice1} Voice2 = {GetVoice MyScore voice2}

Apply compositional rules:

rules for al notes {MyScore forAll(test: isNote proc {$ Note} {InCMajor Note} {NoBigJump Note} {StartAndEndWithLongest Note} {SlowRhythmChanges Note} end)} rules for notes of first voice {Voice1 forAll(test: isNote proc {$ Note} {StartAndEndWithFundamental Note} {NoDissonance Note Voice2} end)} The first 12 notes of each voice form a canon in a fifth for Note1 in {List.take {Voice1 getItems($)} 12} Note2 in {List.take {Voice2 getItems($)} 12} do {Note1 getPitch($)} + 7 : {Note2 getPitch($)} {Note1 getDuration($)} : {Note2 getDuration($)} end search strategy (i.e. distribution strategy) {FD.distribute {SDistro.makeFDDistribution unit(order:startTime value:random)} {MyScore collect($ test:fun {$ X} {X isParameter($)} andthen {Not {X isTimePoint($)}} andthen {Not {{X getItem($)} isContainer($)}} end)}} end end

{ExploreOne SimpleCanon}