diff --git a/lilypond/includes/part_I.ly b/lilypond/includes/part_I.ly index fad68f5..118203a 100644 --- a/lilypond/includes/part_I.ly +++ b/lilypond/includes/part_I.ly @@ -11,3 +11,4 @@ \include "/home/mwinter/Sketches/seeds_and_ledgers/source/resources/string_quartet_3_rise_coda_only/4dd2a130/lilypond/part_I.ly" \include "/home/mwinter/Sketches/seeds_and_ledgers/source/resources/string_quartet_3_rise_coda_only/767e70f0/lilypond/part_I.ly" \include "/home/mwinter/Sketches/seeds_and_ledgers/source/resources/string_quartet_3_rise_coda_only/536cac90/lilypond/part_I.ly" +\include "/home/mwinter/Sketches/seeds_and_ledgers/source/resources/string_quartet_3_rise_coda_only/5ededd80/lilypond/part_I.ly" diff --git a/lilypond/includes/part_II.ly b/lilypond/includes/part_II.ly index 1a93ad0..c059a30 100644 --- a/lilypond/includes/part_II.ly +++ b/lilypond/includes/part_II.ly @@ -11,3 +11,4 @@ \include "/home/mwinter/Sketches/seeds_and_ledgers/source/resources/string_quartet_3_rise_coda_only/4dd2a130/lilypond/part_II.ly" \include "/home/mwinter/Sketches/seeds_and_ledgers/source/resources/string_quartet_3_rise_coda_only/767e70f0/lilypond/part_II.ly" \include "/home/mwinter/Sketches/seeds_and_ledgers/source/resources/string_quartet_3_rise_coda_only/536cac90/lilypond/part_II.ly" +\include "/home/mwinter/Sketches/seeds_and_ledgers/source/resources/string_quartet_3_rise_coda_only/5ededd80/lilypond/part_II.ly" diff --git a/lilypond/includes/part_III.ly b/lilypond/includes/part_III.ly index 9d3d7c1..69d3434 100644 --- a/lilypond/includes/part_III.ly +++ b/lilypond/includes/part_III.ly @@ -11,3 +11,4 @@ \include "/home/mwinter/Sketches/seeds_and_ledgers/source/resources/string_quartet_3_rise_coda_only/4dd2a130/lilypond/part_III.ly" \include "/home/mwinter/Sketches/seeds_and_ledgers/source/resources/string_quartet_3_rise_coda_only/767e70f0/lilypond/part_III.ly" \include "/home/mwinter/Sketches/seeds_and_ledgers/source/resources/string_quartet_3_rise_coda_only/536cac90/lilypond/part_III.ly" +\include "/home/mwinter/Sketches/seeds_and_ledgers/source/resources/string_quartet_3_rise_coda_only/5ededd80/lilypond/part_III.ly" diff --git a/lilypond/includes/part_IV.ly b/lilypond/includes/part_IV.ly index c138422..1592c57 100644 --- a/lilypond/includes/part_IV.ly +++ b/lilypond/includes/part_IV.ly @@ -11,3 +11,4 @@ \include "/home/mwinter/Sketches/seeds_and_ledgers/source/resources/string_quartet_3_rise_coda_only/4dd2a130/lilypond/part_IV.ly" \include "/home/mwinter/Sketches/seeds_and_ledgers/source/resources/string_quartet_3_rise_coda_only/767e70f0/lilypond/part_IV.ly" \include "/home/mwinter/Sketches/seeds_and_ledgers/source/resources/string_quartet_3_rise_coda_only/536cac90/lilypond/part_IV.ly" +\include "/home/mwinter/Sketches/seeds_and_ledgers/source/resources/string_quartet_3_rise_coda_only/5ededd80/lilypond/part_IV.ly" diff --git a/lilypond/score_template.pdf b/lilypond/score_template.pdf index a14634b..c6d05a2 100644 Binary files a/lilypond/score_template.pdf and b/lilypond/score_template.pdf differ diff --git a/lilypond/string_quartet_2/edited/seeds_and_ledgers_2.pdf b/lilypond/string_quartet_2/edited/seeds_and_ledgers_2.pdf index 23be8dc..c7a034b 100644 Binary files a/lilypond/string_quartet_2/edited/seeds_and_ledgers_2.pdf and b/lilypond/string_quartet_2/edited/seeds_and_ledgers_2.pdf differ diff --git a/lilypond/string_quartet_3/coda/edited/seeds_and_ledgers_3_coda.pdf b/lilypond/string_quartet_3/coda/edited/seeds_and_ledgers_3_coda.pdf index 873b271..bd498e9 100644 Binary files a/lilypond/string_quartet_3/coda/edited/seeds_and_ledgers_3_coda.pdf and b/lilypond/string_quartet_3/coda/edited/seeds_and_ledgers_3_coda.pdf differ diff --git a/lilypond/string_quartet_3/coda/original_output/score_template.pdf b/lilypond/string_quartet_3/coda/original_output/score_template.pdf index d30c6dd..745f17a 100644 Binary files a/lilypond/string_quartet_3/coda/original_output/score_template.pdf and b/lilypond/string_quartet_3/coda/original_output/score_template.pdf differ diff --git a/lilypond/string_quartet_3/main/edited/seeds_and_ledgers_3.ly b/lilypond/string_quartet_3/main/edited/seeds_and_ledgers_3.ly index 392d692..66adcf3 100644 --- a/lilypond/string_quartet_3/main/edited/seeds_and_ledgers_3.ly +++ b/lilypond/string_quartet_3/main/edited/seeds_and_ledgers_3.ly @@ -30,8 +30,8 @@ print-first-page-number = ##t print-page-number = ##t - oddHeaderMarkup = \markup { \fill-line { \line { \unless \on-first-page {\pad-markup #2 { \concat {\italic {"test"}}}}}}} - evenHeaderMarkup = \markup { \fill-line { \line { \unless \on-first-page {\pad-markup #2 { \concat {\italic {"test"}}}}}}} + oddHeaderMarkup = \markup { \fill-line { \line { \unless \on-first-page {\pad-markup #2 { \concat {\italic {"seeds and ledges 3"}}}}}}} + evenHeaderMarkup = \markup { \fill-line { \line { \unless \on-first-page {\pad-markup #2 { \concat {\italic {"seeds and ledges 3"}}}}}}} oddFooterMarkup = \markup { \fill-line { \concat { "-" diff --git a/lilypond/string_quartet_3/main/edited/seeds_and_ledgers_3.pdf b/lilypond/string_quartet_3/main/edited/seeds_and_ledgers_3.pdf index 93261fe..4880f06 100644 Binary files a/lilypond/string_quartet_3/main/edited/seeds_and_ledgers_3.pdf and b/lilypond/string_quartet_3/main/edited/seeds_and_ledgers_3.pdf differ diff --git a/resources/piece_ledger/314s49e1/lilypond/part_I.ly b/resources/piece_ledger/314s49e1/lilypond/part_I.ly index 5fe9b6e..51eaa47 100644 --- a/resources/piece_ledger/314s49e1/lilypond/part_I.ly +++ b/resources/piece_ledger/314s49e1/lilypond/part_I.ly @@ -1,54 +1,56 @@ { - { r4 r8.[ c'16^\markup { \pad-markup #0.2 "+0"}] ~ c'2 ~ } + { r4 r8.[ d'16^\markup { \pad-markup #0.2 "+0"}] ~ d'2 ~ } \bar "|" - { c'1 ~ } + { d'1 ~ } \bar "|" - { c'1 ~ } + { d'1 ~ } \bar "|" - { c'1 ~ } + { d'1 ~ } \bar "|" - { c'1 ~ } + { d'1 ~ } \bar "|" - { c'1 ~ } + { d'1 ~ } \bar "|" - { c'1 ~ } + { d'1 ~ } \bar "|" - { c'1 ~ } + { d'1 ~ } \bar "|" - { c'1 ~ } + { d'1 ~ } \bar "|" - { c'1 ~ } + { d'1 ~ } \bar "|" - { c'1 ~ } + { d'1 ~ } \bar "|" - { c'1 } + { d'1 } \bar "|" - { b1^\markup { \pad-markup #0.2 "+47"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 11↓" }} ~ } + { cis'1^\markup { \pad-markup #0.2 "+47"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 11↓" }} ~ } \bar "|" - { b1 ~ } + { cis'1 ~ } \bar "|" - { b4 ~ b8[ ais8^\markup { \pad-markup #0.2 "+35"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }}] ~ ais8.[ a16^\markup { \pad-markup #0.2 "-20"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↓" }}] ~ a4 ~ } + { cis'4 ~ cis'8[ c'8^\markup { \pad-markup #0.2 "+35"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }}] ~ c'8.[ b16^\markup { \pad-markup #0.2 "-20"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↓" }}] ~ b4 ~ } \bar "|" - { a1 ~ } + { b1 ~ } \bar "|" - { a1 ~ } + { b1 ~ } + \bar "|" + { b1 ~ } \bar "|" - { a1 ~ } + { b16[ b8.^\markup { \pad-markup #0.2 "+16"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 7↑" }}] ~ b2. } \bar "|" - { a16[ a8.^\markup { \pad-markup #0.2 "+16"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 7↑" }}] ~ a2. } + { ais1^\markup { \pad-markup #0.2 "-13"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↑" }} ~ } \bar "|" - { gis1^\markup { \pad-markup #0.2 "-13"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↑" }} ~ } + { ais8.[ ais16^\markup { \pad-markup #0.2 "-40"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 5↓" }}] ~ ais2. ~ } \bar "|" - { gis8.[ gis16^\markup { \pad-markup #0.2 "-40"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 5↓" }}] ~ gis2. ~ } + { ais4 ~ ais8[ g8^\markup { \pad-markup #0.2 "-2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }}] ~ g4 gis4^\markup { \pad-markup #0.2 "-5"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 11↓" }} ~ } \bar "|" - { gis4 ~ gis8[ f8^\markup { \pad-markup #0.2 "-2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }}] ~ f4 fis4^\markup { \pad-markup #0.2 "-5"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 11↓" }} ~ } + { gis2. ~ gis8[ ais8^\markup { \pad-markup #0.2 "-13"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 13↑" }}] ~ } \bar "|" - { fis2. ~ fis8[ gis8^\markup { \pad-markup #0.2 "-13"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 13↑" }}] ~ } + { ais1 ~ } \bar "|" - { gis1 ~ } + { ais1 ~ } \bar "|" - { gis1 ~ } + { ais1 } \bar "|" - { gis1} + { r1 } \bar "||" } \ No newline at end of file diff --git a/resources/piece_ledger/314s49e1/lilypond/part_II.ly b/resources/piece_ledger/314s49e1/lilypond/part_II.ly index ac6a85b..710340c 100644 --- a/resources/piece_ledger/314s49e1/lilypond/part_II.ly +++ b/resources/piece_ledger/314s49e1/lilypond/part_II.ly @@ -13,27 +13,29 @@ \bar "|" { r1 } \bar "|" - { r16[ ais8.^\markup { \pad-markup #0.2 "-31"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 7↑" }}] ~ ais2. ~ } + { r16[ c'8.^\markup { \pad-markup #0.2 "-31"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 7↑" }}] ~ c'2. ~ } \bar "|" - { ais2. gis4^\markup { \pad-markup #0.2 "+14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 5↓" }} ~ } + { c'2. ais4^\markup { \pad-markup #0.2 "+14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 5↓" }} ~ } \bar "|" - { gis16[ fis8.^\markup { \pad-markup #0.2 "+49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 11↓" }}] ~ fis2. ~ } + { ais16[ gis8.^\markup { \pad-markup #0.2 "+49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 11↓" }}] ~ gis2. ~ } \bar "|" - { fis1 ~ } + { gis1 ~ } \bar "|" - { fis1 ~ } + { gis1 ~ } \bar "|" - { fis1 ~ } + { gis1 ~ } \bar "|" - { fis1 ~ } + { gis1 ~ } \bar "|" - { fis1 ~ } + { gis1 ~ } \bar "|" - { fis1 ~ } + { gis1 ~ } \bar "|" - { fis1 ~ } + { gis1 ~ } \bar "|" - { fis2 ~ fis8.[ r16] r4 } + { gis2 ~ gis8.[ r16] r4 } + \bar "|" + { r1 } \bar "|" { r1 } \bar "|" diff --git a/resources/piece_ledger/314s49e1/lilypond/part_III.ly b/resources/piece_ledger/314s49e1/lilypond/part_III.ly index 8288ca0..8d307ee 100644 --- a/resources/piece_ledger/314s49e1/lilypond/part_III.ly +++ b/resources/piece_ledger/314s49e1/lilypond/part_III.ly @@ -1,15 +1,15 @@ { - { r2. e'4^\markup { \pad-markup #0.2 "-41"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↓" }} ~ } + { r2. fis'4^\markup { \pad-markup #0.2 "-41"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↓" }} ~ } \bar "|" - { e'2 e'4^\markup { \pad-markup #0.2 "-14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }} ~ e'8.[ f'16^\markup { \pad-markup #0.2 "-2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }}] ~ } + { fis'2 fis'4^\markup { \pad-markup #0.2 "-14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }} ~ fis'8.[ g'16^\markup { \pad-markup #0.2 "-2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }}] ~ } \bar "|" - { f'4 ~ f'8[ g'8^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }}] ~ g'4 ~ g'8[ ais'8^\markup { \pad-markup #0.2 "-31"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↑" }}] ~ } + { g'4 ~ g'8[ a'8^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }}] ~ a'4 ~ a'8[ c''8^\markup { \pad-markup #0.2 "-31"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↑" }}] ~ } \bar "|" - { ais'4 ~ ais'8[ c''8^\markup { \pad-markup #0.2 "+0"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }}] ~ c''2 } + { c''4 ~ c''8[ d''8^\markup { \pad-markup #0.2 "+0"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }}] ~ d''2 } \bar "|" - { gis'4^\markup { \pad-markup #0.2 "+41"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↑" }} ~ gis'8.[ gis'16^\markup { \pad-markup #0.2 "+14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↓" }}] ~ gis'4 ~ gis'8[ f'8^\markup { \pad-markup #0.2 "-2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }}] ~ } + { ais'4^\markup { \pad-markup #0.2 "+41"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↑" }} ~ ais'8.[ ais'16^\markup { \pad-markup #0.2 "+14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↓" }}] ~ ais'4 ~ ais'8[ g'8^\markup { \pad-markup #0.2 "-2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }}] ~ } \bar "|" - { f'2 e'4^\markup { \pad-markup #0.2 "-14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }} ~ e'8[ r8] } + { g'2 fis'4^\markup { \pad-markup #0.2 "-14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }} ~ fis'8[ r8] } \bar "|" { r1 } \bar "|" @@ -21,33 +21,35 @@ \bar "|" { r1 } \bar "|" - { r2 r16[ dis'8.^\markup { \pad-markup #0.2 "-38"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 5↓" }}] ~ dis'4 ~ } + { r2 r16[ f'8.^\markup { \pad-markup #0.2 "-38"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 5↓" }}] ~ f'4 ~ } \bar "|" - { dis'1 ~ } + { f'1 ~ } \bar "|" - { dis'8[ dis'8^\markup { \pad-markup #0.2 "-11"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 13↑" }}] ~ dis'2 d'4^\markup { \pad-markup #0.2 "-49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↑" }} ~ } + { f'8[ f'8^\markup { \pad-markup #0.2 "-11"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 13↑" }}] ~ f'2 e'4^\markup { \pad-markup #0.2 "-49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↑" }} ~ } \bar "|" - { d'1 ~ } + { e'1 ~ } \bar "|" - { d'4 ~ d'8[ ais8^\markup { \pad-markup #0.2 "+35"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }}] ~ ais2 ~ } + { e'4 ~ e'8[ c'8^\markup { \pad-markup #0.2 "+35"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }}] ~ c'2 ~ } \bar "|" - { ais1 ~ } + { c'1 ~ } \bar "|" - { ais8.[ b16^\markup { \pad-markup #0.2 "+47"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↓" }}] ~ b2. ~ } + { c'8.[ cis'16^\markup { \pad-markup #0.2 "+47"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↓" }}] ~ cis'2. ~ } \bar "|" - { b1 ~ } + { cis'1 ~ } \bar "|" - { b1 ~ } + { cis'1 ~ } \bar "|" - { b1 ~ } + { cis'1 ~ } \bar "|" - { b1 ~ } + { cis'1 ~ } \bar "|" - { b1 ~ } + { cis'1 ~ } \bar "|" - { b1 ~ } + { cis'1 ~ } \bar "|" - { b2 ~ b16[ r8.] r4 } + { cis'2 ~ cis'16[ r8.] r4 } + \bar "|" + { r1 } \bar "|" { r1 } \bar "||" diff --git a/resources/piece_ledger/314s49e1/lilypond/part_IV.ly b/resources/piece_ledger/314s49e1/lilypond/part_IV.ly index 43e8385..dc3e114 100644 --- a/resources/piece_ledger/314s49e1/lilypond/part_IV.ly +++ b/resources/piece_ledger/314s49e1/lilypond/part_IV.ly @@ -1,54 +1,56 @@ { - { c'1^\markup { \pad-markup #0.2 "+0"} ~ } + { d'1^\markup { \pad-markup #0.2 "+0"} ~ } \bar "|" - { c'1 ~ } + { d'1 ~ } \bar "|" - { c'1 ~ } + { d'1 ~ } \bar "|" - { c'1 ~ } + { d'1 ~ } \bar "|" - { c'1 ~ } + { d'1 ~ } \bar "|" - { c'1 ~ } + { d'1 ~ } \bar "|" - { c'4 ~ c'16[ e'8.^\markup { \pad-markup #0.2 "-41"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 13↓" }}] ~ e'2 ~ } + { d'4 ~ d'16[ fis'8.^\markup { \pad-markup #0.2 "-41"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 13↓" }}] ~ fis'2 ~ } \bar "|" - { e'2 ~ e'8.[ g'16^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↑" }}] ~ g'4 ~ } + { fis'2 ~ fis'8.[ a'16^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↑" }}] ~ a'4 ~ } \bar "|" - { g'4 ~ g'8[ ais'8^\markup { \pad-markup #0.2 "-31"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 1↑" }}] ~ ais'2 ~ } + { a'4 ~ a'8[ c''8^\markup { \pad-markup #0.2 "-31"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 1↑" }}] ~ c''2 ~ } \bar "|" - { ais'4 ~ ais'8.[ gis'16^\markup { \pad-markup #0.2 "+41"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 13↑" }}] ~ gis'2 } + { c''4 ~ c''8.[ ais'16^\markup { \pad-markup #0.2 "+41"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 13↑" }}] ~ ais'2 } \bar "|" - { gis'2^\markup { \pad-markup #0.2 "+14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 5↓" }} ~ gis'8[ g'8^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↑" }}] ~ g'4 ~ } + { ais'2^\markup { \pad-markup #0.2 "+14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 5↓" }} ~ ais'8[ a'8^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↑" }}] ~ a'4 ~ } \bar "|" - { g'8[ f'8^\markup { \pad-markup #0.2 "-2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↓" }}] ~ f'2. ~ } + { a'8[ g'8^\markup { \pad-markup #0.2 "-2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↓" }}] ~ g'2. ~ } \bar "|" - { f'4 ~ f'8[ e'8^\markup { \pad-markup #0.2 "+18"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 7↑" }}] ~ e'2 ~ } + { g'4 ~ g'8[ fis'8^\markup { \pad-markup #0.2 "+18"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 7↑" }}] ~ fis'2 ~ } \bar "|" - { e'1 ~ } + { fis'1 ~ } \bar "|" - { e'16[ fis'8.^\markup { \pad-markup #0.2 "+49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 1↑" }}] ~ fis'2. ~ } + { fis'16[ gis'8.^\markup { \pad-markup #0.2 "+49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 1↑" }}] ~ gis'2. ~ } \bar "|" - { fis'1 ~ } + { gis'1 ~ } \bar "|" - { fis'16[ a'8.^\markup { \pad-markup #0.2 "-20"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }}] ~ a'2 ~ a'16[ ais'8.^\markup { \pad-markup #0.2 "+8"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 13↓" }}] ~ } + { gis'16[ b'8.^\markup { \pad-markup #0.2 "-20"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }}] ~ b'2 ~ b'16[ c''8.^\markup { \pad-markup #0.2 "+8"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 13↓" }}] ~ } \bar "|" - { ais'1 ~ } + { c''1 ~ } \bar "|" - { ais'2 ~ ais'16[ b'8.^\markup { \pad-markup #0.2 "+47"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }}] ~ b'4 ~ } + { c''2 ~ c''16[ cis''8.^\markup { \pad-markup #0.2 "+47"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }}] ~ cis''4 ~ } \bar "|" - { b'2 ~ b'8[ a'8^\markup { \pad-markup #0.2 "+16"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 7↑" }}] ~ a'4 ~ } + { cis''2 ~ cis''8[ b'8^\markup { \pad-markup #0.2 "+16"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 7↑" }}] ~ b'4 ~ } \bar "|" - { a'2 ~ a'8.[ fis'16^\markup { \pad-markup #0.2 "+49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↑" }}] ~ fis'4 ~ } + { b'2 ~ b'8.[ gis'16^\markup { \pad-markup #0.2 "+49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↑" }}] ~ gis'4 ~ } \bar "|" - { fis'16[ f'8.^\markup { \pad-markup #0.2 "-2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 11↑" }}] ~ f'2. ~ } + { gis'16[ g'8.^\markup { \pad-markup #0.2 "-2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 11↑" }}] ~ g'2. ~ } \bar "|" - { f'4 ~ f'8.[ e'16^\markup { \pad-markup #0.2 "+45"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↓" }}] ~ e'2 ~ } + { g'4 ~ g'8.[ fis'16^\markup { \pad-markup #0.2 "+45"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↓" }}] ~ fis'2 ~ } \bar "|" - { e'1 ~ } + { fis'1 ~ } + \bar "|" + { fis'1 ~ } \bar "|" - { e'1 ~ } + { fis'4 ~ fis'16[ r8.] r2 } \bar "|" - { e'4 ~ e'16[ r8.] r2 } + { r1 } \bar "||" } \ No newline at end of file diff --git a/resources/piece_ledger/4c01589b/lilypond/part_I.ly b/resources/piece_ledger/4c01589b/lilypond/part_I.ly index a806b97..b63de1f 100644 --- a/resources/piece_ledger/4c01589b/lilypond/part_I.ly +++ b/resources/piece_ledger/4c01589b/lilypond/part_I.ly @@ -1,38 +1,40 @@ { - { r2. r8[ e'8^\markup { \pad-markup #0.2 "-14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 5↑" }}] ~ } + { r2. r8[ fis'8^\markup { \pad-markup #0.2 "-14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 5↑" }}] ~ } \bar "|" - { e'1 ~ } + { fis'1 ~ } \bar "|" - { e'4 ~ e'8[ f'8^\markup { \pad-markup #0.2 "-2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↓" }}] ~ f'4 ~ f'16[ e'8.^\markup { \pad-markup #0.2 "-41"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 13↓" }}] ~ } + { fis'4 ~ fis'8[ g'8^\markup { \pad-markup #0.2 "-2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↓" }}] ~ g'4 ~ g'16[ fis'8.^\markup { \pad-markup #0.2 "-41"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 13↓" }}] ~ } \bar "|" - { e'1 ~ } + { fis'1 ~ } \bar "|" - { e'2 d'2^\markup { \pad-markup #0.2 "+31"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 7↓" }} ~ } + { fis'2 e'2^\markup { \pad-markup #0.2 "+31"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 7↓" }} ~ } \bar "|" - { d'1 ~ } + { e'1 ~ } \bar "|" - { d'1 ~ } + { e'1 ~ } \bar "|" - { d'1 ~ } + { e'1 ~ } + \bar "|" + { e'1 ~ } \bar "|" - { d'1 ~ } + { e'1 ~ } \bar "|" - { d'1 ~ } + { e'1 ~ } \bar "|" - { d'1 ~ } + { e'2 r2 } \bar "|" - { d'2 r2 } + { r8.[ e'16^\markup { \pad-markup #0.2 "+31"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 7↓" }}] ~ e'2. ~ } \bar "|" - { r8.[ d'16^\markup { \pad-markup #0.2 "+31"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 7↓" }}] ~ d'2. ~ } + { e'1 ~ } \bar "|" - { d'1 ~ } + { e'1 ~ } \bar "|" - { d'1 ~ } + { e'1 ~ } \bar "|" - { d'1 ~ } + { e'1 ~ } \bar "|" - { d'1 ~ } + { e'1 ~ } \bar "|" - { d'1} + { e'16[ r8.] r2. } \bar "||" } \ No newline at end of file diff --git a/resources/piece_ledger/4c01589b/lilypond/part_II.ly b/resources/piece_ledger/4c01589b/lilypond/part_II.ly index 26c0d70..452075b 100644 --- a/resources/piece_ledger/4c01589b/lilypond/part_II.ly +++ b/resources/piece_ledger/4c01589b/lilypond/part_II.ly @@ -1,38 +1,40 @@ { - { c'1^\markup { \pad-markup #0.2 "+0"} ~ } + { d'1^\markup { \pad-markup #0.2 "+0"} ~ } \bar "|" - { c'1 ~ } + { d'1 ~ } \bar "|" - { c'1 ~ } + { d'1 ~ } \bar "|" - { c'1 ~ } + { d'1 ~ } \bar "|" - { c'2. ~ c'8.[ b16^\markup { \pad-markup #0.2 "-12"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }}] ~ } + { d'2. ~ d'8.[ cis'16^\markup { \pad-markup #0.2 "-12"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }}] ~ } \bar "|" - { b4 b2.^\markup { \pad-markup #0.2 "-39"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↓" }} ~ } + { cis'4 cis'2.^\markup { \pad-markup #0.2 "-39"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↓" }} ~ } \bar "|" - { b16[ cis'8.^\markup { \pad-markup #0.2 "-47"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 11↑" }}] ~ cis'4 ~ cis'8[ ais8^\markup { \pad-markup #0.2 "+45"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 5↓" }}] ~ ais4 ~ } + { cis'16[ dis'8.^\markup { \pad-markup #0.2 "-47"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 11↑" }}] ~ dis'4 ~ dis'8[ c'8^\markup { \pad-markup #0.2 "+45"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 5↓" }}] ~ c'4 ~ } \bar "|" - { ais8[ a8^\markup { \pad-markup #0.2 "+33"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↓" }}] ~ a8[ b8^\markup { \pad-markup #0.2 "-28"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 13↑" }}] ~ b2 ~ } + { c'8[ b8^\markup { \pad-markup #0.2 "+33"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↓" }}] ~ b8[ cis'8^\markup { \pad-markup #0.2 "-28"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 13↑" }}] ~ cis'2 ~ } \bar "|" - { b8.[ c'16^\markup { \pad-markup #0.2 "+0"}] ~ c'2 ~ c'8.[ b16^\markup { \pad-markup #0.2 "-39"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↓" }}] ~ } + { cis'8.[ d'16^\markup { \pad-markup #0.2 "+0"}] ~ d'2 ~ d'8.[ cis'16^\markup { \pad-markup #0.2 "-39"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↓" }}] ~ } \bar "|" - { b1 ~ } + { cis'1 ~ } \bar "|" - { b1 ~ } + { cis'1 ~ } \bar "|" - { b2 c'2^\markup { \pad-markup #0.2 "+0"} ~ } + { cis'2 d'2^\markup { \pad-markup #0.2 "+0"} ~ } \bar "|" - { c'1 ~ } + { d'1 ~ } \bar "|" - { c'1 ~ } + { d'1 ~ } \bar "|" - { c'1 ~ } + { d'1 ~ } \bar "|" - { c'1 ~ } + { d'1 ~ } \bar "|" - { c'1 ~ } + { d'1 ~ } \bar "|" - { c'8.[ r16] r2. } + { d'8.[ r16] r2. } + \bar "|" + { r1 } \bar "||" } \ No newline at end of file diff --git a/resources/piece_ledger/4c01589b/lilypond/part_III.ly b/resources/piece_ledger/4c01589b/lilypond/part_III.ly index 69e87d9..e1a0b8e 100644 --- a/resources/piece_ledger/4c01589b/lilypond/part_III.ly +++ b/resources/piece_ledger/4c01589b/lilypond/part_III.ly @@ -1,38 +1,40 @@ { - { r2. r8[ ais8^\markup { \pad-markup #0.2 "-31"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 7↑" }}] ~ } + { r2. r8[ c'8^\markup { \pad-markup #0.2 "-31"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 7↑" }}] ~ } \bar "|" - { ais2 gis2^\markup { \pad-markup #0.2 "+14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 5↓" }} ~ } + { c'2 ais2^\markup { \pad-markup #0.2 "+14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 5↓" }} ~ } \bar "|" - { gis4 ~ gis8[ g8^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↑" }}] ~ g2 ~ } + { ais4 ~ ais8[ a8^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↑" }}] ~ a2 ~ } \bar "|" - { g1 ~ } + { a1 ~ } \bar "|" - { g1 ~ } + { a1 ~ } \bar "|" - { g1 ~ } + { a1 ~ } \bar "|" - { g1 ~ } + { a1 ~ } \bar "|" - { g1 ~ } + { a1 ~ } \bar "|" - { g1 ~ } + { a1 ~ } \bar "|" - { g8.[ g16^\markup { \pad-markup #0.2 "+29"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↓" }}] ~ g8.[ a16^\markup { \pad-markup #0.2 "+33"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↓" }}] ~ a2 ~ } + { a8.[ a16^\markup { \pad-markup #0.2 "+29"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↓" }}] ~ a8.[ b16^\markup { \pad-markup #0.2 "+33"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↓" }}] ~ b2 ~ } \bar "|" - { a8.[ gis16^\markup { \pad-markup #0.2 "+30"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 7↑" }}] ~ gis2 ~ gis8.[ a16^\markup { \pad-markup #0.2 "-20"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 11↓" }}] ~ } + { b8.[ ais16^\markup { \pad-markup #0.2 "+30"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 7↑" }}] ~ ais2 ~ ais8.[ b16^\markup { \pad-markup #0.2 "-20"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 11↓" }}] ~ } \bar "|" - { a2 r2 } + { b2 r2 } \bar "|" { r1 } \bar "|" - { r16[ gis8.^\markup { \pad-markup #0.2 "-18"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 11↑" }}] ~ gis2. } + { r16[ ais8.^\markup { \pad-markup #0.2 "-18"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 11↑" }}] ~ ais2. } \bar "|" - { gis4^\markup { \pad-markup #0.2 "+41"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 13↑" }} ~ gis8[ gis8^\markup { \pad-markup #0.2 "+14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 5↓" }}] ~ gis2 } + { ais4^\markup { \pad-markup #0.2 "+41"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 13↑" }} ~ ais8[ ais8^\markup { \pad-markup #0.2 "+14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 5↓" }}] ~ ais2 } \bar "|" - { g2^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }} g2^\markup { \pad-markup #0.2 "+29"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↓" }} ~ } + { a2^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }} a2^\markup { \pad-markup #0.2 "+29"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↓" }} ~ } \bar "|" - { g8.[ a16^\markup { \pad-markup #0.2 "-20"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 11↓" }}] ~ a2. ~ } + { a8.[ b16^\markup { \pad-markup #0.2 "-20"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 11↓" }}] ~ b2. ~ } \bar "|" - { a1} + { b1 ~ } + \bar "|" + { b16[ r8.] r2. } \bar "||" } \ No newline at end of file diff --git a/resources/piece_ledger/4c01589b/lilypond/part_IV.ly b/resources/piece_ledger/4c01589b/lilypond/part_IV.ly index 2ab46c8..8df7bd6 100644 --- a/resources/piece_ledger/4c01589b/lilypond/part_IV.ly +++ b/resources/piece_ledger/4c01589b/lilypond/part_IV.ly @@ -1,38 +1,40 @@ { - { r2. r8[ gis8^\markup { \pad-markup #0.2 "+41"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 13↑" }}] ~ } + { r2. r8[ ais8^\markup { \pad-markup #0.2 "+41"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 13↑" }}] ~ } \bar "|" - { gis1 ~ } + { ais1 ~ } \bar "|" - { gis4 ~ gis8[ ais8^\markup { \pad-markup #0.2 "-31"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 7↑" }}] ~ ais4 ~ ais16[ d'8.^\markup { \pad-markup #0.2 "+31"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 7↓" }}] ~ } + { ais4 ~ ais8[ c'8^\markup { \pad-markup #0.2 "-31"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 7↑" }}] ~ c'4 ~ c'16[ e'8.^\markup { \pad-markup #0.2 "+31"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 7↓" }}] ~ } \bar "|" - { d'2 ~ d'8[ f'8^\markup { \pad-markup #0.2 "-2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↓" }}] ~ f'4 ~ } + { e'2 ~ e'8[ g'8^\markup { \pad-markup #0.2 "-2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↓" }}] ~ g'4 ~ } \bar "|" - { f'2 g'2^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }} ~ } + { g'2 a'2^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }} ~ } \bar "|" - { g'1 ~ } + { a'1 ~ } \bar "|" - { g'1 ~ } + { a'1 ~ } \bar "|" - { g'1 ~ } + { a'1 ~ } \bar "|" - { g'1 ~ } + { a'1 ~ } \bar "|" - { g'1 ~ } + { a'1 ~ } \bar "|" - { g'1 ~ } + { a'1 ~ } \bar "|" - { g'1 ~ } + { a'1 ~ } \bar "|" - { g'1 ~ } + { a'1 ~ } \bar "|" - { g'1 ~ } + { a'1 ~ } \bar "|" - { g'1 ~ } + { a'1 ~ } \bar "|" - { g'1 ~ } + { a'1 ~ } \bar "|" - { g'1 ~ } + { a'1 ~ } \bar "|" - { g'8.[ r16] r2. } + { a'8.[ r16] r2. } + \bar "|" + { r1 } \bar "||" } \ No newline at end of file diff --git a/resources/piece_ledger/7e170ef8/lilypond/part_I.ly b/resources/piece_ledger/7e170ef8/lilypond/part_I.ly index c8ca6a7..b5838f7 100644 --- a/resources/piece_ledger/7e170ef8/lilypond/part_I.ly +++ b/resources/piece_ledger/7e170ef8/lilypond/part_I.ly @@ -1,34 +1,36 @@ { - { r2. r8[ e'8^\markup { \pad-markup #0.2 "-14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 5↑" }}] ~ } + { r2. r8[ fis'8^\markup { \pad-markup #0.2 "-14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 5↑" }}] ~ } \bar "|" - { e'8.[ f'16^\markup { \pad-markup #0.2 "-2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↓" }}] ~ f'4 ~ f'8[ e'8^\markup { \pad-markup #0.2 "-41"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 13↓" }}] ~ e'4 ~ } + { fis'8.[ g'16^\markup { \pad-markup #0.2 "-2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↓" }}] ~ g'4 ~ g'8[ fis'8^\markup { \pad-markup #0.2 "-41"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 13↓" }}] ~ fis'4 ~ } \bar "|" - { e'4 ~ e'16[ fis'8.^\markup { \pad-markup #0.2 "-49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 11↑" }}] ~ fis'16[ g'8.^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↑" }}] ~ g'4 ~ } + { fis'4 ~ fis'16[ gis'8.^\markup { \pad-markup #0.2 "-49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 11↑" }}] ~ gis'16[ a'8.^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↑" }}] ~ a'4 ~ } \bar "|" - { g'8.[ gis'16^\markup { \pad-markup #0.2 "+14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 5↓" }}] ~ gis'2. ~ } + { a'8.[ ais'16^\markup { \pad-markup #0.2 "+14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 5↓" }}] ~ ais'2. ~ } \bar "|" - { gis'2. ~ gis'8.[ fis'16^\markup { \pad-markup #0.2 "-49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 11↑" }}] ~ } + { ais'2. ~ ais'8.[ gis'16^\markup { \pad-markup #0.2 "-49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 11↑" }}] ~ } \bar "|" - { fis'2. ~ fis'16[ fis'8.^\markup { \pad-markup #0.2 "+49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 11↓" }}] ~ } + { gis'2. ~ gis'16[ gis'8.^\markup { \pad-markup #0.2 "+49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 11↓" }}] ~ } \bar "|" - { fis'2 ~ fis'8.[ gis'16^\markup { \pad-markup #0.2 "+41"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }}] ~ gis'4 ~ } + { gis'2 ~ gis'8.[ ais'16^\markup { \pad-markup #0.2 "+41"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }}] ~ ais'4 ~ } \bar "|" - { gis'1 ~ } + { ais'1 ~ } \bar "|" - { gis'2 gis'2^\markup { \pad-markup #0.2 "+14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }} ~ } + { ais'2 ais'2^\markup { \pad-markup #0.2 "+14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }} ~ } \bar "|" - { gis'1 ~ } + { ais'1 ~ } \bar "|" - { gis'1 ~ } + { ais'1 ~ } \bar "|" - { gis'1 ~ } + { ais'1 ~ } \bar "|" - { gis'1 ~ } + { ais'1 ~ } \bar "|" - { gis'2. ~ gis'16[ ais'8.^\markup { \pad-markup #0.2 "-31"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↑" }}] ~ } + { ais'2. ~ ais'16[ c''8.^\markup { \pad-markup #0.2 "-31"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↑" }}] ~ } \bar "|" - { ais'4 ~ ais'8.[ c''16^\markup { \pad-markup #0.2 "+0"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }}] ~ c''2 ~ } + { c''4 ~ c''8.[ d''16^\markup { \pad-markup #0.2 "+0"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }}] ~ d''2 ~ } \bar "|" - { c''16[ cis''8.^\markup { \pad-markup #0.2 "+39"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 13↑" }}] ~ cis''2 ~ cis''16[ d''8.^\markup { \pad-markup #0.2 "+31"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 1↑" }}]} + { d''16[ dis''8.^\markup { \pad-markup #0.2 "+39"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 13↑" }}] ~ dis''2 ~ dis''16[ e''8.^\markup { \pad-markup #0.2 "+31"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 1↑" }}] ~ } + \bar "|" + { e''4 ~ e''8.[ r16] r2 } \bar "||" } \ No newline at end of file diff --git a/resources/piece_ledger/7e170ef8/lilypond/part_II.ly b/resources/piece_ledger/7e170ef8/lilypond/part_II.ly index 7683e88..4288d43 100644 --- a/resources/piece_ledger/7e170ef8/lilypond/part_II.ly +++ b/resources/piece_ledger/7e170ef8/lilypond/part_II.ly @@ -1,23 +1,23 @@ { - { c'1^\markup { \pad-markup #0.2 "+0"} ~ } + { d'1^\markup { \pad-markup #0.2 "+0"} ~ } \bar "|" - { c'1 ~ } + { d'1 ~ } \bar "|" - { c'1 ~ } + { d'1 ~ } \bar "|" - { c'1 ~ } + { d'1 ~ } \bar "|" - { c'2. ~ c'8.[ d'16^\markup { \pad-markup #0.2 "+31"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↓" }}] ~ } + { d'2. ~ d'8.[ e'16^\markup { \pad-markup #0.2 "+31"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↓" }}] ~ } \bar "|" - { d'1 ~ } + { e'1 ~ } \bar "|" - { d'1 ~ } + { e'1 ~ } \bar "|" - { d'1 ~ } + { e'1 ~ } \bar "|" - { d'1 ~ } + { e'1 ~ } \bar "|" - { d'8.[ r16] r2. } + { e'8.[ r16] r2. } \bar "|" { r1 } \bar "|" @@ -25,10 +25,12 @@ \bar "|" { r1 } \bar "|" - { r2. r16[ d'8.^\markup { \pad-markup #0.2 "+31"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↓" }}] ~ } + { r2. r16[ e'8.^\markup { \pad-markup #0.2 "+31"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↓" }}] ~ } \bar "|" - { d'1 ~ } + { e'1 ~ } + \bar "|" + { e'1 ~ } \bar "|" - { d'1} + { e'4 ~ e'8.[ r16] r2 } \bar "||" } \ No newline at end of file diff --git a/resources/piece_ledger/7e170ef8/lilypond/part_III.ly b/resources/piece_ledger/7e170ef8/lilypond/part_III.ly index c3f7109..e72209f 100644 --- a/resources/piece_ledger/7e170ef8/lilypond/part_III.ly +++ b/resources/piece_ledger/7e170ef8/lilypond/part_III.ly @@ -1,34 +1,36 @@ { - { r2. r8[ ais8^\markup { \pad-markup #0.2 "-31"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 7↑" }}] ~ } + { r2. r8[ c'8^\markup { \pad-markup #0.2 "-31"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 7↑" }}] ~ } \bar "|" - { ais1 ~ } + { c'1 ~ } \bar "|" - { ais4 ~ ais16[ g8.^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↑" }}] ~ g16[ gis8.^\markup { \pad-markup #0.2 "+41"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 13↑" }}] ~ gis4 ~ } + { c'4 ~ c'16[ a8.^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↑" }}] ~ a16[ ais8.^\markup { \pad-markup #0.2 "+41"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 13↑" }}] ~ ais4 ~ } \bar "|" - { gis8.[ gis16^\markup { \pad-markup #0.2 "+14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }}] ~ gis2. ~ } + { ais8.[ ais16^\markup { \pad-markup #0.2 "+14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }}] ~ ais2. ~ } \bar "|" - { gis2. ~ gis8.[ ais16^\markup { \pad-markup #0.2 "-31"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↑" }}] ~ } + { ais2. ~ ais8.[ c'16^\markup { \pad-markup #0.2 "-31"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↑" }}] ~ } \bar "|" - { ais1 ~ } + { c'1 ~ } \bar "|" - { ais2 ~ ais8.[ gis16^\markup { \pad-markup #0.2 "+41"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↑" }}] ~ gis4 ~ } + { c'2 ~ c'8.[ ais16^\markup { \pad-markup #0.2 "+41"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↑" }}] ~ ais4 ~ } \bar "|" - { gis2 ~ gis16[ gis8.^\markup { \pad-markup #0.2 "+14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↓" }}] ~ gis4 ~ } + { ais2 ~ ais16[ ais8.^\markup { \pad-markup #0.2 "+14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↓" }}] ~ ais4 ~ } + \bar "|" + { ais1 ~ } \bar "|" - { gis1 ~ } + { ais2. ~ ais8[ a8^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }}] ~ } \bar "|" - { gis2. ~ gis8[ g8^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }}] ~ } + { a4 ~ a8[ c'8^\markup { \pad-markup #0.2 "+45"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 7↓" }}] ~ c'4 ~ c'8.[ e'16^\markup { \pad-markup #0.2 "-35"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 11↑" }}] ~ } \bar "|" - { g4 ~ g8[ ais8^\markup { \pad-markup #0.2 "+45"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 7↓" }}] ~ ais4 ~ ais8.[ d'16^\markup { \pad-markup #0.2 "-35"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 11↑" }}] ~ } + { e'2. dis'4^\markup { \pad-markup #0.2 "+12"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↓" }} ~ } \bar "|" - { d'2. cis'4^\markup { \pad-markup #0.2 "+12"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↓" }} ~ } + { dis'2 ~ dis'8[ fis'8^\markup { \pad-markup #0.2 "-14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }}] ~ fis'4 ~ } \bar "|" - { cis'2 ~ cis'8[ e'8^\markup { \pad-markup #0.2 "-14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }}] ~ e'4 ~ } + { fis'8.[ g'16^\markup { \pad-markup #0.2 "-2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }}] ~ g'2. ~ } \bar "|" - { e'8.[ f'16^\markup { \pad-markup #0.2 "-2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }}] ~ f'2. ~ } + { g'1 ~ } \bar "|" - { f'1 ~ } + { g'1 ~ } \bar "|" - { f'1} + { g'4 ~ g'8.[ r16] r2 } \bar "||" } \ No newline at end of file diff --git a/resources/piece_ledger/7e170ef8/lilypond/part_IV.ly b/resources/piece_ledger/7e170ef8/lilypond/part_IV.ly index 1bf0348..4e63ca1 100644 --- a/resources/piece_ledger/7e170ef8/lilypond/part_IV.ly +++ b/resources/piece_ledger/7e170ef8/lilypond/part_IV.ly @@ -7,28 +7,30 @@ \bar "|" { r1 } \bar "|" - { r8[ c'8^\markup { \pad-markup #0.2 "+0"}] ~ c'2. ~ } + { r8[ d'8^\markup { \pad-markup #0.2 "+0"}] ~ d'2. ~ } \bar "|" - { c'1 ~ } + { d'1 ~ } \bar "|" - { c'1 ~ } + { d'1 ~ } \bar "|" - { c'1 ~ } + { d'1 ~ } \bar "|" - { c'1 ~ } + { d'1 ~ } \bar "|" - { c'1 ~ } + { d'1 ~ } \bar "|" - { c'1 ~ } + { d'1 ~ } \bar "|" - { c'1 ~ } + { d'1 ~ } \bar "|" - { c'1 ~ } + { d'1 ~ } \bar "|" - { c'1 ~ } + { d'1 ~ } \bar "|" - { c'1 ~ } + { d'1 ~ } \bar "|" - { c'1} + { d'1 ~ } + \bar "|" + { d'4 ~ d'8.[ r16] r2 } \bar "||" } \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/piece_ledger_pas.json b/resources/resources_bak_2024_01_03/piece_ledger_pas.json deleted file mode 100644 index f04a134..0000000 --- a/resources/resources_bak_2024_01_03/piece_ledger_pas.json +++ /dev/null @@ -1,27 +0,0 @@ -{ -"ledger": -[ - "314s49e1", - "7e170ef8", - "7ac10d34", - "628d5c8b", - "6abf27d4", - "6d743c5c", - "5625a95a", - "5267b235", - "6a3f7c7c", - "6d0c2f19", - "7bf874ce", - "50fec831", - "7fd4d544", - "6f1305ed", - "7c7a96a2", - "7c8bc6df", - "46210507", - "74faf83f", - "703e109b", - "4b96f62d", - "449aeaa6", - "6409252e" -] -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/piece_ledger_pas.json_bak b/resources/resources_bak_2024_01_03/piece_ledger_pas.json_bak deleted file mode 100644 index f69bd2d..0000000 --- a/resources/resources_bak_2024_01_03/piece_ledger_pas.json_bak +++ /dev/null @@ -1,26 +0,0 @@ -{ -"ledger": -[ - "314s49e1", - "7e170ef8", - "7ac10d34", - "628d5c8b", - "6abf27d4", - "6d743c5c", - "5625a95a", - "5267b235", - "6a3f7c7c", - "6d0c2f19", - "7bf874ce", - "50fec831", - "7fd4d544", - "6f1305ed", - "7c7a96a2", - "7c8bc6df", - "46210507", - "74faf83f", - "703e109b", - "4b96f62d", - "449aeaa6" -] -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/piece_ledger_pas/314s49e1/314s49e1_code.scd b/resources/resources_bak_2024_01_03/piece_ledger_pas/314s49e1/314s49e1_code.scd deleted file mode 100644 index 2d77a32..0000000 --- a/resources/resources_bak_2024_01_03/piece_ledger_pas/314s49e1/314s49e1_code.scd +++ /dev/null @@ -1,581 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrder, genSubMotif, updateVoices; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var writeResources, prettifyArray, setSeeds, sanityCheck, msgInterpret; - -// global vars (many set by OSC funcs at bottom) -var refSeed, seed, lastXChanges, popSize, exPath, dir, primes, dims, tuples, ranges, durFunc, seq, group, player; - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - pDistance.gaussCurve(1, mean, sd) -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genOrder = {arg minLength = 0, maxLength = 5; - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noProgIns = (popSize - 1).rand + 1; - noSusIns = (popSize - noProgIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxLength - minLength).rand + minLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = 1/pow(hdSum.value(voices.deepCopy.put(ins, candidate)), 2); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = [1, 1, 1, 1, 1]; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, res, lastIns, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - lastIns = nil; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - (silent ++ sus ++ prog).do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - //dur = [durFunc.value(), 0].wchoose([1, 0].normalizeSum); - dur = durFunc.value(lastIns, ins); - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur.round(0.125)]); - }); - - lastIns = ins; - }); - - // pad ending - if(isLastOrder, { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - //dur = [durFunc.value(), 0].wchoose([1, 0].normalizeSum); - dur = durFunc.value(lastIns, ins); - res = res.add([voices.deepCopy.postln, dur.round(0.125)]); - }); - lastIns = ins; - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold}); - res; -}; - - -//------primary routines - -genMotif = {arg inOrders; - var orders, repeats, fSeq; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - orders = inOrders; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -genPatterns = {arg seq; - var voices, durs, patterns, res; - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice; - var clumps, hdScores, freqs, fDurs; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \instrument, \test, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1) - ); - }); - ); - res -}; - -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; - - -//------resource management funcs - -setSeeds = {arg inRefSeed, inSeed; - refSeed = if(inRefSeed.isNumber, {inRefSeed.asInteger}, {nil}); - seed = if(inSeed > 1, {inSeed.asInteger}, {rrand(100000, 999999)}); - thisThread.randSeed = seed; -}; - -prettifyArray = {arg data, finDepth = 1; - var prettyString = "", rCount = 0, writeArray; - - writeArray = {arg array; - var depth, indent; - depth = array.maxDepth; - indent = rCount.collect({" "}).join(""); - prettyString = prettyString ++ indent ++ "[\n"; - rCount = rCount + 1; - if(depth > 5, { - array.do({arg subArray; - writeArray.value(subArray); - }); - }, { - array.do({arg data, d; - prettyString = prettyString ++ indent ++ " " ++ data.asCompileString ++ if(d != (array.size - 1), {",\n"}, {""}); - }); - }); - rCount = rCount - 1; - if(rCount < (finDepth - 1), {prettyString = prettyString.drop((finDepth - 1).neg)}); - //if(rCount == 0, {prettyString = prettyString.drop((finDepth - 1).neg)}); - prettyString = prettyString ++ "\n" ++ indent ++ "]" ++ if(rCount > 0, {",\n"}, {""}); - }; - - writeArray.value(data); - prettyString -}; - -writeResources = {arg seq, path; - var dir, file, resString; - file = File(path,"w"); - - resString = "{\nmusic_data:\n"; - resString = resString ++ prettifyArray.value(seq, 3); - - resString = resString ++ ",\nlast_changes:\n"; - resString = resString ++ prettifyArray.value(lastXChanges, 1); - - resString = resString ++ ",\nseed: " ++ seed ++ ",\nref_seed: " ++ refSeed ++ "\n}"; - - file.write(resString); - file.close; -}; - -sanityCheck = {arg motif, index; - //print functions - very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in; - var res; - res = in.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - res = res.replace("\'", "").replace("\"", "").replace("Rest", "\"Rest\""); - res.interpret -}; - - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -refSeed = nil; -group = Group.new; - - -//------OSC funcs - -OSCdef(\gen, {arg msg, time, addr, port; - var orders, condition; - msg.postln; - durFunc = nil; - - addr.sendMsg("/STATE/SEND"); - - { - while({durFunc == nil}, {0.1.wait}); - setSeeds.value(msg[1].postln, msg[2]); - - lastXChanges = if(refSeed == nil, { - [initVoices.value().deepCopy]; - }, { - var file; - file = File((dir +/+ "resources" +/+ refSeed ++ "_music" ++ ".json").standardizePath, "r"); - msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - if(msg.size == 4, { - orders = msgInterpret.value(msg[3]); - }, { - var minLength, maxLength; - minLength = msg[3]; - maxLength = msg[4]; - orders = ((maxLength - minLength).rand + minLength).collect({genOrder.value(msg[5], msg[6])}); - }); - - orders.postln; - seed.postln; - refSeed.postln; - - seq = genMotif.value(orders); - //patterns = genPatterns.value(seq); - addr.sendMsg("/current_seed", seed); - addr.sendMsg("/order", prettifyArray.value(orders, 1)); - addr.sendMsg("/mus_seq", prettifyArray.value(seq, 3)); - }.fork; - -}, \gen); - -OSCdef(\commit, {arg msg, time, addr, port; - var ledgerPath, oldLedger, newLedger, musSeq; - //msg.postln; - seed.postln; - //File.copy(exPath, (dir +/+ "resources" +/+ seed ++ "_code" ++ ".scd").standardizePath); - //addr.sendMsg("/SESSION/SAVE", (dir +/+ "resources" +/+ seed ++ "_gui_session" ++ ".json").standardizePath); - //addr.sendMsg("/STATE/SAVE", (dir +/+ "resources" +/+ seed ++ "_gui_state" ++ ".state").standardizePath); - - writeResources.value(seq, (dir +/+ "resources" +/+ seed ++ "_music" ++ ".json").standardizePath); - - ledgerPath = (dir +/+ "resources" +/+ "piece_ledger" ++ ".json").standardizePath; - oldLedger = File(ledgerPath, "r"); - musSeq = msgInterpret.value(oldLedger.readAllString.parseJSON["ledger"]); - oldLedger.close; - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - newLedger = File(ledgerPath, "w"); - musSeq = musSeq.add(seed); - newLedger.write("{\nledger:\n" ++ prettifyArray.value(musSeq, 1) ++ "\n}"); - newLedger.close; - - //refSeed = seed; -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - player.stop; - group.set(\gate, 0); - }, { - var cSize, ledgerPath, ledger, patterns, pSeq; - ledgerPath = (dir +/+ "resources" +/+ "piece_ledger" ++ ".json").standardizePath; - ledger = msgInterpret.value(File(ledgerPath, "r").readAllString.parseJSON["ledger"]); - pSeq = []; - if(msg[2].asString != "all", {ledger = ledger.keep(msg[2].asInteger - 1)}); - ledger.do({arg rSeed; - var file; - file = File((dir +/+ "resources" +/+ rSeed.postln ++ "_music" ++ ".json").standardizePath, "r"); - pSeq = pSeq.add(msgInterpret.value(file.readAllString.parseJSON["music_data"])); - file.close; - }); - pSeq = pSeq.add(seq); - patterns = genPatterns.value(pSeq); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - }); - player = player.play - }); -}, \transport); - -OSCdef(\range, {arg msg; - msg.postln; - ranges[msg[1]][msg[2]] = msg[3] -}, \range); - -OSCdef(\dur_probs_env, {arg msg; - var env, pTable, min, max, cProb; - msg.postln; - env = Env.pairs([[0, 0]] ++ msg[4..].clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - min = msg[1]; - max = msg[2]; - cProb = msg[3]; - durFunc = {arg lIns, cIns; - if(lIns.postln == cIns.postln, { - pTable.tableRand * (max - min) + min - }, { - if(1.0.rand < cProb.postln, {0}, {pTable.tableRand * (max - min) + min}).postln; - }); - }; -}, \dur_probs_env); -) - -( -SynthDef(\test, {arg freq, gate = 1, sustain, amp, dur; - var trig, exc, sig1, sig2, noHarms; - noHarms = 30; - exc = Saw.ar(freq, TRand.ar(0.5, 1, Impulse.ar(freq))) * 0.001 + Dust.ar(10000, 0.01); - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(1, 2)}) ], exc) * 0.5).softclip; - sig1 = HPF.ar(sig1, 300); - Out.ar([0, 1], sig1 * EnvGen.kr(Env.adsr(0.3, 0.3, 0.9, 0.5, 0.9), gate, doneAction: 2)); -}).add; -) - -( -SynthDef(\test, {arg freq, gate = 1, sustain, amp, dur; - var trig, exc, sig1, sig2, noHarms, freqFinal, start, end; - noHarms = 30; - freq = WhiteNoise.ar * 3 + freq; - freqFinal = Duty.ar((1/freq), 0, freq); - trig = Changed.ar(freqFinal); - start = Demand.ar(trig, 0, Dwhite(-1, -0.75)); - end = Demand.ar(trig, 0, Dwhite(0.75, 1)); - exc = Phasor.ar(trig, (end - start) * freqFinal / SampleRate.ir, start, end, 0) * 0.001 + Dust.ar(10000, 0.01); - - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(2, 3)}) ], exc) * 0.5).softclip; - sig1 = HPF.ar(sig1, 300); - Out.ar([0, 1], sig1 * EnvGen.kr(Env.adsr(0.3, 0.3, 0.9, 0.5, 0.9), gate, doneAction: 2)); -}).add; -) - - -File((~dir +/+ "resources" +/+ 517313 ++ "_music" ++ ".json").standardizePath, "r").readAllString.parseJSON["last_changes"].asString.interpret[0][0][0].isNumber - -"{\"a\": 1}".parseYAML["a"].asInteger; -"{\"a\": 1}".parseJSON["a"].isNumber; \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/piece_ledger_pas/314s49e1/314s49e1_mus_model.json b/resources/resources_bak_2024_01_03/piece_ledger_pas/314s49e1/314s49e1_mus_model.json deleted file mode 100644 index c78a753..0000000 --- a/resources/resources_bak_2024_01_03/piece_ledger_pas/314s49e1/314s49e1_mus_model.json +++ /dev/null @@ -1,74 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 0.875 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ] ], 0.625 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ] ], 1.5 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ] ], 0.875 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ] ], 0.875 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ] ], 1.0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 1, 0, 0 ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ] ], 1.0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ] ], 1.25 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 1 ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ] ], 0.875 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, -1, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ] ], 0.875 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ] ], 1.25 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ] ], 0.75 ] - ], - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ] ], 0.875 ], - [ [ [ 1, 0, 0, 0, 0, -1 ], [ "Rest" ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ] ], 1.5 ], - [ [ [ 1, 0, 0, 0, 0, -1 ], [ "Rest" ], [ -1, 0, 0, 1, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 1.25 ], - [ [ [ 0, 1, 0, 0, 0, 0 ], [ "Rest" ], [ -1, 0, 0, 1, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 1.375 ], - [ [ [ 0, 0, 0, 1, 0, 0 ], [ "Rest" ], [ -1, 0, 0, 1, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 0.75 ], - [ [ [ 0, 0, 0, 1, 0, 0 ], [ "Rest" ], [ 0, 0, -1, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 0.625 ], - [ [ [ 0, 0, 0, 1, 0, 0 ], [ "Rest" ], [ 0, 0, 0, 0, -1, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 0.75 ], - [ [ [ 0, 0, 0, 0, 0, 1 ], [ "Rest" ], [ 0, 0, 0, 0, -1, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 1.125 ], - [ [ [ 1, 0, -1, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 0, 0, -1, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 1.25 ], - [ [ [ 0, 1, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 0, 0, -1, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 1.0 ], - [ [ [ 1, -1, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 0, 0, -1, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 0.875 ] - ], - [ - [ [ [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, -1, 0, -1, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 0.875 ], - [ [ [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, -1, 0, -1, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ] ], 0.75 ], - [ [ [ 0, 0, 0, 1, -1, 0 ], [ 1, 0, -1, 0, -1, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ] ], 1.5 ], - [ [ [ 0, 0, 0, 1, -1, 0 ], [ 0, 0, 0, 0, -1, 1 ], [ 0, 0, 0, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ] ], 1.25 ], - [ [ [ 0, 0, 0, 1, -1, 0 ], [ 0, 1, 0, 0, -1, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ] ], 0.625 ], - [ [ [ 1, 0, 0, 0, -1, 0 ], [ 0, 1, 0, 0, -1, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ] ], 0.625 ], - [ [ [ 1, 0, 0, 0, -1, 0 ], [ 0, 1, 0, 0, -1, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 0, 0, 1, 0, -1, 0 ] ], 0.625 ], - [ [ [ 1, 0, 0, 0, -1, 0 ], [ 0, 1, 0, 0, -1, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 1, 0, 0, -1, -1, 0 ] ], 1.375 ], - [ [ [ 1, 0, 0, 0, -1, 0 ], [ 0, 0, 1, 0, -1, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 1, 0, 0, -1, -1, 0 ] ], 1.375 ], - [ [ [ 2, 0, 0, -1, -1, 0 ], [ 0, 0, 1, 0, -1, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 1, 0, 0, -1, -1, 0 ] ], 1.5 ], - [ [ [ 2, 0, 0, 0, -1, -1 ], [ 0, 0, 1, 0, -1, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 1, 0, 0, -1, -1, 0 ] ], 0.75 ], - [ [ [ 2, 0, 0, 0, -1, -1 ], [ 1, -1, 0, 0, -1, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 1, 0, 0, -1, -1, 0 ] ], 1.0 ] - ], - [ - [ [ [ 2, 0, 0, 0, -1, -1 ], [ 1, -1, 0, 0, -1, 0 ], [ "Rest" ], [ 1, 0, 0, -1, -1, 0 ] ], 0.75 ], - [ [ [ 2, 0, 0, 0, -1, -1 ], [ 1, -1, 0, 0, -1, 0 ], [ "Rest" ], [ 0, -1, 0, 1, -1, 0 ] ], 1.0 ], - [ [ [ 2, -1, 0, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ], [ "Rest" ], [ 0, -1, 0, 1, -1, 0 ] ], 0.875 ], - [ [ [ 2, -1, 0, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ], [ "Rest" ], [ 0, -1, 0, 0, -1, 1 ] ], 1.25 ], - [ [ [ 1, -1, 0, 1, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ], [ "Rest" ], [ 0, -1, 0, 0, -1, 1 ] ], 1.125 ], - [ [ [ 1, -1, 0, 1, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ], [ "Rest" ], [ 1, -1, -1, 0, -1, 0 ] ], 1.0 ], - [ [ [ 1, 0, 0, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ], [ "Rest" ], [ 1, -1, -1, 0, -1, 0 ] ], 0.75 ], - [ [ [ 1, -1, 0, 0, 0, 0 ], [ 1, -1, 0, 0, -1, 0 ], [ "Rest" ], [ 1, -1, -1, 0, -1, 0 ] ], 0.625 ], - [ [ [ 1, -1, 0, 0, 0, 0 ], [ 1, -1, 0, 0, -1, 0 ], [ "Rest" ], [ 0, -1, 0, 0, 0, 0 ] ], 0.75 ], - [ [ [ 1, -1, 0, 0, 0, 0 ], [ 1, -1, 0, 0, -1, 0 ], [ "Rest" ], [ 1, -1, 0, 0, -2, 0 ] ], 1.375 ], - [ [ [ 2, -2, 0, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ], [ "Rest" ], [ 1, -1, 0, 0, -2, 0 ] ], 0.875 ], - [ [ [ 2, -2, 0, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ], [ "Rest" ], [ 0, -1, 0, 0, -1, 1 ] ], 3.375 ], - [ [ [ 2, -2, 0, 0, -1, 0 ], [ "Rest" ], [ "Rest" ], [ 0, -1, 0, 0, -1, 1 ] ], 1.5 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ 0, -1, 0, 0, -1, 1 ] ], 1.375 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 1.0 ] - ] - ] -], -"last_changes": -[ - [ [ 1, -1, 0, 0, 0, 0 ], [ 1, -1, 0, 0, -1, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 1, -1, -1, 0, -1, 0 ] ], - [ [ 1, -1, 0, 0, 0, 0 ], [ 1, -1, 0, 0, -1, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 0, -1, 0, 0, 0, 0 ] ], - [ [ 1, -1, 0, 0, 0, 0 ], [ 1, -1, 0, 0, -1, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 1, -1, 0, 0, -2, 0 ] ], - [ [ 2, -2, 0, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 1, -1, 0, 0, -2, 0 ] ], - [ [ 2, -2, 0, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 0, -1, 0, 0, -1, 1 ] ] -], -"ref_uid": "nil" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/piece_ledger_pas/449aeaa6/449aeaa6_code.scd b/resources/resources_bak_2024_01_03/piece_ledger_pas/449aeaa6/449aeaa6_code.scd deleted file mode 100644 index 3ec9b1a..0000000 --- a/resources/resources_bak_2024_01_03/piece_ledger_pas/449aeaa6/449aeaa6_code.scd +++ /dev/null @@ -1,907 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - pDistance.gaussCurve(1, mean, sd) -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = 1/pow(hdSum.value(voices.deepCopy.put(ins, candidate)), 2); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~msg.postln; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1, 3)}, {rrand(0.3, 0.5)}); - }); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - //res.postln; - if(res.every({arg char; char.isDecDigit}), {res = res.asInteger}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file; - file = File(path, "w"); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "passages_weights", "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((dir +/+ ".." +/+ "resources" +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - - curUID = genUID.value; - - File.mkdir((dir +/+ ".." +/+ "resources" +/+ curUID).standardizePath); - File.copy(exPath, (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - ledger = ledger.drop(-1).add(curUID); - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (dir +/+ ".." +/+ "resources" +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - -) - -( -//synthdefs -~stringModelBusArray = 4.collect({Bus.audio(s, 1)}); -~sineBusArray = 4.collect({Bus.audio(s, 1)}); -~bassBusArray = 1.collect({Bus.audio(s, 1)}); -~hdustBusArray = 1.collect({Bus.audio(s, 1)}); -~samplerBusArray = 2.collect({Bus.audio(s, 1)}); -~sBuf = Buffer.alloc(s, 10, 2); -SynthDef(\string_model, {arg freq, gate = 1, sustain, amp, dur, attack, release = 1, busIndex = 0; - var trig, exc, sig1, sig2, noHarms; - noHarms = rrand(20, 40); - exc = Saw.ar(freq, TRand.ar(0.5, 1, Impulse.ar(freq))) * 0.001 + Dust.ar(10000, 0.01); - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(1, 2)}) ], exc) * 0.8).softclip; - //sig1 = HPF.ar(sig1, 300); - Out.ar(Select.kr(busIndex, ~stringModelBusArray), sig1 * amp * EnvGen.kr(Env.adsr(attack, 0.3, 0.9, release, 0.9, -3), gate, doneAction: 2)); - //Out.ar([0, 1], sig1 * EnvGen.kr(Env.asr(dur, 0.3, 1), gate, doneAction: 2)); -}).add; - -SynthDef(\sine, {arg freq, gate = 1, sustain, amp, dur, busIndex = 0; - var sig; - sig = SinOsc.ar(freq); - Out.ar(Select.kr(busIndex, ~sineBusArray), sig * EnvGen.kr(Env.asr(0.3, 0.4, 0.3), gate, timeScale: dur, doneAction: 2)); - //Out.ar(Select.kr(busIndex, ~sineBusArray), sig * EnvGen.kr(Env.sine(dur), gate, doneAction: 2)); -}).add; - -SynthDef(\mixer, {arg freq, gate = 1, sustain, amp, dur, out; - var nameSpaces, sigs, hierarchicalDust; - - hierarchicalDust = ( - TIRand.kr(0, 1, Impulse.kr(100)) * - TIRand.kr(0, 1, Impulse.kr(10)) * - TIRand.kr(0, 1, Impulse.kr(1)) - ); - - sigs = [~stringModelBusArray, ~sineBusArray, ~bassBusArray, ~hdustBusArray, ~samplerBusArray].collect({arg busArray, i; - var nameSpace, sig; - nameSpace = ['string', 'sine', 'bass', 'hdust', 'sampler'][i]; - sig = busArray.collect({arg bus, c; In.ar(bus, 1) * NamedControl.kr(\ ++ nameSpace ++ '_volume_' ++ c, 1, 0.1)}); - sig = sig.collect({arg channel, c; Pan2.ar(channel, NamedControl.kr(\ ++ nameSpace ++ '_pan_' ++ c, i / (busArray.size - 1), 0.1) * 2 - 1)}); - sig = sig.collect({arg channel, c; channel * NamedControl.kr(\ ++ nameSpace ++ '_mute_' ++ c, 1, 0.1)}); - sig = Mix.ar(sig) * pow(NamedControl.kr(\ ++ nameSpace ++ '_volume_master', 1, 0.1), 2); - }); - - sigs = Mix.ar(sigs / 4); - Out.ar(0, sigs) -}).add; - -SynthDef(\bass, { - var switches, drone; - switches = {|i| Dust.kr(0.1)} ! 9; - drone = {|i| var harm = pow(2, 2 - (i / 3).trunc), amp = (1 / pow(harm, 2)); - SinOsc.ar(60 * harm + TRand.kr(-3, 3, switches[i]), 0, amp)} ! 9; - Out.ar(~bassBusArray[0], Mix.new(drone) * 0.2); -}).add; - -SynthDef(\sampler, { - Out.ar(~samplerBusArray, PlayBuf.ar(2, ~sBuf, BufRateScale.kr(~sBuf), doneAction: 2)) -}).add; - -// main routine -SynthDef(\hdust, { - arg gate = 0; - var hierarchical_dust, low_sine, high_sine, brown_noise, white_noise; - // this triggers the combinations of sources - // it is similar to the Supercollider UGen called dust but with a hierarchical structure - hierarchical_dust = ( - TIRand.kr(0, 1, Impulse.kr(100)) * - TIRand.kr(0, 1, Impulse.kr(10)) * - TIRand.kr(0, 1, Impulse.kr(1)) * - TIRand.kr(0, 1, Impulse.kr(0.1)) - ); - // adjust the multiplier at the end of each line for adjusting levels - // note with each trigger, each source has a 1 in 3 chance of sounding - low_sine = SinOsc.ar(76.midicps / 16) * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.1; - high_sine = SinOsc.ar(76.midicps * 8) * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.01; - brown_noise = BrownNoise.ar() * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.025; - white_noise = WhiteNoise.ar() * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.02; - Out.ar(~hdustBusArray[0], - ((low_sine + high_sine + brown_noise + white_noise) ) - ); -}).add; - -) - -( -var bass, hdust, sampler, mixer; -bass = Synth.tail(~group, \bass); -hdust = Synth.tail(~group, \hdust); -sampler = Synth.head(~group, \sampler); -mixer = Synth.tail(~group, \mixer); -OSCdef(\mixer, {arg msg, time, addr, port; - mixer.set((msg[1] ++ '_' ++ msg[2] ++ '_' ++ msg[3]), msg[4]) -}, \mixer); - -OSCdef(\sampler, {arg msg, time, addr, port; - msg.postln; - sampler.free; - ~sBuf.free; - ~sBuf = Buffer.read(s, msg[1].asString.postln, action: {sampler = Synth.head(~group, \sampler)}); -}, \sampler); -) - -/* old something -( -SynthDef(\test, {arg freq, gate = 1, sustain, amp, dur; - var trig, exc, sig1, sig2, noHarms, freqFinal, start, end; - noHarms = 30; - freq = WhiteNoise.ar * 3 + freq; - freqFinal = Duty.ar((1/freq), 0, freq); - trig = Changed.ar(freqFinal); - start = Demand.ar(trig, 0, Dwhite(-1, -0.75)); - end = Demand.ar(trig, 0, Dwhite(0.75, 1)); - exc = Phasor.ar(trig, (end - start) * freqFinal / SampleRate.ir, start, end, 0) * 0.001 + Dust.ar(10000, 0.01); - - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(2, 3)}) ], exc) * 0.5).softclip; - sig1 = HPF.ar(sig1, 300); - Out.ar([0, 1], sig1 * EnvGen.kr(Env.adsr(0.3, 0.3, 0.9, 0.5, 0.9), gate, doneAction: 2)); -}).add; -) -*/ - diff --git a/resources/resources_bak_2024_01_03/piece_ledger_pas/449aeaa6/449aeaa6_mus_model.json b/resources/resources_bak_2024_01_03/piece_ledger_pas/449aeaa6/449aeaa6_mus_model.json deleted file mode 100644 index dde9e73..0000000 --- a/resources/resources_bak_2024_01_03/piece_ledger_pas/449aeaa6/449aeaa6_mus_model.json +++ /dev/null @@ -1,83 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ "Rest" ], [ 0, 1, 0, 0, 0, -1 ], [ "Rest" ] ], 4 ], - [ [ [ "Rest" ], [ 0, 1, 0, 1, 0, -1 ], [ 0, 1, 0, 0, 0, -1 ], [ "Rest" ] ], 2 ], - [ [ [ "Rest" ], [ 0, 1, 0, 1, 0, -1 ], [ 0, 1, 0, 0, 0, -1 ], [ 1, 1, 0, 0, -1, -1 ] ], 1.875 ], - [ [ [ -1, 1, 0, 1, 0, -1 ], [ 0, 1, 0, 1, 0, -1 ], [ 0, 1, 0, 0, 0, -1 ], [ 1, 1, 0, 0, -1, -1 ] ], 1.625 ], - [ [ [ -1, 1, 0, 1, 0, -1 ], [ 0, 1, 0, 1, 0, -1 ], [ 0, 1, 0, 0, 0, -1 ], [ 0, 2, 0, 0, 0, -1 ] ], 1.75 ], - [ [ [ -1, 2, 0, 0, 0, -1 ], [ 0, 1, 0, 1, 0, -1 ], [ 0, 1, 0, 0, 0, -1 ], [ 0, 2, 0, 0, 0, -1 ] ], 1.875 ], - [ [ [ -1, 1, 0, 0, 0, 0 ], [ 0, 1, 0, 1, 0, -1 ], [ 0, 1, 0, 0, 0, -1 ], [ 0, 2, 0, 0, 0, -1 ] ], 0 ], - [ [ [ -1, 1, 0, 0, 0, 0 ], [ 1, 1, 0, 0, 0, -1 ], [ 0, 1, 0, 0, 0, -1 ], [ 0, 2, 0, 0, 0, -1 ] ], 2 ], - [ [ [ -1, 1, 0, 0, 0, 0 ], [ 2, 1, 0, -1, 0, -1 ], [ 0, 1, 0, 0, 0, -1 ], [ 0, 2, 0, 0, 0, -1 ] ], 1.375 ], - [ [ [ 0, 1, -1, 0, 0, -1 ], [ 2, 1, 0, -1, 0, -1 ], [ 0, 1, 0, 0, 0, -1 ], [ 0, 2, 0, 0, 0, -1 ] ], 1 ], - [ [ [ 0, 1, -1, 0, 0, -1 ], [ 2, 1, 0, 0, 0, -2 ], [ 0, 1, 0, 0, 0, -1 ], [ 0, 2, 0, 0, 0, -1 ] ], 7.375 ] - ], - [ - [ [ [ -1, 2, 0, 0, 0, -1 ], [ 2, 1, 0, 0, 0, -2 ], [ 0, 1, 0, 0, 0, -1 ], [ 0, 2, 0, 0, 0, -1 ] ], 0 ], - [ [ [ -1, 2, 0, 0, 0, -1 ], [ 2, 1, 0, 0, 0, -2 ], [ 0, 1, 0, 0, 0, -1 ], [ 1, 0, 0, 0, 0, -1 ] ], 0 ], - [ [ [ -1, 2, 0, 0, 0, -1 ], [ 2, 0, 0, 0, 0, -1 ], [ 0, 1, 0, 0, 0, -1 ], [ 1, 0, 0, 0, 0, -1 ] ], 5.375 ] - ], - [ - [ [ [ -1, 2, 0, 0, 0, -1 ], [ "Rest" ], [ 0, 1, 0, 0, 0, -1 ], [ 1, 0, 0, 0, 0, -1 ] ], 0 ], - [ [ [ -1, 2, 0, 0, 0, -1 ], [ "Rest" ], [ 0, 1, 0, 0, 0, -1 ], [ "Rest" ] ], 2 ], - [ [ [ -1, 2, 0, 0, 0, -1 ], [ "Rest" ], [ -1, 2, 1, 0, 0, -1 ], [ "Rest" ] ], 1.25 ], - [ [ [ -1, 2, 0, 0, 0, -1 ], [ "Rest" ], [ -1, 2, 0, 0, 1, -1 ], [ "Rest" ] ], 1.875 ], - [ [ [ -1, 2, 0, 0, 0, -1 ], [ "Rest" ], [ 0, 2, 0, 0, -1, -1 ], [ "Rest" ] ], 1.25 ], - [ [ [ -1, 2, 0, 0, 0, -1 ], [ "Rest" ], [ -1, 3, 0, 0, 0, -1 ], [ "Rest" ] ], 1.375 ], - [ [ [ -1, 2, 0, 0, 0, -1 ], [ "Rest" ], [ 0, 2, -1, 0, 0, -1 ], [ "Rest" ] ], 8.375 ] - ], - [ - [ [ [ -1, 2, 0, 0, 0, -1 ], [ 2, 2, -1, 0, 0, -2 ], [ 0, 2, -1, 0, 0, -1 ], [ "Rest" ] ], 1.75 ], - [ [ [ -1, 2, 0, 0, 0, -1 ], [ 2, 2, -1, 0, 0, -2 ], [ 0, 2, -1, 0, 0, -1 ], [ 1, 2, -1, 0, 0, -2 ] ], 0 ], - [ [ [ -1, 2, -1, 0, 1, -1 ], [ 2, 2, -1, 0, 0, -2 ], [ 0, 2, -1, 0, 0, -1 ], [ 1, 2, -1, 0, 0, -2 ] ], 2 ], - [ [ [ 0, 2, -1, 0, 0, -2 ], [ 2, 2, -1, 0, 0, -2 ], [ 0, 2, -1, 0, 0, -1 ], [ 1, 2, -1, 0, 0, -2 ] ], 1.5 ], - [ [ [ 0, 2, -1, 0, 0, -2 ], [ 2, 2, -1, -1, 0, -1 ], [ 0, 2, -1, 0, 0, -1 ], [ 1, 2, -1, 0, 0, -2 ] ], 7 ] - ], - [ - [ [ [ 0, 2, -1, 0, 0, -2 ], [ "Rest" ], [ 0, 2, -1, 0, 0, -1 ], [ 1, 2, -1, 0, 0, -2 ] ], 1.5 ], - [ [ [ 0, 2, -1, 0, 0, -2 ], [ "Rest" ], [ 0, 2, -1, 0, 0, -1 ], [ "Rest" ] ], 1.25 ], - [ [ [ 0, 2, -1, -1, 0, -1 ], [ "Rest" ], [ 0, 2, -1, 0, 0, -1 ], [ "Rest" ] ], 1.875 ], - [ [ [ -1, 2, -1, 0, 0, -1 ], [ "Rest" ], [ 0, 2, -1, 0, 0, -1 ], [ "Rest" ] ], 1.5 ], - [ [ [ -2, 2, -1, 0, 0, 0 ], [ "Rest" ], [ 0, 2, -1, 0, 0, -1 ], [ "Rest" ] ], 1 ], - [ [ [ -1, 2, -2, 0, 0, -1 ], [ "Rest" ], [ 0, 2, -1, 0, 0, -1 ], [ "Rest" ] ], 1.375 ], - [ [ [ -2, 2, -1, 1, 0, -1 ], [ "Rest" ], [ 0, 2, -1, 0, 0, -1 ], [ "Rest" ] ], 6.75 ], - [ [ [ "Rest" ], [ "Rest" ], [ 0, 2, -1, 0, 0, -1 ], [ "Rest" ] ], 1.125 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 7.5 ] - ] - ] -], -"last_changes": -[ - [ [ 0, 2, -1, -1, 0, -1 ], [ 2, 2, -1, -1, 0, -1 ], [ 0, 2, -1, 0, 0, -1 ], [ 1, 2, -1, 0, 0, -2 ] ], - [ [ -1, 2, -1, 0, 0, -1 ], [ 2, 2, -1, -1, 0, -1 ], [ 0, 2, -1, 0, 0, -1 ], [ 1, 2, -1, 0, 0, -2 ] ], - [ [ -2, 2, -1, 0, 0, 0 ], [ 2, 2, -1, -1, 0, -1 ], [ 0, 2, -1, 0, 0, -1 ], [ 1, 2, -1, 0, 0, -2 ] ], - [ [ -1, 2, -2, 0, 0, -1 ], [ 2, 2, -1, -1, 0, -1 ], [ 0, 2, -1, 0, 0, -1 ], [ 1, 2, -1, 0, 0, -2 ] ], - [ [ -2, 2, -1, 1, 0, -1 ], [ 2, 2, -1, -1, 0, -1 ], [ 0, 2, -1, 0, 0, -1 ], [ 1, 2, -1, 0, 0, -2 ] ] -], -"cur_uid": "449aeaa6", -"ref_uid": "628d5c8b", -"order_seed": 338959, -"dur_seed": 810921, -"motifs_seed": 154723, -"entrances_probs_vals": [ 0.29, 0, 7.0238095238095, 0.77, 2.1703296703297, 0.20725388601036, 0.68581081081081, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"passages_probs_vals": [ 0.29, 0, 7.0238095238095, 0.77, 2.1703296703297, 0.20725388601036, 0.68581081081081, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"exits_probs_vals": [ 0.29, 0, 7.0238095238095, 0.77, 2.1703296703297, 0.20725388601036, 0.68581081081081, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"ranges": [ [ -3600, -349 ], [ 799, 1758 ], [ -282, 1013 ], [ -282, 799 ] ], -"passages_weights": [ 0.75, 0.75, 0.75, 0.75, 0.75 ], -"order": -[ - [ [ 2 ], [ 1, 3, 0, 3, 0, 0, 1, 1, 0, 1 ], [ ] ], - [ [ 2 ], [ 0, 3, 1 ], [ ] ], - [ [ 0 ], [ 2, 2, 2, 2, 2 ], [ 1, 3 ] ], - [ [ 2 ], [ 1, 3, 0, 0, 1 ], [ ] ], - [ [ 2 ], [ 0, 0, 0, 0, 0 ], [ 1, 3 ] ] -], -"sus_weights": [ 0.75, 0.34, 0 ], -"order_size": [ 2, 6 ], -"passages_size": [ 0, 10 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/piece_ledger_pas/46210507/46210507_code.scd b/resources/resources_bak_2024_01_03/piece_ledger_pas/46210507/46210507_code.scd deleted file mode 100644 index a4e8b56..0000000 --- a/resources/resources_bak_2024_01_03/piece_ledger_pas/46210507/46210507_code.scd +++ /dev/null @@ -1,907 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - pDistance.gaussCurve(1, mean, sd) -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = 1/pow(hdSum.value(voices.deepCopy.put(ins, candidate)), 2); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~msg.postln; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1, 3)}, {rrand(0.3, 0.5)}); - }); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - //res.postln; - if(res.every({arg char; char.isDecDigit}), {res = res.asInteger}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file; - file = File(path, "w"); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "passages_weights", "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((dir +/+ ".." +/+ "resources" +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - - curUID = genUID.value; - - File.mkdir((dir +/+ ".." +/+ "resources" +/+ curUID).standardizePath); - File.copy(exPath, (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - ledger = ledger.drop(-1).add(curUID); - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (dir +/+ ".." +/+ "resources" +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - -) - -( -//synthdefs -~stringModelBusArray = 4.collect({Bus.audio(s, 1)}); -~sineBusArray = 4.collect({Bus.audio(s, 1)}); -~bassBusArray = 1.collect({Bus.audio(s, 1)}); -~hdustBusArray = 1.collect({Bus.audio(s, 1)}); -~samplerBusArray = 2.collect({Bus.audio(s, 1)}); -~sBuf = Buffer.alloc(s, 10, 2); -SynthDef(\string_model, {arg freq, gate = 1, sustain, amp, dur, attack, release = 1, busIndex = 0; - var trig, exc, sig1, sig2, noHarms; - noHarms = 30; - exc = Saw.ar(freq, TRand.ar(0.5, 1, Impulse.ar(freq))) * 0.001 + Dust.ar(10000, 0.01); - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(1, 2)}) ], exc) * 0.8).softclip; - sig1 = HPF.ar(sig1, 300); - Out.ar(Select.kr(busIndex, ~stringModelBusArray), sig1 * amp * EnvGen.kr(Env.adsr(attack, 0.3, 0.9, release, 0.9, -3), gate, doneAction: 2)); - //Out.ar([0, 1], sig1 * EnvGen.kr(Env.asr(dur, 0.3, 1), gate, doneAction: 2)); -}).add; - -SynthDef(\sine, {arg freq, gate = 1, sustain, amp, dur, busIndex = 0; - var sig; - sig = SinOsc.ar(freq); - Out.ar(Select.kr(busIndex, ~sineBusArray), sig * EnvGen.kr(Env.asr(0.3, 0.4, 0.3), gate, timeScale: dur, doneAction: 2)); - //Out.ar(Select.kr(busIndex, ~sineBusArray), sig * EnvGen.kr(Env.sine(dur), gate, doneAction: 2)); -}).add; - -SynthDef(\mixer, {arg freq, gate = 1, sustain, amp, dur, out; - var nameSpaces, sigs, hierarchicalDust; - - hierarchicalDust = ( - TIRand.kr(0, 1, Impulse.kr(100)) * - TIRand.kr(0, 1, Impulse.kr(10)) * - TIRand.kr(0, 1, Impulse.kr(1)) - ); - - sigs = [~stringModelBusArray, ~sineBusArray, ~bassBusArray, ~hdustBusArray, ~samplerBusArray].collect({arg busArray, i; - var nameSpace, sig; - nameSpace = ['string', 'sine', 'bass', 'hdust', 'sampler'][i]; - sig = busArray.collect({arg bus, c; In.ar(bus, 1) * NamedControl.kr(\ ++ nameSpace ++ '_volume_' ++ c, 1, 0.1)}); - sig = sig.collect({arg channel, c; Pan2.ar(channel, NamedControl.kr(\ ++ nameSpace ++ '_pan_' ++ c, i / (busArray.size - 1), 0.1) * 2 - 1)}); - sig = sig.collect({arg channel, c; channel * NamedControl.kr(\ ++ nameSpace ++ '_mute_' ++ c, 1, 0.1)}); - sig = Mix.ar(sig) * pow(NamedControl.kr(\ ++ nameSpace ++ '_volume_master', 1, 0.1), 2); - }); - - sigs = Mix.ar(sigs / 4); - Out.ar(0, sigs) -}).add; - -SynthDef(\bass, { - var switches, drone; - switches = {|i| Dust.kr(0.1)} ! 9; - drone = {|i| var harm = pow(2, 2 - (i / 3).trunc), amp = (1 / pow(harm, 2)); - SinOsc.ar(60 * harm + TRand.kr(-3, 3, switches[i]), 0, amp)} ! 9; - Out.ar(~bassBusArray[0], Mix.new(drone) * 0.2); -}).add; - -SynthDef(\sampler, { - Out.ar(~samplerBusArray, PlayBuf.ar(2, ~sBuf, BufRateScale.kr(~sBuf), doneAction: 2)) -}).add; - -// main routine -SynthDef(\hdust, { - arg gate = 0; - var hierarchical_dust, low_sine, high_sine, brown_noise, white_noise; - // this triggers the combinations of sources - // it is similar to the Supercollider UGen called dust but with a hierarchical structure - hierarchical_dust = ( - TIRand.kr(0, 1, Impulse.kr(100)) * - TIRand.kr(0, 1, Impulse.kr(10)) * - TIRand.kr(0, 1, Impulse.kr(1)) * - TIRand.kr(0, 1, Impulse.kr(0.1)) - ); - // adjust the multiplier at the end of each line for adjusting levels - // note with each trigger, each source has a 1 in 3 chance of sounding - low_sine = SinOsc.ar(76.midicps / 16) * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.1; - high_sine = SinOsc.ar(76.midicps * 8) * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.01; - brown_noise = BrownNoise.ar() * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.025; - white_noise = WhiteNoise.ar() * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.02; - Out.ar(~hdustBusArray[0], - ((low_sine + high_sine + brown_noise + white_noise) ) - ); -}).add; - -) - -( -var bass, hdust, sampler, mixer; -bass = Synth.tail(~group, \bass); -hdust = Synth.tail(~group, \hdust); -sampler = Synth.head(~group, \sampler); -mixer = Synth.tail(~group, \mixer); -OSCdef(\mixer, {arg msg, time, addr, port; - mixer.set((msg[1] ++ '_' ++ msg[2] ++ '_' ++ msg[3]), msg[4]) -}, \mixer); - -OSCdef(\sampler, {arg msg, time, addr, port; - msg.postln; - sampler.free; - ~sBuf.free; - ~sBuf = Buffer.read(s, msg[1].asString.postln, action: {sampler = Synth.head(~group, \sampler)}); -}, \sampler); -) - -/* old something -( -SynthDef(\test, {arg freq, gate = 1, sustain, amp, dur; - var trig, exc, sig1, sig2, noHarms, freqFinal, start, end; - noHarms = 30; - freq = WhiteNoise.ar * 3 + freq; - freqFinal = Duty.ar((1/freq), 0, freq); - trig = Changed.ar(freqFinal); - start = Demand.ar(trig, 0, Dwhite(-1, -0.75)); - end = Demand.ar(trig, 0, Dwhite(0.75, 1)); - exc = Phasor.ar(trig, (end - start) * freqFinal / SampleRate.ir, start, end, 0) * 0.001 + Dust.ar(10000, 0.01); - - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(2, 3)}) ], exc) * 0.5).softclip; - sig1 = HPF.ar(sig1, 300); - Out.ar([0, 1], sig1 * EnvGen.kr(Env.adsr(0.3, 0.3, 0.9, 0.5, 0.9), gate, doneAction: 2)); -}).add; -) -*/ - diff --git a/resources/resources_bak_2024_01_03/piece_ledger_pas/46210507/46210507_mus_model.json b/resources/resources_bak_2024_01_03/piece_ledger_pas/46210507/46210507_mus_model.json deleted file mode 100644 index 3ec4056..0000000 --- a/resources/resources_bak_2024_01_03/piece_ledger_pas/46210507/46210507_mus_model.json +++ /dev/null @@ -1,59 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ] ], 2.375 ], - [ [ [ "Rest" ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, -1, 0, 0, 0 ] ], 1.625 ], - [ [ [ "Rest" ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, -1, 0 ] ], 1.125 ], - [ [ [ "Rest" ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ -1, 1, 0, 0, 0, 0 ] ], 3 ] - ], - [ - [ [ [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ -1, 1, 0, 0, 0, 0 ] ], 3.125 ], - [ [ [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ -1, 1, 0, 0, 0, 0 ] ], 1.125 ], - [ [ [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ -1, 0, 0, 0, 0, 1 ] ], 1.25 ], - [ [ [ -1, 0, 0, 0, 1, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ -1, 0, 0, 0, 0, 1 ] ], 1.375 ], - [ [ [ -1, 0, 0, 0, 1, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ 0, 0, -1, 0, 0, 0 ] ], 1.5 ], - [ [ [ 0, -1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ 0, 0, -1, 0, 0, 0 ] ], 0.875 ], - [ [ [ -1, 0, 1, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ 0, 0, -1, 0, 0, 0 ] ], 2 ] - ], - [ - [ [ [ -1, 0, 1, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ "Rest" ] ], 1 ], - [ [ [ -1, 0, 1, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ], [ "Rest" ] ], 1.375 ], - [ [ [ -1, 0, 1, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ], [ "Rest" ] ], 1.75 ], - [ [ [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ], [ "Rest" ] ], 1.375 ], - [ [ [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ] ], 1.625 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 2.375 ] - ] - ] -], -"last_changes": -[ - [ [ -1, 0, 0, 0, 1, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ 0, 0, -1, 0, 0, 0 ] ], - [ [ 0, -1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ 0, 0, -1, 0, 0, 0 ] ], - [ [ -1, 0, 1, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ 0, 0, -1, 0, 0, 0 ] ], - [ [ -1, 0, 1, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ], [ 0, 0, -1, 0, 0, 0 ] ], - [ [ -1, 0, 1, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ], [ 0, 0, -1, 0, 0, 0 ] ] -], -"cur_uid": "46210507", -"ref_uid": "nil", -"order_seed": 944186, -"dur_seed": 424778, -"motifs_seed": 515266, -"entrances_probs_vals": [ 0, 0.48, 1.7460317460317, 0.58, 1.68, 0.20725388601036, 0.68581081081081, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"passages_probs_vals": [ 0, 0.48, 1.7460317460317, 0.58, 1.68, 0.20725388601036, 0.68581081081081, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"exits_probs_vals": [ 0, 0.48, 1.7460317460317, 0.58, 1.68, 0.20725388601036, 0.68581081081081, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"ranges": [ [ -3600, -627.86377708978 ], [ -3600, 260 ], [ -980.80495356037, 2066 ], [ -627.86377708978, 2053 ] ], -"passages_weights": [ 0.75, 0.75, 0.75, 0.75, 0.75 ], -"order": -[ - [ [ 2 ], [ 3, 3, 3 ], [ 0, 1 ] ], - [ [ 1 ], [ 2, 3, 0, 3, 0, 0 ], [ ] ], - [ [ 0, 1 ], [ 2, 2 ], [ 3 ] ] -], -"sus_weights": [ 0.73, 0.49, 0 ], -"order_size": [ 1, 7 ], -"passages_size": [ 0, 5 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/piece_ledger_pas/4b96f62d/4b96f62d_code.scd b/resources/resources_bak_2024_01_03/piece_ledger_pas/4b96f62d/4b96f62d_code.scd deleted file mode 100644 index 3ec9b1a..0000000 --- a/resources/resources_bak_2024_01_03/piece_ledger_pas/4b96f62d/4b96f62d_code.scd +++ /dev/null @@ -1,907 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - pDistance.gaussCurve(1, mean, sd) -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = 1/pow(hdSum.value(voices.deepCopy.put(ins, candidate)), 2); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~msg.postln; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1, 3)}, {rrand(0.3, 0.5)}); - }); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - //res.postln; - if(res.every({arg char; char.isDecDigit}), {res = res.asInteger}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file; - file = File(path, "w"); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "passages_weights", "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((dir +/+ ".." +/+ "resources" +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - - curUID = genUID.value; - - File.mkdir((dir +/+ ".." +/+ "resources" +/+ curUID).standardizePath); - File.copy(exPath, (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - ledger = ledger.drop(-1).add(curUID); - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (dir +/+ ".." +/+ "resources" +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - -) - -( -//synthdefs -~stringModelBusArray = 4.collect({Bus.audio(s, 1)}); -~sineBusArray = 4.collect({Bus.audio(s, 1)}); -~bassBusArray = 1.collect({Bus.audio(s, 1)}); -~hdustBusArray = 1.collect({Bus.audio(s, 1)}); -~samplerBusArray = 2.collect({Bus.audio(s, 1)}); -~sBuf = Buffer.alloc(s, 10, 2); -SynthDef(\string_model, {arg freq, gate = 1, sustain, amp, dur, attack, release = 1, busIndex = 0; - var trig, exc, sig1, sig2, noHarms; - noHarms = rrand(20, 40); - exc = Saw.ar(freq, TRand.ar(0.5, 1, Impulse.ar(freq))) * 0.001 + Dust.ar(10000, 0.01); - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(1, 2)}) ], exc) * 0.8).softclip; - //sig1 = HPF.ar(sig1, 300); - Out.ar(Select.kr(busIndex, ~stringModelBusArray), sig1 * amp * EnvGen.kr(Env.adsr(attack, 0.3, 0.9, release, 0.9, -3), gate, doneAction: 2)); - //Out.ar([0, 1], sig1 * EnvGen.kr(Env.asr(dur, 0.3, 1), gate, doneAction: 2)); -}).add; - -SynthDef(\sine, {arg freq, gate = 1, sustain, amp, dur, busIndex = 0; - var sig; - sig = SinOsc.ar(freq); - Out.ar(Select.kr(busIndex, ~sineBusArray), sig * EnvGen.kr(Env.asr(0.3, 0.4, 0.3), gate, timeScale: dur, doneAction: 2)); - //Out.ar(Select.kr(busIndex, ~sineBusArray), sig * EnvGen.kr(Env.sine(dur), gate, doneAction: 2)); -}).add; - -SynthDef(\mixer, {arg freq, gate = 1, sustain, amp, dur, out; - var nameSpaces, sigs, hierarchicalDust; - - hierarchicalDust = ( - TIRand.kr(0, 1, Impulse.kr(100)) * - TIRand.kr(0, 1, Impulse.kr(10)) * - TIRand.kr(0, 1, Impulse.kr(1)) - ); - - sigs = [~stringModelBusArray, ~sineBusArray, ~bassBusArray, ~hdustBusArray, ~samplerBusArray].collect({arg busArray, i; - var nameSpace, sig; - nameSpace = ['string', 'sine', 'bass', 'hdust', 'sampler'][i]; - sig = busArray.collect({arg bus, c; In.ar(bus, 1) * NamedControl.kr(\ ++ nameSpace ++ '_volume_' ++ c, 1, 0.1)}); - sig = sig.collect({arg channel, c; Pan2.ar(channel, NamedControl.kr(\ ++ nameSpace ++ '_pan_' ++ c, i / (busArray.size - 1), 0.1) * 2 - 1)}); - sig = sig.collect({arg channel, c; channel * NamedControl.kr(\ ++ nameSpace ++ '_mute_' ++ c, 1, 0.1)}); - sig = Mix.ar(sig) * pow(NamedControl.kr(\ ++ nameSpace ++ '_volume_master', 1, 0.1), 2); - }); - - sigs = Mix.ar(sigs / 4); - Out.ar(0, sigs) -}).add; - -SynthDef(\bass, { - var switches, drone; - switches = {|i| Dust.kr(0.1)} ! 9; - drone = {|i| var harm = pow(2, 2 - (i / 3).trunc), amp = (1 / pow(harm, 2)); - SinOsc.ar(60 * harm + TRand.kr(-3, 3, switches[i]), 0, amp)} ! 9; - Out.ar(~bassBusArray[0], Mix.new(drone) * 0.2); -}).add; - -SynthDef(\sampler, { - Out.ar(~samplerBusArray, PlayBuf.ar(2, ~sBuf, BufRateScale.kr(~sBuf), doneAction: 2)) -}).add; - -// main routine -SynthDef(\hdust, { - arg gate = 0; - var hierarchical_dust, low_sine, high_sine, brown_noise, white_noise; - // this triggers the combinations of sources - // it is similar to the Supercollider UGen called dust but with a hierarchical structure - hierarchical_dust = ( - TIRand.kr(0, 1, Impulse.kr(100)) * - TIRand.kr(0, 1, Impulse.kr(10)) * - TIRand.kr(0, 1, Impulse.kr(1)) * - TIRand.kr(0, 1, Impulse.kr(0.1)) - ); - // adjust the multiplier at the end of each line for adjusting levels - // note with each trigger, each source has a 1 in 3 chance of sounding - low_sine = SinOsc.ar(76.midicps / 16) * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.1; - high_sine = SinOsc.ar(76.midicps * 8) * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.01; - brown_noise = BrownNoise.ar() * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.025; - white_noise = WhiteNoise.ar() * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.02; - Out.ar(~hdustBusArray[0], - ((low_sine + high_sine + brown_noise + white_noise) ) - ); -}).add; - -) - -( -var bass, hdust, sampler, mixer; -bass = Synth.tail(~group, \bass); -hdust = Synth.tail(~group, \hdust); -sampler = Synth.head(~group, \sampler); -mixer = Synth.tail(~group, \mixer); -OSCdef(\mixer, {arg msg, time, addr, port; - mixer.set((msg[1] ++ '_' ++ msg[2] ++ '_' ++ msg[3]), msg[4]) -}, \mixer); - -OSCdef(\sampler, {arg msg, time, addr, port; - msg.postln; - sampler.free; - ~sBuf.free; - ~sBuf = Buffer.read(s, msg[1].asString.postln, action: {sampler = Synth.head(~group, \sampler)}); -}, \sampler); -) - -/* old something -( -SynthDef(\test, {arg freq, gate = 1, sustain, amp, dur; - var trig, exc, sig1, sig2, noHarms, freqFinal, start, end; - noHarms = 30; - freq = WhiteNoise.ar * 3 + freq; - freqFinal = Duty.ar((1/freq), 0, freq); - trig = Changed.ar(freqFinal); - start = Demand.ar(trig, 0, Dwhite(-1, -0.75)); - end = Demand.ar(trig, 0, Dwhite(0.75, 1)); - exc = Phasor.ar(trig, (end - start) * freqFinal / SampleRate.ir, start, end, 0) * 0.001 + Dust.ar(10000, 0.01); - - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(2, 3)}) ], exc) * 0.5).softclip; - sig1 = HPF.ar(sig1, 300); - Out.ar([0, 1], sig1 * EnvGen.kr(Env.adsr(0.3, 0.3, 0.9, 0.5, 0.9), gate, doneAction: 2)); -}).add; -) -*/ - diff --git a/resources/resources_bak_2024_01_03/piece_ledger_pas/4b96f62d/4b96f62d_mus_model.json b/resources/resources_bak_2024_01_03/piece_ledger_pas/4b96f62d/4b96f62d_mus_model.json deleted file mode 100644 index c8a77ec..0000000 --- a/resources/resources_bak_2024_01_03/piece_ledger_pas/4b96f62d/4b96f62d_mus_model.json +++ /dev/null @@ -1,48 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ "Rest" ], [ 7, -7, -4, 0, -1, -2 ], [ "Rest" ] ], 2.25 ], - [ [ [ "Rest" ], [ "Rest" ], [ 7, -7, -4, 0, -1, -2 ], [ 7, -5, -2, 0, -1, -2 ] ], 3.875 ], - [ [ [ 8, -7, -4, 1, -1, -2 ], [ "Rest" ], [ 7, -7, -4, 0, -1, -2 ], [ 7, -5, -2, 0, -1, -2 ] ], 1.125 ], - [ [ [ 8, -7, -4, 1, -1, -2 ], [ 7, -8, -4, 0, -1, -2 ], [ 7, -7, -4, 0, -1, -2 ], [ 7, -5, -2, 0, -1, -2 ] ], 6.5 ] - ], - [ - [ [ [ 8, -7, -4, 1, -1, -2 ], [ "Rest" ], [ 7, -7, -4, 0, -1, -2 ], [ 7, -5, -2, 0, -1, -2 ] ], 2 ], - [ [ [ 8, -7, -4, 1, -1, -2 ], [ "Rest" ], [ 6, -7, -3, 1, -1, -2 ], [ 7, -5, -2, 0, -1, -2 ] ], 7.125 ], - [ [ [ "Rest" ], [ "Rest" ], [ 6, -7, -3, 1, -1, -2 ], [ 7, -5, -2, 0, -1, -2 ] ], 0 ], - [ [ [ "Rest" ], [ "Rest" ], [ 6, -7, -3, 1, -1, -2 ], [ "Rest" ] ], 1.625 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 5.5 ] - ] - ] -], -"last_changes": -[ - [ [ 8, -6, -4, 0, -1, -2 ], [ 6, -5, -4, 0, -1, -3 ], [ 6, -5, -4, 0, -1, -2 ], [ 7, -5, -2, 0, -1, -2 ] ], - [ [ 8, -6, -4, 0, -1, -2 ], [ 6, -5, -4, 0, -1, -3 ], [ 7, -7, -4, 0, -1, -2 ], [ 7, -5, -2, 0, -1, -2 ] ], - [ [ 8, -7, -4, 1, -1, -2 ], [ 6, -5, -4, 0, -1, -3 ], [ 7, -7, -4, 0, -1, -2 ], [ 7, -5, -2, 0, -1, -2 ] ], - [ [ 8, -7, -4, 1, -1, -2 ], [ 7, -8, -4, 0, -1, -2 ], [ 7, -7, -4, 0, -1, -2 ], [ 7, -5, -2, 0, -1, -2 ] ], - [ [ 8, -7, -4, 1, -1, -2 ], [ 7, -8, -4, 0, -1, -2 ], [ 6, -7, -3, 1, -1, -2 ], [ 7, -5, -2, 0, -1, -2 ] ] -], -"cur_uid": "4b96f62d", -"ref_uid": "703e109b", -"order_seed": 550421, -"dur_seed": 808010, -"motifs_seed": 180604, -"entrances_probs_vals": [ 0.52, 0.56, 5.1984126984127, 0.76923076923077, 2.31, 0.20725388601036, 0.68581081081081, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"passages_probs_vals": [ 0.52, 0.56, 5.1984126984127, 0.76923076923077, 2.31, 0.20725388601036, 0.68581081081081, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"exits_probs_vals": [ 0.52, 0.56, 5.1984126984127, 0.76923076923077, 2.31, 0.20725388601036, 0.68581081081081, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"ranges": [ [ 1211.1455108359, 2400 ], [ -1650, 450 ], [ -405, 1137 ], [ 951.08359133127, 2053 ] ], -"passages_weights": [ 0.75, 0.75, 0.75, 0.75, 0.75 ], -"order": -[ - [ [ 2, 3 ], [ 0, 1 ], [ ] ], - [ [ 3, 0 ], [ 2 ], [ 1 ] ] -], -"sus_weights": [ 0.73, 0.49, 0 ], -"order_size": [ 1, 3 ], -"passages_size": [ 0, 0 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/piece_ledger_pas/50fec831/50fec831_code.scd b/resources/resources_bak_2024_01_03/piece_ledger_pas/50fec831/50fec831_code.scd deleted file mode 100644 index ab370bd..0000000 --- a/resources/resources_bak_2024_01_03/piece_ledger_pas/50fec831/50fec831_code.scd +++ /dev/null @@ -1,887 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - pDistance.gaussCurve(1, mean, sd) -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = 1/pow(hdSum.value(voices.deepCopy.put(ins, candidate)), 2); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~msg.postln; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - //res.postln; - if(res.every({arg char; char.isDecDigit}), {res = res.asInteger}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file; - file = File(path, "w"); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "passages_weights", "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - lastXChanges = if(refUID == nil, { - [initVoices.value().deepCopy]; - }, { - var file; - file = File((dir +/+ ".." +/+ "resources" +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - seq = seedFunc.value(genMotif, motifSeed).value; - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - - curUID = genUID.value; - - File.mkdir((dir +/+ ".." +/+ "resources" +/+ curUID).standardizePath); - File.copy(exPath, (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - ledger = ledger.drop(-1).add(curUID); - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - player.stop; - group.set(\gate, 0); - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (dir +/+ ".." +/+ "resources" +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - -) - -( -//synthdefs -~stringModelBusArray = 4.collect({Bus.audio(s, 1)}); -~sineBusArray = 4.collect({Bus.audio(s, 1)}); -~bassBusArray = 1.collect({Bus.audio(s, 1)}); -~hdustBusArray = 1.collect({Bus.audio(s, 1)}); -~samplerBusArray = 2.collect({Bus.audio(s, 1)}); -~sBuf = Buffer.alloc(s, 10, 2); -SynthDef(\string_model, {arg freq, gate = 1, sustain, amp, dur, busIndex = 0; - var trig, exc, sig1, sig2, noHarms; - noHarms = 30; - exc = Saw.ar(freq, TRand.ar(0.5, 1, Impulse.ar(freq))) * 0.001 + Dust.ar(10000, 0.01); - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(1, 2)}) ], exc) * 0.8).softclip; - sig1 = HPF.ar(sig1, 300); - Out.ar(Select.kr(busIndex, ~stringModelBusArray), sig1 * EnvGen.kr(Env.adsr(0.3, 0.3, 0.9, 0.5, 0.9), gate, doneAction: 2)); - //Out.ar([0, 1], sig1 * EnvGen.kr(Env.asr(dur, 0.3, 1), gate, doneAction: 2)); -}).add; - -SynthDef(\sine, {arg freq, gate = 1, sustain, amp, dur, busIndex = 0; - var sig; - sig = SinOsc.ar(freq); - Out.ar(Select.kr(busIndex, ~sineBusArray), sig * EnvGen.kr(Env.asr(0.3, 0.4, 0.3), gate, timeScale: dur, doneAction: 2)); -}).add; - -SynthDef(\mixer, {arg freq, gate = 1, sustain, amp, dur, out; - var nameSpaces, sigs, hierarchicalDust; - - hierarchicalDust = ( - TIRand.kr(0, 1, Impulse.kr(100)) * - TIRand.kr(0, 1, Impulse.kr(10)) * - TIRand.kr(0, 1, Impulse.kr(1)) - ); - - sigs = [~stringModelBusArray, ~sineBusArray, ~bassBusArray, ~hdustBusArray, ~samplerBusArray].collect({arg busArray, i; - var nameSpace, sig; - nameSpace = ['string', 'sine', 'bass', 'hdust', 'sampler'][i]; - sig = busArray.collect({arg bus, c; In.ar(bus, 1) * NamedControl.kr(\ ++ nameSpace ++ '_volume_' ++ c, 1, 0.1)}); - sig = sig.collect({arg channel, c; Pan2.ar(channel, NamedControl.kr(\ ++ nameSpace ++ '_pan_' ++ c, i / (busArray.size - 1), 0.1) * 2 - 1)}); - sig = sig.collect({arg channel, c; channel * NamedControl.kr(\ ++ nameSpace ++ '_mute_' ++ c, 1, 0.1)}); - sig = Mix.ar(sig) * pow(NamedControl.kr(\ ++ nameSpace ++ '_volume_master', 1, 0.1), 2); - }); - - sigs = Mix.ar(sigs / 4); - Out.ar(0, sigs) -}).add; - -SynthDef(\bass, { - var switches, drone; - switches = {|i| Dust.kr(0.1)} ! 9; - drone = {|i| var harm = pow(2, 2 - (i / 3).trunc), amp = (1 / pow(harm, 2)); - SinOsc.ar(60 * harm + TRand.kr(-3, 3, switches[i]), 0, amp)} ! 9; - Out.ar(~bassBusArray[0], Mix.new(drone) * 0.2); -}).add; - -SynthDef(\sampler, { - Out.ar(~samplerBusArray, PlayBuf.ar(2, ~sBuf, BufRateScale.kr(~sBuf), doneAction: 2)) -}).add; - -// main routine -SynthDef(\hdust, { - arg gate = 0; - var hierarchical_dust, low_sine, high_sine, brown_noise, white_noise; - // this triggers the combinations of sources - // it is similar to the Supercollider UGen called dust but with a hierarchical structure - hierarchical_dust = ( - TIRand.kr(0, 1, Impulse.kr(100)) * - TIRand.kr(0, 1, Impulse.kr(10)) * - TIRand.kr(0, 1, Impulse.kr(1)) * - TIRand.kr(0, 1, Impulse.kr(0.1)) - ); - // adjust the multiplier at the end of each line for adjusting levels - // note with each trigger, each source has a 1 in 3 chance of sounding - low_sine = SinOsc.ar(76.midicps / 16) * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.1; - high_sine = SinOsc.ar(76.midicps * 8) * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.01; - brown_noise = BrownNoise.ar() * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.025; - white_noise = WhiteNoise.ar() * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.02; - Out.ar(~hdustBusArray[0], - ((low_sine + high_sine + brown_noise + white_noise) ) - ); -}).add; - -) - -( -var bass, hdust, sampler, mixer; -bass = Synth.tail(~group, \bass); -hdust = Synth.tail(~group, \hdust); -sampler = Synth.head(~group, \sampler); -mixer = Synth.tail(~group, \mixer); -OSCdef(\mixer, {arg msg, time, addr, port; - mixer.set((msg[1] ++ '_' ++ msg[2] ++ '_' ++ msg[3]), msg[4]) -}, \mixer); - -OSCdef(\sampler, {arg msg, time, addr, port; - msg.postln; - sampler.free; - ~sBuf.free; - ~sBuf = Buffer.read(s, msg[1].asString.postln, action: {sampler = Synth.head(~group, \sampler)}); -}, \sampler); -) - -/* old something -( -SynthDef(\test, {arg freq, gate = 1, sustain, amp, dur; - var trig, exc, sig1, sig2, noHarms, freqFinal, start, end; - noHarms = 30; - freq = WhiteNoise.ar * 3 + freq; - freqFinal = Duty.ar((1/freq), 0, freq); - trig = Changed.ar(freqFinal); - start = Demand.ar(trig, 0, Dwhite(-1, -0.75)); - end = Demand.ar(trig, 0, Dwhite(0.75, 1)); - exc = Phasor.ar(trig, (end - start) * freqFinal / SampleRate.ir, start, end, 0) * 0.001 + Dust.ar(10000, 0.01); - - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(2, 3)}) ], exc) * 0.5).softclip; - sig1 = HPF.ar(sig1, 300); - Out.ar([0, 1], sig1 * EnvGen.kr(Env.adsr(0.3, 0.3, 0.9, 0.5, 0.9), gate, doneAction: 2)); -}).add; -) -*/ - diff --git a/resources/resources_bak_2024_01_03/piece_ledger_pas/50fec831/50fec831_mus_model.json b/resources/resources_bak_2024_01_03/piece_ledger_pas/50fec831/50fec831_mus_model.json deleted file mode 100644 index e3299cd..0000000 --- a/resources/resources_bak_2024_01_03/piece_ledger_pas/50fec831/50fec831_mus_model.json +++ /dev/null @@ -1,51 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 1 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ], [ 0, 1, 0, 0, 0, 0 ] ], 4.5 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ], [ "Rest" ], [ 0, 1, 0, 0, 0, 0 ] ], 0.75 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ -1, 1, 0, 0, 0, 1 ], [ "Rest" ], [ 0, 1, 0, 0, 0, 0 ] ], 4.25 ] - ], - [ - [ [ [ 0, 1, 0, 0, 0, -1 ], [ -1, 1, 0, 0, 0, 1 ], [ "Rest" ], [ 0, 1, 0, 0, 0, 0 ] ], 0.75 ], - [ [ [ 0, 1, 0, 0, 0, -1 ], [ -1, 1, 0, 1, 0, 0 ], [ "Rest" ], [ 0, 1, 0, 0, 0, 0 ] ], 0.625 ], - [ [ [ 0, 1, 0, 0, 0, -1 ], [ -1, 1, 0, 1, 0, 0 ], [ 0, 1, 1, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ] ], 0.75 ], - [ [ [ -1, 1, 0, 0, 1, 0 ], [ -1, 1, 0, 1, 0, 0 ], [ 0, 1, 1, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ] ], 4.875 ], - [ [ [ -1, 1, 0, 0, 1, 0 ], [ "Rest" ], [ 0, 1, 1, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ] ], 1 ], - [ [ [ -1, 1, 0, 0, 1, 0 ], [ "Rest" ], [ 0, 1, 1, 0, 0, 0 ], [ "Rest" ] ], 1 ], - [ [ [ "Rest" ], [ "Rest" ], [ 0, 1, 1, 0, 0, 0 ], [ "Rest" ] ], 1 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 3.125 ] - ] - ] -], -"last_changes": -[ - [ [ 0, 0, 0, 0, 0, 0 ], [ -1, 1, 0, 0, 0, 1 ], [ 1, -1, 1, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ] ], - [ [ 0, 1, 0, 0, 0, -1 ], [ -1, 1, 0, 0, 0, 1 ], [ 1, -1, 1, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ] ], - [ [ 0, 1, 0, 0, 0, -1 ], [ -1, 1, 0, 1, 0, 0 ], [ 1, -1, 1, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ] ], - [ [ 0, 1, 0, 0, 0, -1 ], [ -1, 1, 0, 1, 0, 0 ], [ 0, 1, 1, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ] ], - [ [ -1, 1, 0, 0, 1, 0 ], [ -1, 1, 0, 1, 0, 0 ], [ 0, 1, 1, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ] ] -], -"cur_uid": "50fec831", -"ref_uid": "7264e3ac", -"order_seed": 982967, -"dur_seed": 762088, -"motifs_seed": 404006, -"entrances_probs_vals": [ 0, 1.67, 4.8015873015873, 0.24725274725275, 1.15, 0.20725388601036, 0.68581081081081, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"passages_probs_vals": [ 0, 1.67, 4.8015873015873, 0.24725274725275, 1.15, 0.20725388601036, 0.68581081081081, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"exits_probs_vals": [ 0, 1.67, 4.8015873015873, 0.24725274725275, 1.15, 0.20725388601036, 0.68581081081081, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"ranges": [ [ -1100, 460.68111455108 ], [ -507, 1084.8297213622 ], [ 884.21052631579, 2237 ], [ 1040.2476780186, 2053 ] ], -"passages_weights": [ 0.75, 0.75, 0.75, 0.75, 0.75 ], -"order": -[ - [ [ 0, 3 ], [ 1, 1 ], [ 2 ] ], - [ [ 3 ], [ 0, 1, 2, 0 ], [ ] ] -], -"sus_weights": [ 0.73, 0.23, 0 ], -"order_size": [ 1, 3 ], -"passages_size": [ 0, 2 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/piece_ledger_pas/5267b235/5267b235_code.scd b/resources/resources_bak_2024_01_03/piece_ledger_pas/5267b235/5267b235_code.scd deleted file mode 100644 index ab370bd..0000000 --- a/resources/resources_bak_2024_01_03/piece_ledger_pas/5267b235/5267b235_code.scd +++ /dev/null @@ -1,887 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - pDistance.gaussCurve(1, mean, sd) -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = 1/pow(hdSum.value(voices.deepCopy.put(ins, candidate)), 2); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~msg.postln; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - //res.postln; - if(res.every({arg char; char.isDecDigit}), {res = res.asInteger}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file; - file = File(path, "w"); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "passages_weights", "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - lastXChanges = if(refUID == nil, { - [initVoices.value().deepCopy]; - }, { - var file; - file = File((dir +/+ ".." +/+ "resources" +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - seq = seedFunc.value(genMotif, motifSeed).value; - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - - curUID = genUID.value; - - File.mkdir((dir +/+ ".." +/+ "resources" +/+ curUID).standardizePath); - File.copy(exPath, (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - ledger = ledger.drop(-1).add(curUID); - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - player.stop; - group.set(\gate, 0); - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (dir +/+ ".." +/+ "resources" +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - -) - -( -//synthdefs -~stringModelBusArray = 4.collect({Bus.audio(s, 1)}); -~sineBusArray = 4.collect({Bus.audio(s, 1)}); -~bassBusArray = 1.collect({Bus.audio(s, 1)}); -~hdustBusArray = 1.collect({Bus.audio(s, 1)}); -~samplerBusArray = 2.collect({Bus.audio(s, 1)}); -~sBuf = Buffer.alloc(s, 10, 2); -SynthDef(\string_model, {arg freq, gate = 1, sustain, amp, dur, busIndex = 0; - var trig, exc, sig1, sig2, noHarms; - noHarms = 30; - exc = Saw.ar(freq, TRand.ar(0.5, 1, Impulse.ar(freq))) * 0.001 + Dust.ar(10000, 0.01); - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(1, 2)}) ], exc) * 0.8).softclip; - sig1 = HPF.ar(sig1, 300); - Out.ar(Select.kr(busIndex, ~stringModelBusArray), sig1 * EnvGen.kr(Env.adsr(0.3, 0.3, 0.9, 0.5, 0.9), gate, doneAction: 2)); - //Out.ar([0, 1], sig1 * EnvGen.kr(Env.asr(dur, 0.3, 1), gate, doneAction: 2)); -}).add; - -SynthDef(\sine, {arg freq, gate = 1, sustain, amp, dur, busIndex = 0; - var sig; - sig = SinOsc.ar(freq); - Out.ar(Select.kr(busIndex, ~sineBusArray), sig * EnvGen.kr(Env.asr(0.3, 0.4, 0.3), gate, timeScale: dur, doneAction: 2)); -}).add; - -SynthDef(\mixer, {arg freq, gate = 1, sustain, amp, dur, out; - var nameSpaces, sigs, hierarchicalDust; - - hierarchicalDust = ( - TIRand.kr(0, 1, Impulse.kr(100)) * - TIRand.kr(0, 1, Impulse.kr(10)) * - TIRand.kr(0, 1, Impulse.kr(1)) - ); - - sigs = [~stringModelBusArray, ~sineBusArray, ~bassBusArray, ~hdustBusArray, ~samplerBusArray].collect({arg busArray, i; - var nameSpace, sig; - nameSpace = ['string', 'sine', 'bass', 'hdust', 'sampler'][i]; - sig = busArray.collect({arg bus, c; In.ar(bus, 1) * NamedControl.kr(\ ++ nameSpace ++ '_volume_' ++ c, 1, 0.1)}); - sig = sig.collect({arg channel, c; Pan2.ar(channel, NamedControl.kr(\ ++ nameSpace ++ '_pan_' ++ c, i / (busArray.size - 1), 0.1) * 2 - 1)}); - sig = sig.collect({arg channel, c; channel * NamedControl.kr(\ ++ nameSpace ++ '_mute_' ++ c, 1, 0.1)}); - sig = Mix.ar(sig) * pow(NamedControl.kr(\ ++ nameSpace ++ '_volume_master', 1, 0.1), 2); - }); - - sigs = Mix.ar(sigs / 4); - Out.ar(0, sigs) -}).add; - -SynthDef(\bass, { - var switches, drone; - switches = {|i| Dust.kr(0.1)} ! 9; - drone = {|i| var harm = pow(2, 2 - (i / 3).trunc), amp = (1 / pow(harm, 2)); - SinOsc.ar(60 * harm + TRand.kr(-3, 3, switches[i]), 0, amp)} ! 9; - Out.ar(~bassBusArray[0], Mix.new(drone) * 0.2); -}).add; - -SynthDef(\sampler, { - Out.ar(~samplerBusArray, PlayBuf.ar(2, ~sBuf, BufRateScale.kr(~sBuf), doneAction: 2)) -}).add; - -// main routine -SynthDef(\hdust, { - arg gate = 0; - var hierarchical_dust, low_sine, high_sine, brown_noise, white_noise; - // this triggers the combinations of sources - // it is similar to the Supercollider UGen called dust but with a hierarchical structure - hierarchical_dust = ( - TIRand.kr(0, 1, Impulse.kr(100)) * - TIRand.kr(0, 1, Impulse.kr(10)) * - TIRand.kr(0, 1, Impulse.kr(1)) * - TIRand.kr(0, 1, Impulse.kr(0.1)) - ); - // adjust the multiplier at the end of each line for adjusting levels - // note with each trigger, each source has a 1 in 3 chance of sounding - low_sine = SinOsc.ar(76.midicps / 16) * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.1; - high_sine = SinOsc.ar(76.midicps * 8) * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.01; - brown_noise = BrownNoise.ar() * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.025; - white_noise = WhiteNoise.ar() * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.02; - Out.ar(~hdustBusArray[0], - ((low_sine + high_sine + brown_noise + white_noise) ) - ); -}).add; - -) - -( -var bass, hdust, sampler, mixer; -bass = Synth.tail(~group, \bass); -hdust = Synth.tail(~group, \hdust); -sampler = Synth.head(~group, \sampler); -mixer = Synth.tail(~group, \mixer); -OSCdef(\mixer, {arg msg, time, addr, port; - mixer.set((msg[1] ++ '_' ++ msg[2] ++ '_' ++ msg[3]), msg[4]) -}, \mixer); - -OSCdef(\sampler, {arg msg, time, addr, port; - msg.postln; - sampler.free; - ~sBuf.free; - ~sBuf = Buffer.read(s, msg[1].asString.postln, action: {sampler = Synth.head(~group, \sampler)}); -}, \sampler); -) - -/* old something -( -SynthDef(\test, {arg freq, gate = 1, sustain, amp, dur; - var trig, exc, sig1, sig2, noHarms, freqFinal, start, end; - noHarms = 30; - freq = WhiteNoise.ar * 3 + freq; - freqFinal = Duty.ar((1/freq), 0, freq); - trig = Changed.ar(freqFinal); - start = Demand.ar(trig, 0, Dwhite(-1, -0.75)); - end = Demand.ar(trig, 0, Dwhite(0.75, 1)); - exc = Phasor.ar(trig, (end - start) * freqFinal / SampleRate.ir, start, end, 0) * 0.001 + Dust.ar(10000, 0.01); - - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(2, 3)}) ], exc) * 0.5).softclip; - sig1 = HPF.ar(sig1, 300); - Out.ar([0, 1], sig1 * EnvGen.kr(Env.adsr(0.3, 0.3, 0.9, 0.5, 0.9), gate, doneAction: 2)); -}).add; -) -*/ - diff --git a/resources/resources_bak_2024_01_03/piece_ledger_pas/5267b235/5267b235_mus_model.json b/resources/resources_bak_2024_01_03/piece_ledger_pas/5267b235/5267b235_mus_model.json deleted file mode 100644 index 56ea9be..0000000 --- a/resources/resources_bak_2024_01_03/piece_ledger_pas/5267b235/5267b235_mus_model.json +++ /dev/null @@ -1,43 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ] ], 2.25 ], - [ [ [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ] ], 1.75 ], - [ [ [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 3.125 ], - [ [ [ 2, 0, 0, -1, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 2.625 ], - [ [ [ 2, -1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 3 ], - [ [ [ 2, -1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ] ], 1.25 ], - [ [ [ 2, -1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ] ], 2.75 ], - [ [ [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ] ], 2.75 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 1.5 ] - ] - ] -], -"last_changes": -[ - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], - [ [ 2, 0, 0, -1, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], - [ [ 2, -1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ] -], -"cur_uid": "5267b235", -"ref_uid": "nil", -"order_seed": 474005, -"dur_seed": 826425, -"motifs_seed": 116157, -"entrances_probs_vals": [ 0, 0, 1.984126984127, 0, 3.0769230769231, 0, 0.64527027027027, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"passages_probs_vals": [ 0, 0, 1.984126984127, 0, 3.0769230769231, 0, 0.64527027027027, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"exits_probs_vals": [ 0, 0, 1.984126984127, 0, 3.0769230769231, 0, 0.64527027027027, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"ranges": [ [ 1419.1950464396, 2400 ], [ 1519.5046439628, 2400 ], [ 1541.7956656347, 2237 ], [ 1519.5046439628, 2053 ] ], -"passages_weights": [ 0.75, 0.75, 0.75, 0.75, 0.75 ], -"order": -[ - [ [ 2, 1, 3 ], [ 0, 0 ], [ ] ] -], -"sus_weights": [ 0.75, 0.69, 0.75 ], -"order_size": [ 1, 2 ], -"passages_size": [ 0, 2 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/piece_ledger_pas/5625a95a/5625a95a_code.scd b/resources/resources_bak_2024_01_03/piece_ledger_pas/5625a95a/5625a95a_code.scd deleted file mode 100644 index ab370bd..0000000 --- a/resources/resources_bak_2024_01_03/piece_ledger_pas/5625a95a/5625a95a_code.scd +++ /dev/null @@ -1,887 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - pDistance.gaussCurve(1, mean, sd) -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = 1/pow(hdSum.value(voices.deepCopy.put(ins, candidate)), 2); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~msg.postln; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - //res.postln; - if(res.every({arg char; char.isDecDigit}), {res = res.asInteger}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file; - file = File(path, "w"); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "passages_weights", "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - lastXChanges = if(refUID == nil, { - [initVoices.value().deepCopy]; - }, { - var file; - file = File((dir +/+ ".." +/+ "resources" +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - seq = seedFunc.value(genMotif, motifSeed).value; - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - - curUID = genUID.value; - - File.mkdir((dir +/+ ".." +/+ "resources" +/+ curUID).standardizePath); - File.copy(exPath, (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - ledger = ledger.drop(-1).add(curUID); - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - player.stop; - group.set(\gate, 0); - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (dir +/+ ".." +/+ "resources" +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - -) - -( -//synthdefs -~stringModelBusArray = 4.collect({Bus.audio(s, 1)}); -~sineBusArray = 4.collect({Bus.audio(s, 1)}); -~bassBusArray = 1.collect({Bus.audio(s, 1)}); -~hdustBusArray = 1.collect({Bus.audio(s, 1)}); -~samplerBusArray = 2.collect({Bus.audio(s, 1)}); -~sBuf = Buffer.alloc(s, 10, 2); -SynthDef(\string_model, {arg freq, gate = 1, sustain, amp, dur, busIndex = 0; - var trig, exc, sig1, sig2, noHarms; - noHarms = 30; - exc = Saw.ar(freq, TRand.ar(0.5, 1, Impulse.ar(freq))) * 0.001 + Dust.ar(10000, 0.01); - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(1, 2)}) ], exc) * 0.8).softclip; - sig1 = HPF.ar(sig1, 300); - Out.ar(Select.kr(busIndex, ~stringModelBusArray), sig1 * EnvGen.kr(Env.adsr(0.3, 0.3, 0.9, 0.5, 0.9), gate, doneAction: 2)); - //Out.ar([0, 1], sig1 * EnvGen.kr(Env.asr(dur, 0.3, 1), gate, doneAction: 2)); -}).add; - -SynthDef(\sine, {arg freq, gate = 1, sustain, amp, dur, busIndex = 0; - var sig; - sig = SinOsc.ar(freq); - Out.ar(Select.kr(busIndex, ~sineBusArray), sig * EnvGen.kr(Env.asr(0.3, 0.4, 0.3), gate, timeScale: dur, doneAction: 2)); -}).add; - -SynthDef(\mixer, {arg freq, gate = 1, sustain, amp, dur, out; - var nameSpaces, sigs, hierarchicalDust; - - hierarchicalDust = ( - TIRand.kr(0, 1, Impulse.kr(100)) * - TIRand.kr(0, 1, Impulse.kr(10)) * - TIRand.kr(0, 1, Impulse.kr(1)) - ); - - sigs = [~stringModelBusArray, ~sineBusArray, ~bassBusArray, ~hdustBusArray, ~samplerBusArray].collect({arg busArray, i; - var nameSpace, sig; - nameSpace = ['string', 'sine', 'bass', 'hdust', 'sampler'][i]; - sig = busArray.collect({arg bus, c; In.ar(bus, 1) * NamedControl.kr(\ ++ nameSpace ++ '_volume_' ++ c, 1, 0.1)}); - sig = sig.collect({arg channel, c; Pan2.ar(channel, NamedControl.kr(\ ++ nameSpace ++ '_pan_' ++ c, i / (busArray.size - 1), 0.1) * 2 - 1)}); - sig = sig.collect({arg channel, c; channel * NamedControl.kr(\ ++ nameSpace ++ '_mute_' ++ c, 1, 0.1)}); - sig = Mix.ar(sig) * pow(NamedControl.kr(\ ++ nameSpace ++ '_volume_master', 1, 0.1), 2); - }); - - sigs = Mix.ar(sigs / 4); - Out.ar(0, sigs) -}).add; - -SynthDef(\bass, { - var switches, drone; - switches = {|i| Dust.kr(0.1)} ! 9; - drone = {|i| var harm = pow(2, 2 - (i / 3).trunc), amp = (1 / pow(harm, 2)); - SinOsc.ar(60 * harm + TRand.kr(-3, 3, switches[i]), 0, amp)} ! 9; - Out.ar(~bassBusArray[0], Mix.new(drone) * 0.2); -}).add; - -SynthDef(\sampler, { - Out.ar(~samplerBusArray, PlayBuf.ar(2, ~sBuf, BufRateScale.kr(~sBuf), doneAction: 2)) -}).add; - -// main routine -SynthDef(\hdust, { - arg gate = 0; - var hierarchical_dust, low_sine, high_sine, brown_noise, white_noise; - // this triggers the combinations of sources - // it is similar to the Supercollider UGen called dust but with a hierarchical structure - hierarchical_dust = ( - TIRand.kr(0, 1, Impulse.kr(100)) * - TIRand.kr(0, 1, Impulse.kr(10)) * - TIRand.kr(0, 1, Impulse.kr(1)) * - TIRand.kr(0, 1, Impulse.kr(0.1)) - ); - // adjust the multiplier at the end of each line for adjusting levels - // note with each trigger, each source has a 1 in 3 chance of sounding - low_sine = SinOsc.ar(76.midicps / 16) * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.1; - high_sine = SinOsc.ar(76.midicps * 8) * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.01; - brown_noise = BrownNoise.ar() * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.025; - white_noise = WhiteNoise.ar() * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.02; - Out.ar(~hdustBusArray[0], - ((low_sine + high_sine + brown_noise + white_noise) ) - ); -}).add; - -) - -( -var bass, hdust, sampler, mixer; -bass = Synth.tail(~group, \bass); -hdust = Synth.tail(~group, \hdust); -sampler = Synth.head(~group, \sampler); -mixer = Synth.tail(~group, \mixer); -OSCdef(\mixer, {arg msg, time, addr, port; - mixer.set((msg[1] ++ '_' ++ msg[2] ++ '_' ++ msg[3]), msg[4]) -}, \mixer); - -OSCdef(\sampler, {arg msg, time, addr, port; - msg.postln; - sampler.free; - ~sBuf.free; - ~sBuf = Buffer.read(s, msg[1].asString.postln, action: {sampler = Synth.head(~group, \sampler)}); -}, \sampler); -) - -/* old something -( -SynthDef(\test, {arg freq, gate = 1, sustain, amp, dur; - var trig, exc, sig1, sig2, noHarms, freqFinal, start, end; - noHarms = 30; - freq = WhiteNoise.ar * 3 + freq; - freqFinal = Duty.ar((1/freq), 0, freq); - trig = Changed.ar(freqFinal); - start = Demand.ar(trig, 0, Dwhite(-1, -0.75)); - end = Demand.ar(trig, 0, Dwhite(0.75, 1)); - exc = Phasor.ar(trig, (end - start) * freqFinal / SampleRate.ir, start, end, 0) * 0.001 + Dust.ar(10000, 0.01); - - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(2, 3)}) ], exc) * 0.5).softclip; - sig1 = HPF.ar(sig1, 300); - Out.ar([0, 1], sig1 * EnvGen.kr(Env.adsr(0.3, 0.3, 0.9, 0.5, 0.9), gate, doneAction: 2)); -}).add; -) -*/ - diff --git a/resources/resources_bak_2024_01_03/piece_ledger_pas/5625a95a/5625a95a_mus_model.json b/resources/resources_bak_2024_01_03/piece_ledger_pas/5625a95a/5625a95a_mus_model.json deleted file mode 100644 index 2bd7c20..0000000 --- a/resources/resources_bak_2024_01_03/piece_ledger_pas/5625a95a/5625a95a_mus_model.json +++ /dev/null @@ -1,43 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ] ], 0.125 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ] ], 3.625 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 2, 0, 0, 0, 0, -1 ], [ 0, 0, 0, 0, 0, 0 ] ], 1.75 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 2, -1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 4.125 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ] ], 0.875 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ] ], 2.375 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 0.25 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 2.75 ] - ] - ] -], -"last_changes": -[ - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 2, 0, 0, 0, 0, -1 ], [ 0, 0, 0, 0, 0, 0 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 2, -1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ] -], -"cur_uid": "5625a95a", -"ref_uid": "nil", -"order_seed": 871476, -"dur_seed": 417039, -"motifs_seed": 168381, -"entrances_probs_vals": [ 0, 0, 1.984126984127, 0, 3.0769230769231, 0, 0.64527027027027, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"passages_probs_vals": [ 0, 0, 1.984126984127, 0, 3.0769230769231, 0, 0.64527027027027, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"exits_probs_vals": [ 0, 0, 1.984126984127, 0, 3.0769230769231, 0, 0.64527027027027, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"ranges": [ [ 1419.1950464396, 2400 ], [ 1519.5046439628, 2400 ], [ 1541.7956656347, 2237 ], [ 1519.5046439628, 2053 ] ], -"passages_weights": [ 0.75, 0.75, 0.75, 0.75, 0.75 ], -"order": -[ - [ [ 0, 3, 1 ], [ 2, 2 ], [ ] ] -], -"sus_weights": [ 0.75, 0.69, 0.75 ], -"order_size": [ 1, 2 ], -"passages_size": [ 0, 2 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/piece_ledger_pas/628d5c8b/628d5c8b_code.scd b/resources/resources_bak_2024_01_03/piece_ledger_pas/628d5c8b/628d5c8b_code.scd deleted file mode 100644 index 90f0b1e..0000000 --- a/resources/resources_bak_2024_01_03/piece_ledger_pas/628d5c8b/628d5c8b_code.scd +++ /dev/null @@ -1,741 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON; - -// model vars -//(model and global vars mostly set by OSC funcs -var curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, orders, susWeights, passagesWeights, passagesSize, orderSize; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc; - -// other global vars -var lastXChanges, popSize, exPath, dir, primes, dims, tuples, -seq, group, player, ledgerPath, ledger, currentlyPlayingUID; - - -// install JSON quark -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - pDistance.gaussCurve(1, mean, sd) -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, min, max, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - durFunc = {arg allowChord; - var res; - res = if(allowChord.not, { - pTable.tableRand * (max - min) + min - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (max - min) + min}); - }).round(0.125); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = 1/pow(hdSum.value(voices.deepCopy.put(ins, candidate)), 2); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - allowChord = if((sus ++ silent).includes(ins), { - //(sus ++ silent).includes(ins) && (ins != sus.last); - ins != sus.last; - }, { - if(i < (flatOrder.size - 1), {(isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not}, {false}); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord); - }, { - dur = passagesDurFunc.value(allowChord); - }); - //dur = passagesDurFunc.value(allowChord); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - dur = exitsDurFunc.value(allowChord); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~msg.postln; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr; - var voices, durs, patterns, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - res = Ppar( - voices.flop.collect({arg voice; - var clumps, hdScores, freqs, fDurs; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \instrument, \test, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1) - ) - }) ++ - [ - Pbind( - \type, \osc, - \addr, addr, - //\indexPath, "/cur_play_index", - //\indexMsg, Pseq(indices, 1), - //\seqPath, "/mus_seq", - //\seqMsg, Pseq(seq, 1), - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - ); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - //res.postln; - if(res.every({arg char; char.isDecDigit}), {res = res.asInteger}); - }); - }); - res -}; - -writeResources = {arg path; - var file, nameSpaces, modelItems, resString; - file = File(path,"w"); - - nameSpaces = [ - "music_data", "last_changes", - "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "passages_weights", "order", "sus_weights", "order_size", "passages_size" - ]; - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize - ]; - - resString = [nameSpaces, modelItems].flop.collect({arg item; - var nameSpace, modelItem, depth = 0, insert = " "; - # nameSpace, modelItem = item; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (modelItem == nil), {modelItem = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(modelItem, depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var nameSpaces, data; - - //model = File(path, "r").readAllString.parseJSON; - - nameSpaces = [ - "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "passages_weights", "order", "sus_weights", "order_size", "passages_size" - ]; - - data = nameSpaces.collect({arg nS; msgInterpret.value(jsonObject[nS])}); - - //data.postln; - - # curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize = data; - - popSize = ranges.size; -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - loadModelFile.value(msg[1].asString); -}, \load_model); - - -OSCdef(\generate, {arg msg, time, addr, port; - var path, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - loadModelFile.value(path); - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - lastXChanges = if(refUID == nil, { - [initVoices.value().deepCopy]; - }, { - var file; - file = File((dir +/+ ".." +/+ "resources" +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..2] ++ [entrancesProbVals[3..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..2] ++ [passagesProbVals[3..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..2] ++ [exitsProbVals[3..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - seq = seedFunc.value(genMotif, motifSeed).value; - - modelString = writeResources.value(path); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - addr.sendMsg("/generated", path, modelString); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var newLedger, modelPath, musString, musFile, test1, test2; - msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - curUID = genUID.value; - File.mkdir((dir +/+ ".." +/+ "resources" +/+ curUID).standardizePath); - File.copy(exPath, (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - writeResources.value(modelPath); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - newLedger = File(ledgerPath, "w"); - ledger = ledger.drop(-1).add(curUID); - newLedger.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - newLedger.close; - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - player.stop; - group.set(\gate, 0); - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (dir +/+ ".." +/+ "resources" +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - }); - player = player.play - }); -}, \transport); - -) - -( -SynthDef(\test, {arg freq, gate = 1, sustain, amp, dur; - var trig, exc, sig1, sig2, noHarms; - noHarms = 30; - exc = Saw.ar(freq, TRand.ar(0.5, 1, Impulse.ar(freq))) * 0.001 + Dust.ar(10000, 0.01); - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(1, 2)}) ], exc) * 0.5).softclip; - sig1 = HPF.ar(sig1, 300); - Out.ar([0, 1], sig1 * EnvGen.kr(Env.adsr(0.3, 0.3, 0.9, 0.5, 0.9), gate, doneAction: 2)); -}).add; -) - -( -SynthDef(\test, {arg freq, gate = 1, sustain, amp, dur; - var trig, exc, sig1, sig2, noHarms, freqFinal, start, end; - noHarms = 30; - freq = WhiteNoise.ar * 3 + freq; - freqFinal = Duty.ar((1/freq), 0, freq); - trig = Changed.ar(freqFinal); - start = Demand.ar(trig, 0, Dwhite(-1, -0.75)); - end = Demand.ar(trig, 0, Dwhite(0.75, 1)); - exc = Phasor.ar(trig, (end - start) * freqFinal / SampleRate.ir, start, end, 0) * 0.001 + Dust.ar(10000, 0.01); - - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(2, 3)}) ], exc) * 0.5).softclip; - sig1 = HPF.ar(sig1, 300); - Out.ar([0, 1], sig1 * EnvGen.kr(Env.adsr(0.3, 0.3, 0.9, 0.5, 0.9), gate, doneAction: 2)); -}).add; -) - - - -"{\"a\": 1}".parseYAML["a"].asInteger; -"{\"a\": 1}".parseJSON["a"].isNumber; - -1223423434123.asHexString.toLower - -Date.getDate.rawSeconds -Date.seed.asHexString.toLower - -n = NetAddr("localhost", 8080); -n.sendMsg("/GET/#", (NetAddr.localAddr.hostname ++ ":" ++ NetAddr.localAddr.port), "/passage_probs_vals"); \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/piece_ledger_pas/628d5c8b/628d5c8b_mus_model.json b/resources/resources_bak_2024_01_03/piece_ledger_pas/628d5c8b/628d5c8b_mus_model.json deleted file mode 100644 index a7c647e..0000000 --- a/resources/resources_bak_2024_01_03/piece_ledger_pas/628d5c8b/628d5c8b_mus_model.json +++ /dev/null @@ -1,56 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 0.625 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ], [ 0, 1, 0, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 1, 0, 0, 0, 0, -1 ], [ 0, 1, 0, 0, 0, 0 ] ], 1.75 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 1, 0, 0, 0, 0, -1 ], [ 1, 0, 0, 0, -1, 0 ] ], 1.875 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 1, 0, 0, 0, 0, -1 ], [ 0, 0, 0, 0, 1, 0 ] ], 1.5 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 1, 0, 0, 0, 0, -1 ], [ 0, 0, 1, 0, 0, 0 ] ], 0.75 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 1, 0, 0, 0, 0, -1 ], [ 1, 0, 0, -1, 0, 0 ] ], 1.25 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 1, 0, 0, 0, 0, -1 ], [ -1, 0, 0, 1, 0, 0 ] ], 1.625 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 1, 0, 0, 0, 0, -1 ], [ 0, 1, 0, 0, 0, 0 ] ], 1.875 ] - ], - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ], [ 0, 1, 0, 0, 0, 0 ] ], 1 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 1, 0 ], [ 0, 1, 0, 0, 0, 0 ] ], 1.125 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 0, 1, -1, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ] ], 0.75 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 0, 1, 0, 0, -1, 0 ], [ 0, 1, 0, 0, 0, 0 ] ], 1.5 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 0, -1, 0, 0, 0, 1 ], [ 0, 1, 0, 0, 0, 0 ] ], 1.5 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, -1 ], [ 0, 1, 0, 0, 0, 0 ] ], 1.75 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 1, 0, 0, 0, 0 ] ], 1.125 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ] ], 0.5 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 0 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 1.25 ] - ] - ] -], -"last_changes": -[ - [ [ 0, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 1, 0 ], [ 0, 1, 0, 0, 0, 0 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 0, 1, -1, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 0, 1, 0, 0, -1, 0 ], [ 0, 1, 0, 0, 0, 0 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 0, -1, 0, 0, 0, 1 ], [ 0, 1, 0, 0, 0, 0 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, -1 ], [ 0, 1, 0, 0, 0, 0 ] ] -], -"cur_uid": "628d5c8b", -"ref_uid": "7e170ef8", -"order_seed": 227004, -"dur_seed": 357129, -"motifs_seed": 170994, -"entrances_probs_vals": [ 0.75, 0.5, 2, 0, 0.5, 0.26424870466321, 0.75675675675676, 0.5, 0.5, 0.58549222797927, 0.72635135135135, 1, 0.5 ], -"passages_probs_vals": [ 0.75, 0.5, 2, 0, 0.5, 0.20725388601036, 0.68581081081081, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"exits_probs_vals": [ 0.75, 0.5, 2, 0, 0.5, 0.20725388601036, 0.68581081081081, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"ranges": [ [ 65, 727 ], [ 799, 1758 ], [ -282, 1013 ], [ -282, 799 ] ], -"passages_weights": [ 0.75, 0.75, 0.75, 0.75, 0.75 ], -"order": -[ - [ [ 0 ], [ 3, 2, 3, 3, 3, 3, 3, 3 ], [ 1 ] ], - [ [ 0, 3, 1 ], [ 2, 2, 2, 2, 2 ], [ ] ] -], -"sus_weights": [ 0.75, 0.69, 0.75 ], -"order_size": [ 2, 6 ], -"passages_size": [ 0, 10 ] -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/piece_ledger_pas/6409252e/6409252e_code.scd b/resources/resources_bak_2024_01_03/piece_ledger_pas/6409252e/6409252e_code.scd deleted file mode 100644 index 3ec9b1a..0000000 --- a/resources/resources_bak_2024_01_03/piece_ledger_pas/6409252e/6409252e_code.scd +++ /dev/null @@ -1,907 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - pDistance.gaussCurve(1, mean, sd) -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = 1/pow(hdSum.value(voices.deepCopy.put(ins, candidate)), 2); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~msg.postln; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1, 3)}, {rrand(0.3, 0.5)}); - }); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - //res.postln; - if(res.every({arg char; char.isDecDigit}), {res = res.asInteger}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file; - file = File(path, "w"); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "passages_weights", "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((dir +/+ ".." +/+ "resources" +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - - curUID = genUID.value; - - File.mkdir((dir +/+ ".." +/+ "resources" +/+ curUID).standardizePath); - File.copy(exPath, (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - ledger = ledger.drop(-1).add(curUID); - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (dir +/+ ".." +/+ "resources" +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - -) - -( -//synthdefs -~stringModelBusArray = 4.collect({Bus.audio(s, 1)}); -~sineBusArray = 4.collect({Bus.audio(s, 1)}); -~bassBusArray = 1.collect({Bus.audio(s, 1)}); -~hdustBusArray = 1.collect({Bus.audio(s, 1)}); -~samplerBusArray = 2.collect({Bus.audio(s, 1)}); -~sBuf = Buffer.alloc(s, 10, 2); -SynthDef(\string_model, {arg freq, gate = 1, sustain, amp, dur, attack, release = 1, busIndex = 0; - var trig, exc, sig1, sig2, noHarms; - noHarms = rrand(20, 40); - exc = Saw.ar(freq, TRand.ar(0.5, 1, Impulse.ar(freq))) * 0.001 + Dust.ar(10000, 0.01); - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(1, 2)}) ], exc) * 0.8).softclip; - //sig1 = HPF.ar(sig1, 300); - Out.ar(Select.kr(busIndex, ~stringModelBusArray), sig1 * amp * EnvGen.kr(Env.adsr(attack, 0.3, 0.9, release, 0.9, -3), gate, doneAction: 2)); - //Out.ar([0, 1], sig1 * EnvGen.kr(Env.asr(dur, 0.3, 1), gate, doneAction: 2)); -}).add; - -SynthDef(\sine, {arg freq, gate = 1, sustain, amp, dur, busIndex = 0; - var sig; - sig = SinOsc.ar(freq); - Out.ar(Select.kr(busIndex, ~sineBusArray), sig * EnvGen.kr(Env.asr(0.3, 0.4, 0.3), gate, timeScale: dur, doneAction: 2)); - //Out.ar(Select.kr(busIndex, ~sineBusArray), sig * EnvGen.kr(Env.sine(dur), gate, doneAction: 2)); -}).add; - -SynthDef(\mixer, {arg freq, gate = 1, sustain, amp, dur, out; - var nameSpaces, sigs, hierarchicalDust; - - hierarchicalDust = ( - TIRand.kr(0, 1, Impulse.kr(100)) * - TIRand.kr(0, 1, Impulse.kr(10)) * - TIRand.kr(0, 1, Impulse.kr(1)) - ); - - sigs = [~stringModelBusArray, ~sineBusArray, ~bassBusArray, ~hdustBusArray, ~samplerBusArray].collect({arg busArray, i; - var nameSpace, sig; - nameSpace = ['string', 'sine', 'bass', 'hdust', 'sampler'][i]; - sig = busArray.collect({arg bus, c; In.ar(bus, 1) * NamedControl.kr(\ ++ nameSpace ++ '_volume_' ++ c, 1, 0.1)}); - sig = sig.collect({arg channel, c; Pan2.ar(channel, NamedControl.kr(\ ++ nameSpace ++ '_pan_' ++ c, i / (busArray.size - 1), 0.1) * 2 - 1)}); - sig = sig.collect({arg channel, c; channel * NamedControl.kr(\ ++ nameSpace ++ '_mute_' ++ c, 1, 0.1)}); - sig = Mix.ar(sig) * pow(NamedControl.kr(\ ++ nameSpace ++ '_volume_master', 1, 0.1), 2); - }); - - sigs = Mix.ar(sigs / 4); - Out.ar(0, sigs) -}).add; - -SynthDef(\bass, { - var switches, drone; - switches = {|i| Dust.kr(0.1)} ! 9; - drone = {|i| var harm = pow(2, 2 - (i / 3).trunc), amp = (1 / pow(harm, 2)); - SinOsc.ar(60 * harm + TRand.kr(-3, 3, switches[i]), 0, amp)} ! 9; - Out.ar(~bassBusArray[0], Mix.new(drone) * 0.2); -}).add; - -SynthDef(\sampler, { - Out.ar(~samplerBusArray, PlayBuf.ar(2, ~sBuf, BufRateScale.kr(~sBuf), doneAction: 2)) -}).add; - -// main routine -SynthDef(\hdust, { - arg gate = 0; - var hierarchical_dust, low_sine, high_sine, brown_noise, white_noise; - // this triggers the combinations of sources - // it is similar to the Supercollider UGen called dust but with a hierarchical structure - hierarchical_dust = ( - TIRand.kr(0, 1, Impulse.kr(100)) * - TIRand.kr(0, 1, Impulse.kr(10)) * - TIRand.kr(0, 1, Impulse.kr(1)) * - TIRand.kr(0, 1, Impulse.kr(0.1)) - ); - // adjust the multiplier at the end of each line for adjusting levels - // note with each trigger, each source has a 1 in 3 chance of sounding - low_sine = SinOsc.ar(76.midicps / 16) * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.1; - high_sine = SinOsc.ar(76.midicps * 8) * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.01; - brown_noise = BrownNoise.ar() * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.025; - white_noise = WhiteNoise.ar() * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.02; - Out.ar(~hdustBusArray[0], - ((low_sine + high_sine + brown_noise + white_noise) ) - ); -}).add; - -) - -( -var bass, hdust, sampler, mixer; -bass = Synth.tail(~group, \bass); -hdust = Synth.tail(~group, \hdust); -sampler = Synth.head(~group, \sampler); -mixer = Synth.tail(~group, \mixer); -OSCdef(\mixer, {arg msg, time, addr, port; - mixer.set((msg[1] ++ '_' ++ msg[2] ++ '_' ++ msg[3]), msg[4]) -}, \mixer); - -OSCdef(\sampler, {arg msg, time, addr, port; - msg.postln; - sampler.free; - ~sBuf.free; - ~sBuf = Buffer.read(s, msg[1].asString.postln, action: {sampler = Synth.head(~group, \sampler)}); -}, \sampler); -) - -/* old something -( -SynthDef(\test, {arg freq, gate = 1, sustain, amp, dur; - var trig, exc, sig1, sig2, noHarms, freqFinal, start, end; - noHarms = 30; - freq = WhiteNoise.ar * 3 + freq; - freqFinal = Duty.ar((1/freq), 0, freq); - trig = Changed.ar(freqFinal); - start = Demand.ar(trig, 0, Dwhite(-1, -0.75)); - end = Demand.ar(trig, 0, Dwhite(0.75, 1)); - exc = Phasor.ar(trig, (end - start) * freqFinal / SampleRate.ir, start, end, 0) * 0.001 + Dust.ar(10000, 0.01); - - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(2, 3)}) ], exc) * 0.5).softclip; - sig1 = HPF.ar(sig1, 300); - Out.ar([0, 1], sig1 * EnvGen.kr(Env.adsr(0.3, 0.3, 0.9, 0.5, 0.9), gate, doneAction: 2)); -}).add; -) -*/ - diff --git a/resources/resources_bak_2024_01_03/piece_ledger_pas/6409252e/6409252e_mus_model.json b/resources/resources_bak_2024_01_03/piece_ledger_pas/6409252e/6409252e_mus_model.json deleted file mode 100644 index 50778fb..0000000 --- a/resources/resources_bak_2024_01_03/piece_ledger_pas/6409252e/6409252e_mus_model.json +++ /dev/null @@ -1,49 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ -2, 3, -2, 1, 1, 1 ], [ "Rest" ], [ "Rest" ] ], 0.125 ], - [ [ [ -5, 3, -2, 2, 1, 1 ], [ -2, 3, -2, 1, 1, 1 ], [ "Rest" ], [ "Rest" ] ], 0.5 ], - [ [ [ -5, 3, -2, 2, 1, 1 ], [ -2, 3, -2, 1, 1, 1 ], [ "Rest" ], [ -4, 5, -2, 2, 2, -1 ] ], 0.625 ], - [ [ [ -5, 3, -2, 2, 1, 1 ], [ -2, 3, -2, 1, 1, 1 ], [ -2, 2, -2, 1, 1, 1 ], [ -4, 5, -2, 2, 2, -1 ] ], 5.625 ] - ], - [ - [ [ [ -5, 3, -2, 2, 1, 1 ], [ -2, 3, -2, 1, 1, 1 ], [ -3, 4, -2, 2, 2, -1 ], [ -4, 5, -2, 2, 2, -1 ] ], 1.125 ], - [ [ [ -5, 3, -2, 2, 1, 1 ], [ -3, 3, -1, 2, 1, 1 ], [ -3, 4, -2, 2, 2, -1 ], [ -4, 5, -2, 2, 2, -1 ] ], 2.5 ], - [ [ [ -5, 3, -2, 2, 1, 1 ], [ -3, 3, -1, 2, 1, 1 ], [ -3, 4, -2, 2, 2, -1 ], [ "Rest" ] ], 1.375 ], - [ [ [ "Rest" ], [ -3, 3, -1, 2, 1, 1 ], [ -3, 4, -2, 2, 2, -1 ], [ "Rest" ] ], 0.75 ], - [ [ [ "Rest" ], [ "Rest" ], [ -3, 4, -2, 2, 2, -1 ], [ "Rest" ] ], 0 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 1.125 ] - ] - ] -], -"last_changes": -[ - [ [ -5, 3, -2, 2, 1, 1 ], [ -4, 5, -2, 3, 2, -1 ], [ -4, 3, -2, 3, 1, 1 ], [ -4, 5, -2, 2, 2, -1 ] ], - [ [ -5, 3, -2, 2, 1, 1 ], [ -2, 3, -2, 1, 1, 1 ], [ -4, 3, -2, 3, 1, 1 ], [ -4, 5, -2, 2, 2, -1 ] ], - [ [ -5, 3, -2, 2, 1, 1 ], [ -2, 3, -2, 1, 1, 1 ], [ -2, 2, -2, 1, 1, 1 ], [ -4, 5, -2, 2, 2, -1 ] ], - [ [ -5, 3, -2, 2, 1, 1 ], [ -2, 3, -2, 1, 1, 1 ], [ -3, 4, -2, 2, 2, -1 ], [ -4, 5, -2, 2, 2, -1 ] ], - [ [ -5, 3, -2, 2, 1, 1 ], [ -3, 3, -1, 2, 1, 1 ], [ -3, 4, -2, 2, 2, -1 ], [ -4, 5, -2, 2, 2, -1 ] ] -], -"cur_uid": "6409252e", -"ref_uid": "tmp", -"order_seed": 825836, -"dur_seed": 453411, -"motifs_seed": 115471, -"entrances_probs_vals": [ 0.29, 0, 1.3492063492064, 0, 0.65934065934066, 0.20725388601036, 0.68581081081081, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"passages_probs_vals": [ 0.29, 0, 5, 0.58, 1.7582417582418, 0.20725388601036, 0.68581081081081, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"exits_probs_vals": [ 0.29, 0, 5, 0.58, 1.7582417582418, 0.20725388601036, 0.68581081081081, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"ranges": [ [ -3600, -349 ], [ 799, 1758 ], [ -282, 1013 ], [ -282, 799 ] ], -"passages_weights": [ 0.75, 0.75, 0.75, 0.75, 0.75 ], -"order": -[ - [ [ 1, 0, 3 ], [ 2 ], [ ] ], - [ [ 3, 0 ], [ 2, 1 ], [ ] ] -], -"sus_weights": [ 0.39, 0.32, 0.77 ], -"order_size": [ 1, 3 ], -"passages_size": [ 0, 0 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/piece_ledger_pas/6a3f7c7c/6a3f7c7c_code.scd b/resources/resources_bak_2024_01_03/piece_ledger_pas/6a3f7c7c/6a3f7c7c_code.scd deleted file mode 100644 index ab370bd..0000000 --- a/resources/resources_bak_2024_01_03/piece_ledger_pas/6a3f7c7c/6a3f7c7c_code.scd +++ /dev/null @@ -1,887 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - pDistance.gaussCurve(1, mean, sd) -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = 1/pow(hdSum.value(voices.deepCopy.put(ins, candidate)), 2); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~msg.postln; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - //res.postln; - if(res.every({arg char; char.isDecDigit}), {res = res.asInteger}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file; - file = File(path, "w"); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "passages_weights", "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - lastXChanges = if(refUID == nil, { - [initVoices.value().deepCopy]; - }, { - var file; - file = File((dir +/+ ".." +/+ "resources" +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - seq = seedFunc.value(genMotif, motifSeed).value; - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - - curUID = genUID.value; - - File.mkdir((dir +/+ ".." +/+ "resources" +/+ curUID).standardizePath); - File.copy(exPath, (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - ledger = ledger.drop(-1).add(curUID); - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - player.stop; - group.set(\gate, 0); - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (dir +/+ ".." +/+ "resources" +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - -) - -( -//synthdefs -~stringModelBusArray = 4.collect({Bus.audio(s, 1)}); -~sineBusArray = 4.collect({Bus.audio(s, 1)}); -~bassBusArray = 1.collect({Bus.audio(s, 1)}); -~hdustBusArray = 1.collect({Bus.audio(s, 1)}); -~samplerBusArray = 2.collect({Bus.audio(s, 1)}); -~sBuf = Buffer.alloc(s, 10, 2); -SynthDef(\string_model, {arg freq, gate = 1, sustain, amp, dur, busIndex = 0; - var trig, exc, sig1, sig2, noHarms; - noHarms = 30; - exc = Saw.ar(freq, TRand.ar(0.5, 1, Impulse.ar(freq))) * 0.001 + Dust.ar(10000, 0.01); - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(1, 2)}) ], exc) * 0.8).softclip; - sig1 = HPF.ar(sig1, 300); - Out.ar(Select.kr(busIndex, ~stringModelBusArray), sig1 * EnvGen.kr(Env.adsr(0.3, 0.3, 0.9, 0.5, 0.9), gate, doneAction: 2)); - //Out.ar([0, 1], sig1 * EnvGen.kr(Env.asr(dur, 0.3, 1), gate, doneAction: 2)); -}).add; - -SynthDef(\sine, {arg freq, gate = 1, sustain, amp, dur, busIndex = 0; - var sig; - sig = SinOsc.ar(freq); - Out.ar(Select.kr(busIndex, ~sineBusArray), sig * EnvGen.kr(Env.asr(0.3, 0.4, 0.3), gate, timeScale: dur, doneAction: 2)); -}).add; - -SynthDef(\mixer, {arg freq, gate = 1, sustain, amp, dur, out; - var nameSpaces, sigs, hierarchicalDust; - - hierarchicalDust = ( - TIRand.kr(0, 1, Impulse.kr(100)) * - TIRand.kr(0, 1, Impulse.kr(10)) * - TIRand.kr(0, 1, Impulse.kr(1)) - ); - - sigs = [~stringModelBusArray, ~sineBusArray, ~bassBusArray, ~hdustBusArray, ~samplerBusArray].collect({arg busArray, i; - var nameSpace, sig; - nameSpace = ['string', 'sine', 'bass', 'hdust', 'sampler'][i]; - sig = busArray.collect({arg bus, c; In.ar(bus, 1) * NamedControl.kr(\ ++ nameSpace ++ '_volume_' ++ c, 1, 0.1)}); - sig = sig.collect({arg channel, c; Pan2.ar(channel, NamedControl.kr(\ ++ nameSpace ++ '_pan_' ++ c, i / (busArray.size - 1), 0.1) * 2 - 1)}); - sig = sig.collect({arg channel, c; channel * NamedControl.kr(\ ++ nameSpace ++ '_mute_' ++ c, 1, 0.1)}); - sig = Mix.ar(sig) * pow(NamedControl.kr(\ ++ nameSpace ++ '_volume_master', 1, 0.1), 2); - }); - - sigs = Mix.ar(sigs / 4); - Out.ar(0, sigs) -}).add; - -SynthDef(\bass, { - var switches, drone; - switches = {|i| Dust.kr(0.1)} ! 9; - drone = {|i| var harm = pow(2, 2 - (i / 3).trunc), amp = (1 / pow(harm, 2)); - SinOsc.ar(60 * harm + TRand.kr(-3, 3, switches[i]), 0, amp)} ! 9; - Out.ar(~bassBusArray[0], Mix.new(drone) * 0.2); -}).add; - -SynthDef(\sampler, { - Out.ar(~samplerBusArray, PlayBuf.ar(2, ~sBuf, BufRateScale.kr(~sBuf), doneAction: 2)) -}).add; - -// main routine -SynthDef(\hdust, { - arg gate = 0; - var hierarchical_dust, low_sine, high_sine, brown_noise, white_noise; - // this triggers the combinations of sources - // it is similar to the Supercollider UGen called dust but with a hierarchical structure - hierarchical_dust = ( - TIRand.kr(0, 1, Impulse.kr(100)) * - TIRand.kr(0, 1, Impulse.kr(10)) * - TIRand.kr(0, 1, Impulse.kr(1)) * - TIRand.kr(0, 1, Impulse.kr(0.1)) - ); - // adjust the multiplier at the end of each line for adjusting levels - // note with each trigger, each source has a 1 in 3 chance of sounding - low_sine = SinOsc.ar(76.midicps / 16) * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.1; - high_sine = SinOsc.ar(76.midicps * 8) * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.01; - brown_noise = BrownNoise.ar() * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.025; - white_noise = WhiteNoise.ar() * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.02; - Out.ar(~hdustBusArray[0], - ((low_sine + high_sine + brown_noise + white_noise) ) - ); -}).add; - -) - -( -var bass, hdust, sampler, mixer; -bass = Synth.tail(~group, \bass); -hdust = Synth.tail(~group, \hdust); -sampler = Synth.head(~group, \sampler); -mixer = Synth.tail(~group, \mixer); -OSCdef(\mixer, {arg msg, time, addr, port; - mixer.set((msg[1] ++ '_' ++ msg[2] ++ '_' ++ msg[3]), msg[4]) -}, \mixer); - -OSCdef(\sampler, {arg msg, time, addr, port; - msg.postln; - sampler.free; - ~sBuf.free; - ~sBuf = Buffer.read(s, msg[1].asString.postln, action: {sampler = Synth.head(~group, \sampler)}); -}, \sampler); -) - -/* old something -( -SynthDef(\test, {arg freq, gate = 1, sustain, amp, dur; - var trig, exc, sig1, sig2, noHarms, freqFinal, start, end; - noHarms = 30; - freq = WhiteNoise.ar * 3 + freq; - freqFinal = Duty.ar((1/freq), 0, freq); - trig = Changed.ar(freqFinal); - start = Demand.ar(trig, 0, Dwhite(-1, -0.75)); - end = Demand.ar(trig, 0, Dwhite(0.75, 1)); - exc = Phasor.ar(trig, (end - start) * freqFinal / SampleRate.ir, start, end, 0) * 0.001 + Dust.ar(10000, 0.01); - - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(2, 3)}) ], exc) * 0.5).softclip; - sig1 = HPF.ar(sig1, 300); - Out.ar([0, 1], sig1 * EnvGen.kr(Env.adsr(0.3, 0.3, 0.9, 0.5, 0.9), gate, doneAction: 2)); -}).add; -) -*/ - diff --git a/resources/resources_bak_2024_01_03/piece_ledger_pas/6a3f7c7c/6a3f7c7c_mus_model.json b/resources/resources_bak_2024_01_03/piece_ledger_pas/6a3f7c7c/6a3f7c7c_mus_model.json deleted file mode 100644 index 829f700..0000000 --- a/resources/resources_bak_2024_01_03/piece_ledger_pas/6a3f7c7c/6a3f7c7c_mus_model.json +++ /dev/null @@ -1,43 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ 2, -1, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 2.75 ], - [ [ [ 2, -1, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ] ], 4.5 ], - [ [ [ 2, -1, 0, 0, 0, 0 ], [ "Rest" ], [ 2, 0, 0, 0, 0, -1 ], [ 0, 0, 0, 0, 0, 0 ] ], 2.25 ], - [ [ [ 2, -1, 0, 0, 0, 0 ], [ "Rest" ], [ 1, 0, 1, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 3.5 ], - [ [ [ "Rest" ], [ "Rest" ], [ 1, 0, 1, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 2.25 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ] ], 0.125 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 3 ] - ] - ] -], -"last_changes": -[ - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], - [ [ 2, 0, 0, -1, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], - [ [ 2, -1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], - [ [ 2, -1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 2, 0, 0, 0, 0, -1 ], [ 0, 0, 0, 0, 0, 0 ] ], - [ [ 2, -1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 1, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ] -], -"cur_uid": "6a3f7c7c", -"ref_uid": "5267b235", -"order_seed": 857701, -"dur_seed": 870436, -"motifs_seed": 456020, -"entrances_probs_vals": [ 0, 0, 1.984126984127, 0, 3.0769230769231, 0, 0.64527027027027, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"passages_probs_vals": [ 0, 0, 1.984126984127, 0, 3.0769230769231, 0, 0.64527027027027, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"exits_probs_vals": [ 0, 0, 1.984126984127, 0, 3.0769230769231, 0, 0.64527027027027, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"ranges": [ [ 1419.1950464396, 2400 ], [ 1519.5046439628, 2400 ], [ 1541.7956656347, 2237 ], [ 1519.5046439628, 2053 ] ], -"passages_weights": [ 0.75, 0.75, 0.75, 0.75, 0.75 ], -"order": -[ - [ [ 0, 3 ], [ 2, 2 ], [ 1 ] ] -], -"sus_weights": [ 0.75, 0.69, 0.75 ], -"order_size": [ 1, 2 ], -"passages_size": [ 0, 2 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/piece_ledger_pas/6abf27d4/6abf27d4_code.scd b/resources/resources_bak_2024_01_03/piece_ledger_pas/6abf27d4/6abf27d4_code.scd deleted file mode 100644 index 127f295..0000000 --- a/resources/resources_bak_2024_01_03/piece_ledger_pas/6abf27d4/6abf27d4_code.scd +++ /dev/null @@ -1,808 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - pDistance.gaussCurve(1, mean, sd) -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = 1/pow(hdSum.value(voices.deepCopy.put(ins, candidate)), 2); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~msg.postln; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr; - var voices, durs, patterns, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - res = Ppar( - voices.flop.collect({arg voice; - var clumps, hdScores, freqs, fDurs; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \instrument, \test, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1) - ) - }) ++ - [ - Pbind( - \type, \osc, - \addr, addr, - //\indexPath, "/cur_play_index", - //\indexMsg, Pseq(indices, 1), - //\seqPath, "/mus_seq", - //\seqMsg, Pseq(seq, 1), - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - ); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - //res.postln; - if(res.every({arg char; char.isDecDigit}), {res = res.asInteger}); - }); - }); - res -}; - -/* -writeResources = {arg path; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = [nameSpaces, modelItems].flop.collect({arg item; - var nameSpace, modelItem, depth = 0, insert = " "; - # nameSpace, modelItem = item; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (modelItem == nil), {modelItem = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(modelItem, depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; -*/ - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - //model = File(path, "r").readAllString.parseJSON; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "passages_weights", "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - lastXChanges = if(refUID == nil, { - [initVoices.value().deepCopy]; - }, { - var file; - file = File((dir +/+ ".." +/+ "resources" +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - seq = seedFunc.value(genMotif, motifSeed).value; - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - addr.sendMsg("/generated", path, modelString); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - dict.postln; - musicChanged = (musicData != seq).postln; - - curUID = genUID.value; - - File.mkdir((dir +/+ ".." +/+ "resources" +/+ curUID).standardizePath); - File.copy(exPath, (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, {dict["motif_edited"] = "true"}); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - newLedger = File(ledgerPath, "w"); - ledger = ledger.drop(-1).add(curUID); - newLedger.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - newLedger.close; - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - player.stop; - group.set(\gate, 0); - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (dir +/+ ".." +/+ "resources" +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - }); - player = player.play - }); -}, \transport); - -) - -( -SynthDef(\test, {arg freq, gate = 1, sustain, amp, dur; - var trig, exc, sig1, sig2, noHarms; - noHarms = 30; - exc = Saw.ar(freq, TRand.ar(0.5, 1, Impulse.ar(freq))) * 0.001 + Dust.ar(10000, 0.01); - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(1, 2)}) ], exc) * 0.5).softclip; - sig1 = HPF.ar(sig1, 300); - Out.ar([0, 1], sig1 * EnvGen.kr(Env.adsr(0.3, 0.3, 0.9, 0.5, 0.9), gate, doneAction: 2)); - //Out.ar([0, 1], sig1 * EnvGen.kr(Env.asr(dur, 0.3, 1), gate, doneAction: 2)); -}).add; -) - -( -SynthDef(\test, {arg freq, gate = 1, sustain, amp, dur; - var trig, exc, sig1, sig2, noHarms, freqFinal, start, end; - noHarms = 30; - freq = WhiteNoise.ar * 3 + freq; - freqFinal = Duty.ar((1/freq), 0, freq); - trig = Changed.ar(freqFinal); - start = Demand.ar(trig, 0, Dwhite(-1, -0.75)); - end = Demand.ar(trig, 0, Dwhite(0.75, 1)); - exc = Phasor.ar(trig, (end - start) * freqFinal / SampleRate.ir, start, end, 0) * 0.001 + Dust.ar(10000, 0.01); - - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(2, 3)}) ], exc) * 0.5).softclip; - sig1 = HPF.ar(sig1, 300); - Out.ar([0, 1], sig1 * EnvGen.kr(Env.adsr(0.3, 0.3, 0.9, 0.5, 0.9), gate, doneAction: 2)); -}).add; -) - - - -"{\"a\": 1}".parseYAML["a"].asInteger; -"{\"a\": 1}".parseJSON["a"].isNumber; - -1223423434123.asHexString.toLower - -Date.getDate.rawSeconds -Date.seed.asHexString.toLower - -n = NetAddr("localhost", 8080); -n.sendMsg("/GET/#", (NetAddr.localAddr.hostname ++ ":" ++ NetAddr.localAddr.port), "/passage_probs_vals"); \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/piece_ledger_pas/6abf27d4/6abf27d4_mus_model.json b/resources/resources_bak_2024_01_03/piece_ledger_pas/6abf27d4/6abf27d4_mus_model.json deleted file mode 100644 index 818ccbc..0000000 --- a/resources/resources_bak_2024_01_03/piece_ledger_pas/6abf27d4/6abf27d4_mus_model.json +++ /dev/null @@ -1,93 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 8.375 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ -1, 0, 0, 0, 0, 1 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 1.5 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ -1, 1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 0.875 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, -1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 0.75 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ -1, 0, 1, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 0.75 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, -1, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 10.75 ] - ], - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, -1, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ] ], 0.625 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, -1, 0, 0 ], [ -1, 0, 0, 1, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ] ], 0.625 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ -1, 0, 0, 0, 0, 0 ], [ -1, 0, 0, 1, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ] ], 0.75 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, -1 ], [ -1, 0, 0, 1, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ] ], 0.875 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, -1 ], [ -1, 0, 0, 1, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], 1.25 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, -1 ], [ 0, 0, -1, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], 1.75 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, -1 ], [ 0, 0, -1, 0, 0, 0 ], [ 0, 0, 0, 0, 1, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, -1 ], [ -1, 0, 0, 0, 0, 1 ], [ 0, 0, 0, 0, 1, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ -1, 0, 1, 0, 0, 0 ], [ -1, 0, 0, 0, 0, 1 ], [ 0, 0, 0, 0, 1, 0 ] ], 1.875 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ -1, 0, 1, 0, 0, 0 ], [ -1, 1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 1, 0 ] ], 8 ] - ], - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ -1, 0, -1, 0, 1, 0 ], [ -1, 1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 1, 0 ] ], 1 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ -1, 1, -1, 0, 0, 0 ], [ -1, 1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 1, 0 ] ], 1 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, -1, 0, 0 ], [ -1, 1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 1, 0 ] ], 1.625 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ -2, 0, 0, 0, 1, 1 ], [ -1, 1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 1, 0 ] ], 0.875 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ -1, 0, 0, 0, 0, 0 ], [ -1, 1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 1, 0 ] ], 1.25 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ -2, 1, 0, 0, 1, 0 ], [ -1, 1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 1, 0 ] ], 8.625 ] - ], - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ -2, 1, 0, 0, 1, 0 ], [ -1, 1, 0, 0, 0, 0 ], [ 1, 0, -1, 0, 0, 0 ] ], 1.75 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ -2, 1, 0, 0, 1, 0 ], [ -1, 1, 0, 0, 0, 0 ], [ 1, 1, 0, -1, 0, 0 ] ], 1.875 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ -2, 1, 0, 0, 1, 0 ], [ -1, 1, 0, 0, 0, 0 ], [ 0, 1, -1, 0, 1, 0 ] ], 0.625 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ -2, 1, 0, 0, 1, 0 ], [ -1, 1, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ] ], 0.625 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ -2, 1, 0, 0, 1, 0 ], [ -1, 1, 0, 0, 0, 0 ], [ -1, 1, 0, 0, 2, 0 ] ], 9.25 ] - ], - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ -2, 1, 0, 0, 1, 0 ], [ -1, 0, 0, 0, 1, 0 ], [ -1, 1, 0, 0, 2, 0 ] ], 1.875 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ -2, 1, 0, 0, 1, 0 ], [ 0, 0, -1, 0, 0, 0 ], [ -1, 1, 0, 0, 2, 0 ] ], 1.625 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ -2, 1, 0, 0, 1, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ -1, 1, 0, 0, 2, 0 ] ], 1.625 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ -2, 1, 0, 0, 1, 0 ], [ 0, -1, 0, 0, 0, 0 ], [ -1, 1, 0, 0, 2, 0 ] ], 1 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ -2, 1, 0, 0, 1, 0 ], [ -1, 1, 0, 0, 1, -1 ], [ -1, 1, 0, 0, 2, 0 ] ], 9.75 ] - ], - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ -1, 1, 0, 0, 1, -1 ], [ -1, 1, 0, 0, 2, 0 ] ], 0 ], - [ [ [ "Rest" ], [ "Rest" ], [ -1, 1, 0, 0, 1, -1 ], [ -1, 1, 0, 0, 2, 0 ] ], 1.25 ], - [ [ [ "Rest" ], [ "Rest" ], [ -3, 1, 0, 0, 2, 1 ], [ -1, 1, 0, 0, 2, 0 ] ], 1.875 ], - [ [ [ "Rest" ], [ "Rest" ], [ -3, 2, 0, 0, 2, 0 ], [ -1, 1, 0, 0, 2, 0 ] ], 1.25 ], - [ [ [ "Rest" ], [ "Rest" ], [ -2, 1, -1, 0, 2, 0 ], [ -1, 1, 0, 0, 2, 0 ] ], 2 ], - [ [ [ "Rest" ], [ "Rest" ], [ -3, 1, 0, 1, 2, 0 ], [ -1, 1, 0, 0, 2, 0 ] ], 7.625 ], - [ [ [ "Rest" ], [ "Rest" ], [ -3, 1, 0, 1, 2, 0 ], [ "Rest" ] ], 1 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 8.375 ] - ] - ] -], -"last_changes": -[ - [ [ 0, 0, 0, 0, 0, 0 ], [ -2, 1, 0, 0, 1, 0 ], [ -1, 1, 0, 0, 1, -1 ], [ -1, 1, 0, 0, 2, 0 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ -2, 1, 0, 0, 1, 0 ], [ -3, 1, 0, 0, 2, 1 ], [ -1, 1, 0, 0, 2, 0 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ -2, 1, 0, 0, 1, 0 ], [ -3, 2, 0, 0, 2, 0 ], [ -1, 1, 0, 0, 2, 0 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ -2, 1, 0, 0, 1, 0 ], [ -2, 1, -1, 0, 2, 0 ], [ -1, 1, 0, 0, 2, 0 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ -2, 1, 0, 0, 1, 0 ], [ -3, 1, 0, 1, 2, 0 ], [ -1, 1, 0, 0, 2, 0 ] ] -], -"cur_uid": "6abf27d4", -"ref_uid": "nil", -"order_seed": 587621, -"dur_seed": 706606, -"motifs_seed": 392608, -"entrances_probs_vals": [ 0.34, 6.468253968254, 9.2857142857143, 0.5, 2, 0, 0.5, 0.24509803921569, 0.89189189189189, 0.5, 1, 0.5, 0.5, 0.8562091503268, 0.69932432432432, 1, 0.5 ], -"passages_probs_vals": [ 0.34, 6.468253968254, 9.2857142857143, 0.5, 2, 0, 0.5, 0.24509803921569, 0.89189189189189, 0.5, 1, 0.5, 0.5, 0.8562091503268, 0.69932432432432, 1, 0.5 ], -"exits_probs_vals": [ 0.34, 6.468253968254, 9.2857142857143, 0.5, 2, 0, 0.5, 0.24509803921569, 0.89189189189189, 0.5, 1, 0.5, 0.5, 0.8562091503268, 0.69932432432432, 1, 0.5 ], -"ranges": [ [ -1200, 2400 ], [ -1200, 2400 ], [ -1200, 2400 ], [ -1200, 2400 ] ], -"passages_weights": [ 0.75, 0.75, 0.75, 0.75, 0.75 ], -"order": -[ - [ [ 0, 2, 3 ], [ 1, 1, 1, 1, 1 ], [ ] ], - [ [ 0 ], [ 3, 2, 1, 1, 3, 2, 3, 2, 1, 2 ], [ ] ], - [ [ 0, 3, 2 ], [ 1, 1, 1, 1, 1, 1 ], [ ] ], - [ [ 1, 2, 0 ], [ 3, 3, 3, 3, 3 ], [ ] ], - [ [ 1, 3, 0 ], [ 2, 2, 2, 2, 2 ], [ ] ], - [ [ 3 ], [ 2, 2, 2, 2 ], [ 1, 0 ] ] -], -"sus_weights": [ 0.75, 0.75, 0.75 ], -"order_size": [ 1, 10 ], -"passages_size": [ 0, 10 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/piece_ledger_pas/6d0c2f19/6d0c2f19_code.scd b/resources/resources_bak_2024_01_03/piece_ledger_pas/6d0c2f19/6d0c2f19_code.scd deleted file mode 100644 index ab370bd..0000000 --- a/resources/resources_bak_2024_01_03/piece_ledger_pas/6d0c2f19/6d0c2f19_code.scd +++ /dev/null @@ -1,887 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - pDistance.gaussCurve(1, mean, sd) -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = 1/pow(hdSum.value(voices.deepCopy.put(ins, candidate)), 2); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~msg.postln; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - //res.postln; - if(res.every({arg char; char.isDecDigit}), {res = res.asInteger}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file; - file = File(path, "w"); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "passages_weights", "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - lastXChanges = if(refUID == nil, { - [initVoices.value().deepCopy]; - }, { - var file; - file = File((dir +/+ ".." +/+ "resources" +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - seq = seedFunc.value(genMotif, motifSeed).value; - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - - curUID = genUID.value; - - File.mkdir((dir +/+ ".." +/+ "resources" +/+ curUID).standardizePath); - File.copy(exPath, (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - ledger = ledger.drop(-1).add(curUID); - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - player.stop; - group.set(\gate, 0); - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (dir +/+ ".." +/+ "resources" +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - -) - -( -//synthdefs -~stringModelBusArray = 4.collect({Bus.audio(s, 1)}); -~sineBusArray = 4.collect({Bus.audio(s, 1)}); -~bassBusArray = 1.collect({Bus.audio(s, 1)}); -~hdustBusArray = 1.collect({Bus.audio(s, 1)}); -~samplerBusArray = 2.collect({Bus.audio(s, 1)}); -~sBuf = Buffer.alloc(s, 10, 2); -SynthDef(\string_model, {arg freq, gate = 1, sustain, amp, dur, busIndex = 0; - var trig, exc, sig1, sig2, noHarms; - noHarms = 30; - exc = Saw.ar(freq, TRand.ar(0.5, 1, Impulse.ar(freq))) * 0.001 + Dust.ar(10000, 0.01); - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(1, 2)}) ], exc) * 0.8).softclip; - sig1 = HPF.ar(sig1, 300); - Out.ar(Select.kr(busIndex, ~stringModelBusArray), sig1 * EnvGen.kr(Env.adsr(0.3, 0.3, 0.9, 0.5, 0.9), gate, doneAction: 2)); - //Out.ar([0, 1], sig1 * EnvGen.kr(Env.asr(dur, 0.3, 1), gate, doneAction: 2)); -}).add; - -SynthDef(\sine, {arg freq, gate = 1, sustain, amp, dur, busIndex = 0; - var sig; - sig = SinOsc.ar(freq); - Out.ar(Select.kr(busIndex, ~sineBusArray), sig * EnvGen.kr(Env.asr(0.3, 0.4, 0.3), gate, timeScale: dur, doneAction: 2)); -}).add; - -SynthDef(\mixer, {arg freq, gate = 1, sustain, amp, dur, out; - var nameSpaces, sigs, hierarchicalDust; - - hierarchicalDust = ( - TIRand.kr(0, 1, Impulse.kr(100)) * - TIRand.kr(0, 1, Impulse.kr(10)) * - TIRand.kr(0, 1, Impulse.kr(1)) - ); - - sigs = [~stringModelBusArray, ~sineBusArray, ~bassBusArray, ~hdustBusArray, ~samplerBusArray].collect({arg busArray, i; - var nameSpace, sig; - nameSpace = ['string', 'sine', 'bass', 'hdust', 'sampler'][i]; - sig = busArray.collect({arg bus, c; In.ar(bus, 1) * NamedControl.kr(\ ++ nameSpace ++ '_volume_' ++ c, 1, 0.1)}); - sig = sig.collect({arg channel, c; Pan2.ar(channel, NamedControl.kr(\ ++ nameSpace ++ '_pan_' ++ c, i / (busArray.size - 1), 0.1) * 2 - 1)}); - sig = sig.collect({arg channel, c; channel * NamedControl.kr(\ ++ nameSpace ++ '_mute_' ++ c, 1, 0.1)}); - sig = Mix.ar(sig) * pow(NamedControl.kr(\ ++ nameSpace ++ '_volume_master', 1, 0.1), 2); - }); - - sigs = Mix.ar(sigs / 4); - Out.ar(0, sigs) -}).add; - -SynthDef(\bass, { - var switches, drone; - switches = {|i| Dust.kr(0.1)} ! 9; - drone = {|i| var harm = pow(2, 2 - (i / 3).trunc), amp = (1 / pow(harm, 2)); - SinOsc.ar(60 * harm + TRand.kr(-3, 3, switches[i]), 0, amp)} ! 9; - Out.ar(~bassBusArray[0], Mix.new(drone) * 0.2); -}).add; - -SynthDef(\sampler, { - Out.ar(~samplerBusArray, PlayBuf.ar(2, ~sBuf, BufRateScale.kr(~sBuf), doneAction: 2)) -}).add; - -// main routine -SynthDef(\hdust, { - arg gate = 0; - var hierarchical_dust, low_sine, high_sine, brown_noise, white_noise; - // this triggers the combinations of sources - // it is similar to the Supercollider UGen called dust but with a hierarchical structure - hierarchical_dust = ( - TIRand.kr(0, 1, Impulse.kr(100)) * - TIRand.kr(0, 1, Impulse.kr(10)) * - TIRand.kr(0, 1, Impulse.kr(1)) * - TIRand.kr(0, 1, Impulse.kr(0.1)) - ); - // adjust the multiplier at the end of each line for adjusting levels - // note with each trigger, each source has a 1 in 3 chance of sounding - low_sine = SinOsc.ar(76.midicps / 16) * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.1; - high_sine = SinOsc.ar(76.midicps * 8) * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.01; - brown_noise = BrownNoise.ar() * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.025; - white_noise = WhiteNoise.ar() * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.02; - Out.ar(~hdustBusArray[0], - ((low_sine + high_sine + brown_noise + white_noise) ) - ); -}).add; - -) - -( -var bass, hdust, sampler, mixer; -bass = Synth.tail(~group, \bass); -hdust = Synth.tail(~group, \hdust); -sampler = Synth.head(~group, \sampler); -mixer = Synth.tail(~group, \mixer); -OSCdef(\mixer, {arg msg, time, addr, port; - mixer.set((msg[1] ++ '_' ++ msg[2] ++ '_' ++ msg[3]), msg[4]) -}, \mixer); - -OSCdef(\sampler, {arg msg, time, addr, port; - msg.postln; - sampler.free; - ~sBuf.free; - ~sBuf = Buffer.read(s, msg[1].asString.postln, action: {sampler = Synth.head(~group, \sampler)}); -}, \sampler); -) - -/* old something -( -SynthDef(\test, {arg freq, gate = 1, sustain, amp, dur; - var trig, exc, sig1, sig2, noHarms, freqFinal, start, end; - noHarms = 30; - freq = WhiteNoise.ar * 3 + freq; - freqFinal = Duty.ar((1/freq), 0, freq); - trig = Changed.ar(freqFinal); - start = Demand.ar(trig, 0, Dwhite(-1, -0.75)); - end = Demand.ar(trig, 0, Dwhite(0.75, 1)); - exc = Phasor.ar(trig, (end - start) * freqFinal / SampleRate.ir, start, end, 0) * 0.001 + Dust.ar(10000, 0.01); - - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(2, 3)}) ], exc) * 0.5).softclip; - sig1 = HPF.ar(sig1, 300); - Out.ar([0, 1], sig1 * EnvGen.kr(Env.adsr(0.3, 0.3, 0.9, 0.5, 0.9), gate, doneAction: 2)); -}).add; -) -*/ - diff --git a/resources/resources_bak_2024_01_03/piece_ledger_pas/6d0c2f19/6d0c2f19_mus_model.json b/resources/resources_bak_2024_01_03/piece_ledger_pas/6d0c2f19/6d0c2f19_mus_model.json deleted file mode 100644 index a36e0d1..0000000 --- a/resources/resources_bak_2024_01_03/piece_ledger_pas/6d0c2f19/6d0c2f19_mus_model.json +++ /dev/null @@ -1,44 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ 2, 0, 0, -1, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ], [ 2, 0, 0, -1, 0, 0 ] ], 0.375 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ "Rest" ], [ 2, 0, 0, -1, 0, 0 ] ], 4.875 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ], [ 2, 0, 0, -1, 0, 0 ] ], 2.375 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ], [ "Rest" ] ], 0.375 ], - [ [ [ "Rest" ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ], [ "Rest" ] ], 0.375 ], - [ [ [ "Rest" ], [ 1, -1, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ] ], 0 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 3.875 ] - ] - ] -], -"last_changes": -[ - [ [ 0, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ 0, 0, 0, 1, 0, 0 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ 1, -1, 0, 0, 0, 1 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ 2, 0, 0, -1, 0, 0 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ], [ 2, 0, 0, -1, 0, 0 ] ] -], -"cur_uid": "6d0c2f19", -"ref_uid": "7e170ef8", -"order_seed": 861383, -"dur_seed": 654405, -"motifs_seed": 513928, -"entrances_probs_vals": [ 0.75, 1.67, 4.8015873015873, 0, 0.5, 0.20725388601036, 0.68581081081081, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"passages_probs_vals": [ 0.75, 1.67, 4.8015873015873, 0, 0.5, 0.20725388601036, 0.68581081081081, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"exits_probs_vals": [ 0.75, 1.87, 5.1984126984127, 0, 0.5, 0.20725388601036, 0.68581081081081, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"ranges": [ [ -384, 2400 ], [ -507, 2400 ], [ -282, 2237 ], [ -1200, 2053 ] ], -"passages_weights": [ 0.75, 0.75, 0.75, 0.75, 0.75 ], -"order": -[ - [ [ 3, 0, 1 ], [ 2 ], [ ] ] -], -"sus_weights": [ 0.75, 0.69, 0.75 ], -"order_size": [ 1, 2 ], -"passages_size": [ 0, 1 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/piece_ledger_pas/6d743c5c/6d743c5c_code.scd b/resources/resources_bak_2024_01_03/piece_ledger_pas/6d743c5c/6d743c5c_code.scd deleted file mode 100644 index 1b05aa0..0000000 --- a/resources/resources_bak_2024_01_03/piece_ledger_pas/6d743c5c/6d743c5c_code.scd +++ /dev/null @@ -1,881 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - pDistance.gaussCurve(1, mean, sd) -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = 1/pow(hdSum.value(voices.deepCopy.put(ins, candidate)), 2); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~msg.postln; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - //res.postln; - if(res.every({arg char; char.isDecDigit}), {res = res.asInteger}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file; - file = File(path, "w"); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "passages_weights", "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - lastXChanges = if(refUID == nil, { - [initVoices.value().deepCopy]; - }, { - var file; - file = File((dir +/+ ".." +/+ "resources" +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - seq = seedFunc.value(genMotif, motifSeed).value; - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - addr.sendMsg("/generated", path, modelString); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - - curUID = genUID.value; - - File.mkdir((dir +/+ ".." +/+ "resources" +/+ curUID).standardizePath); - File.copy(exPath, (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - ledger = ledger.drop(-1).add(curUID); - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - player.stop; - group.set(\gate, 0); - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (dir +/+ ".." +/+ "resources" +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - -) - -( -//synthdefs -~stringModelBusArray = 4.collect({Bus.audio(s, 1)}); -~sineBusArray = 4.collect({Bus.audio(s, 1)}); -~bassBusArray = 1.collect({Bus.audio(s, 1)}); -~hdustBusArray = 1.collect({Bus.audio(s, 1)}); -~samplerBusArray = 2.collect({Bus.audio(s, 1)}); -~sBuf = Buffer.alloc(s, 10, 2); -SynthDef(\string_model, {arg freq, gate = 1, sustain, amp, dur, busIndex = 0; - var trig, exc, sig1, sig2, noHarms; - noHarms = 30; - exc = Saw.ar(freq, TRand.ar(0.5, 1, Impulse.ar(freq))) * 0.001 + Dust.ar(10000, 0.01); - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(1, 2)}) ], exc) * 0.5).softclip; - sig1 = HPF.ar(sig1, 300); - Out.ar(Select.kr(busIndex, ~stringModelBusArray), sig1 * EnvGen.kr(Env.asr(0.3, 0.3, 0.9, 0.5, 0.9), gate, doneAction: 2)); - //Out.ar([0, 1], sig1 * EnvGen.kr(Env.asr(dur, 0.3, 1), gate, doneAction: 2)); -}).add; - -SynthDef(\sine, {arg freq, gate = 1, sustain, amp, dur, busIndex = 0; - var sig; - sig = SinOsc.ar(freq); - Out.ar(Select.kr(busIndex, ~sineBusArray), sig * EnvGen.kr(Env.asr(0.3, 0.4, 0.3), gate, timeScale: dur, doneAction: 2)); -}).add; - -SynthDef(\mixer, {arg freq, gate = 1, sustain, amp, dur, out; - var nameSpaces, sigs; - - sigs = [~stringModelBusArray, ~sineBusArray, ~bassBusArray, ~hdustBusArray, ~samplerBusArray].collect({arg busArray, i; - var nameSpace, sig; - nameSpace = ['string', 'sine', 'bass', 'hdust', 'sampler'][i]; - sig = busArray.collect({arg bus, c; In.ar(bus, 1) * NamedControl.kr(\ ++ nameSpace ++ '_volume_' ++ c, 1, 0.1)}); - sig = sig.collect({arg channel, c; Pan2.ar(channel, NamedControl.kr(\ ++ nameSpace ++ '_pan_' ++ c, i / (busArray.size - 1), 0.1) * 2 - 1)}); - sig = sig.collect({arg channel, c; channel * NamedControl.kr(\ ++ nameSpace ++ '_mute_' ++ c, 1, 0.1)}); - sig = Mix.ar(sig) * NamedControl.kr(\ ++ nameSpace ++ '_volume_master', 1, 0.1); - }); - - sigs = Mix.ar(sigs / 4); - Out.ar(0, sigs) -}).add; - -SynthDef(\bass, { - var switches, drone; - switches = {|i| Dust.kr(0.1)} ! 9; - drone = {|i| var harm = pow(2, 2 - (i / 3).trunc), amp = (1 / pow(harm, 2)); - SinOsc.ar(60 * harm + TRand.kr(-3, 3, switches[i]), 0, amp)} ! 9; - Out.ar(~bassBusArray[0], Mix.new(drone) * 0.2); -}).add; - -SynthDef(\sampler, { - Out.ar(~samplerBusArray, PlayBuf.ar(2, ~sBuf, BufRateScale.kr(~sBuf), doneAction: 2)) -}).add; - -// main routine -SynthDef(\hdust, { - arg gate = 0; - var hierarchical_dust, low_sine, high_sine, brown_noise, white_noise; - // this triggers the combinations of sources - // it is similar to the Supercollider UGen called dust but with a hierarchical structure - hierarchical_dust = ( - TIRand.kr(0, 1, Impulse.kr(100)) * - TIRand.kr(0, 1, Impulse.kr(10)) * - TIRand.kr(0, 1, Impulse.kr(1)) * - TIRand.kr(0, 1, Impulse.kr(0.1)) - ); - // adjust the multiplier at the end of each line for adjusting levels - // note with each trigger, each source has a 1 in 3 chance of sounding - low_sine = SinOsc.ar(76.midicps / 16) * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.1; - high_sine = SinOsc.ar(76.midicps * 8) * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.01; - brown_noise = BrownNoise.ar() * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.025; - white_noise = WhiteNoise.ar() * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.02; - Out.ar(~hdustBusArray[0], - ((low_sine + high_sine + brown_noise + white_noise) ) - ); -}).add; - -) - -( -var bass, hdust, sampler, mixer; -bass = Synth.tail(~group, \bass); -hdust = Synth.tail(~group, \hdust); -sampler = Synth.head(~group, \sampler); -mixer = Synth.tail(~group, \mixer); -OSCdef(\mixer, {arg msg, time, addr, port; - mixer.set((msg[1] ++ '_' ++ msg[2] ++ '_' ++ msg[3]), msg[4]) -}, \mixer); - -OSCdef(\sampler, {arg msg, time, addr, port; - msg.postln; - sampler.free; - ~sBuf.free; - ~sBuf = Buffer.read(s, msg[1].asString.postln, action: {sampler = Synth.head(~group, \sampler)}); -}, \sampler); -) - -/* old something -( -SynthDef(\test, {arg freq, gate = 1, sustain, amp, dur; - var trig, exc, sig1, sig2, noHarms, freqFinal, start, end; - noHarms = 30; - freq = WhiteNoise.ar * 3 + freq; - freqFinal = Duty.ar((1/freq), 0, freq); - trig = Changed.ar(freqFinal); - start = Demand.ar(trig, 0, Dwhite(-1, -0.75)); - end = Demand.ar(trig, 0, Dwhite(0.75, 1)); - exc = Phasor.ar(trig, (end - start) * freqFinal / SampleRate.ir, start, end, 0) * 0.001 + Dust.ar(10000, 0.01); - - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(2, 3)}) ], exc) * 0.5).softclip; - sig1 = HPF.ar(sig1, 300); - Out.ar([0, 1], sig1 * EnvGen.kr(Env.adsr(0.3, 0.3, 0.9, 0.5, 0.9), gate, doneAction: 2)); -}).add; -) -*/ - diff --git a/resources/resources_bak_2024_01_03/piece_ledger_pas/6d743c5c/6d743c5c_mus_model.json b/resources/resources_bak_2024_01_03/piece_ledger_pas/6d743c5c/6d743c5c_mus_model.json deleted file mode 100644 index b1611ee..0000000 --- a/resources/resources_bak_2024_01_03/piece_ledger_pas/6d743c5c/6d743c5c_mus_model.json +++ /dev/null @@ -1,41 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 1.375 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ] ], 0.75 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ] ], 1.875 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 2, 0, 0, 0, 0, -1 ] ], 3.375 ], - [ [ [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 2, 0, 0, 0, 0, -1 ] ], 0.25 ], - [ [ [ "Rest" ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ 2, 0, 0, 0, 0, -1 ] ], 2 ], - [ [ [ "Rest" ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ] ], 2.25 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 2.125 ] - ] - ] -], -"last_changes": -[ - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 2, 0, 0, 0, 0, -1 ] ] -], -"cur_uid": "6d743c5c", -"ref_uid": "nil", -"order_seed": 232987, -"dur_seed": 390795, -"motifs_seed": 257319, -"entrances_probs_vals": [ 0, 0, 1.984126984127, 0, 3.0769230769231, 0, 0.64527027027027, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"passages_probs_vals": [ 0, 0, 1.984126984127, 0, 3.0769230769231, 0, 0.64527027027027, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"exits_probs_vals": [ 0, 0, 1.984126984127, 0, 3.0769230769231, 0, 0.64527027027027, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"ranges": [ [ 1419.1950464396, 2400 ], [ 1519.5046439628, 2400 ], [ 1541.7956656347, 2237 ], [ 1519.5046439628, 2053 ] ], -"passages_weights": [ 0.75, 0.75, 0.75, 0.75, 0.75 ], -"order": -[ - [ [ 0, 1, 2 ], [ 3 ], [ ] ] -], -"sus_weights": [ 0.75, 0.69, 0.75 ], -"order_size": [ 1, 2 ], -"passages_size": [ 0, 2 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/piece_ledger_pas/6f1305ed/6f1305ed_code.scd b/resources/resources_bak_2024_01_03/piece_ledger_pas/6f1305ed/6f1305ed_code.scd deleted file mode 100644 index 830a192..0000000 --- a/resources/resources_bak_2024_01_03/piece_ledger_pas/6f1305ed/6f1305ed_code.scd +++ /dev/null @@ -1,894 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - pDistance.gaussCurve(1, mean, sd) -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = 1/pow(hdSum.value(voices.deepCopy.put(ins, candidate)), 2); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~msg.postln; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - //res.postln; - if(res.every({arg char; char.isDecDigit}), {res = res.asInteger}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file; - file = File(path, "w"); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "passages_weights", "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((dir +/+ ".." +/+ "resources" +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - - curUID = genUID.value; - - File.mkdir((dir +/+ ".." +/+ "resources" +/+ curUID).standardizePath); - File.copy(exPath, (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - ledger = ledger.drop(-1).add(curUID); - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - player.stop; - group.set(\gate, 0); - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (dir +/+ ".." +/+ "resources" +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - -) - -( -//synthdefs -~stringModelBusArray = 4.collect({Bus.audio(s, 1)}); -~sineBusArray = 4.collect({Bus.audio(s, 1)}); -~bassBusArray = 1.collect({Bus.audio(s, 1)}); -~hdustBusArray = 1.collect({Bus.audio(s, 1)}); -~samplerBusArray = 2.collect({Bus.audio(s, 1)}); -~sBuf = Buffer.alloc(s, 10, 2); -SynthDef(\string_model, {arg freq, gate = 1, sustain, amp, dur, busIndex = 0; - var trig, exc, sig1, sig2, noHarms; - noHarms = 30; - exc = Saw.ar(freq, TRand.ar(0.5, 1, Impulse.ar(freq))) * 0.001 + Dust.ar(10000, 0.01); - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(1, 2)}) ], exc) * 0.8).softclip; - sig1 = HPF.ar(sig1, 300); - Out.ar(Select.kr(busIndex, ~stringModelBusArray), sig1 * EnvGen.kr(Env.adsr(0.3, 0.3, 0.9, 0.5, 0.9), gate, doneAction: 2)); - //Out.ar([0, 1], sig1 * EnvGen.kr(Env.asr(dur, 0.3, 1), gate, doneAction: 2)); -}).add; - -SynthDef(\sine, {arg freq, gate = 1, sustain, amp, dur, busIndex = 0; - var sig; - sig = SinOsc.ar(freq); - Out.ar(Select.kr(busIndex, ~sineBusArray), sig * EnvGen.kr(Env.asr(0.3, 0.4, 0.3), gate, timeScale: dur, doneAction: 2)); -}).add; - -SynthDef(\mixer, {arg freq, gate = 1, sustain, amp, dur, out; - var nameSpaces, sigs, hierarchicalDust; - - hierarchicalDust = ( - TIRand.kr(0, 1, Impulse.kr(100)) * - TIRand.kr(0, 1, Impulse.kr(10)) * - TIRand.kr(0, 1, Impulse.kr(1)) - ); - - sigs = [~stringModelBusArray, ~sineBusArray, ~bassBusArray, ~hdustBusArray, ~samplerBusArray].collect({arg busArray, i; - var nameSpace, sig; - nameSpace = ['string', 'sine', 'bass', 'hdust', 'sampler'][i]; - sig = busArray.collect({arg bus, c; In.ar(bus, 1) * NamedControl.kr(\ ++ nameSpace ++ '_volume_' ++ c, 1, 0.1)}); - sig = sig.collect({arg channel, c; Pan2.ar(channel, NamedControl.kr(\ ++ nameSpace ++ '_pan_' ++ c, i / (busArray.size - 1), 0.1) * 2 - 1)}); - sig = sig.collect({arg channel, c; channel * NamedControl.kr(\ ++ nameSpace ++ '_mute_' ++ c, 1, 0.1)}); - sig = Mix.ar(sig) * pow(NamedControl.kr(\ ++ nameSpace ++ '_volume_master', 1, 0.1), 2); - }); - - sigs = Mix.ar(sigs / 4); - Out.ar(0, sigs) -}).add; - -SynthDef(\bass, { - var switches, drone; - switches = {|i| Dust.kr(0.1)} ! 9; - drone = {|i| var harm = pow(2, 2 - (i / 3).trunc), amp = (1 / pow(harm, 2)); - SinOsc.ar(60 * harm + TRand.kr(-3, 3, switches[i]), 0, amp)} ! 9; - Out.ar(~bassBusArray[0], Mix.new(drone) * 0.2); -}).add; - -SynthDef(\sampler, { - Out.ar(~samplerBusArray, PlayBuf.ar(2, ~sBuf, BufRateScale.kr(~sBuf), doneAction: 2)) -}).add; - -// main routine -SynthDef(\hdust, { - arg gate = 0; - var hierarchical_dust, low_sine, high_sine, brown_noise, white_noise; - // this triggers the combinations of sources - // it is similar to the Supercollider UGen called dust but with a hierarchical structure - hierarchical_dust = ( - TIRand.kr(0, 1, Impulse.kr(100)) * - TIRand.kr(0, 1, Impulse.kr(10)) * - TIRand.kr(0, 1, Impulse.kr(1)) * - TIRand.kr(0, 1, Impulse.kr(0.1)) - ); - // adjust the multiplier at the end of each line for adjusting levels - // note with each trigger, each source has a 1 in 3 chance of sounding - low_sine = SinOsc.ar(76.midicps / 16) * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.1; - high_sine = SinOsc.ar(76.midicps * 8) * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.01; - brown_noise = BrownNoise.ar() * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.025; - white_noise = WhiteNoise.ar() * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.02; - Out.ar(~hdustBusArray[0], - ((low_sine + high_sine + brown_noise + white_noise) ) - ); -}).add; - -) - -( -var bass, hdust, sampler, mixer; -bass = Synth.tail(~group, \bass); -hdust = Synth.tail(~group, \hdust); -sampler = Synth.head(~group, \sampler); -mixer = Synth.tail(~group, \mixer); -OSCdef(\mixer, {arg msg, time, addr, port; - mixer.set((msg[1] ++ '_' ++ msg[2] ++ '_' ++ msg[3]), msg[4]) -}, \mixer); - -OSCdef(\sampler, {arg msg, time, addr, port; - msg.postln; - sampler.free; - ~sBuf.free; - ~sBuf = Buffer.read(s, msg[1].asString.postln, action: {sampler = Synth.head(~group, \sampler)}); -}, \sampler); -) - -/* old something -( -SynthDef(\test, {arg freq, gate = 1, sustain, amp, dur; - var trig, exc, sig1, sig2, noHarms, freqFinal, start, end; - noHarms = 30; - freq = WhiteNoise.ar * 3 + freq; - freqFinal = Duty.ar((1/freq), 0, freq); - trig = Changed.ar(freqFinal); - start = Demand.ar(trig, 0, Dwhite(-1, -0.75)); - end = Demand.ar(trig, 0, Dwhite(0.75, 1)); - exc = Phasor.ar(trig, (end - start) * freqFinal / SampleRate.ir, start, end, 0) * 0.001 + Dust.ar(10000, 0.01); - - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(2, 3)}) ], exc) * 0.5).softclip; - sig1 = HPF.ar(sig1, 300); - Out.ar([0, 1], sig1 * EnvGen.kr(Env.adsr(0.3, 0.3, 0.9, 0.5, 0.9), gate, doneAction: 2)); -}).add; -) -*/ - diff --git a/resources/resources_bak_2024_01_03/piece_ledger_pas/6f1305ed/6f1305ed_mus_model.json b/resources/resources_bak_2024_01_03/piece_ledger_pas/6f1305ed/6f1305ed_mus_model.json deleted file mode 100644 index 89155f1..0000000 --- a/resources/resources_bak_2024_01_03/piece_ledger_pas/6f1305ed/6f1305ed_mus_model.json +++ /dev/null @@ -1,51 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ 0, 0, 0, 0, 1, -1 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 1 ], - [ [ [ 0, 0, 0, 0, 1, -1 ], [ 1, -1, 0, 0, 1, -1 ], [ "Rest" ], [ "Rest" ] ], 2.875 ], - [ [ [ 0, 0, 0, 0, 1, -1 ], [ 1, -1, 0, 0, 1, -1 ], [ "Rest" ], [ 2, -1, 0, 0, 1, -1 ] ], 3.75 ] - ], - [ - [ [ [ 0, 0, 0, 0, 1, -1 ], [ 1, -1, 0, 0, 1, -1 ], [ 2, 0, 0, 0, 1, -1 ], [ 2, -1, 0, 0, 1, -1 ] ], 2.875 ], - [ [ [ 0, 0, 0, 0, 1, -1 ], [ 0, 0, 1, 0, 1, -1 ], [ 2, 0, 0, 0, 1, -1 ], [ 2, -1, 0, 0, 1, -1 ] ], 1.75 ], - [ [ [ 0, 0, 0, 0, 1, -1 ], [ 0, 0, 1, 0, 1, -1 ], [ 2, 0, 0, 0, 1, -1 ], [ 1, 1, 0, 0, 1, -1 ] ], 1.875 ], - [ [ [ -1, 0, 0, 1, 1, -1 ], [ 0, 0, 1, 0, 1, -1 ], [ 2, 0, 0, 0, 1, -1 ], [ 1, 1, 0, 0, 1, -1 ] ], 1.75 ], - [ [ [ -1, 0, 0, 1, 1, -1 ], [ 1, 0, 0, -1, 1, -1 ], [ 2, 0, 0, 0, 1, -1 ], [ 1, 1, 0, 0, 1, -1 ] ], 2.75 ], - [ [ [ -1, 0, 0, 1, 1, -1 ], [ 1, 0, 0, -1, 1, -1 ], [ 2, 0, 0, 0, 1, -1 ], [ "Rest" ] ], 0.375 ], - [ [ [ -1, 0, 0, 1, 1, -1 ], [ 1, 0, 0, -1, 1, -1 ], [ "Rest" ], [ "Rest" ] ], 0.625 ], - [ [ [ "Rest" ], [ 1, 0, 0, -1, 1, -1 ], [ "Rest" ], [ "Rest" ] ], 0.5 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 4 ] - ] - ] -], -"last_changes": -[ - [ [ 0, 0, 0, 0, 1, -1 ], [ 1, -1, 0, 0, 1, -1 ], [ 2, 0, 0, 0, 1, -1 ], [ 2, -1, 0, 0, 1, -1 ] ], - [ [ 0, 0, 0, 0, 1, -1 ], [ 0, 0, 1, 0, 1, -1 ], [ 2, 0, 0, 0, 1, -1 ], [ 2, -1, 0, 0, 1, -1 ] ], - [ [ 0, 0, 0, 0, 1, -1 ], [ 0, 0, 1, 0, 1, -1 ], [ 2, 0, 0, 0, 1, -1 ], [ 1, 1, 0, 0, 1, -1 ] ], - [ [ -1, 0, 0, 1, 1, -1 ], [ 0, 0, 1, 0, 1, -1 ], [ 2, 0, 0, 0, 1, -1 ], [ 1, 1, 0, 0, 1, -1 ] ], - [ [ -1, 0, 0, 1, 1, -1 ], [ 1, 0, 0, -1, 1, -1 ], [ 2, 0, 0, 0, 1, -1 ], [ 1, 1, 0, 0, 1, -1 ] ] -], -"cur_uid": "6f1305ed", -"ref_uid": "tmp", -"order_seed": 414624, -"dur_seed": 257250, -"motifs_seed": 938764, -"entrances_probs_vals": [ 0, 1.11, 3.2936507936508, 0.85, 2.1153846153846, 0.20725388601036, 0.68581081081081, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"passages_probs_vals": [ 0, 1.11, 3.2936507936508, 0.85, 2.1153846153846, 0.20725388601036, 0.68581081081081, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"exits_probs_vals": [ 0, 1.83, 4.8809523809524, 0.24725274725275, 1.15, 0.20725388601036, 0.68581081081081, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"ranges": [ [ -1100, 460.68111455108 ], [ -507, 1084.8297213622 ], [ 884.21052631579, 2237 ], [ 1040.2476780186, 2053 ] ], -"passages_weights": [ 0.75, 0.75, 0.75, 0.75, 0.75 ], -"order": -[ - [ [ 0, 1 ], [ 3 ], [ 2 ] ], - [ [ 2 ], [ 1, 3, 0, 1 ], [ ] ] -], -"sus_weights": [ 0.73, 0.23, 0 ], -"order_size": [ 2, 2 ], -"passages_size": [ 0, 2 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/piece_ledger_pas/703e109b/703e109b_code.scd b/resources/resources_bak_2024_01_03/piece_ledger_pas/703e109b/703e109b_code.scd deleted file mode 100644 index 3ec9b1a..0000000 --- a/resources/resources_bak_2024_01_03/piece_ledger_pas/703e109b/703e109b_code.scd +++ /dev/null @@ -1,907 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - pDistance.gaussCurve(1, mean, sd) -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = 1/pow(hdSum.value(voices.deepCopy.put(ins, candidate)), 2); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~msg.postln; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1, 3)}, {rrand(0.3, 0.5)}); - }); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - //res.postln; - if(res.every({arg char; char.isDecDigit}), {res = res.asInteger}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file; - file = File(path, "w"); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "passages_weights", "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((dir +/+ ".." +/+ "resources" +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - - curUID = genUID.value; - - File.mkdir((dir +/+ ".." +/+ "resources" +/+ curUID).standardizePath); - File.copy(exPath, (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - ledger = ledger.drop(-1).add(curUID); - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (dir +/+ ".." +/+ "resources" +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - -) - -( -//synthdefs -~stringModelBusArray = 4.collect({Bus.audio(s, 1)}); -~sineBusArray = 4.collect({Bus.audio(s, 1)}); -~bassBusArray = 1.collect({Bus.audio(s, 1)}); -~hdustBusArray = 1.collect({Bus.audio(s, 1)}); -~samplerBusArray = 2.collect({Bus.audio(s, 1)}); -~sBuf = Buffer.alloc(s, 10, 2); -SynthDef(\string_model, {arg freq, gate = 1, sustain, amp, dur, attack, release = 1, busIndex = 0; - var trig, exc, sig1, sig2, noHarms; - noHarms = rrand(20, 40); - exc = Saw.ar(freq, TRand.ar(0.5, 1, Impulse.ar(freq))) * 0.001 + Dust.ar(10000, 0.01); - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(1, 2)}) ], exc) * 0.8).softclip; - //sig1 = HPF.ar(sig1, 300); - Out.ar(Select.kr(busIndex, ~stringModelBusArray), sig1 * amp * EnvGen.kr(Env.adsr(attack, 0.3, 0.9, release, 0.9, -3), gate, doneAction: 2)); - //Out.ar([0, 1], sig1 * EnvGen.kr(Env.asr(dur, 0.3, 1), gate, doneAction: 2)); -}).add; - -SynthDef(\sine, {arg freq, gate = 1, sustain, amp, dur, busIndex = 0; - var sig; - sig = SinOsc.ar(freq); - Out.ar(Select.kr(busIndex, ~sineBusArray), sig * EnvGen.kr(Env.asr(0.3, 0.4, 0.3), gate, timeScale: dur, doneAction: 2)); - //Out.ar(Select.kr(busIndex, ~sineBusArray), sig * EnvGen.kr(Env.sine(dur), gate, doneAction: 2)); -}).add; - -SynthDef(\mixer, {arg freq, gate = 1, sustain, amp, dur, out; - var nameSpaces, sigs, hierarchicalDust; - - hierarchicalDust = ( - TIRand.kr(0, 1, Impulse.kr(100)) * - TIRand.kr(0, 1, Impulse.kr(10)) * - TIRand.kr(0, 1, Impulse.kr(1)) - ); - - sigs = [~stringModelBusArray, ~sineBusArray, ~bassBusArray, ~hdustBusArray, ~samplerBusArray].collect({arg busArray, i; - var nameSpace, sig; - nameSpace = ['string', 'sine', 'bass', 'hdust', 'sampler'][i]; - sig = busArray.collect({arg bus, c; In.ar(bus, 1) * NamedControl.kr(\ ++ nameSpace ++ '_volume_' ++ c, 1, 0.1)}); - sig = sig.collect({arg channel, c; Pan2.ar(channel, NamedControl.kr(\ ++ nameSpace ++ '_pan_' ++ c, i / (busArray.size - 1), 0.1) * 2 - 1)}); - sig = sig.collect({arg channel, c; channel * NamedControl.kr(\ ++ nameSpace ++ '_mute_' ++ c, 1, 0.1)}); - sig = Mix.ar(sig) * pow(NamedControl.kr(\ ++ nameSpace ++ '_volume_master', 1, 0.1), 2); - }); - - sigs = Mix.ar(sigs / 4); - Out.ar(0, sigs) -}).add; - -SynthDef(\bass, { - var switches, drone; - switches = {|i| Dust.kr(0.1)} ! 9; - drone = {|i| var harm = pow(2, 2 - (i / 3).trunc), amp = (1 / pow(harm, 2)); - SinOsc.ar(60 * harm + TRand.kr(-3, 3, switches[i]), 0, amp)} ! 9; - Out.ar(~bassBusArray[0], Mix.new(drone) * 0.2); -}).add; - -SynthDef(\sampler, { - Out.ar(~samplerBusArray, PlayBuf.ar(2, ~sBuf, BufRateScale.kr(~sBuf), doneAction: 2)) -}).add; - -// main routine -SynthDef(\hdust, { - arg gate = 0; - var hierarchical_dust, low_sine, high_sine, brown_noise, white_noise; - // this triggers the combinations of sources - // it is similar to the Supercollider UGen called dust but with a hierarchical structure - hierarchical_dust = ( - TIRand.kr(0, 1, Impulse.kr(100)) * - TIRand.kr(0, 1, Impulse.kr(10)) * - TIRand.kr(0, 1, Impulse.kr(1)) * - TIRand.kr(0, 1, Impulse.kr(0.1)) - ); - // adjust the multiplier at the end of each line for adjusting levels - // note with each trigger, each source has a 1 in 3 chance of sounding - low_sine = SinOsc.ar(76.midicps / 16) * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.1; - high_sine = SinOsc.ar(76.midicps * 8) * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.01; - brown_noise = BrownNoise.ar() * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.025; - white_noise = WhiteNoise.ar() * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.02; - Out.ar(~hdustBusArray[0], - ((low_sine + high_sine + brown_noise + white_noise) ) - ); -}).add; - -) - -( -var bass, hdust, sampler, mixer; -bass = Synth.tail(~group, \bass); -hdust = Synth.tail(~group, \hdust); -sampler = Synth.head(~group, \sampler); -mixer = Synth.tail(~group, \mixer); -OSCdef(\mixer, {arg msg, time, addr, port; - mixer.set((msg[1] ++ '_' ++ msg[2] ++ '_' ++ msg[3]), msg[4]) -}, \mixer); - -OSCdef(\sampler, {arg msg, time, addr, port; - msg.postln; - sampler.free; - ~sBuf.free; - ~sBuf = Buffer.read(s, msg[1].asString.postln, action: {sampler = Synth.head(~group, \sampler)}); -}, \sampler); -) - -/* old something -( -SynthDef(\test, {arg freq, gate = 1, sustain, amp, dur; - var trig, exc, sig1, sig2, noHarms, freqFinal, start, end; - noHarms = 30; - freq = WhiteNoise.ar * 3 + freq; - freqFinal = Duty.ar((1/freq), 0, freq); - trig = Changed.ar(freqFinal); - start = Demand.ar(trig, 0, Dwhite(-1, -0.75)); - end = Demand.ar(trig, 0, Dwhite(0.75, 1)); - exc = Phasor.ar(trig, (end - start) * freqFinal / SampleRate.ir, start, end, 0) * 0.001 + Dust.ar(10000, 0.01); - - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(2, 3)}) ], exc) * 0.5).softclip; - sig1 = HPF.ar(sig1, 300); - Out.ar([0, 1], sig1 * EnvGen.kr(Env.adsr(0.3, 0.3, 0.9, 0.5, 0.9), gate, doneAction: 2)); -}).add; -) -*/ - diff --git a/resources/resources_bak_2024_01_03/piece_ledger_pas/703e109b/703e109b_mus_model.json b/resources/resources_bak_2024_01_03/piece_ledger_pas/703e109b/703e109b_mus_model.json deleted file mode 100644 index c0a214c..0000000 --- a/resources/resources_bak_2024_01_03/piece_ledger_pas/703e109b/703e109b_mus_model.json +++ /dev/null @@ -1,48 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ "Rest" ], [ 6, -5, -4, 0, -1, -2 ], [ "Rest" ] ], 0.875 ], - [ [ [ "Rest" ], [ "Rest" ], [ 6, -5, -4, 0, -1, -2 ], [ 7, -5, -2, 0, -1, -2 ] ], 3 ], - [ [ [ 8, -6, -4, 0, -1, -2 ], [ "Rest" ], [ 6, -5, -4, 0, -1, -2 ], [ 7, -5, -2, 0, -1, -2 ] ], 1.25 ], - [ [ [ 8, -6, -4, 0, -1, -2 ], [ 6, -5, -4, 0, -1, -3 ], [ 6, -5, -4, 0, -1, -2 ], [ 7, -5, -2, 0, -1, -2 ] ], 2 ] - ], - [ - [ [ [ 8, -6, -4, 0, -1, -2 ], [ "Rest" ], [ 6, -5, -4, 0, -1, -2 ], [ 7, -5, -2, 0, -1, -2 ] ], 0 ], - [ [ [ 8, -6, -4, 0, -1, -2 ], [ "Rest" ], [ 7, -7, -4, 0, -1, -2 ], [ 7, -5, -2, 0, -1, -2 ] ], 2.375 ], - [ [ [ 8, -6, -4, 0, -1, -2 ], [ "Rest" ], [ 7, -7, -4, 0, -1, -2 ], [ "Rest" ] ], 0.875 ], - [ [ [ "Rest" ], [ "Rest" ], [ 7, -7, -4, 0, -1, -2 ], [ "Rest" ] ], 0 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 1.625 ] - ] - ] -], -"last_changes": -[ - [ [ 7, -5, -3, 0, -1, -2 ], [ 5, -5, -2, 0, -2, -2 ], [ 5, -5, -2, 0, 0, -2 ], [ 7, -5, -2, 0, -1, -2 ] ], - [ [ 7, -5, -3, 0, -1, -2 ], [ 5, -5, -2, 0, -2, -2 ], [ 6, -5, -4, 0, -1, -2 ], [ 7, -5, -2, 0, -1, -2 ] ], - [ [ 8, -6, -4, 0, -1, -2 ], [ 5, -5, -2, 0, -2, -2 ], [ 6, -5, -4, 0, -1, -2 ], [ 7, -5, -2, 0, -1, -2 ] ], - [ [ 8, -6, -4, 0, -1, -2 ], [ 6, -5, -4, 0, -1, -3 ], [ 6, -5, -4, 0, -1, -2 ], [ 7, -5, -2, 0, -1, -2 ] ], - [ [ 8, -6, -4, 0, -1, -2 ], [ 6, -5, -4, 0, -1, -3 ], [ 7, -7, -4, 0, -1, -2 ], [ 7, -5, -2, 0, -1, -2 ] ] -], -"cur_uid": "703e109b", -"ref_uid": "tmp", -"order_seed": 550421, -"dur_seed": 315472, -"motifs_seed": 675194, -"entrances_probs_vals": [ 0.52, 0.56, 2.4206349206349, 0.25, 1.24, 0.20725388601036, 0.68581081081081, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"passages_probs_vals": [ 0.52, 0.56, 2.4206349206349, 0.25, 1.24, 0.20725388601036, 0.68581081081081, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"exits_probs_vals": [ 0.52, 0.56, 2.4206349206349, 0.25, 1.24, 0.20725388601036, 0.68581081081081, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"ranges": [ [ 1211.1455108359, 2400 ], [ -1650, 450 ], [ -405, 1137 ], [ 951.08359133127, 2053 ] ], -"passages_weights": [ 0.75, 0.75, 0.75, 0.75, 0.75 ], -"order": -[ - [ [ 2, 3 ], [ 0, 1 ], [ ] ], - [ [ 3, 0 ], [ 2 ], [ 1 ] ] -], -"sus_weights": [ 0.73, 0.49, 0 ], -"order_size": [ 1, 3 ], -"passages_size": [ 0, 0 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/piece_ledger_pas/74faf83f/74faf83f_code.scd b/resources/resources_bak_2024_01_03/piece_ledger_pas/74faf83f/74faf83f_code.scd deleted file mode 100644 index 3ec9b1a..0000000 --- a/resources/resources_bak_2024_01_03/piece_ledger_pas/74faf83f/74faf83f_code.scd +++ /dev/null @@ -1,907 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - pDistance.gaussCurve(1, mean, sd) -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = 1/pow(hdSum.value(voices.deepCopy.put(ins, candidate)), 2); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~msg.postln; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1, 3)}, {rrand(0.3, 0.5)}); - }); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - //res.postln; - if(res.every({arg char; char.isDecDigit}), {res = res.asInteger}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file; - file = File(path, "w"); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "passages_weights", "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((dir +/+ ".." +/+ "resources" +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - - curUID = genUID.value; - - File.mkdir((dir +/+ ".." +/+ "resources" +/+ curUID).standardizePath); - File.copy(exPath, (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - ledger = ledger.drop(-1).add(curUID); - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (dir +/+ ".." +/+ "resources" +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - -) - -( -//synthdefs -~stringModelBusArray = 4.collect({Bus.audio(s, 1)}); -~sineBusArray = 4.collect({Bus.audio(s, 1)}); -~bassBusArray = 1.collect({Bus.audio(s, 1)}); -~hdustBusArray = 1.collect({Bus.audio(s, 1)}); -~samplerBusArray = 2.collect({Bus.audio(s, 1)}); -~sBuf = Buffer.alloc(s, 10, 2); -SynthDef(\string_model, {arg freq, gate = 1, sustain, amp, dur, attack, release = 1, busIndex = 0; - var trig, exc, sig1, sig2, noHarms; - noHarms = rrand(20, 40); - exc = Saw.ar(freq, TRand.ar(0.5, 1, Impulse.ar(freq))) * 0.001 + Dust.ar(10000, 0.01); - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(1, 2)}) ], exc) * 0.8).softclip; - //sig1 = HPF.ar(sig1, 300); - Out.ar(Select.kr(busIndex, ~stringModelBusArray), sig1 * amp * EnvGen.kr(Env.adsr(attack, 0.3, 0.9, release, 0.9, -3), gate, doneAction: 2)); - //Out.ar([0, 1], sig1 * EnvGen.kr(Env.asr(dur, 0.3, 1), gate, doneAction: 2)); -}).add; - -SynthDef(\sine, {arg freq, gate = 1, sustain, amp, dur, busIndex = 0; - var sig; - sig = SinOsc.ar(freq); - Out.ar(Select.kr(busIndex, ~sineBusArray), sig * EnvGen.kr(Env.asr(0.3, 0.4, 0.3), gate, timeScale: dur, doneAction: 2)); - //Out.ar(Select.kr(busIndex, ~sineBusArray), sig * EnvGen.kr(Env.sine(dur), gate, doneAction: 2)); -}).add; - -SynthDef(\mixer, {arg freq, gate = 1, sustain, amp, dur, out; - var nameSpaces, sigs, hierarchicalDust; - - hierarchicalDust = ( - TIRand.kr(0, 1, Impulse.kr(100)) * - TIRand.kr(0, 1, Impulse.kr(10)) * - TIRand.kr(0, 1, Impulse.kr(1)) - ); - - sigs = [~stringModelBusArray, ~sineBusArray, ~bassBusArray, ~hdustBusArray, ~samplerBusArray].collect({arg busArray, i; - var nameSpace, sig; - nameSpace = ['string', 'sine', 'bass', 'hdust', 'sampler'][i]; - sig = busArray.collect({arg bus, c; In.ar(bus, 1) * NamedControl.kr(\ ++ nameSpace ++ '_volume_' ++ c, 1, 0.1)}); - sig = sig.collect({arg channel, c; Pan2.ar(channel, NamedControl.kr(\ ++ nameSpace ++ '_pan_' ++ c, i / (busArray.size - 1), 0.1) * 2 - 1)}); - sig = sig.collect({arg channel, c; channel * NamedControl.kr(\ ++ nameSpace ++ '_mute_' ++ c, 1, 0.1)}); - sig = Mix.ar(sig) * pow(NamedControl.kr(\ ++ nameSpace ++ '_volume_master', 1, 0.1), 2); - }); - - sigs = Mix.ar(sigs / 4); - Out.ar(0, sigs) -}).add; - -SynthDef(\bass, { - var switches, drone; - switches = {|i| Dust.kr(0.1)} ! 9; - drone = {|i| var harm = pow(2, 2 - (i / 3).trunc), amp = (1 / pow(harm, 2)); - SinOsc.ar(60 * harm + TRand.kr(-3, 3, switches[i]), 0, amp)} ! 9; - Out.ar(~bassBusArray[0], Mix.new(drone) * 0.2); -}).add; - -SynthDef(\sampler, { - Out.ar(~samplerBusArray, PlayBuf.ar(2, ~sBuf, BufRateScale.kr(~sBuf), doneAction: 2)) -}).add; - -// main routine -SynthDef(\hdust, { - arg gate = 0; - var hierarchical_dust, low_sine, high_sine, brown_noise, white_noise; - // this triggers the combinations of sources - // it is similar to the Supercollider UGen called dust but with a hierarchical structure - hierarchical_dust = ( - TIRand.kr(0, 1, Impulse.kr(100)) * - TIRand.kr(0, 1, Impulse.kr(10)) * - TIRand.kr(0, 1, Impulse.kr(1)) * - TIRand.kr(0, 1, Impulse.kr(0.1)) - ); - // adjust the multiplier at the end of each line for adjusting levels - // note with each trigger, each source has a 1 in 3 chance of sounding - low_sine = SinOsc.ar(76.midicps / 16) * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.1; - high_sine = SinOsc.ar(76.midicps * 8) * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.01; - brown_noise = BrownNoise.ar() * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.025; - white_noise = WhiteNoise.ar() * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.02; - Out.ar(~hdustBusArray[0], - ((low_sine + high_sine + brown_noise + white_noise) ) - ); -}).add; - -) - -( -var bass, hdust, sampler, mixer; -bass = Synth.tail(~group, \bass); -hdust = Synth.tail(~group, \hdust); -sampler = Synth.head(~group, \sampler); -mixer = Synth.tail(~group, \mixer); -OSCdef(\mixer, {arg msg, time, addr, port; - mixer.set((msg[1] ++ '_' ++ msg[2] ++ '_' ++ msg[3]), msg[4]) -}, \mixer); - -OSCdef(\sampler, {arg msg, time, addr, port; - msg.postln; - sampler.free; - ~sBuf.free; - ~sBuf = Buffer.read(s, msg[1].asString.postln, action: {sampler = Synth.head(~group, \sampler)}); -}, \sampler); -) - -/* old something -( -SynthDef(\test, {arg freq, gate = 1, sustain, amp, dur; - var trig, exc, sig1, sig2, noHarms, freqFinal, start, end; - noHarms = 30; - freq = WhiteNoise.ar * 3 + freq; - freqFinal = Duty.ar((1/freq), 0, freq); - trig = Changed.ar(freqFinal); - start = Demand.ar(trig, 0, Dwhite(-1, -0.75)); - end = Demand.ar(trig, 0, Dwhite(0.75, 1)); - exc = Phasor.ar(trig, (end - start) * freqFinal / SampleRate.ir, start, end, 0) * 0.001 + Dust.ar(10000, 0.01); - - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(2, 3)}) ], exc) * 0.5).softclip; - sig1 = HPF.ar(sig1, 300); - Out.ar([0, 1], sig1 * EnvGen.kr(Env.adsr(0.3, 0.3, 0.9, 0.5, 0.9), gate, doneAction: 2)); -}).add; -) -*/ - diff --git a/resources/resources_bak_2024_01_03/piece_ledger_pas/74faf83f/74faf83f_mus_model.json b/resources/resources_bak_2024_01_03/piece_ledger_pas/74faf83f/74faf83f_mus_model.json deleted file mode 100644 index 38b642a..0000000 --- a/resources/resources_bak_2024_01_03/piece_ledger_pas/74faf83f/74faf83f_mus_model.json +++ /dev/null @@ -1,83 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ "Rest" ], [ 0, 2, 0, 1, -2, 0 ], [ "Rest" ] ], 1.625 ], - [ [ [ "Rest" ], [ "Rest" ], [ 0, 2, 0, 1, -2, 0 ], [ 0, 2, 0, 2, -2, -1 ] ], 1.625 ], - [ [ [ -3, 2, 0, 2, -2, -2 ], [ "Rest" ], [ 0, 2, 0, 1, -2, 0 ], [ 0, 2, 0, 2, -2, -1 ] ], 2.75 ] - ], - [ - [ [ [ -3, 2, 0, 2, -2, -2 ], [ "Rest" ], [ 0, 2, 0, 1, -2, 0 ], [ "Rest" ] ], 0.75 ], - [ [ [ -3, 2, 0, 2, -2, -2 ], [ -2, 3, 0, 1, -2, -1 ], [ 0, 2, 0, 1, -2, 0 ], [ "Rest" ] ], 2.75 ], - [ [ [ -3, 3, 0, 1, -3, -1 ], [ -2, 3, 0, 1, -2, -1 ], [ 0, 2, 0, 1, -2, 0 ], [ "Rest" ] ], 1.25 ], - [ [ [ -3, 3, 0, 1, -3, -1 ], [ -2, 3, 0, 1, -2, -1 ], [ 1, 3, 0, 0, -2, -1 ], [ "Rest" ] ], 2.5 ] - ], - [ - [ [ [ -3, 3, 0, 1, -3, -1 ], [ -2, 3, 0, 1, -2, -1 ], [ "Rest" ], [ "Rest" ] ], 0.75 ], - [ [ [ -3, 3, 0, 1, -3, -1 ], [ -2, 3, 0, 1, -2, -1 ], [ "Rest" ], [ 0, 2, 0, 2, -2, -1 ] ], 3.25 ], - [ [ [ -3, 3, 0, 1, -3, -1 ], [ -2, 2, -1, 2, -2, -1 ], [ "Rest" ], [ 0, 2, 0, 2, -2, -1 ] ], 0.75 ], - [ [ [ -3, 1, 0, 2, -2, -1 ], [ -2, 2, -1, 2, -2, -1 ], [ "Rest" ], [ 0, 2, 0, 2, -2, -1 ] ], 1.625 ], - [ [ [ -3, 1, 0, 2, -2, -1 ], [ -3, 3, 0, 2, -2, -1 ], [ "Rest" ], [ 0, 2, 0, 2, -2, -1 ] ], 1 ], - [ [ [ -3, 1, 0, 2, -2, -1 ], [ -2, 1, 0, 2, -2, -1 ], [ "Rest" ], [ 0, 2, 0, 2, -2, -1 ] ], 1.25 ], - [ [ [ -3, 2, 0, 1, -2, -1 ], [ -2, 1, 0, 2, -2, -1 ], [ "Rest" ], [ 0, 2, 0, 2, -2, -1 ] ], 0.875 ], - [ [ [ -3, 2, 0, 2, -2, -2 ], [ -2, 1, 0, 2, -2, -1 ], [ "Rest" ], [ 0, 2, 0, 2, -2, -1 ] ], 1.625 ] - ], - [ - [ [ [ "Rest" ], [ -2, 1, 0, 2, -2, -1 ], [ "Rest" ], [ 0, 2, 0, 2, -2, -1 ] ], 0.75 ], - [ [ [ "Rest" ], [ -2, 1, 0, 2, -2, -1 ], [ 1, 3, 0, 0, -2, -1 ], [ 0, 2, 0, 2, -2, -1 ] ], 2.625 ], - [ [ [ "Rest" ], [ -2, 4, 0, 0, -2, -1 ], [ 1, 3, 0, 0, -2, -1 ], [ 0, 2, 0, 2, -2, -1 ] ], 0.75 ], - [ [ [ "Rest" ], [ -2, 4, 0, 0, -2, -1 ], [ 1, 3, 0, 0, -2, -1 ], [ 0, 3, 0, 1, -2, -1 ] ], 0.875 ], - [ [ [ "Rest" ], [ -2, 4, 0, 0, -2, -1 ], [ 1, 3, 0, 0, -2, -1 ], [ 0, 3, 0, 0, -2, 0 ] ], 2.375 ] - ], - [ - [ [ [ "Rest" ], [ "Rest" ], [ 1, 3, 0, 0, -2, -1 ], [ 0, 3, 0, 0, -2, 0 ] ], 1.625 ], - [ [ [ -3, 2, 0, 2, -2, -2 ], [ "Rest" ], [ 1, 3, 0, 0, -2, -1 ], [ 0, 3, 0, 0, -2, 0 ] ], 2.5 ], - [ [ [ -3, 2, 0, 2, -2, -2 ], [ "Rest" ], [ 0, 3, 0, 2, -2, -2 ], [ 0, 3, 0, 0, -2, 0 ] ], 1.25 ], - [ [ [ -3, 2, 0, 2, -2, -2 ], [ "Rest" ], [ 0, 3, 0, 2, -2, -2 ], [ 0, 2, 0, 2, -1, -2 ] ], 2.75 ] - ], - [ - [ [ [ -3, 2, 0, 2, -2, -2 ], [ -2, 4, 0, 0, -2, -1 ], [ 0, 3, 0, 2, -2, -2 ], [ 0, 2, 0, 2, -1, -2 ] ], 1.75 ], - [ [ [ -3, 2, 0, 2, -2, -2 ], [ -2, 4, 0, 0, -2, -1 ], [ 0, 4, 1, 0, -2, -1 ], [ 0, 2, 0, 2, -1, -2 ] ], 1.25 ], - [ [ [ -3, 2, 0, 2, -2, -2 ], [ -2, 4, 0, 0, -2, -1 ], [ 0, 4, 1, 0, -2, -1 ], [ 1, 4, 0, 0, -2, -2 ] ], 1.625 ], - [ [ [ -4, 4, 0, 1, -2, -1 ], [ -2, 4, 0, 0, -2, -1 ], [ 0, 4, 1, 0, -2, -1 ], [ 1, 4, 0, 0, -2, -2 ] ], 2.125 ], - [ [ [ "Rest" ], [ -2, 4, 0, 0, -2, -1 ], [ 0, 4, 1, 0, -2, -1 ], [ 1, 4, 0, 0, -2, -2 ] ], 1.375 ], - [ [ [ "Rest" ], [ "Rest" ], [ 0, 4, 1, 0, -2, -1 ], [ 1, 4, 0, 0, -2, -2 ] ], 1 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ 1, 4, 0, 0, -2, -2 ] ], 0.875 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 3 ] - ] - ] -], -"last_changes": -[ - [ [ -3, 2, 0, 2, -2, -2 ], [ -2, 4, 0, 0, -2, -1 ], [ 0, 3, 0, 2, -2, -2 ], [ 0, 3, 0, 0, -2, 0 ] ], - [ [ -3, 2, 0, 2, -2, -2 ], [ -2, 4, 0, 0, -2, -1 ], [ 0, 3, 0, 2, -2, -2 ], [ 0, 2, 0, 2, -1, -2 ] ], - [ [ -3, 2, 0, 2, -2, -2 ], [ -2, 4, 0, 0, -2, -1 ], [ 0, 4, 1, 0, -2, -1 ], [ 0, 2, 0, 2, -1, -2 ] ], - [ [ -3, 2, 0, 2, -2, -2 ], [ -2, 4, 0, 0, -2, -1 ], [ 0, 4, 1, 0, -2, -1 ], [ 1, 4, 0, 0, -2, -2 ] ], - [ [ -4, 4, 0, 1, -2, -1 ], [ -2, 4, 0, 0, -2, -1 ], [ 0, 4, 1, 0, -2, -1 ], [ 1, 4, 0, 0, -2, -2 ] ] -], -"cur_uid": "74faf83f", -"ref_uid": "tmp", -"order_seed": 329828, -"dur_seed": 441173, -"motifs_seed": 330575, -"entrances_probs_vals": [ 0, 0.48, 1.7460317460317, 0.58, 1.68, 0.20725388601036, 0.68581081081081, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"passages_probs_vals": [ 0, 0.48, 1.7460317460317, 0.58, 1.68, 0.20725388601036, 0.68581081081081, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"exits_probs_vals": [ 0, 0.48, 1.7460317460317, 0.58, 1.68, 0.20725388601036, 0.68581081081081, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"ranges": [ [ -3600, -1408.0495356037 ], [ -3600, -609.2879256966 ], [ 858.20433436532, 2066 ], [ 951.08359133127, 2053 ] ], -"passages_weights": [ 0.75, 0.75, 0.75, 0.75, 0.75 ], -"order": -[ - [ [ 2, 3 ], [ 0 ], [ 1 ] ], - [ [ 1 ], [ 0, 2 ], [ 3 ] ], - [ [ 3 ], [ 1, 0, 1, 1, 0, 0 ], [ 2 ] ], - [ [ 2 ], [ 1, 3, 3 ], [ 0 ] ], - [ [ 0 ], [ 2, 3 ], [ 1 ] ], - [ [ 1 ], [ 2, 3, 0 ], [ ] ] -], -"sus_weights": [ 0.73, 0.49, 0 ], -"order_size": [ 1, 7 ], -"passages_size": [ 0, 5 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/piece_ledger_pas/7ac10d34/7ac10d34_code.scd b/resources/resources_bak_2024_01_03/piece_ledger_pas/7ac10d34/7ac10d34_code.scd deleted file mode 100644 index 65c17df..0000000 --- a/resources/resources_bak_2024_01_03/piece_ledger_pas/7ac10d34/7ac10d34_code.scd +++ /dev/null @@ -1,719 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON; - -// model vars -//(model and global vars mostly set by OSC funcs -var curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, orders, susWeights, passagesWeights, passagesSize, orderSize; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc; - -// other global vars -var lastXChanges, popSize, exPath, dir, primes, dims, tuples, -seq, group, player, ledgerPath, ledger, currentlyPlayingUID; - - -// install JSON quark -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - pDistance.gaussCurve(1, mean, sd) -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, min, max, envData; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - durFunc = {arg allowChord; - var res; - res = if(allowChord.not, { - pTable.tableRand * (max - min) + min - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (max - min) + min}); - }).round(0.125); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, durSeed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = 1/pow(hdSum.value(voices.deepCopy.put(ins, candidate)), 2); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - allowChord = if((sus ++ silent).includes(ins), { - (sus ++ silent).includes(ins) && (ins != sus.last); - }, { - if(i < (flatOrder.size - 1), {(isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not}, {false}); - }); - dur = passagesDurFunc.value(allowChord); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(isLastOrder, { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - dur = passagesDurFunc.value(allowChord); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); - -genPatterns = {arg inSeq, addr; - var voices, durs, patterns, res, indices, sectionDurs, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - indices = inSeq.collect({arg mSeq, m; mSeq[1]}); - ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - res = Ppar( - voices.flop.collect({arg voice; - var clumps, hdScores, freqs, fDurs; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \instrument, \test, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1) - ) - }) ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \indexPath, "/cur_play_index", - \indexMsg, Pseq(indices.postln, 1), - \seqPath, "/mus_seq", - \seqMsg, Pseq(seq, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - ); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < (maxDepth - 0), { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - //res.postln; - if(res.every({arg char; char.isDecDigit}), {res = res.asInteger}); - }); - }); - res -}; - -writeResources = {arg path; - var file, nameSpaces, modelItems, resString; - file = File(path,"w"); - - nameSpaces = [ - "music_data", "last_changes", - "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "passages_weights", "order", "sus_weights", "order_size", "passages_size" - ]; - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize - ]; - - resString = [nameSpaces, modelItems].flop.collect({arg item; - var nameSpace, modelItem, depth = 0, insert = " "; - # nameSpace, modelItem = item; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(modelItem.postln, depth).postln - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg model; - var nameSpaces, data; - - //model = File(path, "r").readAllString.parseJSON; - - nameSpaces = [ - "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "passages_weights", "order", "sus_weights", "order_size", "passages_size" - ]; - - data = nameSpaces.collect({arg nS; msgInterpret.value(model[nS]).postln}); - - data.postln; - - # curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize = data; - - popSize = ranges.size; -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg ledger; ledger = ledger["ledger"]}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - loadModelFile.value(msg[1].asString); -}, \load_model); - - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dFormat, condition, musPath; - msg.postln; - - path = msg[1].asString; - - loadModelFile.value(path); - - refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - lastXChanges = if(refUID == nil, { - [initVoices.value().deepCopy]; - }, { - var file; - refUID.postln; - file = File((dir +/+ ".." +/+ "resources" +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..2] ++ [entrancesProbVals[3..]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..2] ++ [passagesProbVals[3..]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..2] ++ [exitsProbVals[3..]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - seq = seedFunc.value(genMotif, motifSeed).value; - - //musPath = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - writeResources.value(path); - - //orders = nil; - //addr.sendMsg("/current_uid", curUID); - //addr.sendMsg("/ledger", prettifyArray.value(ledger, 1).replace("\"", "")); - //addr.sendMsg("/ledger_size", ledger.size); - //addr.sendMsg("/mus_seq", prettifyArray.value(seq, 3)); - addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var newLedger, modelPath, musString, musFile, test1, test2; - msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - curUID = genUID.value; - File.mkdir((dir +/+ ".." +/+ "resources" +/+ curUID).standardizePath); - File.copy(exPath, (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - writeResources.value(modelPath); - - File.delete(ledgerPath.postln ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - newLedger = File(ledgerPath.postln, "w"); - ledger = ledger.postln.drop(-1).add(curUID); - newLedger.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - newLedger.close; - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - player.stop; - group.set(\gate, 0); - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var file; - (indexStart + index).postln; - file = File((dir +/+ ".." +/+ "resources" +/+ uid +/+ uid ++ "_music" ++ ".json").standardizePath, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, {pSeq = pSeq.add([seq, ledger.size - 1])}); - patterns = genPatterns.value(pSeq, addr); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - }); - player = player.play - }); -}, \transport); - -) - -( -SynthDef(\test, {arg freq, gate = 1, sustain, amp, dur; - var trig, exc, sig1, sig2, noHarms; - noHarms = 30; - exc = Saw.ar(freq, TRand.ar(0.5, 1, Impulse.ar(freq))) * 0.001 + Dust.ar(10000, 0.01); - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(1, 2)}) ], exc) * 0.5).softclip; - sig1 = HPF.ar(sig1, 300); - Out.ar([0, 1], sig1 * EnvGen.kr(Env.adsr(0.3, 0.3, 0.9, 0.5, 0.9), gate, doneAction: 2)); -}).add; -) - -( -SynthDef(\test, {arg freq, gate = 1, sustain, amp, dur; - var trig, exc, sig1, sig2, noHarms, freqFinal, start, end; - noHarms = 30; - freq = WhiteNoise.ar * 3 + freq; - freqFinal = Duty.ar((1/freq), 0, freq); - trig = Changed.ar(freqFinal); - start = Demand.ar(trig, 0, Dwhite(-1, -0.75)); - end = Demand.ar(trig, 0, Dwhite(0.75, 1)); - exc = Phasor.ar(trig, (end - start) * freqFinal / SampleRate.ir, start, end, 0) * 0.001 + Dust.ar(10000, 0.01); - - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(2, 3)}) ], exc) * 0.5).softclip; - sig1 = HPF.ar(sig1, 300); - Out.ar([0, 1], sig1 * EnvGen.kr(Env.adsr(0.3, 0.3, 0.9, 0.5, 0.9), gate, doneAction: 2)); -}).add; -) - - - -"{\"a\": 1}".parseYAML["a"].asInteger; -"{\"a\": 1}".parseJSON["a"].isNumber; - -1223423434123.asHexString.toLower - -Date.getDate.rawSeconds -Date.seed.asHexString.toLower - -n = NetAddr("localhost", 8080); -n.sendMsg("/GET/#", (NetAddr.localAddr.hostname ++ ":" ++ NetAddr.localAddr.port), "/passage_probs_vals"); \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/piece_ledger_pas/7ac10d34/7ac10d34_gui_state.json b/resources/resources_bak_2024_01_03/piece_ledger_pas/7ac10d34/7ac10d34_gui_state.json deleted file mode 100644 index 84e6edd..0000000 --- a/resources/resources_bak_2024_01_03/piece_ledger_pas/7ac10d34/7ac10d34_gui_state.json +++ /dev/null @@ -1,1359 +0,0 @@ -{ - "motif_label": "motif", - "seeds_label": "seeds", - "order": "[\n [ [ 3, 1, 0 ], [ 2 ], [ ] ],\n [ [ 1, 2 ], [ 0, 0, 0, 0, 0, 0, 0, 0, 0 ], [ 3 ] ],\n [ [ 3, 2 ], [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ], [ 0 ] ],\n [ [ 2, 3 ], [ 0, 1, 0 ], [ ] ]\n]", - "order_lock": 1, - "order_size": [ - 3, - 8 - ], - "order_size_v2": 8, - "order_size_v1": 3, - "order_size_panel": -1, - "passage_size_v2": 8, - "passage_size_v1": 2, - "passage_size_panel": -1, - "sus_weights": [ - null, - null, - null - ], - "range_matrix": [ - null, - null, - null, - null - ], - "instrumentation": [ - 0, - 0 - ], - "entrances_probs_sync": "passages", - "entrances": -1, - "passages_probs_sync": "passages", - "passages": -1, - "exits_probs_sync": "passages", - "exits": -1, - "dur_panel": 0, - "durations": -1, - "passages_weights": [ - null, - null, - null, - null, - null - ], - "weights": -1, - "seeds_tab_panel": 0, - "weights_seed_lock": 0, - "weights_seed": 534103, - "sus_weights/0_slider_val": 0.21, - "sus_weights/0_slider_slider": 0.21, - "sus_weights/0_slider_input": 0.21, - "sus_weights/0_slider_label": 1, - "sus_weights/0_slider": -1, - "sus_weights/1_slider_val": 0.35, - "sus_weights/1_slider_slider": 0.35, - "sus_weights/1_slider_input": 0.35, - "sus_weights/1_slider_label": 2, - "sus_weights/1_slider": -1, - "sus_weights/2_slider_val": 0.21, - "sus_weights/2_slider_slider": 0.21, - "sus_weights/2_slider_input": 0.21, - "sus_weights/2_slider_label": 3, - "sus_weights/2_slider": -1, - "passages_weights/0_slider_val": 0.49, - "passages_weights/0_slider_slider": 0.49, - "passages_weights/0_slider_input": 0.49, - "passages_weights/0_slider_label": "step", - "passages_weights/0_slider": -1, - "passages_weights/1_slider_val": 0.53, - "passages_weights/1_slider_slider": 0.53, - "passages_weights/1_slider_input": 0.53, - "passages_weights/1_slider_label": "dc", - "passages_weights/1_slider": -1, - "passages_weights/2_slider_val": 0.35, - "passages_weights/2_slider_slider": 0.35, - "passages_weights/2_slider_input": 0.35, - "passages_weights/2_slider_label": "range", - "passages_weights/2_slider": -1, - "passages_weights/3_slider_val": 0.59, - "passages_weights/3_slider_slider": 0.59, - "passages_weights/3_slider_input": 0.59, - "passages_weights/3_slider_label": "registration", - "passages_weights/3_slider": -1, - "passages_weights/4_slider_val": 0.39, - "passages_weights/4_slider_slider": 0.39, - "passages_weights/4_slider_input": 0.39, - "passages_weights/4_slider_label": "hd", - "passages_weights/4_slider": -1, - "range_matrix/0_val_input_min": -853.2067988668555, - "range_matrix/0_val_rslider": [ - -853.2067988668555, - 401 - ], - "range_matrix/0_val_input_max": 401, - "range_matrix/0_val": -1, - "range_matrix/1_val_input_min": -659, - "range_matrix/1_val_rslider": [ - -659, - 880 - ], - "range_matrix/1_val_input_max": 880, - "range_matrix/1_val": -1, - "range_matrix/2_val_input_min": -241, - "range_matrix/2_val_rslider": [ - -241, - 1869 - ], - "range_matrix/2_val_input_max": 1869, - "range_matrix/2_val": -1, - "range_matrix/3_val_input_min": -27, - "range_matrix/3_val_rslider": [ - -27, - 2063 - ], - "range_matrix/3_val_input_max": 2063, - "range_matrix/3_val": -1, - "entrances_probs_chord_slider_val": 0.66, - "entrances_probs_chord_slider_slider": 0.66, - "entrances_probs_chord_slider_input": 0.66, - "entrances_probs_chord_slider_label": "chord prob", - "entrances_probs_chord_slider": -1, - "entrances_probs_vals": [ - 0.63, - 0, - 5, - 0, - 0.5, - 0.23316062176165803, - 0.7094594594594594, - 0.3963730569948187, - 0.8716216216216216, - 0.4948186528497409, - 0.5912162162162162, - 0.5362694300518135, - 0.8614864864864865, - 0.6424870466321243, - 0.5912162162162162, - 0.7901554404145078, - 0.8277027027027027, - 1, - 0.5 - ], - "entrances_probs": -1, - "passages_probs_chord_slider_val": 0.63, - "passages_probs_chord_slider_slider": 0.63, - "passages_probs_chord_slider_input": 0.63, - "passages_probs_chord_slider_label": "chord prob", - "passages_probs_chord_slider": -1, - "passages_probs_vals": [ - 0.63, - 0, - 5, - 0, - 0.5, - 0.23316062176165803, - 0.7094594594594594, - 0.3963730569948187, - 0.8716216216216216, - 0.4948186528497409, - 0.5912162162162162, - 0.5362694300518135, - 0.8614864864864865, - 0.6424870466321243, - 0.5912162162162162, - 0.7901554404145078, - 0.8277027027027027, - 1, - 0.5 - ], - "passages_probs": -1, - "exits_probs_chord_slider_val": 0, - "exits_probs_chord_slider_slider": 0, - "exits_probs_chord_slider_input": 0, - "exits_probs_chord_slider_label": "chord prob", - "exits_probs_chord_slider": -1, - "exits_probs_vals": [ - 0, - 0, - 5, - 0, - 0.5, - 0.23316062176165803, - 0.7094594594594594, - 0.4948186528497409, - 0.5912162162162162, - 0.7901554404145078, - 0.8277027027027027, - 1, - 0.5 - ], - "exits_probs": -1, - "step_env_env_vals": [ - 0, - 5, - 0, - 0, - 0, - 0, - 0.14609053497942387, - 0.7613636363636364, - 0.20164609053497942, - 0.26136363636363635, - 0.24279835390946503, - 0.7215909090909092, - 0.39094650205761317, - 0.875, - 0.4567901234567901, - 0.44318181818181823, - 0.5432098765432098, - 0.34659090909090906, - 0.6481481481481481, - 0.8011363636363636, - 0.6810699588477366, - 0.5170454545454546, - 0.8868312757201646, - 0.49431818181818177, - 0.8868312757201646, - 0.49431818181818177 - ], - "step_env_env_canvas": [ - [ - 0, - 0 - ], - [ - 0, - 0 - ], - [ - 0.14609053497942387, - 0.7613636363636364 - ], - [ - 0.20164609053497942, - 0.26136363636363635 - ], - [ - 0.24279835390946503, - 0.7215909090909092 - ], - [ - 0.39094650205761317, - 0.875 - ], - [ - 0.4567901234567901, - 0.44318181818181823 - ], - [ - 0.5432098765432098, - 0.34659090909090906 - ], - [ - 0.6481481481481481, - 0.8011363636363636 - ], - [ - 0.6810699588477366, - 0.5170454545454546 - ], - [ - 0.8868312757201646, - 0.49431818181818177 - ], - [ - 0.8868312757201646, - 0.49431818181818177 - ], - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0 - ], - "step_env_env_size": 12, - "step_env_env_flatten": 0, - "step_env_env_rslider": [ - 0, - 5 - ], - "step_env_env_rslider_v2": 5, - "step_env_env_rslider_v1": 0, - "step_env_env_mpos": "", - "step_env_env": -1, - "entrances_probs_dur_env_vals": [ - 0.515267175572519, - 4.599236641221374, - 0, - 0.5, - 0.2772020725388601, - 0.7972972972972973, - 0.45077720207253885, - 0.8783783783783784, - 0.5, - 0.5, - 0.727979274611399, - 0.45270270270270274, - 0.7357512953367875, - 0.6486486486486487, - 0.8911917098445595, - 0.7905405405405406, - 1, - 0.5 - ], - "entrances_probs_dur_env_canvas": [ - [ - 0, - 0.5 - ], - [ - 0.2772020725388601, - 0.7972972972972973 - ], - [ - 0.45077720207253885, - 0.8783783783783784 - ], - [ - 0.5, - 0.5 - ], - [ - 0.727979274611399, - 0.45270270270270274 - ], - [ - 0.7357512953367875, - 0.6486486486486487 - ], - [ - 0.8911917098445595, - 0.7905405405405406 - ], - [ - 1, - 0.5 - ], - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0 - ], - "entrances_probs_dur_env_size": 8, - "entrances_probs_dur_env_flatten": 0, - "entrances_probs_dur_env_rslider": [ - 0.515267175572519, - 4.599236641221374 - ], - "entrances_probs_dur_env_rslider_v2": 4.599236641221374, - "entrances_probs_dur_env_rslider_v1": 0.515267175572519, - "entrances_probs_dur_env_mpos": "", - "entrances_probs_dur_env": -1, - "passages_probs_dur_env_vals": [ - 0, - 5, - 0, - 0.5, - 0.23316062176165803, - 0.7094594594594594, - 0.3963730569948187, - 0.8716216216216216, - 0.4948186528497409, - 0.5912162162162162, - 0.5362694300518135, - 0.8614864864864865, - 0.6424870466321243, - 0.5912162162162162, - 0.7901554404145078, - 0.8277027027027027, - 1, - 0.5 - ], - "passages_probs_dur_env_canvas": [ - [ - 0, - 0.5 - ], - [ - 0.23316062176165803, - 0.7094594594594594 - ], - [ - 0.3963730569948187, - 0.8716216216216216 - ], - [ - 0.4948186528497409, - 0.5912162162162162 - ], - [ - 0.5362694300518135, - 0.8614864864864865 - ], - [ - 0.6424870466321243, - 0.5912162162162162 - ], - [ - 0.7901554404145078, - 0.8277027027027027 - ], - [ - 1, - 0.5 - ], - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0 - ], - "passages_probs_dur_env_size": 8, - "passages_probs_dur_env_flatten": 0, - "passages_probs_dur_env_rslider": [ - 0, - 5 - ], - "passages_probs_dur_env_rslider_v2": 5, - "passages_probs_dur_env_rslider_v1": 0, - "passages_probs_dur_env_mpos": "", - "passages_probs_dur_env": -1, - "exits_probs_dur_env_vals": [ - 0, - 5, - 0, - 0.5, - 0.5, - 0.5, - 1, - 0.5 - ], - "exits_probs_dur_env_canvas": [ - [ - 0, - 0.5 - ], - [ - 0.5, - 0.5 - ], - [ - 1, - 0.5 - ], - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0 - ], - "exits_probs_dur_env_size": 3, - "exits_probs_dur_env_flatten": 0, - "exits_probs_dur_env_rslider": [ - 0, - 5 - ], - "exits_probs_dur_env_rslider_v2": 5, - "exits_probs_dur_env_rslider_v1": 0, - "exits_probs_dur_env_mpos": "", - "exits_probs_dur_env": -1, - "mus_seq": [ - [ - [ - [ - [ - [ - "Rest" - ], - [ - 1, - 1, - -2, - -1, - 1, - 0 - ], - [ - "Rest" - ], - [ - "Rest" - ] - ], - 0 - ], - [ - [ - [ - "Rest" - ], - [ - 1, - 1, - -2, - -1, - 1, - 0 - ], - [ - 1, - 1, - -3, - 0, - 1, - -1 - ], - [ - "Rest" - ] - ], - 1.75 - ], - [ - [ - [ - "Rest" - ], - [ - 1, - 1, - -2, - -1, - 1, - 0 - ], - [ - 1, - 1, - -3, - 0, - 1, - -1 - ], - [ - 1, - 1, - -2, - -1, - 0, - 0 - ] - ], - 1.75 - ], - [ - [ - [ - 0, - 1, - -3, - 0, - 2, - -1 - ], - [ - 1, - 1, - -2, - -1, - 1, - 0 - ], - [ - 1, - 1, - -3, - 0, - 1, - -1 - ], - [ - 1, - 1, - -2, - -1, - 0, - 0 - ] - ], - 0.75 - ], - [ - [ - [ - 1, - 1, - -2, - -2, - 1, - 0 - ], - [ - 1, - 1, - -2, - -1, - 1, - 0 - ], - [ - 1, - 1, - -3, - 0, - 1, - -1 - ], - [ - 1, - 1, - -2, - -1, - 0, - 0 - ] - ], - 0.625 - ], - [ - [ - [ - 1, - 1, - -3, - -1, - 0, - 0 - ], - [ - 1, - 1, - -2, - -1, - 1, - 0 - ], - [ - 1, - 1, - -3, - 0, - 1, - -1 - ], - [ - 1, - 1, - -2, - -1, - 0, - 0 - ] - ], - 0.625 - ], - [ - [ - [ - 1, - 0, - -3, - 0, - 1, - -1 - ], - [ - 1, - 1, - -2, - -1, - 1, - 0 - ], - [ - 1, - 1, - -3, - 0, - 1, - -1 - ], - [ - 1, - 1, - -2, - -1, - 0, - 0 - ] - ], - 1.75 - ] - ], - [ - [ - [ - [ - "Rest" - ], - [ - 1, - 1, - -2, - -1, - 1, - 0 - ], - [ - 1, - 1, - -3, - 0, - 1, - -1 - ], - [ - 1, - 1, - -2, - -1, - 0, - 0 - ] - ], - 0 - ], - [ - [ - [ - "Rest" - ], - [ - 1, - 1, - -2, - -1, - 1, - 0 - ], - [ - 1, - 1, - -3, - -1, - 1, - 0 - ], - [ - 1, - 1, - -2, - -1, - 0, - 0 - ] - ], - 1.75 - ], - [ - [ - [ - "Rest" - ], - [ - 1, - 1, - -2, - -1, - 1, - 0 - ], - [ - 0, - 1, - -2, - 0, - 1, - 0 - ], - [ - 1, - 1, - -2, - -1, - 0, - 0 - ] - ], - 1.375 - ], - [ - [ - [ - "Rest" - ], - [ - 1, - 1, - -2, - -1, - 1, - 0 - ], - [ - 0, - 2, - -2, - -1, - 1, - 0 - ], - [ - 1, - 1, - -2, - -1, - 0, - 0 - ] - ], - 0.75 - ], - [ - [ - [ - "Rest" - ], - [ - 1, - 1, - -2, - -1, - 1, - 0 - ], - [ - 0, - 1, - -2, - -1, - 2, - 0 - ], - [ - 1, - 1, - -2, - -1, - 0, - 0 - ] - ], - 1.75 - ], - [ - [ - [ - "Rest" - ], - [ - 1, - 1, - -2, - -1, - 1, - 0 - ], - [ - 1, - 0, - -2, - -1, - 1, - 0 - ], - [ - 1, - 1, - -2, - -1, - 0, - 0 - ] - ], - 1.875 - ], - [ - [ - [ - "Rest" - ], - [ - 1, - 1, - -2, - -1, - 1, - 0 - ], - [ - 1, - 1, - -2, - -1, - 1, - -1 - ], - [ - 1, - 1, - -2, - -1, - 0, - 0 - ] - ], - 1 - ] - ], - [ - [ - [ - [ - 1, - 0, - -3, - 0, - 1, - -1 - ], - [ - 1, - 1, - -2, - -1, - 1, - 0 - ], - [ - 1, - 1, - -2, - -1, - 1, - -1 - ], - [ - 1, - 1, - -2, - -1, - 0, - 0 - ] - ], - 0 - ], - [ - [ - [ - 1, - 0, - -3, - 0, - 1, - -1 - ], - [ - 1, - 1, - -2, - -1, - 1, - 0 - ], - [ - 2, - 0, - -3, - -1, - 1, - -1 - ], - [ - 1, - 1, - -2, - -1, - 0, - 0 - ] - ], - 1.625 - ], - [ - [ - [ - 1, - 0, - -3, - 0, - 1, - -1 - ], - [ - 1, - 1, - -2, - -1, - 1, - 0 - ], - [ - 0, - 1, - -1, - -1, - 1, - 0 - ], - [ - 1, - 1, - -2, - -1, - 0, - 0 - ] - ], - 1.75 - ], - [ - [ - [ - 1, - 0, - -3, - 0, - 1, - -1 - ], - [ - 1, - 1, - -2, - -1, - 1, - 0 - ], - [ - 0, - 1, - -1, - -1, - 1, - 0 - ], - [ - "Rest" - ] - ], - 0 - ], - [ - [ - [ - "Rest" - ], - [ - 1, - 1, - -2, - -1, - 1, - 0 - ], - [ - 0, - 1, - -1, - -1, - 1, - 0 - ], - [ - "Rest" - ] - ], - 1.875 - ], - [ - [ - [ - "Rest" - ], - [ - "Rest" - ], - [ - 0, - 1, - -1, - -1, - 1, - 0 - ], - [ - "Rest" - ] - ], - 0 - ], - [ - [ - [ - "Rest" - ], - [ - "Rest" - ], - [ - "Rest" - ], - [ - "Rest" - ] - ], - 0.875 - ] - ] - ] - ], - "root": [ - 0.20743639921722112, - 0 - ], - "order_seed": 798574, - "dur_seed": 884869, - "passages_size": [ - 0, - 10 - ], - "dur_seed_lock": 1, - "order_seed_lock": 0, - "seeds_panel": -1, - "motif_panel": [ - 0, - 0 - ], - "ref_uid": "6f1a789f", - "cur_uid": "7ac10d34" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/piece_ledger_pas/7ac10d34/7ac10d34_mus_model.json b/resources/resources_bak_2024_01_03/piece_ledger_pas/7ac10d34/7ac10d34_mus_model.json deleted file mode 100644 index 73f197b..0000000 --- a/resources/resources_bak_2024_01_03/piece_ledger_pas/7ac10d34/7ac10d34_mus_model.json +++ /dev/null @@ -1,59 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 1.375 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 0, 0, 0, 1 ], [ "Rest" ] ], 0.875 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 1, 0, 0, 0, 0 ], [ "Rest" ] ], 0.875 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 0, 0, 1, 0 ], [ "Rest" ] ], 0.75 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 1, 0, 0, 0, -1, 0 ], [ "Rest" ] ], 1.5 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 1, -1, 0, 0, 0, 0 ], [ "Rest" ] ], 1.125 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 1, 0, 0, 0 ], [ "Rest" ] ], 1.625 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 1, 0, 0, -1, 0, 0 ], [ "Rest" ] ], 1.625 ] - ], - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 2, -1, 0, -1, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ "Rest" ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 2, -1, 0, -1, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ 2, 0, 0, -1, 0, 0 ] ], 1.25 ], - [ [ [ 1, -1, 1, -1, 0, 0 ], [ 2, -1, 0, -1, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ 2, 0, 0, -1, 0, 0 ] ], 1.125 ], - [ [ [ 2, -2, 0, -1, 0, 0 ], [ 2, -1, 0, -1, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ 2, 0, 0, -1, 0, 0 ] ], 1 ], - [ [ [ 0, 1, 0, -1, 0, 0 ], [ 2, -1, 0, -1, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ 2, 0, 0, -1, 0, 0 ] ], 0.5 ], - [ [ [ 1, 0, -1, -1, 0, 0 ], [ 2, -1, 0, -1, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ 2, 0, 0, -1, 0, 0 ] ], 1.625 ], - [ [ [ 2, -1, 0, -1, 0, -1 ], [ 2, -1, 0, -1, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ 2, 0, 0, -1, 0, 0 ] ], 2 ], - [ [ [ 2, -1, 0, -2, 0, 0 ], [ 2, -1, 0, -1, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ 2, 0, 0, -1, 0, 0 ] ], 1.75 ], - [ [ [ 1, -1, 1, -1, 0, 0 ], [ 2, -1, 0, -1, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ 2, 0, 0, -1, 0, 0 ] ], 1.5 ], - [ [ [ 2, -2, 0, -1, 0, 0 ], [ 2, -1, 0, -1, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ 2, 0, 0, -1, 0, 0 ] ], 1.25 ], - [ [ [ 2, -2, 0, -1, 0, 0 ], [ 2, -1, 0, -1, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ "Rest" ] ], 0.875 ], - [ [ [ 2, -2, 0, -1, 0, 0 ], [ 2, -1, 0, -1, 0, 0 ], [ "Rest" ], [ "Rest" ] ], 0 ], - [ [ [ 2, -2, 0, -1, 0, 0 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 0 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 1.375 ] - ] - ] -], -"last_changes": -[ - [ [ 1, 0, -1, -1, 0, 0 ], [ 2, -1, 0, -1, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ 2, 0, 0, -1, 0, 0 ] ], - [ [ 2, -1, 0, -1, 0, -1 ], [ 2, -1, 0, -1, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ 2, 0, 0, -1, 0, 0 ] ], - [ [ 2, -1, 0, -2, 0, 0 ], [ 2, -1, 0, -1, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ 2, 0, 0, -1, 0, 0 ] ], - [ [ 1, -1, 1, -1, 0, 0 ], [ 2, -1, 0, -1, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ 2, 0, 0, -1, 0, 0 ] ], - [ [ 2, -2, 0, -1, 0, 0 ], [ 2, -1, 0, -1, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ 2, 0, 0, -1, 0, 0 ] ] -], -"cur_uid": "7ac10d34", -"ref_uid": "46b6952a", -"order_seed": 638872, -"dur_seed": 225879, -"motifs_seed": 992393, -"entrances_probs_vals": [ 0.75, 0.5, 2, 0, 0.5, 0.26424870466321, 0.75675675675676, 0.5, 0.5, 0.58549222797927, 0.72635135135135, 1, 0.5 ], -"passages_probs_vals": [ 0.75, 0.5, 2, 0, 0.5, 0.20725388601036, 0.68581081081081, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"exits_probs_vals": [ 0.75, 0.5, 2, 0, 0.5, 0.20725388601036, 0.68581081081081, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"ranges": [ [ -384, 2400 ], [ -507, 2400 ], [ -282, 2237 ], [ -1200, 2053 ] ], -"passages_weights": [ 0.75, 0.75, 0.75, 0.75, 0.75 ], -"order": -[ - [ [ 0 ], [ 2, 2, 2, 2, 2, 2, 2 ], [ 3, 1 ] ], - [ [ 1, 2, 3 ], [ 0, 0, 0, 0, 0, 0, 0, 0 ], [ ] ] -], -"sus_weights": [ 0.75, 0.69, 0.75 ], -"order_size": [ 2, 6 ], -"passages_size": [ 0, 10 ] -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/piece_ledger_pas/7bf874ce/7bf874ce_code.scd b/resources/resources_bak_2024_01_03/piece_ledger_pas/7bf874ce/7bf874ce_code.scd deleted file mode 100644 index ab370bd..0000000 --- a/resources/resources_bak_2024_01_03/piece_ledger_pas/7bf874ce/7bf874ce_code.scd +++ /dev/null @@ -1,887 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - pDistance.gaussCurve(1, mean, sd) -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = 1/pow(hdSum.value(voices.deepCopy.put(ins, candidate)), 2); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~msg.postln; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - //res.postln; - if(res.every({arg char; char.isDecDigit}), {res = res.asInteger}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file; - file = File(path, "w"); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "passages_weights", "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - lastXChanges = if(refUID == nil, { - [initVoices.value().deepCopy]; - }, { - var file; - file = File((dir +/+ ".." +/+ "resources" +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - seq = seedFunc.value(genMotif, motifSeed).value; - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - - curUID = genUID.value; - - File.mkdir((dir +/+ ".." +/+ "resources" +/+ curUID).standardizePath); - File.copy(exPath, (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - ledger = ledger.drop(-1).add(curUID); - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - player.stop; - group.set(\gate, 0); - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (dir +/+ ".." +/+ "resources" +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - -) - -( -//synthdefs -~stringModelBusArray = 4.collect({Bus.audio(s, 1)}); -~sineBusArray = 4.collect({Bus.audio(s, 1)}); -~bassBusArray = 1.collect({Bus.audio(s, 1)}); -~hdustBusArray = 1.collect({Bus.audio(s, 1)}); -~samplerBusArray = 2.collect({Bus.audio(s, 1)}); -~sBuf = Buffer.alloc(s, 10, 2); -SynthDef(\string_model, {arg freq, gate = 1, sustain, amp, dur, busIndex = 0; - var trig, exc, sig1, sig2, noHarms; - noHarms = 30; - exc = Saw.ar(freq, TRand.ar(0.5, 1, Impulse.ar(freq))) * 0.001 + Dust.ar(10000, 0.01); - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(1, 2)}) ], exc) * 0.8).softclip; - sig1 = HPF.ar(sig1, 300); - Out.ar(Select.kr(busIndex, ~stringModelBusArray), sig1 * EnvGen.kr(Env.adsr(0.3, 0.3, 0.9, 0.5, 0.9), gate, doneAction: 2)); - //Out.ar([0, 1], sig1 * EnvGen.kr(Env.asr(dur, 0.3, 1), gate, doneAction: 2)); -}).add; - -SynthDef(\sine, {arg freq, gate = 1, sustain, amp, dur, busIndex = 0; - var sig; - sig = SinOsc.ar(freq); - Out.ar(Select.kr(busIndex, ~sineBusArray), sig * EnvGen.kr(Env.asr(0.3, 0.4, 0.3), gate, timeScale: dur, doneAction: 2)); -}).add; - -SynthDef(\mixer, {arg freq, gate = 1, sustain, amp, dur, out; - var nameSpaces, sigs, hierarchicalDust; - - hierarchicalDust = ( - TIRand.kr(0, 1, Impulse.kr(100)) * - TIRand.kr(0, 1, Impulse.kr(10)) * - TIRand.kr(0, 1, Impulse.kr(1)) - ); - - sigs = [~stringModelBusArray, ~sineBusArray, ~bassBusArray, ~hdustBusArray, ~samplerBusArray].collect({arg busArray, i; - var nameSpace, sig; - nameSpace = ['string', 'sine', 'bass', 'hdust', 'sampler'][i]; - sig = busArray.collect({arg bus, c; In.ar(bus, 1) * NamedControl.kr(\ ++ nameSpace ++ '_volume_' ++ c, 1, 0.1)}); - sig = sig.collect({arg channel, c; Pan2.ar(channel, NamedControl.kr(\ ++ nameSpace ++ '_pan_' ++ c, i / (busArray.size - 1), 0.1) * 2 - 1)}); - sig = sig.collect({arg channel, c; channel * NamedControl.kr(\ ++ nameSpace ++ '_mute_' ++ c, 1, 0.1)}); - sig = Mix.ar(sig) * pow(NamedControl.kr(\ ++ nameSpace ++ '_volume_master', 1, 0.1), 2); - }); - - sigs = Mix.ar(sigs / 4); - Out.ar(0, sigs) -}).add; - -SynthDef(\bass, { - var switches, drone; - switches = {|i| Dust.kr(0.1)} ! 9; - drone = {|i| var harm = pow(2, 2 - (i / 3).trunc), amp = (1 / pow(harm, 2)); - SinOsc.ar(60 * harm + TRand.kr(-3, 3, switches[i]), 0, amp)} ! 9; - Out.ar(~bassBusArray[0], Mix.new(drone) * 0.2); -}).add; - -SynthDef(\sampler, { - Out.ar(~samplerBusArray, PlayBuf.ar(2, ~sBuf, BufRateScale.kr(~sBuf), doneAction: 2)) -}).add; - -// main routine -SynthDef(\hdust, { - arg gate = 0; - var hierarchical_dust, low_sine, high_sine, brown_noise, white_noise; - // this triggers the combinations of sources - // it is similar to the Supercollider UGen called dust but with a hierarchical structure - hierarchical_dust = ( - TIRand.kr(0, 1, Impulse.kr(100)) * - TIRand.kr(0, 1, Impulse.kr(10)) * - TIRand.kr(0, 1, Impulse.kr(1)) * - TIRand.kr(0, 1, Impulse.kr(0.1)) - ); - // adjust the multiplier at the end of each line for adjusting levels - // note with each trigger, each source has a 1 in 3 chance of sounding - low_sine = SinOsc.ar(76.midicps / 16) * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.1; - high_sine = SinOsc.ar(76.midicps * 8) * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.01; - brown_noise = BrownNoise.ar() * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.025; - white_noise = WhiteNoise.ar() * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.02; - Out.ar(~hdustBusArray[0], - ((low_sine + high_sine + brown_noise + white_noise) ) - ); -}).add; - -) - -( -var bass, hdust, sampler, mixer; -bass = Synth.tail(~group, \bass); -hdust = Synth.tail(~group, \hdust); -sampler = Synth.head(~group, \sampler); -mixer = Synth.tail(~group, \mixer); -OSCdef(\mixer, {arg msg, time, addr, port; - mixer.set((msg[1] ++ '_' ++ msg[2] ++ '_' ++ msg[3]), msg[4]) -}, \mixer); - -OSCdef(\sampler, {arg msg, time, addr, port; - msg.postln; - sampler.free; - ~sBuf.free; - ~sBuf = Buffer.read(s, msg[1].asString.postln, action: {sampler = Synth.head(~group, \sampler)}); -}, \sampler); -) - -/* old something -( -SynthDef(\test, {arg freq, gate = 1, sustain, amp, dur; - var trig, exc, sig1, sig2, noHarms, freqFinal, start, end; - noHarms = 30; - freq = WhiteNoise.ar * 3 + freq; - freqFinal = Duty.ar((1/freq), 0, freq); - trig = Changed.ar(freqFinal); - start = Demand.ar(trig, 0, Dwhite(-1, -0.75)); - end = Demand.ar(trig, 0, Dwhite(0.75, 1)); - exc = Phasor.ar(trig, (end - start) * freqFinal / SampleRate.ir, start, end, 0) * 0.001 + Dust.ar(10000, 0.01); - - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(2, 3)}) ], exc) * 0.5).softclip; - sig1 = HPF.ar(sig1, 300); - Out.ar([0, 1], sig1 * EnvGen.kr(Env.adsr(0.3, 0.3, 0.9, 0.5, 0.9), gate, doneAction: 2)); -}).add; -) -*/ - diff --git a/resources/resources_bak_2024_01_03/piece_ledger_pas/7bf874ce/7bf874ce_mus_model.json b/resources/resources_bak_2024_01_03/piece_ledger_pas/7bf874ce/7bf874ce_mus_model.json deleted file mode 100644 index 4675781..0000000 --- a/resources/resources_bak_2024_01_03/piece_ledger_pas/7bf874ce/7bf874ce_mus_model.json +++ /dev/null @@ -1,59 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ "Rest" ], [ 1, 0, 0, 0, 0, -1 ], [ "Rest" ] ], 0.375 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 1, 0, 0, 0, 0, -1 ], [ "Rest" ] ], 2.25 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 1, 0, 0, 0, 0, -1 ], [ 1, 0, 1, 0, 0, 0 ] ], 0.375 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ], [ 1, 0, 1, 0, 0, 0 ] ], 0.5 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ], [ 2, 0, 0, 0, 0, -1 ] ], 0.375 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ], [ 2, 0, 0, 0, 0, -1 ] ], 3.625 ] - ], - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 1, 0, 0, 0, 0, -1 ], [ 2, 0, 0, 0, 0, -1 ] ], 0.875 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 1, 0, 0, 0, 0, -1 ], [ "Rest" ] ], 0.625 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 0, 1, 0, 0 ], [ "Rest" ] ], 0.75 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 1, 0, 0, 0, 0, 0 ], [ "Rest" ] ], 4.125 ] - ], - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ], [ "Rest" ] ], 0.375 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 0, 1, 1, 0, 0, 0 ], [ "Rest" ] ], 0.5 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 0, 1, 1, 0, 0, 0 ], [ 1, 0, 1, 0, 0, 0 ] ], 4 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 1, 1, 0, 0, 0 ], [ 1, 0, 1, 0, 0, 0 ] ], 0.5 ], - [ [ [ "Rest" ], [ "Rest" ], [ 0, 1, 1, 0, 0, 0 ], [ 1, 0, 1, 0, 0, 0 ] ], 0.875 ], - [ [ [ "Rest" ], [ "Rest" ], [ 0, 1, 1, 0, 0, 0 ], [ "Rest" ] ], 0.5 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 4.375 ] - ] - ] -], -"last_changes": -[ - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ], [ 2, 0, 0, 0, 0, -1 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 0, 0, 0, 1, 0, 0 ], [ 2, 0, 0, 0, 0, -1 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ], [ 2, 0, 0, 0, 0, -1 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 0, 1, 1, 0, 0, 0 ], [ 2, 0, 0, 0, 0, -1 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 0, 1, 1, 0, 0, 0 ], [ 1, 0, 1, 0, 0, 0 ] ] -], -"cur_uid": "7bf874ce", -"ref_uid": "6d0c2f19", -"order_seed": 460016, -"dur_seed": 553757, -"motifs_seed": 771464, -"entrances_probs_vals": [ 0, 1.67, 4.8015873015873, 0.24725274725275, 1.15, 0.20725388601036, 0.68581081081081, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"passages_probs_vals": [ 0, 1.67, 4.8015873015873, 0.24725274725275, 1.15, 0.20725388601036, 0.68581081081081, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"exits_probs_vals": [ 0, 1.67, 4.8015873015873, 0.24725274725275, 1.15, 0.20725388601036, 0.68581081081081, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"ranges": [ [ -1100, 460.68111455108 ], [ -507, 1084.8297213622 ], [ 884.21052631579, 2237 ], [ 1040.2476780186, 2053 ] ], -"passages_weights": [ 0.75, 0.75, 0.75, 0.75, 0.75 ], -"order": -[ - [ [ 2, 0 ], [ 3, 1, 3, 1 ], [ ] ], - [ [ 0 ], [ 2, 2 ], [ 1, 3 ] ], - [ [ 1, 0 ], [ 2, 3 ], [ ] ] -], -"sus_weights": [ 0.75, 0.69, 0.75 ], -"order_size": [ 1, 4 ], -"passages_size": [ 0, 3 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/piece_ledger_pas/7c7a96a2/7c7a96a2_code.scd b/resources/resources_bak_2024_01_03/piece_ledger_pas/7c7a96a2/7c7a96a2_code.scd deleted file mode 100644 index 1b308bc..0000000 --- a/resources/resources_bak_2024_01_03/piece_ledger_pas/7c7a96a2/7c7a96a2_code.scd +++ /dev/null @@ -1,897 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - pDistance.gaussCurve(1, mean, sd) -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = 1/pow(hdSum.value(voices.deepCopy.put(ins, candidate)), 2); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~msg.postln; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, rels; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - rels = freqs.drop(-1).collect({rrand(0.3, 0.5)}) ++ [rrand(1, 2)]; - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - //res.postln; - if(res.every({arg char; char.isDecDigit}), {res = res.asInteger}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file; - file = File(path, "w"); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "passages_weights", "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((dir +/+ ".." +/+ "resources" +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - - curUID = genUID.value; - - File.mkdir((dir +/+ ".." +/+ "resources" +/+ curUID).standardizePath); - File.copy(exPath, (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - ledger = ledger.drop(-1).add(curUID); - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - player.stop; - group.set(\gate, 0); - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (dir +/+ ".." +/+ "resources" +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - -) - -( -//synthdefs -~stringModelBusArray = 4.collect({Bus.audio(s, 1)}); -~sineBusArray = 4.collect({Bus.audio(s, 1)}); -~bassBusArray = 1.collect({Bus.audio(s, 1)}); -~hdustBusArray = 1.collect({Bus.audio(s, 1)}); -~samplerBusArray = 2.collect({Bus.audio(s, 1)}); -~sBuf = Buffer.alloc(s, 10, 2); -SynthDef(\string_model, {arg freq, gate = 1, sustain, amp, dur, busIndex = 0; - var trig, exc, sig1, sig2, noHarms; - noHarms = 30; - exc = Saw.ar(freq, TRand.ar(0.5, 1, Impulse.ar(freq))) * 0.001 + Dust.ar(10000, 0.01); - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(1, 2)}) ], exc) * 0.8).softclip; - sig1 = HPF.ar(sig1, 300); - Out.ar(Select.kr(busIndex, ~stringModelBusArray), sig1 * EnvGen.kr(Env.adsr(0.3, 0.3, 0.9, 3, 0.9), gate, doneAction: 2)); - //Out.ar([0, 1], sig1 * EnvGen.kr(Env.asr(dur, 0.3, 1), gate, doneAction: 2)); -}).add; - -SynthDef(\sine, {arg freq, gate = 1, sustain, amp, dur, busIndex = 0; - var sig; - sig = SinOsc.ar(freq); - Out.ar(Select.kr(busIndex, ~sineBusArray), sig * EnvGen.kr(Env.asr(0.3, 0.4, 0.3), gate, timeScale: dur, doneAction: 2)); - //Out.ar(Select.kr(busIndex, ~sineBusArray), sig * EnvGen.kr(Env.sine(dur), gate, doneAction: 2)); -}).add; - -SynthDef(\mixer, {arg freq, gate = 1, sustain, amp, dur, out; - var nameSpaces, sigs, hierarchicalDust; - - hierarchicalDust = ( - TIRand.kr(0, 1, Impulse.kr(100)) * - TIRand.kr(0, 1, Impulse.kr(10)) * - TIRand.kr(0, 1, Impulse.kr(1)) - ); - - sigs = [~stringModelBusArray, ~sineBusArray, ~bassBusArray, ~hdustBusArray, ~samplerBusArray].collect({arg busArray, i; - var nameSpace, sig; - nameSpace = ['string', 'sine', 'bass', 'hdust', 'sampler'][i]; - sig = busArray.collect({arg bus, c; In.ar(bus, 1) * NamedControl.kr(\ ++ nameSpace ++ '_volume_' ++ c, 1, 0.1)}); - sig = sig.collect({arg channel, c; Pan2.ar(channel, NamedControl.kr(\ ++ nameSpace ++ '_pan_' ++ c, i / (busArray.size - 1), 0.1) * 2 - 1)}); - sig = sig.collect({arg channel, c; channel * NamedControl.kr(\ ++ nameSpace ++ '_mute_' ++ c, 1, 0.1)}); - sig = Mix.ar(sig) * pow(NamedControl.kr(\ ++ nameSpace ++ '_volume_master', 1, 0.1), 2); - }); - - sigs = Mix.ar(sigs / 4); - Out.ar(0, sigs) -}).add; - -SynthDef(\bass, { - var switches, drone; - switches = {|i| Dust.kr(0.1)} ! 9; - drone = {|i| var harm = pow(2, 2 - (i / 3).trunc), amp = (1 / pow(harm, 2)); - SinOsc.ar(60 * harm + TRand.kr(-3, 3, switches[i]), 0, amp)} ! 9; - Out.ar(~bassBusArray[0], Mix.new(drone) * 0.2); -}).add; - -SynthDef(\sampler, { - Out.ar(~samplerBusArray, PlayBuf.ar(2, ~sBuf, BufRateScale.kr(~sBuf), doneAction: 2)) -}).add; - -// main routine -SynthDef(\hdust, { - arg gate = 0; - var hierarchical_dust, low_sine, high_sine, brown_noise, white_noise; - // this triggers the combinations of sources - // it is similar to the Supercollider UGen called dust but with a hierarchical structure - hierarchical_dust = ( - TIRand.kr(0, 1, Impulse.kr(100)) * - TIRand.kr(0, 1, Impulse.kr(10)) * - TIRand.kr(0, 1, Impulse.kr(1)) * - TIRand.kr(0, 1, Impulse.kr(0.1)) - ); - // adjust the multiplier at the end of each line for adjusting levels - // note with each trigger, each source has a 1 in 3 chance of sounding - low_sine = SinOsc.ar(76.midicps / 16) * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.1; - high_sine = SinOsc.ar(76.midicps * 8) * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.01; - brown_noise = BrownNoise.ar() * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.025; - white_noise = WhiteNoise.ar() * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.02; - Out.ar(~hdustBusArray[0], - ((low_sine + high_sine + brown_noise + white_noise) ) - ); -}).add; - -) - -( -var bass, hdust, sampler, mixer; -bass = Synth.tail(~group, \bass); -hdust = Synth.tail(~group, \hdust); -sampler = Synth.head(~group, \sampler); -mixer = Synth.tail(~group, \mixer); -OSCdef(\mixer, {arg msg, time, addr, port; - mixer.set((msg[1] ++ '_' ++ msg[2] ++ '_' ++ msg[3]), msg[4]) -}, \mixer); - -OSCdef(\sampler, {arg msg, time, addr, port; - msg.postln; - sampler.free; - ~sBuf.free; - ~sBuf = Buffer.read(s, msg[1].asString.postln, action: {sampler = Synth.head(~group, \sampler)}); -}, \sampler); -) - -/* old something -( -SynthDef(\test, {arg freq, gate = 1, sustain, amp, dur; - var trig, exc, sig1, sig2, noHarms, freqFinal, start, end; - noHarms = 30; - freq = WhiteNoise.ar * 3 + freq; - freqFinal = Duty.ar((1/freq), 0, freq); - trig = Changed.ar(freqFinal); - start = Demand.ar(trig, 0, Dwhite(-1, -0.75)); - end = Demand.ar(trig, 0, Dwhite(0.75, 1)); - exc = Phasor.ar(trig, (end - start) * freqFinal / SampleRate.ir, start, end, 0) * 0.001 + Dust.ar(10000, 0.01); - - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(2, 3)}) ], exc) * 0.5).softclip; - sig1 = HPF.ar(sig1, 300); - Out.ar([0, 1], sig1 * EnvGen.kr(Env.adsr(0.3, 0.3, 0.9, 0.5, 0.9), gate, doneAction: 2)); -}).add; -) -*/ - diff --git a/resources/resources_bak_2024_01_03/piece_ledger_pas/7c7a96a2/7c7a96a2_mus_model.json b/resources/resources_bak_2024_01_03/piece_ledger_pas/7c7a96a2/7c7a96a2_mus_model.json deleted file mode 100644 index cd8ded8..0000000 --- a/resources/resources_bak_2024_01_03/piece_ledger_pas/7c7a96a2/7c7a96a2_mus_model.json +++ /dev/null @@ -1,45 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ 1, 0, 0, -1, 1, -1 ], [ "Rest" ], [ "Rest" ] ], 1.625 ], - [ [ [ "Rest" ], [ 1, 0, 0, -1, 1, -1 ], [ "Rest" ], [ 3, 0, 0, -1, 0, -1 ] ], 1.25 ], - [ [ [ 0, 1, 0, -1, 1, -1 ], [ 1, 0, 0, -1, 1, -1 ], [ "Rest" ], [ 3, 0, 0, -1, 0, -1 ] ], 1.25 ], - [ [ [ 0, 1, 0, -1, 1, -1 ], [ 1, 0, 0, -1, 1, -1 ], [ 3, 0, -1, -1, 1, -1 ], [ 3, 0, 0, -1, 0, -1 ] ], 1.5 ], - [ [ [ 0, 0, 0, -1, 2, -1 ], [ 1, 0, 0, -1, 1, -1 ], [ 3, 0, -1, -1, 1, -1 ], [ 3, 0, 0, -1, 0, -1 ] ], 2.125 ], - [ [ [ 0, 0, 0, -1, 2, -1 ], [ 1, 0, 0, -1, 1, -1 ], [ "Rest" ], [ 3, 0, 0, -1, 0, -1 ] ], 1.5 ], - [ [ [ 0, 0, 0, -1, 2, -1 ], [ "Rest" ], [ "Rest" ], [ 3, 0, 0, -1, 0, -1 ] ], 1.125 ], - [ [ [ 0, 0, 0, -1, 2, -1 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 1.375 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 1.75 ] - ] - ] -], -"last_changes": -[ - [ [ -1, 0, 0, 1, 1, -1 ], [ 1, 0, 0, -1, 1, -1 ], [ 2, 0, 0, 0, 1, -1 ], [ 1, 1, 0, 0, 1, -1 ] ], - [ [ -1, 0, 0, 1, 1, -1 ], [ 1, 0, 0, -1, 1, -1 ], [ 2, 0, 0, 0, 1, -1 ], [ 3, 0, 0, -1, 0, -1 ] ], - [ [ 0, 1, 0, -1, 1, -1 ], [ 1, 0, 0, -1, 1, -1 ], [ 2, 0, 0, 0, 1, -1 ], [ 3, 0, 0, -1, 0, -1 ] ], - [ [ 0, 1, 0, -1, 1, -1 ], [ 1, 0, 0, -1, 1, -1 ], [ 3, 0, -1, -1, 1, -1 ], [ 3, 0, 0, -1, 0, -1 ] ], - [ [ 0, 0, 0, -1, 2, -1 ], [ 1, 0, 0, -1, 1, -1 ], [ 3, 0, -1, -1, 1, -1 ], [ 3, 0, 0, -1, 0, -1 ] ] -], -"cur_uid": "7c7a96a2", -"ref_uid": "6f1305ed", -"order_seed": 768571, -"dur_seed": 647965, -"motifs_seed": 710750, -"entrances_probs_vals": [ 0, 0.48, 1.7460317460317, 0.58, 1.6758241758242, 0.20725388601036, 0.68581081081081, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"passages_probs_vals": [ 0, 0.48, 1.7460317460317, 0.58, 1.6758241758242, 0.20725388601036, 0.68581081081081, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"exits_probs_vals": [ 0, 0.48, 1.7460317460317, 0.58, 1.6758241758242, 0.20725388601036, 0.68581081081081, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"ranges": [ [ -1100, 237.77089783282 ], [ -1066.253869969, 260.06191950464 ], [ 1207.4303405573, 2065.6346749226 ], [ 1040.2476780186, 2053 ] ], -"passages_weights": [ 0.75, 0.75, 0.75, 0.75, 0.75 ], -"order": -[ - [ [ 1 ], [ 3, 0, 2, 0 ], [ ] ] -], -"sus_weights": [ 0.73, 0.49, 0 ], -"order_size": [ 1, 7 ], -"passages_size": [ 0, 2 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/piece_ledger_pas/7c8bc6df/7c8bc6df_code.scd b/resources/resources_bak_2024_01_03/piece_ledger_pas/7c8bc6df/7c8bc6df_code.scd deleted file mode 100644 index a4e8b56..0000000 --- a/resources/resources_bak_2024_01_03/piece_ledger_pas/7c8bc6df/7c8bc6df_code.scd +++ /dev/null @@ -1,907 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - pDistance.gaussCurve(1, mean, sd) -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = 1/pow(hdSum.value(voices.deepCopy.put(ins, candidate)), 2); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~msg.postln; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1, 3)}, {rrand(0.3, 0.5)}); - }); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - //res.postln; - if(res.every({arg char; char.isDecDigit}), {res = res.asInteger}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file; - file = File(path, "w"); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "passages_weights", "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((dir +/+ ".." +/+ "resources" +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - - curUID = genUID.value; - - File.mkdir((dir +/+ ".." +/+ "resources" +/+ curUID).standardizePath); - File.copy(exPath, (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - ledger = ledger.drop(-1).add(curUID); - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (dir +/+ ".." +/+ "resources" +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - -) - -( -//synthdefs -~stringModelBusArray = 4.collect({Bus.audio(s, 1)}); -~sineBusArray = 4.collect({Bus.audio(s, 1)}); -~bassBusArray = 1.collect({Bus.audio(s, 1)}); -~hdustBusArray = 1.collect({Bus.audio(s, 1)}); -~samplerBusArray = 2.collect({Bus.audio(s, 1)}); -~sBuf = Buffer.alloc(s, 10, 2); -SynthDef(\string_model, {arg freq, gate = 1, sustain, amp, dur, attack, release = 1, busIndex = 0; - var trig, exc, sig1, sig2, noHarms; - noHarms = 30; - exc = Saw.ar(freq, TRand.ar(0.5, 1, Impulse.ar(freq))) * 0.001 + Dust.ar(10000, 0.01); - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(1, 2)}) ], exc) * 0.8).softclip; - sig1 = HPF.ar(sig1, 300); - Out.ar(Select.kr(busIndex, ~stringModelBusArray), sig1 * amp * EnvGen.kr(Env.adsr(attack, 0.3, 0.9, release, 0.9, -3), gate, doneAction: 2)); - //Out.ar([0, 1], sig1 * EnvGen.kr(Env.asr(dur, 0.3, 1), gate, doneAction: 2)); -}).add; - -SynthDef(\sine, {arg freq, gate = 1, sustain, amp, dur, busIndex = 0; - var sig; - sig = SinOsc.ar(freq); - Out.ar(Select.kr(busIndex, ~sineBusArray), sig * EnvGen.kr(Env.asr(0.3, 0.4, 0.3), gate, timeScale: dur, doneAction: 2)); - //Out.ar(Select.kr(busIndex, ~sineBusArray), sig * EnvGen.kr(Env.sine(dur), gate, doneAction: 2)); -}).add; - -SynthDef(\mixer, {arg freq, gate = 1, sustain, amp, dur, out; - var nameSpaces, sigs, hierarchicalDust; - - hierarchicalDust = ( - TIRand.kr(0, 1, Impulse.kr(100)) * - TIRand.kr(0, 1, Impulse.kr(10)) * - TIRand.kr(0, 1, Impulse.kr(1)) - ); - - sigs = [~stringModelBusArray, ~sineBusArray, ~bassBusArray, ~hdustBusArray, ~samplerBusArray].collect({arg busArray, i; - var nameSpace, sig; - nameSpace = ['string', 'sine', 'bass', 'hdust', 'sampler'][i]; - sig = busArray.collect({arg bus, c; In.ar(bus, 1) * NamedControl.kr(\ ++ nameSpace ++ '_volume_' ++ c, 1, 0.1)}); - sig = sig.collect({arg channel, c; Pan2.ar(channel, NamedControl.kr(\ ++ nameSpace ++ '_pan_' ++ c, i / (busArray.size - 1), 0.1) * 2 - 1)}); - sig = sig.collect({arg channel, c; channel * NamedControl.kr(\ ++ nameSpace ++ '_mute_' ++ c, 1, 0.1)}); - sig = Mix.ar(sig) * pow(NamedControl.kr(\ ++ nameSpace ++ '_volume_master', 1, 0.1), 2); - }); - - sigs = Mix.ar(sigs / 4); - Out.ar(0, sigs) -}).add; - -SynthDef(\bass, { - var switches, drone; - switches = {|i| Dust.kr(0.1)} ! 9; - drone = {|i| var harm = pow(2, 2 - (i / 3).trunc), amp = (1 / pow(harm, 2)); - SinOsc.ar(60 * harm + TRand.kr(-3, 3, switches[i]), 0, amp)} ! 9; - Out.ar(~bassBusArray[0], Mix.new(drone) * 0.2); -}).add; - -SynthDef(\sampler, { - Out.ar(~samplerBusArray, PlayBuf.ar(2, ~sBuf, BufRateScale.kr(~sBuf), doneAction: 2)) -}).add; - -// main routine -SynthDef(\hdust, { - arg gate = 0; - var hierarchical_dust, low_sine, high_sine, brown_noise, white_noise; - // this triggers the combinations of sources - // it is similar to the Supercollider UGen called dust but with a hierarchical structure - hierarchical_dust = ( - TIRand.kr(0, 1, Impulse.kr(100)) * - TIRand.kr(0, 1, Impulse.kr(10)) * - TIRand.kr(0, 1, Impulse.kr(1)) * - TIRand.kr(0, 1, Impulse.kr(0.1)) - ); - // adjust the multiplier at the end of each line for adjusting levels - // note with each trigger, each source has a 1 in 3 chance of sounding - low_sine = SinOsc.ar(76.midicps / 16) * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.1; - high_sine = SinOsc.ar(76.midicps * 8) * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.01; - brown_noise = BrownNoise.ar() * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.025; - white_noise = WhiteNoise.ar() * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.02; - Out.ar(~hdustBusArray[0], - ((low_sine + high_sine + brown_noise + white_noise) ) - ); -}).add; - -) - -( -var bass, hdust, sampler, mixer; -bass = Synth.tail(~group, \bass); -hdust = Synth.tail(~group, \hdust); -sampler = Synth.head(~group, \sampler); -mixer = Synth.tail(~group, \mixer); -OSCdef(\mixer, {arg msg, time, addr, port; - mixer.set((msg[1] ++ '_' ++ msg[2] ++ '_' ++ msg[3]), msg[4]) -}, \mixer); - -OSCdef(\sampler, {arg msg, time, addr, port; - msg.postln; - sampler.free; - ~sBuf.free; - ~sBuf = Buffer.read(s, msg[1].asString.postln, action: {sampler = Synth.head(~group, \sampler)}); -}, \sampler); -) - -/* old something -( -SynthDef(\test, {arg freq, gate = 1, sustain, amp, dur; - var trig, exc, sig1, sig2, noHarms, freqFinal, start, end; - noHarms = 30; - freq = WhiteNoise.ar * 3 + freq; - freqFinal = Duty.ar((1/freq), 0, freq); - trig = Changed.ar(freqFinal); - start = Demand.ar(trig, 0, Dwhite(-1, -0.75)); - end = Demand.ar(trig, 0, Dwhite(0.75, 1)); - exc = Phasor.ar(trig, (end - start) * freqFinal / SampleRate.ir, start, end, 0) * 0.001 + Dust.ar(10000, 0.01); - - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(2, 3)}) ], exc) * 0.5).softclip; - sig1 = HPF.ar(sig1, 300); - Out.ar([0, 1], sig1 * EnvGen.kr(Env.adsr(0.3, 0.3, 0.9, 0.5, 0.9), gate, doneAction: 2)); -}).add; -) -*/ - diff --git a/resources/resources_bak_2024_01_03/piece_ledger_pas/7c8bc6df/7c8bc6df_mus_model.json b/resources/resources_bak_2024_01_03/piece_ledger_pas/7c8bc6df/7c8bc6df_mus_model.json deleted file mode 100644 index a8f0de5..0000000 --- a/resources/resources_bak_2024_01_03/piece_ledger_pas/7c8bc6df/7c8bc6df_mus_model.json +++ /dev/null @@ -1,84 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ "Rest" ], [ 6, -1, 0, -1, -1, -4 ], [ "Rest" ] ], 2.375 ], - [ [ [ "Rest" ], [ 4, -1, 1, -1, -1, -4 ], [ 6, -1, 0, -1, -1, -4 ], [ "Rest" ] ], 1.25 ], - [ [ [ "Rest" ], [ 5, -2, 0, -1, -1, -4 ], [ 6, -1, 0, -1, -1, -4 ], [ "Rest" ] ], 1.5 ], - [ [ [ "Rest" ], [ 5, -1, 0, -2, -1, -4 ], [ 6, -1, 0, -1, -1, -4 ], [ "Rest" ] ], 1.25 ], - [ [ [ "Rest" ], [ 5, -1, 0, -1, -1, -5 ], [ 6, -1, 0, -1, -1, -4 ], [ "Rest" ] ], 3.125 ] - ], - [ - [ [ [ "Rest" ], [ 5, -1, 0, -1, -1, -5 ], [ 6, -1, 0, -1, -1, -4 ], [ 5, -1, 0, 0, 0, -5 ] ], 2.625 ], - [ [ [ 3, -1, 0, -1, 0, -5 ], [ 5, -1, 0, -1, -1, -5 ], [ 6, -1, 0, -1, -1, -4 ], [ 5, -1, 0, 0, 0, -5 ] ], 1.375 ], - [ [ [ 3, -1, 0, -1, 0, -5 ], [ 5, -1, 0, -1, -1, -5 ], [ 5, -1, 1, 0, 0, -5 ], [ 5, -1, 0, 0, 0, -5 ] ], 2.625 ] - ], - [ - [ [ [ 3, -1, 0, -1, 0, -5 ], [ 3, 0, 1, 0, 0, -5 ], [ 5, -1, 1, 0, 0, -5 ], [ 5, -1, 0, 0, 0, -5 ] ], 1.125 ], - [ [ [ 2, -1, 1, 0, 0, -5 ], [ 3, 0, 1, 0, 0, -5 ], [ 5, -1, 1, 0, 0, -5 ], [ 5, -1, 0, 0, 0, -5 ] ], 0.875 ], - [ [ [ 2, -1, 1, 0, 0, -5 ], [ 3, 0, 1, 0, 0, -5 ], [ 5, -1, 1, 0, 0, -5 ], [ 4, -1, 1, 1, 0, -5 ] ], 1.5 ], - [ [ [ 2, -1, 1, 0, 0, -5 ], [ 3, -1, 1, 1, 0, -5 ], [ 5, -1, 1, 0, 0, -5 ], [ 4, -1, 1, 1, 0, -5 ] ], 1 ], - [ [ [ 3, -1, 1, -1, 0, -5 ], [ 3, -1, 1, 1, 0, -5 ], [ 5, -1, 1, 0, 0, -5 ], [ 4, -1, 1, 1, 0, -5 ] ], 2.125 ] - ], - [ - [ [ [ 3, -1, 1, -1, 0, -5 ], [ 3, -1, 1, 1, 0, -5 ], [ 4, -1, 2, 1, 0, -5 ], [ 4, -1, 1, 1, 0, -5 ] ], 0.75 ], - [ [ [ 2, -1, 1, 1, 0, -6 ], [ 3, -1, 1, 1, 0, -5 ], [ 4, -1, 2, 1, 0, -5 ], [ 4, -1, 1, 1, 0, -5 ] ], 0.75 ], - [ [ [ 2, -2, 1, 1, 0, -5 ], [ 3, -1, 1, 1, 0, -5 ], [ 4, -1, 2, 1, 0, -5 ], [ 4, -1, 1, 1, 0, -5 ] ], 2 ] - ], - [ - [ [ [ 2, -2, 1, 1, 0, -5 ], [ 3, -1, 1, 1, 0, -5 ], [ "Rest" ], [ 4, -1, 1, 1, 0, -5 ] ], 0.75 ], - [ [ [ 2, -1, 1, 1, -1, -5 ], [ 3, -1, 1, 1, 0, -5 ], [ "Rest" ], [ 4, -1, 1, 1, 0, -5 ] ], 1.125 ], - [ [ [ 2, -1, 1, 1, -1, -5 ], [ 2, -1, 1, 2, 0, -5 ], [ "Rest" ], [ 4, -1, 1, 1, 0, -5 ] ], 1 ], - [ [ [ 2, -1, 1, 1, -1, -5 ], [ 3, -1, 0, 1, 0, -5 ], [ "Rest" ], [ 4, -1, 1, 1, 0, -5 ] ], 1.5 ], - [ [ [ 2, -1, 1, 1, -1, -5 ], [ 2, -1, 1, 1, 0, -4 ], [ "Rest" ], [ 4, -1, 1, 1, 0, -5 ] ], 1.5 ], - [ [ [ 1, -1, 1, 1, 1, -5 ], [ 2, -1, 1, 1, 0, -4 ], [ "Rest" ], [ 4, -1, 1, 1, 0, -5 ] ], 0.75 ], - [ [ [ 1, -1, 1, 1, 1, -5 ], [ 2, 0, 1, 1, 0, -5 ], [ "Rest" ], [ 4, -1, 1, 1, 0, -5 ] ], 1.5 ] - ], - [ - [ [ [ 1, -1, 1, 1, 1, -5 ], [ 2, 0, 1, 1, 0, -5 ], [ "Rest" ], [ 3, 0, 1, 1, 1, -5 ] ], 0.75 ], - [ [ [ 1, -1, 1, 1, 1, -5 ], [ 2, 0, 1, 1, 0, -5 ], [ 3, -1, 1, 2, 1, -5 ], [ 3, 0, 1, 1, 1, -5 ] ], 1.625 ], - [ [ [ 1, -1, 1, 1, 1, -5 ], [ 2, -1, 1, 1, 1, -5 ], [ 3, -1, 1, 2, 1, -5 ], [ 3, 0, 1, 1, 1, -5 ] ], 1.125 ], - [ [ [ 1, -1, 1, 1, 1, -5 ], [ 1, -1, 1, 2, 1, -5 ], [ 3, -1, 1, 2, 1, -5 ], [ 3, 0, 1, 1, 1, -5 ] ], 0.875 ], - [ [ [ 1, -1, 1, 1, 1, -5 ], [ 1, 0, 1, 1, 1, -5 ], [ 3, -1, 1, 2, 1, -5 ], [ 3, 0, 1, 1, 1, -5 ] ], 1.5 ], - [ [ [ 1, -1, 1, 1, 1, -5 ], [ 1, 0, 1, 1, 1, -5 ], [ 4, -1, 0, 1, 1, -5 ], [ 3, 0, 1, 1, 1, -5 ] ], 2.625 ], - [ [ [ "Rest" ], [ 1, 0, 1, 1, 1, -5 ], [ 4, -1, 0, 1, 1, -5 ], [ 3, 0, 1, 1, 1, -5 ] ], 1 ], - [ [ [ "Rest" ], [ 1, 0, 1, 1, 1, -5 ], [ 4, -1, 0, 1, 1, -5 ], [ "Rest" ] ], 1.5 ], - [ [ [ "Rest" ], [ "Rest" ], [ 4, -1, 0, 1, 1, -5 ], [ "Rest" ] ], 1.25 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 2.875 ] - ] - ] -], -"last_changes": -[ - [ [ 1, -1, 1, 1, 1, -5 ], [ 2, 0, 1, 1, 0, -5 ], [ 3, -1, 1, 2, 1, -5 ], [ 3, 0, 1, 1, 1, -5 ] ], - [ [ 1, -1, 1, 1, 1, -5 ], [ 2, -1, 1, 1, 1, -5 ], [ 3, -1, 1, 2, 1, -5 ], [ 3, 0, 1, 1, 1, -5 ] ], - [ [ 1, -1, 1, 1, 1, -5 ], [ 1, -1, 1, 2, 1, -5 ], [ 3, -1, 1, 2, 1, -5 ], [ 3, 0, 1, 1, 1, -5 ] ], - [ [ 1, -1, 1, 1, 1, -5 ], [ 1, 0, 1, 1, 1, -5 ], [ 3, -1, 1, 2, 1, -5 ], [ 3, 0, 1, 1, 1, -5 ] ], - [ [ 1, -1, 1, 1, 1, -5 ], [ 1, 0, 1, 1, 1, -5 ], [ 4, -1, 0, 1, 1, -5 ], [ 3, 0, 1, 1, 1, -5 ] ] -], -"cur_uid": "7c8bc6df", -"ref_uid": "tmp", -"order_seed": 487536, -"dur_seed": 140662, -"motifs_seed": 617352, -"entrances_probs_vals": [ 0, 0.48, 1.7460317460317, 0.58, 1.68, 0.20725388601036, 0.68581081081081, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"passages_probs_vals": [ 0, 0.48, 1.7460317460317, 0.58, 1.68, 0.20725388601036, 0.68581081081081, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"exits_probs_vals": [ 0, 0.48, 1.7460317460317, 0.58, 1.68, 0.20725388601036, 0.68581081081081, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"ranges": [ [ -3600, -627.86377708978 ], [ -3600, 260 ], [ -980.80495356037, 2066 ], [ -627.86377708978, 2053 ] ], -"passages_weights": [ 0.75, 0.75, 0.75, 0.75, 0.75 ], -"order": -[ - [ [ 2 ], [ 1, 1, 1, 1 ], [ 3, 0 ] ], - [ [ 1, 3 ], [ 0, 2 ], [ ] ], - [ [ 2 ], [ 1, 0, 3, 1, 0 ], [ ] ], - [ [ 1, 3 ], [ 2, 0, 0 ], [ ] ], - [ [ 3 ], [ 0, 1, 1, 1, 0, 1 ], [ 2 ] ], - [ [ 0 ], [ 3, 2, 1, 1, 1, 2 ], [ ] ] -], -"sus_weights": [ 0.73, 0.49, 0 ], -"order_size": [ 1, 7 ], -"passages_size": [ 0, 5 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/piece_ledger_pas/7e170ef8/7e170ef8_code.scd b/resources/resources_bak_2024_01_03/piece_ledger_pas/7e170ef8/7e170ef8_code.scd deleted file mode 100644 index b11446a..0000000 --- a/resources/resources_bak_2024_01_03/piece_ledger_pas/7e170ef8/7e170ef8_code.scd +++ /dev/null @@ -1,718 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON; - -// model vars -//(model and global vars mostly set by OSC funcs -var curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, orders, susWeights, passagesWeights, passagesSize, orderSize; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc; - -// other global vars -var lastXChanges, popSize, exPath, dir, primes, dims, tuples, -seq, group, player, ledgerPath, ledger, currentlyPlayingUID; - - -// install JSON quark -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - pDistance.gaussCurve(1, mean, sd) -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, min, max, envData; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - durFunc = {arg allowChord; - var res; - res = if(allowChord.not, { - pTable.tableRand * (max - min) + min - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (max - min) + min}); - }).round(0.125); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, durSeed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = 1/pow(hdSum.value(voices.deepCopy.put(ins, candidate)), 2); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - allowChord = if((sus ++ silent).includes(ins), { - (sus ++ silent).includes(ins) && (ins != sus.last); - }, { - if(i < (flatOrder.size - 1), {(isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not}, {false}); - }); - dur = passagesDurFunc.value(allowChord); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(isLastOrder, { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - dur = passagesDurFunc.value(allowChord); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); - -genPatterns = {arg inSeq, addr; - var voices, durs, patterns, res, indices, sectionDurs, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - indices = inSeq.collect({arg mSeq, m; mSeq[1]}); - ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - res = Ppar( - voices.flop.collect({arg voice; - var clumps, hdScores, freqs, fDurs; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \instrument, \test, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1) - ) - }) ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \indexPath, "/cur_play_index", - \indexMsg, Pseq(indices.postln, 1), - \seqPath, "/mus_seq", - \seqMsg, Pseq(seq, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - ); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < (maxDepth - 0), { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - //res.postln; - if(res.every({arg char; char.isDecDigit}), {res = res.asInteger}); - }); - }); - res -}; - -writeResources = {arg path; - var file, nameSpaces, modelItems, resString; - file = File(path,"w"); - - nameSpaces = [ - "music_data", "last_changes", - "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "passages_weights", "order", "sus_weights", "order_size", "passages_size" - ]; - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize - ]; - - resString = [nameSpaces, modelItems].flop.collect({arg item; - var nameSpace, modelItem, depth = 0, insert = " "; - # nameSpace, modelItem = item; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(modelItem.postln, depth).postln - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg model; - var nameSpaces, data; - - //model = File(path, "r").readAllString.parseJSON; - - nameSpaces = [ - "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "passages_weights", "order", "sus_weights", "order_size", "passages_size" - ]; - - data = nameSpaces.collect({arg nS; msgInterpret.value(model[nS]).postln}); - - data.postln; - - # curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize = data; - - popSize = ranges.size; -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg ledger; ledger = ledger["ledger"]}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - loadModelFile.value(msg[1].asString); -}, \load_model); - - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dFormat, condition, musPath; - msg.postln; - - path = msg[1].asString; - - loadModelFile.value(path); - - refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - lastXChanges = if(refUID == nil, { - [initVoices.value().deepCopy]; - }, { - var file; - refUID.postln; - file = File((dir +/+ ".." +/+ "resources" +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..2] ++ [entrancesProbVals[3..]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..2] ++ [passagesProbVals[3..]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..2] ++ [exitsProbVals[3..]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - seq = seedFunc.value(genMotif, motifSeed).value; - - //musPath = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - writeResources.value(path); - - //orders = nil; - //addr.sendMsg("/current_uid", curUID); - //addr.sendMsg("/ledger", prettifyArray.value(ledger, 1).replace("\"", "")); - //addr.sendMsg("/ledger_size", ledger.size); - //addr.sendMsg("/mus_seq", prettifyArray.value(seq, 3)); - addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var newLedger, modelPath, musString, musFile, test1, test2; - msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - curUID = genUID.value; - File.mkdir((dir +/+ ".." +/+ "resources" +/+ curUID).standardizePath); - File.copy(exPath, (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - writeResources.value(modelPath); - - File.delete(ledgerPath.postln ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - newLedger = File(ledgerPath.postln, "w"); - ledger = ledger.postln.drop(-1).add(curUID); - newLedger.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - newLedger.close; - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - player.stop; - group.set(\gate, 0); - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var file; - (indexStart + index).postln; - file = File((dir +/+ ".." +/+ "resources" +/+ uid +/+ uid ++ "_music" ++ ".json").standardizePath, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, {pSeq = pSeq.add([seq, ledger.size - 1])}); - patterns = genPatterns.value(pSeq, addr); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - }); - player = player.play - }); -}, \transport); - -) - -( -SynthDef(\test, {arg freq, gate = 1, sustain, amp, dur; - var trig, exc, sig1, sig2, noHarms; - noHarms = 30; - exc = Saw.ar(freq, TRand.ar(0.5, 1, Impulse.ar(freq))) * 0.001 + Dust.ar(10000, 0.01); - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(1, 2)}) ], exc) * 0.5).softclip; - sig1 = HPF.ar(sig1, 300); - Out.ar([0, 1], sig1 * EnvGen.kr(Env.adsr(0.3, 0.3, 0.9, 0.5, 0.9), gate, doneAction: 2)); -}).add; -) - -( -SynthDef(\test, {arg freq, gate = 1, sustain, amp, dur; - var trig, exc, sig1, sig2, noHarms, freqFinal, start, end; - noHarms = 30; - freq = WhiteNoise.ar * 3 + freq; - freqFinal = Duty.ar((1/freq), 0, freq); - trig = Changed.ar(freqFinal); - start = Demand.ar(trig, 0, Dwhite(-1, -0.75)); - end = Demand.ar(trig, 0, Dwhite(0.75, 1)); - exc = Phasor.ar(trig, (end - start) * freqFinal / SampleRate.ir, start, end, 0) * 0.001 + Dust.ar(10000, 0.01); - - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(2, 3)}) ], exc) * 0.5).softclip; - sig1 = HPF.ar(sig1, 300); - Out.ar([0, 1], sig1 * EnvGen.kr(Env.adsr(0.3, 0.3, 0.9, 0.5, 0.9), gate, doneAction: 2)); -}).add; -) - - - -"{\"a\": 1}".parseYAML["a"].asInteger; -"{\"a\": 1}".parseJSON["a"].isNumber; - -1223423434123.asHexString.toLower - -Date.getDate.rawSeconds -Date.seed.asHexString.toLower - -n = NetAddr("localhost", 8080); -n.sendMsg("/GET/#", (NetAddr.localAddr.hostname ++ ":" ++ NetAddr.localAddr.port), "/passage_probs_vals"); \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/piece_ledger_pas/7e170ef8/7e170ef8_gui_state.json b/resources/resources_bak_2024_01_03/piece_ledger_pas/7e170ef8/7e170ef8_gui_state.json deleted file mode 100644 index 704cf3a..0000000 --- a/resources/resources_bak_2024_01_03/piece_ledger_pas/7e170ef8/7e170ef8_gui_state.json +++ /dev/null @@ -1,1359 +0,0 @@ -{ - "motif_label": "motif", - "seeds_label": "seeds", - "order": "[\n [ [ 3, 1, 0 ], [ 2 ], [ ] ],\n [ [ 1, 2 ], [ 0, 0, 0, 0, 0, 0, 0, 0, 0 ], [ 3 ] ],\n [ [ 3, 2 ], [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ], [ 0 ] ],\n [ [ 2, 3 ], [ 0, 1, 0 ], [ ] ]\n]", - "order_lock": 1, - "order_size": [ - 3, - 8 - ], - "order_size_v2": 8, - "order_size_v1": 3, - "order_size_panel": -1, - "passage_size_v2": 8, - "passage_size_v1": 2, - "passage_size_panel": -1, - "sus_weights": [ - null, - null, - null - ], - "range_matrix": [ - null, - null, - null, - null - ], - "instrumentation": [ - 0, - 0 - ], - "entrances_probs_sync": "passages", - "entrances": -1, - "passages_probs_sync": "passages", - "passages": -1, - "exits_probs_sync": "passages", - "exits": -1, - "dur_panel": 0, - "durations": -1, - "passages_weights": [ - null, - null, - null, - null, - null - ], - "weights": -1, - "seeds_tab_panel": 0, - "weights_seed_lock": 0, - "weights_seed": 534103, - "sus_weights/0_slider_val": 0.21, - "sus_weights/0_slider_slider": 0.21, - "sus_weights/0_slider_input": 0.21, - "sus_weights/0_slider_label": 1, - "sus_weights/0_slider": -1, - "sus_weights/1_slider_val": 0.35, - "sus_weights/1_slider_slider": 0.35, - "sus_weights/1_slider_input": 0.35, - "sus_weights/1_slider_label": 2, - "sus_weights/1_slider": -1, - "sus_weights/2_slider_val": 0.21, - "sus_weights/2_slider_slider": 0.21, - "sus_weights/2_slider_input": 0.21, - "sus_weights/2_slider_label": 3, - "sus_weights/2_slider": -1, - "passages_weights/0_slider_val": 0.49, - "passages_weights/0_slider_slider": 0.49, - "passages_weights/0_slider_input": 0.49, - "passages_weights/0_slider_label": "step", - "passages_weights/0_slider": -1, - "passages_weights/1_slider_val": 0.53, - "passages_weights/1_slider_slider": 0.53, - "passages_weights/1_slider_input": 0.53, - "passages_weights/1_slider_label": "dc", - "passages_weights/1_slider": -1, - "passages_weights/2_slider_val": 0.35, - "passages_weights/2_slider_slider": 0.35, - "passages_weights/2_slider_input": 0.35, - "passages_weights/2_slider_label": "range", - "passages_weights/2_slider": -1, - "passages_weights/3_slider_val": 0.59, - "passages_weights/3_slider_slider": 0.59, - "passages_weights/3_slider_input": 0.59, - "passages_weights/3_slider_label": "registration", - "passages_weights/3_slider": -1, - "passages_weights/4_slider_val": 0.39, - "passages_weights/4_slider_slider": 0.39, - "passages_weights/4_slider_input": 0.39, - "passages_weights/4_slider_label": "hd", - "passages_weights/4_slider": -1, - "range_matrix/0_val_input_min": -853.2067988668555, - "range_matrix/0_val_rslider": [ - -853.2067988668555, - 401 - ], - "range_matrix/0_val_input_max": 401, - "range_matrix/0_val": -1, - "range_matrix/1_val_input_min": -659, - "range_matrix/1_val_rslider": [ - -659, - 880 - ], - "range_matrix/1_val_input_max": 880, - "range_matrix/1_val": -1, - "range_matrix/2_val_input_min": -241, - "range_matrix/2_val_rslider": [ - -241, - 1869 - ], - "range_matrix/2_val_input_max": 1869, - "range_matrix/2_val": -1, - "range_matrix/3_val_input_min": -27, - "range_matrix/3_val_rslider": [ - -27, - 2063 - ], - "range_matrix/3_val_input_max": 2063, - "range_matrix/3_val": -1, - "entrances_probs_chord_slider_val": 0.66, - "entrances_probs_chord_slider_slider": 0.66, - "entrances_probs_chord_slider_input": 0.66, - "entrances_probs_chord_slider_label": "chord prob", - "entrances_probs_chord_slider": -1, - "entrances_probs_vals": [ - 0.63, - 0, - 5, - 0, - 0.5, - 0.23316062176165803, - 0.7094594594594594, - 0.3963730569948187, - 0.8716216216216216, - 0.4948186528497409, - 0.5912162162162162, - 0.5362694300518135, - 0.8614864864864865, - 0.6424870466321243, - 0.5912162162162162, - 0.7901554404145078, - 0.8277027027027027, - 1, - 0.5 - ], - "entrances_probs": -1, - "passages_probs_chord_slider_val": 0.63, - "passages_probs_chord_slider_slider": 0.63, - "passages_probs_chord_slider_input": 0.63, - "passages_probs_chord_slider_label": "chord prob", - "passages_probs_chord_slider": -1, - "passages_probs_vals": [ - 0.63, - 0, - 5, - 0, - 0.5, - 0.23316062176165803, - 0.7094594594594594, - 0.3963730569948187, - 0.8716216216216216, - 0.4948186528497409, - 0.5912162162162162, - 0.5362694300518135, - 0.8614864864864865, - 0.6424870466321243, - 0.5912162162162162, - 0.7901554404145078, - 0.8277027027027027, - 1, - 0.5 - ], - "passages_probs": -1, - "exits_probs_chord_slider_val": 0, - "exits_probs_chord_slider_slider": 0, - "exits_probs_chord_slider_input": 0, - "exits_probs_chord_slider_label": "chord prob", - "exits_probs_chord_slider": -1, - "exits_probs_vals": [ - 0, - 0, - 5, - 0, - 0.5, - 0.23316062176165803, - 0.7094594594594594, - 0.4948186528497409, - 0.5912162162162162, - 0.7901554404145078, - 0.8277027027027027, - 1, - 0.5 - ], - "exits_probs": -1, - "step_env_env_vals": [ - 0, - 5, - 0, - 0, - 0, - 0, - 0.14609053497942387, - 0.7613636363636364, - 0.20164609053497942, - 0.26136363636363635, - 0.24279835390946503, - 0.7215909090909092, - 0.39094650205761317, - 0.875, - 0.4567901234567901, - 0.44318181818181823, - 0.5432098765432098, - 0.34659090909090906, - 0.6481481481481481, - 0.8011363636363636, - 0.6810699588477366, - 0.5170454545454546, - 0.8868312757201646, - 0.49431818181818177, - 0.8868312757201646, - 0.49431818181818177 - ], - "step_env_env_canvas": [ - [ - 0, - 0 - ], - [ - 0, - 0 - ], - [ - 0.14609053497942387, - 0.7613636363636364 - ], - [ - 0.20164609053497942, - 0.26136363636363635 - ], - [ - 0.24279835390946503, - 0.7215909090909092 - ], - [ - 0.39094650205761317, - 0.875 - ], - [ - 0.4567901234567901, - 0.44318181818181823 - ], - [ - 0.5432098765432098, - 0.34659090909090906 - ], - [ - 0.6481481481481481, - 0.8011363636363636 - ], - [ - 0.6810699588477366, - 0.5170454545454546 - ], - [ - 0.8868312757201646, - 0.49431818181818177 - ], - [ - 0.8868312757201646, - 0.49431818181818177 - ], - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0 - ], - "step_env_env_size": 12, - "step_env_env_flatten": 0, - "step_env_env_rslider": [ - 0, - 5 - ], - "step_env_env_rslider_v2": 5, - "step_env_env_rslider_v1": 0, - "step_env_env_mpos": "", - "step_env_env": -1, - "entrances_probs_dur_env_vals": [ - 0.515267175572519, - 4.599236641221374, - 0, - 0.5, - 0.2772020725388601, - 0.7972972972972973, - 0.45077720207253885, - 0.8783783783783784, - 0.5, - 0.5, - 0.727979274611399, - 0.45270270270270274, - 0.7357512953367875, - 0.6486486486486487, - 0.8911917098445595, - 0.7905405405405406, - 1, - 0.5 - ], - "entrances_probs_dur_env_canvas": [ - [ - 0, - 0.5 - ], - [ - 0.2772020725388601, - 0.7972972972972973 - ], - [ - 0.45077720207253885, - 0.8783783783783784 - ], - [ - 0.5, - 0.5 - ], - [ - 0.727979274611399, - 0.45270270270270274 - ], - [ - 0.7357512953367875, - 0.6486486486486487 - ], - [ - 0.8911917098445595, - 0.7905405405405406 - ], - [ - 1, - 0.5 - ], - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0 - ], - "entrances_probs_dur_env_size": 8, - "entrances_probs_dur_env_flatten": 0, - "entrances_probs_dur_env_rslider": [ - 0.515267175572519, - 4.599236641221374 - ], - "entrances_probs_dur_env_rslider_v2": 4.599236641221374, - "entrances_probs_dur_env_rslider_v1": 0.515267175572519, - "entrances_probs_dur_env_mpos": "", - "entrances_probs_dur_env": -1, - "passages_probs_dur_env_vals": [ - 0, - 5, - 0, - 0.5, - 0.23316062176165803, - 0.7094594594594594, - 0.3963730569948187, - 0.8716216216216216, - 0.4948186528497409, - 0.5912162162162162, - 0.5362694300518135, - 0.8614864864864865, - 0.6424870466321243, - 0.5912162162162162, - 0.7901554404145078, - 0.8277027027027027, - 1, - 0.5 - ], - "passages_probs_dur_env_canvas": [ - [ - 0, - 0.5 - ], - [ - 0.23316062176165803, - 0.7094594594594594 - ], - [ - 0.3963730569948187, - 0.8716216216216216 - ], - [ - 0.4948186528497409, - 0.5912162162162162 - ], - [ - 0.5362694300518135, - 0.8614864864864865 - ], - [ - 0.6424870466321243, - 0.5912162162162162 - ], - [ - 0.7901554404145078, - 0.8277027027027027 - ], - [ - 1, - 0.5 - ], - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0 - ], - "passages_probs_dur_env_size": 8, - "passages_probs_dur_env_flatten": 0, - "passages_probs_dur_env_rslider": [ - 0, - 5 - ], - "passages_probs_dur_env_rslider_v2": 5, - "passages_probs_dur_env_rslider_v1": 0, - "passages_probs_dur_env_mpos": "", - "passages_probs_dur_env": -1, - "exits_probs_dur_env_vals": [ - 0, - 5, - 0, - 0.5, - 0.5, - 0.5, - 1, - 0.5 - ], - "exits_probs_dur_env_canvas": [ - [ - 0, - 0.5 - ], - [ - 0.5, - 0.5 - ], - [ - 1, - 0.5 - ], - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0 - ], - "exits_probs_dur_env_size": 3, - "exits_probs_dur_env_flatten": 0, - "exits_probs_dur_env_rslider": [ - 0, - 5 - ], - "exits_probs_dur_env_rslider_v2": 5, - "exits_probs_dur_env_rslider_v1": 0, - "exits_probs_dur_env_mpos": "", - "exits_probs_dur_env": -1, - "mus_seq": [ - [ - [ - [ - [ - [ - "Rest" - ], - [ - 1, - 1, - -2, - -1, - 1, - 0 - ], - [ - "Rest" - ], - [ - "Rest" - ] - ], - 0 - ], - [ - [ - [ - "Rest" - ], - [ - 1, - 1, - -2, - -1, - 1, - 0 - ], - [ - 1, - 1, - -3, - 0, - 1, - -1 - ], - [ - "Rest" - ] - ], - 1.75 - ], - [ - [ - [ - "Rest" - ], - [ - 1, - 1, - -2, - -1, - 1, - 0 - ], - [ - 1, - 1, - -3, - 0, - 1, - -1 - ], - [ - 1, - 1, - -2, - -1, - 0, - 0 - ] - ], - 1.75 - ], - [ - [ - [ - 0, - 1, - -3, - 0, - 2, - -1 - ], - [ - 1, - 1, - -2, - -1, - 1, - 0 - ], - [ - 1, - 1, - -3, - 0, - 1, - -1 - ], - [ - 1, - 1, - -2, - -1, - 0, - 0 - ] - ], - 0.75 - ], - [ - [ - [ - 1, - 1, - -2, - -2, - 1, - 0 - ], - [ - 1, - 1, - -2, - -1, - 1, - 0 - ], - [ - 1, - 1, - -3, - 0, - 1, - -1 - ], - [ - 1, - 1, - -2, - -1, - 0, - 0 - ] - ], - 0.625 - ], - [ - [ - [ - 1, - 1, - -3, - -1, - 0, - 0 - ], - [ - 1, - 1, - -2, - -1, - 1, - 0 - ], - [ - 1, - 1, - -3, - 0, - 1, - -1 - ], - [ - 1, - 1, - -2, - -1, - 0, - 0 - ] - ], - 0.625 - ], - [ - [ - [ - 1, - 0, - -3, - 0, - 1, - -1 - ], - [ - 1, - 1, - -2, - -1, - 1, - 0 - ], - [ - 1, - 1, - -3, - 0, - 1, - -1 - ], - [ - 1, - 1, - -2, - -1, - 0, - 0 - ] - ], - 1.75 - ] - ], - [ - [ - [ - [ - "Rest" - ], - [ - 1, - 1, - -2, - -1, - 1, - 0 - ], - [ - 1, - 1, - -3, - 0, - 1, - -1 - ], - [ - 1, - 1, - -2, - -1, - 0, - 0 - ] - ], - 0 - ], - [ - [ - [ - "Rest" - ], - [ - 1, - 1, - -2, - -1, - 1, - 0 - ], - [ - 1, - 1, - -3, - -1, - 1, - 0 - ], - [ - 1, - 1, - -2, - -1, - 0, - 0 - ] - ], - 1.75 - ], - [ - [ - [ - "Rest" - ], - [ - 1, - 1, - -2, - -1, - 1, - 0 - ], - [ - 0, - 1, - -2, - 0, - 1, - 0 - ], - [ - 1, - 1, - -2, - -1, - 0, - 0 - ] - ], - 1.375 - ], - [ - [ - [ - "Rest" - ], - [ - 1, - 1, - -2, - -1, - 1, - 0 - ], - [ - 0, - 2, - -2, - -1, - 1, - 0 - ], - [ - 1, - 1, - -2, - -1, - 0, - 0 - ] - ], - 0.75 - ], - [ - [ - [ - "Rest" - ], - [ - 1, - 1, - -2, - -1, - 1, - 0 - ], - [ - 0, - 1, - -2, - -1, - 2, - 0 - ], - [ - 1, - 1, - -2, - -1, - 0, - 0 - ] - ], - 1.75 - ], - [ - [ - [ - "Rest" - ], - [ - 1, - 1, - -2, - -1, - 1, - 0 - ], - [ - 1, - 0, - -2, - -1, - 1, - 0 - ], - [ - 1, - 1, - -2, - -1, - 0, - 0 - ] - ], - 1.875 - ], - [ - [ - [ - "Rest" - ], - [ - 1, - 1, - -2, - -1, - 1, - 0 - ], - [ - 1, - 1, - -2, - -1, - 1, - -1 - ], - [ - 1, - 1, - -2, - -1, - 0, - 0 - ] - ], - 1 - ] - ], - [ - [ - [ - [ - 1, - 0, - -3, - 0, - 1, - -1 - ], - [ - 1, - 1, - -2, - -1, - 1, - 0 - ], - [ - 1, - 1, - -2, - -1, - 1, - -1 - ], - [ - 1, - 1, - -2, - -1, - 0, - 0 - ] - ], - 0 - ], - [ - [ - [ - 1, - 0, - -3, - 0, - 1, - -1 - ], - [ - 1, - 1, - -2, - -1, - 1, - 0 - ], - [ - 2, - 0, - -3, - -1, - 1, - -1 - ], - [ - 1, - 1, - -2, - -1, - 0, - 0 - ] - ], - 1.625 - ], - [ - [ - [ - 1, - 0, - -3, - 0, - 1, - -1 - ], - [ - 1, - 1, - -2, - -1, - 1, - 0 - ], - [ - 0, - 1, - -1, - -1, - 1, - 0 - ], - [ - 1, - 1, - -2, - -1, - 0, - 0 - ] - ], - 1.75 - ], - [ - [ - [ - 1, - 0, - -3, - 0, - 1, - -1 - ], - [ - 1, - 1, - -2, - -1, - 1, - 0 - ], - [ - 0, - 1, - -1, - -1, - 1, - 0 - ], - [ - "Rest" - ] - ], - 0 - ], - [ - [ - [ - "Rest" - ], - [ - 1, - 1, - -2, - -1, - 1, - 0 - ], - [ - 0, - 1, - -1, - -1, - 1, - 0 - ], - [ - "Rest" - ] - ], - 1.875 - ], - [ - [ - [ - "Rest" - ], - [ - "Rest" - ], - [ - 0, - 1, - -1, - -1, - 1, - 0 - ], - [ - "Rest" - ] - ], - 0 - ], - [ - [ - [ - "Rest" - ], - [ - "Rest" - ], - [ - "Rest" - ], - [ - "Rest" - ] - ], - 0.875 - ] - ] - ] - ], - "root": [ - 0.20743639921722112, - 0 - ], - "order_seed": 798574, - "dur_seed": 884869, - "passages_size": [ - 0, - 10 - ], - "dur_seed_lock": 1, - "order_seed_lock": 0, - "seeds_panel": -1, - "motif_panel": [ - 0, - 0 - ], - "ref_uid": "6f1a789f", - "cur_uid": "7e170ef8" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/piece_ledger_pas/7e170ef8/7e170ef8_mus_model.json b/resources/resources_bak_2024_01_03/piece_ledger_pas/7e170ef8/7e170ef8_mus_model.json deleted file mode 100644 index c9b8807..0000000 --- a/resources/resources_bak_2024_01_03/piece_ledger_pas/7e170ef8/7e170ef8_mus_model.json +++ /dev/null @@ -1,79 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ] ], 1.75 ], - [ [ [ "Rest" ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ] ], 0 ], - [ [ [ "Rest" ], [ -1, 0, 0, 1, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ] ], 0.625 ], - [ [ [ "Rest" ], [ -1, 0, 0, 1, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ] ], 0.875 ], - [ [ [ "Rest" ], [ -1, 0, 0, 1, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], 1.375 ], - [ [ [ "Rest" ], [ -1, 0, 0, 1, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 1, 0 ] ], 0 ], - [ [ [ "Rest" ], [ -1, 1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 1, 0 ] ], 0.5 ], - [ [ [ "Rest" ], [ -1, 0, 0, 0, 0, 1 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 1, 0 ] ], 0 ], - [ [ [ "Rest" ], [ -1, 0, 0, 0, 0, 1 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ] ], 1.25 ], - [ [ [ "Rest" ], [ -1, 0, 0, 0, 0, 1 ], [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, -1, 0, 0, 0 ] ], 0 ], - [ [ [ "Rest" ], [ 0, 0, -1, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, -1, 0, 0, 0 ] ], 1.875 ] - ], - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, -1, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, -1, 0, 0, 0 ] ], 1.625 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ -1, 0, 0, 1, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, -1, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ -1, 0, 0, 1, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ 1, 0, -1, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ -1, 0, 0, 1, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ 0, 0, 0, 0, 1, 0 ] ], 1.75 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ -1, 0, 0, 1, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ 1, 0, 0, 0, -1, 0 ] ], 1.75 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ -1, 0, 0, 0, 0, 1 ], [ 1, 0, 0, -1, 0, 0 ], [ 1, 0, 0, 0, -1, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ -1, 0, 0, 0, 0, 1 ], [ 1, 0, 0, -1, 0, 0 ], [ 0, 0, 0, 0, 0, 1 ] ], 1.75 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, -1, 0, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ 0, 0, 0, 0, 0, 1 ] ], 1.875 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, -1, 0, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ 1, 0, -1, 0, 0, 0 ] ], 1.375 ] - ], - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, -1, 0, 0, 0 ], [ "Rest" ], [ 1, 0, -1, 0, 0, 0 ] ], 1.375 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ -1, 1, 0, 0, 0, 0 ], [ "Rest" ], [ 1, 0, -1, 0, 0, 0 ] ], 1 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, -1, -1, 0, 0 ], [ "Rest" ], [ 1, 0, -1, 0, 0, 0 ] ], 1.125 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, -1, 0, 1, 0 ], [ "Rest" ], [ 1, 0, -1, 0, 0, 0 ] ], 1.625 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, -1, -1, 0, 0, 0 ], [ "Rest" ], [ 1, 0, -1, 0, 0, 0 ] ], 1.75 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ], [ "Rest" ], [ 1, 0, -1, 0, 0, 0 ] ], 1.125 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ "Rest" ], [ 1, 0, -1, 0, 0, 0 ] ], 1.25 ] - ], - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ 1, 0, -1, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ 0, 0, 0, 1, 0, 0 ] ], 1.25 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ] ], 1.25 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ 1, -1, 0, 0, 0, 1 ] ], 1.5 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ 2, 0, 0, -1, 0, 0 ] ], 1.25 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ "Rest" ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ] ], 0 ], - [ [ [ "Rest" ], [ 1, -1, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ] ], 0 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 1 ] - ] - ] -], -"last_changes": -[ - [ [ 0, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ 1, 0, -1, 0, 0, 0 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ 0, 0, 0, 1, 0, 0 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ 1, -1, 0, 0, 0, 1 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ 2, 0, 0, -1, 0, 0 ] ] -], -"cur_uid": "7e170ef8", -"ref_uid": "nil", -"order_seed": 142640, -"dur_seed": 629022, -"motifs_seed": 973728, -"entrances_probs_vals": [ 0.75, 0.5, 2, 0, 0.5, 0.26424870466321, 0.75675675675676, 0.5, 0.5, 0.58549222797927, 0.72635135135135, 1, 0.5 ], -"passages_probs_vals": [ 0.75, 0.5, 2, 0, 0.5, 0.20725388601036, 0.68581081081081, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"exits_probs_vals": [ 0.75, 0.5, 2, 0, 0.5, 0.20725388601036, 0.68581081081081, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"ranges": [ [ -384, 2400 ], [ -507, 2400 ], [ -282, 2237 ], [ -1200, 2053 ] ], -"passages_weights": [ 0.75, 0.75, 0.75, 0.75, 0.75 ], -"order": -[ - [ [ 2 ], [ 3, 1, 3, 3, 3, 1, 1, 3, 3, 1 ], [ 0 ] ], - [ [ 0 ], [ 1, 2, 3, 3, 1, 3, 1, 3 ], [ ] ], - [ [ 0, 3 ], [ 1, 1, 1, 1, 1, 1 ], [ 2 ] ], - [ [ 1, 2, 0 ], [ 3, 3, 3, 3 ], [ ] ] -], -"sus_weights": [ 0.75, 0.69, 0.75 ], -"order_size": [ 2, 6 ], -"passages_size": [ 0, 10 ] -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/piece_ledger_pas/7fd4d544/7fd4d544_code.scd b/resources/resources_bak_2024_01_03/piece_ledger_pas/7fd4d544/7fd4d544_code.scd deleted file mode 100644 index 830a192..0000000 --- a/resources/resources_bak_2024_01_03/piece_ledger_pas/7fd4d544/7fd4d544_code.scd +++ /dev/null @@ -1,894 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - pDistance.gaussCurve(1, mean, sd) -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = 1/pow(hdSum.value(voices.deepCopy.put(ins, candidate)), 2); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~msg.postln; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - //res.postln; - if(res.every({arg char; char.isDecDigit}), {res = res.asInteger}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, passagesWeights, orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file; - file = File(path, "w"); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "passages_weights", "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((dir +/+ ".." +/+ "resources" +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - - curUID = genUID.value; - - File.mkdir((dir +/+ ".." +/+ "resources" +/+ curUID).standardizePath); - File.copy(exPath, (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - ledger = ledger.drop(-1).add(curUID); - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - player.stop; - group.set(\gate, 0); - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (dir +/+ ".." +/+ "resources" +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - -) - -( -//synthdefs -~stringModelBusArray = 4.collect({Bus.audio(s, 1)}); -~sineBusArray = 4.collect({Bus.audio(s, 1)}); -~bassBusArray = 1.collect({Bus.audio(s, 1)}); -~hdustBusArray = 1.collect({Bus.audio(s, 1)}); -~samplerBusArray = 2.collect({Bus.audio(s, 1)}); -~sBuf = Buffer.alloc(s, 10, 2); -SynthDef(\string_model, {arg freq, gate = 1, sustain, amp, dur, busIndex = 0; - var trig, exc, sig1, sig2, noHarms; - noHarms = 30; - exc = Saw.ar(freq, TRand.ar(0.5, 1, Impulse.ar(freq))) * 0.001 + Dust.ar(10000, 0.01); - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(1, 2)}) ], exc) * 0.8).softclip; - sig1 = HPF.ar(sig1, 300); - Out.ar(Select.kr(busIndex, ~stringModelBusArray), sig1 * EnvGen.kr(Env.adsr(0.3, 0.3, 0.9, 0.5, 0.9), gate, doneAction: 2)); - //Out.ar([0, 1], sig1 * EnvGen.kr(Env.asr(dur, 0.3, 1), gate, doneAction: 2)); -}).add; - -SynthDef(\sine, {arg freq, gate = 1, sustain, amp, dur, busIndex = 0; - var sig; - sig = SinOsc.ar(freq); - Out.ar(Select.kr(busIndex, ~sineBusArray), sig * EnvGen.kr(Env.asr(0.3, 0.4, 0.3), gate, timeScale: dur, doneAction: 2)); -}).add; - -SynthDef(\mixer, {arg freq, gate = 1, sustain, amp, dur, out; - var nameSpaces, sigs, hierarchicalDust; - - hierarchicalDust = ( - TIRand.kr(0, 1, Impulse.kr(100)) * - TIRand.kr(0, 1, Impulse.kr(10)) * - TIRand.kr(0, 1, Impulse.kr(1)) - ); - - sigs = [~stringModelBusArray, ~sineBusArray, ~bassBusArray, ~hdustBusArray, ~samplerBusArray].collect({arg busArray, i; - var nameSpace, sig; - nameSpace = ['string', 'sine', 'bass', 'hdust', 'sampler'][i]; - sig = busArray.collect({arg bus, c; In.ar(bus, 1) * NamedControl.kr(\ ++ nameSpace ++ '_volume_' ++ c, 1, 0.1)}); - sig = sig.collect({arg channel, c; Pan2.ar(channel, NamedControl.kr(\ ++ nameSpace ++ '_pan_' ++ c, i / (busArray.size - 1), 0.1) * 2 - 1)}); - sig = sig.collect({arg channel, c; channel * NamedControl.kr(\ ++ nameSpace ++ '_mute_' ++ c, 1, 0.1)}); - sig = Mix.ar(sig) * pow(NamedControl.kr(\ ++ nameSpace ++ '_volume_master', 1, 0.1), 2); - }); - - sigs = Mix.ar(sigs / 4); - Out.ar(0, sigs) -}).add; - -SynthDef(\bass, { - var switches, drone; - switches = {|i| Dust.kr(0.1)} ! 9; - drone = {|i| var harm = pow(2, 2 - (i / 3).trunc), amp = (1 / pow(harm, 2)); - SinOsc.ar(60 * harm + TRand.kr(-3, 3, switches[i]), 0, amp)} ! 9; - Out.ar(~bassBusArray[0], Mix.new(drone) * 0.2); -}).add; - -SynthDef(\sampler, { - Out.ar(~samplerBusArray, PlayBuf.ar(2, ~sBuf, BufRateScale.kr(~sBuf), doneAction: 2)) -}).add; - -// main routine -SynthDef(\hdust, { - arg gate = 0; - var hierarchical_dust, low_sine, high_sine, brown_noise, white_noise; - // this triggers the combinations of sources - // it is similar to the Supercollider UGen called dust but with a hierarchical structure - hierarchical_dust = ( - TIRand.kr(0, 1, Impulse.kr(100)) * - TIRand.kr(0, 1, Impulse.kr(10)) * - TIRand.kr(0, 1, Impulse.kr(1)) * - TIRand.kr(0, 1, Impulse.kr(0.1)) - ); - // adjust the multiplier at the end of each line for adjusting levels - // note with each trigger, each source has a 1 in 3 chance of sounding - low_sine = SinOsc.ar(76.midicps / 16) * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.1; - high_sine = SinOsc.ar(76.midicps * 8) * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.01; - brown_noise = BrownNoise.ar() * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.025; - white_noise = WhiteNoise.ar() * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.02; - Out.ar(~hdustBusArray[0], - ((low_sine + high_sine + brown_noise + white_noise) ) - ); -}).add; - -) - -( -var bass, hdust, sampler, mixer; -bass = Synth.tail(~group, \bass); -hdust = Synth.tail(~group, \hdust); -sampler = Synth.head(~group, \sampler); -mixer = Synth.tail(~group, \mixer); -OSCdef(\mixer, {arg msg, time, addr, port; - mixer.set((msg[1] ++ '_' ++ msg[2] ++ '_' ++ msg[3]), msg[4]) -}, \mixer); - -OSCdef(\sampler, {arg msg, time, addr, port; - msg.postln; - sampler.free; - ~sBuf.free; - ~sBuf = Buffer.read(s, msg[1].asString.postln, action: {sampler = Synth.head(~group, \sampler)}); -}, \sampler); -) - -/* old something -( -SynthDef(\test, {arg freq, gate = 1, sustain, amp, dur; - var trig, exc, sig1, sig2, noHarms, freqFinal, start, end; - noHarms = 30; - freq = WhiteNoise.ar * 3 + freq; - freqFinal = Duty.ar((1/freq), 0, freq); - trig = Changed.ar(freqFinal); - start = Demand.ar(trig, 0, Dwhite(-1, -0.75)); - end = Demand.ar(trig, 0, Dwhite(0.75, 1)); - exc = Phasor.ar(trig, (end - start) * freqFinal / SampleRate.ir, start, end, 0) * 0.001 + Dust.ar(10000, 0.01); - - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(2, 3)}) ], exc) * 0.5).softclip; - sig1 = HPF.ar(sig1, 300); - Out.ar([0, 1], sig1 * EnvGen.kr(Env.adsr(0.3, 0.3, 0.9, 0.5, 0.9), gate, doneAction: 2)); -}).add; -) -*/ - diff --git a/resources/resources_bak_2024_01_03/piece_ledger_pas/7fd4d544/7fd4d544_mus_model.json b/resources/resources_bak_2024_01_03/piece_ledger_pas/7fd4d544/7fd4d544_mus_model.json deleted file mode 100644 index e83ee7f..0000000 --- a/resources/resources_bak_2024_01_03/piece_ledger_pas/7fd4d544/7fd4d544_mus_model.json +++ /dev/null @@ -1,44 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ 1, 0, 0, 0, 1, 0 ] ], 4.75 ], - [ [ [ "Rest" ], [ -1, 0, 0, 1, 1, 0 ], [ "Rest" ], [ 1, 0, 0, 0, 1, 0 ] ], 1.125 ], - [ [ [ 0, 0, 0, -1, 1, 0 ], [ -1, 0, 0, 1, 1, 0 ], [ "Rest" ], [ 1, 0, 0, 0, 1, 0 ] ], 1 ], - [ [ [ 0, 0, 0, -1, 1, 0 ], [ -1, 0, 0, 1, 1, 0 ], [ 2, 0, 0, 0, 1, -1 ], [ 1, 0, 0, 0, 1, 0 ] ], 5.125 ], - [ [ [ 0, 0, 0, -1, 1, 0 ], [ "Rest" ], [ 2, 0, 0, 0, 1, -1 ], [ 1, 0, 0, 0, 1, 0 ] ], 1.125 ], - [ [ [ 0, 0, 0, -1, 1, 0 ], [ "Rest" ], [ 2, 0, 0, 0, 1, -1 ], [ "Rest" ] ], 0.875 ], - [ [ [ "Rest" ], [ "Rest" ], [ 2, 0, 0, 0, 1, -1 ], [ "Rest" ] ], 0.875 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 4.375 ] - ] - ] -], -"last_changes": -[ - [ [ 0, -1, 0, 0, 1, 0 ], [ 0, 0, -1, 0, 1, 0 ], [ 1, 0, 1, 0, 1, 0 ], [ 1, 0, 0, 0, 1, 0 ] ], - [ [ 0, -1, 0, 0, 1, 0 ], [ 0, 0, -1, 0, 1, 0 ], [ 2, 0, 0, -1, 1, 0 ], [ 1, 0, 0, 0, 1, 0 ] ], - [ [ 0, -1, 0, 0, 1, 0 ], [ -1, 0, 0, 1, 1, 0 ], [ 2, 0, 0, -1, 1, 0 ], [ 1, 0, 0, 0, 1, 0 ] ], - [ [ 0, 0, 0, -1, 1, 0 ], [ -1, 0, 0, 1, 1, 0 ], [ 2, 0, 0, -1, 1, 0 ], [ 1, 0, 0, 0, 1, 0 ] ], - [ [ 0, 0, 0, -1, 1, 0 ], [ -1, 0, 0, 1, 1, 0 ], [ 2, 0, 0, 0, 1, -1 ], [ 1, 0, 0, 0, 1, 0 ] ] -], -"cur_uid": "7fd4d544", -"ref_uid": "tmp", -"order_seed": 159820, -"dur_seed": 341194, -"motifs_seed": 928268, -"entrances_probs_vals": [ 0, 1.67, 4.8015873015873, 0.24725274725275, 1.15, 0.20725388601036, 0.68581081081081, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"passages_probs_vals": [ 0, 1.67, 4.8015873015873, 0.24725274725275, 1.15, 0.20725388601036, 0.68581081081081, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"exits_probs_vals": [ 0, 1.83, 4.8809523809524, 0.24725274725275, 1.15, 0.20725388601036, 0.68581081081081, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"ranges": [ [ -1100, 460.68111455108 ], [ -507, 1084.8297213622 ], [ 884.21052631579, 2237 ], [ 1040.2476780186, 2053 ] ], -"passages_weights": [ 0.75, 0.75, 0.75, 0.75, 0.75 ], -"order": -[ - [ [ 3 ], [ 1, 0, 2 ], [ ] ] -], -"sus_weights": [ 0.73, 0.23, 0 ], -"order_size": [ 1, 2 ], -"passages_size": [ 0, 1 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1.json b/resources/resources_bak_2024_01_03/string_quartet_1.json deleted file mode 100644 index 8e41d98..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1.json +++ /dev/null @@ -1,25 +0,0 @@ -{ -"ledger": -[ - "4a8a6e53", - "66f6a618", - "490b1e6e", - "46985d14", - "761e4585", - "6fb60ab6", - "79e0a4a7", - "43b009ff", - "7d3c9a80", - "4b7745df", - "6ed95c4c", - "6d635e88", - "4e7d35e5", - "7edbdceb", - "784130cc", - "443ec222", - "52c9a980", - "4200a90d", - "61ce9067", - "774ed940" -] -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/4200a90d/4200a90d_code.scd b/resources/resources_bak_2024_01_03/string_quartet_1/4200a90d/4200a90d_code.scd deleted file mode 100644 index a98b916..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/4200a90d/4200a90d_code.scd +++ /dev/null @@ -1,945 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance); -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/4200a90d/4200a90d_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_1/4200a90d/4200a90d_mus_model.json deleted file mode 100644 index de04cf3..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/4200a90d/4200a90d_mus_model.json +++ /dev/null @@ -1,58 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ 1, 0, 1, -2, 1, 1 ] ], 2 ], - [ [ [ "Rest" ], [ "Rest" ], [ 1, 0, 0, -2, 1, 1 ], [ 1, 0, 1, -2, 1, 1 ] ], 1.5 ] - ], - [ - [ [ [ "Rest" ], [ 1, -1, 1, -2, 2, 0 ], [ 1, 0, 0, -2, 1, 1 ], [ 1, 0, 1, -2, 1, 1 ] ], 2 ], - [ [ [ "Rest" ], [ 1, -1, 1, -2, 2, 0 ], [ 2, -2, 1, -2, 2, 0 ], [ 1, 0, 1, -2, 1, 1 ] ], 0 ], - [ [ [ 0, -1, 1, -2, 2, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 2, -2, 1, -2, 2, 0 ], [ 1, 0, 1, -2, 1, 1 ] ], 0.625 ], - [ [ [ 0, -1, 1, -2, 2, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 1, 0, 1, -2, 2, 0 ], [ 1, 0, 1, -2, 1, 1 ] ], 0 ], - [ [ [ -1, -1, 1, -1, 2, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 1, 0, 1, -2, 2, 0 ], [ 1, 0, 1, -2, 1, 1 ] ], 1.25 ], - [ [ [ -1, -1, 1, -2, 2, 1 ], [ 1, -1, 1, -2, 2, 0 ], [ 1, 0, 1, -2, 2, 0 ], [ 1, 0, 1, -2, 1, 1 ] ], 0 ], - [ [ [ -1, -1, 1, -2, 2, 1 ], [ 1, -1, 1, -2, 2, 0 ], [ 1, -1, 1, -2, 2, 1 ], [ 1, 0, 1, -2, 1, 1 ] ], 0 ], - [ [ [ -1, -1, 1, -2, 2, 1 ], [ 1, -1, 1, -2, 2, 0 ], [ 1, -1, 1, -2, 2, 1 ], [ 2, -1, 0, -2, 2, 0 ] ], 1.25 ], - [ [ [ 0, -1, 1, -2, 1, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 1, -1, 1, -2, 2, 1 ], [ 2, -1, 0, -2, 2, 0 ] ], 1.25 ], - [ [ [ 0, -1, 1, -2, 1, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 1, -1, 1, -1, 2, 0 ], [ 2, -1, 0, -2, 2, 0 ] ], 1.125 ], - [ [ [ 0, -1, 1, -2, 1, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 1, -1, 1, -1, 2, 0 ], [ 1, -1, 1, -2, 3, 0 ] ], 2.25 ], - [ [ [ 0, -1, 1, -2, 1, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ "Rest" ], [ 1, -1, 1, -2, 3, 0 ] ], 1.5 ], - [ [ [ 0, -1, 1, -2, 1, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ "Rest" ], [ 1, -1, 1, -2, 3, 0 ] ], 0.875 ], - [ [ [ 0, -1, 1, -2, 1, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ "Rest" ], [ "Rest" ] ], 1.125 ] - ] - ] -], -"last_changes": -[ - [ [ -1, -1, 1, -2, 2, 1 ], [ 1, -1, 1, -2, 2, 0 ], [ 1, -1, 1, -2, 2, 1 ], [ 1, 0, 1, -2, 1, 1 ] ], - [ [ -1, -1, 1, -2, 2, 1 ], [ 1, -1, 1, -2, 2, 0 ], [ 1, -1, 1, -2, 2, 1 ], [ 2, -1, 0, -2, 2, 0 ] ], - [ [ 0, -1, 1, -2, 1, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 1, -1, 1, -2, 2, 1 ], [ 2, -1, 0, -2, 2, 0 ] ], - [ [ 0, -1, 1, -2, 1, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 1, -1, 1, -1, 2, 0 ], [ 2, -1, 0, -2, 2, 0 ] ], - [ [ 0, -1, 1, -2, 1, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 1, -1, 1, -1, 2, 0 ], [ 1, -1, 1, -2, 3, 0 ] ] -], -"cur_uid": "4200a90d", -"ref_uid": "6d635e88", -"order_seed": 516056, -"dur_seed": 358555, -"motifs_seed": 168145, -"entrances_probs_vals": [ 0.18, 0.28, 1.4285714285714, 0.82, 2.0054945054945, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 0.29, 0, 1.1111111111111, 0.65934065934066, 1.37, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 0.18, 0.28, 1.4285714285714, 0.82, 2.0054945054945, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -2411.1455108359, -850.77399380805 ], [ -1872, 450 ], [ -479, 1304.0247678019 ], [ -368, 1173.9938080495 ] ], -"step_probs_vals": [ 0, 1200, 0, 0, 0.082304526748971, 0.99431818181818, 0.33950617283951, 0, 0.72839506172839, 0, 1, 0 ], -"passages_weights": [ 0.35, 0.42, 0.75, 0.9, 0.93 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 3 ], [ 2 ], [ 0, 1 ] ], - [ [ 1 ], [ 2, 0, 2, 0, 0, 2, 3, 0, 2, 3 ], [ ] ] -], -"sus_weights": [ 0.41, 0, 0 ], -"order_size": [ 2, 6 ], -"passages_size": [ 0, 5 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/4200a90d/lilypond/part_I.ly b/resources/resources_bak_2024_01_03/string_quartet_1/4200a90d/lilypond/part_I.ly deleted file mode 100644 index bcf7780..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/4200a90d/lilypond/part_I.ly +++ /dev/null @@ -1,18 +0,0 @@ -{ - { ais'1^\markup { \pad-markup #0.2 "+41"} ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'2 ~ ais'8.[ a'16^\markup { \pad-markup #0.2 "-37"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 5↓" }}] ~ a'4 ~ } - \bar "|" - { a'1 ~ } - \bar "|" - { a'2 fis'2^\markup { \pad-markup #0.2 "+1"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 11↑" }} ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'2. ~ fis'16[ r8.]} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/4200a90d/lilypond/part_II.ly b/resources/resources_bak_2024_01_03/string_quartet_1/4200a90d/lilypond/part_II.ly deleted file mode 100644 index b74e7bb..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/4200a90d/lilypond/part_II.ly +++ /dev/null @@ -1,18 +0,0 @@ -{ - { r1 } - \bar "|" - { g'1^\markup { \pad-markup #0.2 "-46"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 5↓" }} ~ } - \bar "|" - { g'2. f'4^\markup { \pad-markup #0.2 "+47"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↓" }} ~ } - \bar "|" - { f'16[ gis'8.^\markup { \pad-markup #0.2 "-49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }}] ~ gis'4 ~ gis'8.[ a'16^\markup { \pad-markup #0.2 "-10"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }}] ~ a'4 ~ } - \bar "|" - { a'2. ~ a'8.[ ais'16^\markup { \pad-markup #0.2 "+18"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 7↑" }}] ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'2 ~ ais'8[ r8] r4 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/4200a90d/lilypond/part_III.ly b/resources/resources_bak_2024_01_03/string_quartet_1/4200a90d/lilypond/part_III.ly deleted file mode 100644 index 11cd320..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/4200a90d/lilypond/part_III.ly +++ /dev/null @@ -1,18 +0,0 @@ -{ - { r1 } - \bar "|" - { r2. c'4^\markup { \pad-markup #0.2 "+49"} ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/4200a90d/lilypond/part_IV.ly b/resources/resources_bak_2024_01_03/string_quartet_1/4200a90d/lilypond/part_IV.ly deleted file mode 100644 index 5e43176..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/4200a90d/lilypond/part_IV.ly +++ /dev/null @@ -1,18 +0,0 @@ -{ - { r1 } - \bar "|" - { r1 } - \bar "|" - { r2. c4^\markup { \pad-markup #0.2 "+49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }} ~ } - \bar "|" - { c16[ ais,8.^\markup { \pad-markup #0.2 "+18"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 7↑" }}] ~ ais,4 ~ ais,8.[ a,16^\markup { \pad-markup #0.2 "-10"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 13↑" }}] ~ a,4 ~ } - \bar "|" - { a,4 ~ a,16[ g,8.^\markup { \pad-markup #0.2 "-2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 11↓" }}] ~ g,2 ~ } - \bar "|" - { g,1 ~ } - \bar "|" - { g,1 ~ } - \bar "|" - { g,1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/43b009ff/43b009ff_code.scd b/resources/resources_bak_2024_01_03/string_quartet_1/43b009ff/43b009ff_code.scd deleted file mode 100644 index a98b916..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/43b009ff/43b009ff_code.scd +++ /dev/null @@ -1,945 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance); -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/43b009ff/43b009ff_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_1/43b009ff/43b009ff_mus_model.json deleted file mode 100644 index 3c475af..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/43b009ff/43b009ff_mus_model.json +++ /dev/null @@ -1,48 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ 2, -2, 0, -1, 1, 0 ], [ "Rest" ], [ "Rest" ] ], 5.75 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ "Rest" ], [ "Rest" ] ], 2.75 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ "Rest" ], [ 3, -3, 0, -1, 1, 0 ] ], 1.75 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 3, -2, 0, -2, 1, 0 ], [ 3, -3, 0, -1, 1, 0 ] ], 1.5 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 3, -2, 0, -2, 1, 0 ], [ 2, -2, 0, -1, 2, 0 ] ], 4.125 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ "Rest" ], [ 2, -2, 0, -1, 2, 0 ] ], 0.875 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ "Rest" ], [ "Rest" ], [ 2, -2, 0, -1, 2, 0 ] ], 1 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 0.875 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 7.375 ] - ] - ] -], -"last_changes": -[ - [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 2, -1, -1, -1, 1, 0 ], [ 1, -1, 0, 0, 1, 0 ] ], - [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 2, -1, -1, -1, 1, 0 ], [ 2, -2, 1, -1, 1, 0 ] ], - [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 2, -1, -1, -1, 1, 0 ], [ 3, -3, 0, -1, 1, 0 ] ], - [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 3, -2, 0, -2, 1, 0 ], [ 3, -3, 0, -1, 1, 0 ] ], - [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 3, -2, 0, -2, 1, 0 ], [ 2, -2, 0, -1, 2, 0 ] ] -], -"cur_uid": "43b009ff", -"ref_uid": 62820081, -"order_seed": 216475, -"dur_seed": 323751, -"motifs_seed": 466146, -"entrances_probs_vals": [ 0, 1.1904761904762, 3.3333333333333, 0.71, 1.92, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 0, 1.1904761904762, 3.3333333333333, 0.71, 1.92, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 0, 1.1904761904762, 3.3333333333333, 0.71, 1.92, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -3600, -312 ], [ -1872, 1378 ], [ -145, 1583 ], [ -182, 1527 ] ], -"step_probs_vals": [ 0, 1200, 0, 0, 0.082304526748971, 0.99431818181818, 0.14197530864198, 0, 1, 0 ], -"passages_weights": [ 0.75, 0.75, 0.75, 0.75, 0.75 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 1, 0 ], [ 3, 2, 3 ], [ ] ] -], -"sus_weights": [ 0, 0.65, 0 ], -"order_size": [ 1, 1 ], -"passages_size": [ 1, 6 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/43b009ff/lilypond/part_I.ly b/resources/resources_bak_2024_01_03/string_quartet_1/43b009ff/lilypond/part_I.ly deleted file mode 100644 index af37609..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/43b009ff/lilypond/part_I.ly +++ /dev/null @@ -1,28 +0,0 @@ -{ - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r4 b'2.^\markup { \pad-markup #0.2 "-23"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↓" }} ~ } - \bar "|" - { b'2. ~ b'8[ b'8^\markup { \pad-markup #0.2 "+30"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 11↑" }}] ~ } - \bar "|" - { b'1 ~ } - \bar "|" - { b'1 ~ } - \bar "|" - { b'2. ~ b'8[ r8] } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/43b009ff/lilypond/part_II.ly b/resources/resources_bak_2024_01_03/string_quartet_1/43b009ff/lilypond/part_II.ly deleted file mode 100644 index 5c63449..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/43b009ff/lilypond/part_II.ly +++ /dev/null @@ -1,28 +0,0 @@ -{ - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r8[ gis'8^\markup { \pad-markup #0.2 "+10"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 7↓" }}] ~ gis'2. ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'2. ~ gis'8.[ r16] } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/43b009ff/lilypond/part_III.ly b/resources/resources_bak_2024_01_03/string_quartet_1/43b009ff/lilypond/part_III.ly deleted file mode 100644 index 0795a41..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/43b009ff/lilypond/part_III.ly +++ /dev/null @@ -1,28 +0,0 @@ -{ - { fis'1^\markup { \pad-markup #0.2 "-21"} ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'4 ~ fis'8[ r8] r2 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/43b009ff/lilypond/part_IV.ly b/resources/resources_bak_2024_01_03/string_quartet_1/43b009ff/lilypond/part_IV.ly deleted file mode 100644 index ce1dd80..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/43b009ff/lilypond/part_IV.ly +++ /dev/null @@ -1,28 +0,0 @@ -{ - { r1 } - \bar "|" - { r1 } - \bar "|" - { r2. r8[ cis'8^\markup { \pad-markup #0.2 "-19"}] ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'4 ~ cis'16[ r8.] r2 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/443ec222/443ec222_code.scd b/resources/resources_bak_2024_01_03/string_quartet_1/443ec222/443ec222_code.scd deleted file mode 100644 index a98b916..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/443ec222/443ec222_code.scd +++ /dev/null @@ -1,945 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance); -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/443ec222/443ec222_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_1/443ec222/443ec222_mus_model.json deleted file mode 100644 index 26d2794..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/443ec222/443ec222_mus_model.json +++ /dev/null @@ -1,54 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ 1, 0, 1, -2, 1, 1 ] ], 1.75 ], - [ [ [ "Rest" ], [ "Rest" ], [ 1, 0, 1, -2, 1, 0 ], [ 1, 0, 1, -2, 1, 1 ] ], 1.5 ] - ], - [ - [ [ [ "Rest" ], [ "Rest" ], [ 1, 0, 1, -2, 1, 0 ], [ "Rest" ] ], 0 ], - [ [ [ "Rest" ], [ 1, -1, 1, -2, 2, 0 ], [ 1, 0, 1, -2, 1, 0 ], [ "Rest" ] ], 1.5 ], - [ [ [ "Rest" ], [ 1, -1, 1, -2, 2, 0 ], [ 1, -1, 2, -2, 2, 0 ], [ "Rest" ] ], 0 ], - [ [ [ 0, -1, 1, -2, 2, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 1, -1, 2, -2, 2, 0 ], [ "Rest" ] ], 0.75 ], - [ [ [ 0, -1, 1, -2, 2, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 2, -2, 1, -2, 2, 0 ], [ "Rest" ] ], 0.75 ], - [ [ [ -1, -1, 1, -1, 2, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 2, -2, 1, -2, 2, 0 ], [ "Rest" ] ], 0.625 ], - [ [ [ 0, -1, 0, -2, 2, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 2, -2, 1, -2, 2, 0 ], [ "Rest" ] ], 2.125 ], - [ [ [ "Rest" ], [ 1, -1, 1, -2, 2, 0 ], [ 2, -2, 1, -2, 2, 0 ], [ "Rest" ] ], 1.125 ], - [ [ [ "Rest" ], [ 1, -1, 1, -2, 2, 0 ], [ "Rest" ], [ "Rest" ] ], 0.625 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 5.25 ] - ] - ] -], -"last_changes": -[ - [ [ 1, -1, 1, -3, 2, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 1, -1, 2, -2, 2, 0 ], [ 1, 0, 1, -2, 1, 1 ] ], - [ [ 0, -1, 1, -2, 2, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 1, -1, 2, -2, 2, 0 ], [ 1, 0, 1, -2, 1, 1 ] ], - [ [ 0, -1, 1, -2, 2, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 2, -2, 1, -2, 2, 0 ], [ 1, 0, 1, -2, 1, 1 ] ], - [ [ -1, -1, 1, -1, 2, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 2, -2, 1, -2, 2, 0 ], [ 1, 0, 1, -2, 1, 1 ] ], - [ [ 0, -1, 0, -2, 2, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 2, -2, 1, -2, 2, 0 ], [ 1, 0, 1, -2, 1, 1 ] ] -], -"cur_uid": "443ec222", -"ref_uid": "6d635e88", -"order_seed": 516056, -"dur_seed": 358555, -"motifs_seed": 962315, -"entrances_probs_vals": [ 0.18, 0.28, 1.4285714285714, 0.47, 1.62, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 0.29, 0, 1.1111111111111, 0.65934065934066, 1.37, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 0.18, 0.28, 1.4285714285714, 0.47, 1.62, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -2411.1455108359, -850.77399380805 ], [ -1872, 450 ], [ -479, 1304.0247678019 ], [ -368, 1173.9938080495 ] ], -"step_probs_vals": [ 0, 1200, 0, 0, 0.082304526748971, 0.99431818181818, 0.33950617283951, 0, 0.72839506172839, 0, 1, 0 ], -"passages_weights": [ 0.35, 0.42, 0.75, 0.9, 0.93 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 3 ], [ 2 ], [ 0, 1 ] ], - [ [ 1 ], [ 2, 0, 2, 0, 0 ], [ 3 ] ] -], -"sus_weights": [ 0.41, 0, 0 ], -"order_size": [ 2, 6 ], -"passages_size": [ 0, 5 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/443ec222/lilypond/part_I.ly b/resources/resources_bak_2024_01_03/string_quartet_1/443ec222/lilypond/part_I.ly deleted file mode 100644 index da8950a..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/443ec222/lilypond/part_I.ly +++ /dev/null @@ -1,18 +0,0 @@ -{ - { ais'1^\markup { \pad-markup #0.2 "+41"} ~ } - \bar "|" - { ais'2 ~ ais'8[ r8] r4 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/443ec222/lilypond/part_II.ly b/resources/resources_bak_2024_01_03/string_quartet_1/443ec222/lilypond/part_II.ly deleted file mode 100644 index 3245478..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/443ec222/lilypond/part_II.ly +++ /dev/null @@ -1,18 +0,0 @@ -{ - { r2. r8[ d'8^\markup { \pad-markup #0.2 "+0"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 13↓" }}] ~ } - \bar "|" - { d'1 ~ } - \bar "|" - { d'4 ~ d'8[ e'8^\markup { \pad-markup #0.2 "+36"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 5↑" }}] ~ e'4 f'4^\markup { \pad-markup #0.2 "+47"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }} ~ } - \bar "|" - { f'1 ~ } - \bar "|" - { f'1 ~ } - \bar "|" - { f'16[ r8.] r2. } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/443ec222/lilypond/part_III.ly b/resources/resources_bak_2024_01_03/string_quartet_1/443ec222/lilypond/part_III.ly deleted file mode 100644 index 0f68e02..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/443ec222/lilypond/part_III.ly +++ /dev/null @@ -1,18 +0,0 @@ -{ - { r1 } - \bar "|" - { r2 r8[ c'8^\markup { \pad-markup #0.2 "+49"}] ~ c'4 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'4 ~ c'8[ r8] r2 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/443ec222/lilypond/part_IV.ly b/resources/resources_bak_2024_01_03/string_quartet_1/443ec222/lilypond/part_IV.ly deleted file mode 100644 index a524c1b..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/443ec222/lilypond/part_IV.ly +++ /dev/null @@ -1,18 +0,0 @@ -{ - { r1 } - \bar "|" - { r1 } - \bar "|" - { r4 r8[ c8^\markup { \pad-markup #0.2 "+49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }}] ~ c2 ~ } - \bar "|" - { c8[ ais,8^\markup { \pad-markup #0.2 "+18"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 7↑" }}] ~ ais,8.[ a,16^\markup { \pad-markup #0.2 "-37"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 5↓" }}] ~ a,2 ~ } - \bar "|" - { a,2 r2 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/4526b76b/4526b76b_code.scd b/resources/resources_bak_2024_01_03/string_quartet_1/4526b76b/4526b76b_code.scd deleted file mode 100644 index 8e9fe42..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/4526b76b/4526b76b_code.scd +++ /dev/null @@ -1,943 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance); -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/4526b76b/4526b76b_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_1/4526b76b/4526b76b_mus_model.json deleted file mode 100644 index 7489563..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/4526b76b/4526b76b_mus_model.json +++ /dev/null @@ -1,44 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ "Rest" ], [ 1, -1, 0, -1, 1, -1 ], [ "Rest" ] ], 0.625 ], - [ [ [ "Rest" ], [ 2, -2, 0, -1, 1, 0 ], [ 1, -1, 0, -1, 1, -1 ], [ "Rest" ] ], 1.625 ], - [ [ [ "Rest" ], [ 2, -2, 0, -1, 1, 0 ], [ 1, -1, 0, -1, 1, -1 ], [ 3, -1, 0, -2, 1, -1 ] ], 1.625 ], - [ [ [ "Rest" ], [ 2, -2, 0, -1, 1, 0 ], [ 1, -1, 0, -1, 1, -1 ], [ 3, -1, 0, -1, 1, -2 ] ], 11 ], - [ [ [ "Rest" ], [ 2, -2, 0, -1, 1, 0 ], [ "Rest" ], [ 3, -1, 0, -1, 1, -2 ] ], 1.375 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ 3, -1, 0, -1, 1, -2 ] ], 1.5 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 6.25 ] - ] - ] -], -"last_changes": -[ - [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 1, -1, 0, -1, 1, -1 ], [ 1, 0, 0, -1, 1, 0 ] ], - [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 1, -1, 0, -1, 1, -1 ], [ 3, -1, 0, -2, 1, -1 ] ], - [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 1, -1, 0, -1, 1, -1 ], [ 3, -1, 0, -1, 1, -2 ] ] -], -"cur_uid": "4526b76b", -"ref_uid": "6fb60ab6", -"order_seed": 785868, -"dur_seed": 994115, -"motifs_seed": 805843, -"entrances_probs_vals": [ 0.34, 0, 10, 0.5, 2, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 0.34, 0, 10, 0.5, 2.12, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 0.34, 0, 10, 0.5, 2.12, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -3600, -312 ], [ -1872, 1378 ], [ -145, 1583 ], [ -182, 1527 ] ], -"step_probs_vals": [ 0, 1200, 0, 0, 0.082304526748971, 0.99431818181818, 0.14197530864198, 0, 1, 0 ], -"passages_weights": [ 0.75, 0.75, 0.75, 0.75, 0.75 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 2, 1 ], [ 3, 3 ], [ 0 ] ] -], -"sus_weights": [ 0.75, 0.25, 0.25 ], -"order_size": [ 1, 4 ], -"passages_size": [ 0, 3 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/46985d14/46985d14_code.scd b/resources/resources_bak_2024_01_03/string_quartet_1/46985d14/46985d14_code.scd deleted file mode 100644 index 3eb3cbd..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/46985d14/46985d14_code.scd +++ /dev/null @@ -1,1058 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance); -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file; - file = File(path, "w"); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((dir +/+ ".." +/+ "resources" +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((dir +/+ ".." +/+ "resources" +/+ curUID).standardizePath); - File.copy(exPath, (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (dir +/+ ".." +/+ "resources" +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((dir +/+ ".." +/+ "resources" +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (dir +/+ ".." +/+ "resources" +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (dir +/+ ".." +/+ "resources" +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "resources" +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "resources" +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \".." +/+ ".." +/+ "resources" +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - -~transcribe.value(~seq, dir); - -( -//synthdefs -~stringModelBusArray = 4.collect({Bus.audio(s, 1)}); -~sineBusArray = 4.collect({Bus.audio(s, 1)}); -~bassBusArray = 1.collect({Bus.audio(s, 1)}); -~hdustBusArray = 1.collect({Bus.audio(s, 1)}); -~samplerBusArray = 2.collect({Bus.audio(s, 1)}); -~sBuf = Buffer.alloc(s, 10, 2); -SynthDef(\string_model, {arg freq, gate = 1, sustain, amp, dur, attack, release = 1, busIndex = 0; - var trig, exc, sig1, sig2, noHarms; - noHarms = rrand(20, 40); - exc = Saw.ar(freq, TRand.ar(0.5, 1, Impulse.ar(freq))) * 0.001 + Dust.ar(10000, 0.01); - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(1, 2)}) ], exc) * 0.8).softclip; - //sig1 = HPF.ar(sig1, 300); - Out.ar(Select.kr(busIndex, ~stringModelBusArray), sig1 * amp * EnvGen.kr(Env.adsr(attack, 0.3, 0.9, release, 0.9, -3), gate, doneAction: 2)); - //Out.ar([0, 1], sig1 * EnvGen.kr(Env.asr(dur, 0.3, 1), gate, doneAction: 2)); -}).add; - -SynthDef(\sine, {arg freq, gate = 1, sustain, amp, dur, busIndex = 0; - var sig; - sig = SinOsc.ar(freq); - Out.ar(Select.kr(busIndex, ~sineBusArray), sig * EnvGen.kr(Env.asr(0.3, 0.4, 0.3), gate, timeScale: dur, doneAction: 2)); - //Out.ar(Select.kr(busIndex, ~sineBusArray), sig * EnvGen.kr(Env.sine(dur), gate, doneAction: 2)); -}).add; - -SynthDef(\mixer, {arg freq, gate = 1, sustain, amp, dur, out; - var nameSpaces, sigs; - - sigs = [~stringModelBusArray, ~sineBusArray/*, ~bassBusArray, ~hdustBusArray, ~samplerBusArray*/].collect({arg busArray, i; - var nameSpace, sig; - nameSpace = ['string', 'sine', 'bass', 'hdust', 'sampler'][i]; - sig = busArray.collect({arg bus, c; In.ar(bus, 1) * NamedControl.kr(\ ++ nameSpace ++ '_volume_' ++ c, 1, 0.1)}); - sig = sig.collect({arg channel, c; Pan2.ar(channel, NamedControl.kr(\ ++ nameSpace ++ '_pan_' ++ c, i / (busArray.size - 1), 0.1) * 2 - 1)}); - sig = sig.collect({arg channel, c; channel * NamedControl.kr(\ ++ nameSpace ++ '_mute_' ++ c, 1, 0.1)}); - sig = Mix.ar(sig) * pow(NamedControl.kr(\ ++ nameSpace ++ '_volume_master', 1, 0.1), 2); - }); - - sigs = Mix.ar(sigs / 4); - Out.ar(0, sigs) -}).add; - -SynthDef(\bass, { - var switches, drone; - switches = {|i| Dust.kr(0.1)} ! 9; - drone = {|i| var harm = pow(2, 2 - (i / 3).trunc), amp = (1 / pow(harm, 2)); - SinOsc.ar(60 * harm + TRand.kr(-3, 3, switches[i]), 0, amp)} ! 9; - Out.ar(~bassBusArray[0], Mix.new(drone) * 0.2); -}).add; - -SynthDef(\sampler, { - Out.ar(~samplerBusArray, PlayBuf.ar(2, ~sBuf, BufRateScale.kr(~sBuf), doneAction: 2)) -}).add; - -// main routine -SynthDef(\hdust, { - arg gate = 0; - var hierarchical_dust, low_sine, high_sine, brown_noise, white_noise; - // this triggers the combinations of sources - // it is similar to the Supercollider UGen called dust but with a hierarchical structure - hierarchical_dust = ( - TIRand.kr(0, 1, Impulse.kr(100)) * - TIRand.kr(0, 1, Impulse.kr(10)) * - TIRand.kr(0, 1, Impulse.kr(1)) * - TIRand.kr(0, 1, Impulse.kr(0.1)) - ); - // adjust the multiplier at the end of each line for adjusting levels - // note with each trigger, each source has a 1 in 3 chance of sounding - low_sine = SinOsc.ar(76.midicps / 16) * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.1; - high_sine = SinOsc.ar(76.midicps * 8) * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.01; - brown_noise = BrownNoise.ar() * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.025; - white_noise = WhiteNoise.ar() * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.02; - Out.ar(~hdustBusArray[0], - ((low_sine + high_sine + brown_noise + white_noise) ) - ); -}).add; - -) - -( -var bass, hdust, sampler, mixer; -/* -bass = Synth.tail(~group, \bass); -hdust = Synth.tail(~group, \hdust); -sampler = Synth.head(~group, \sampler); -*/ -mixer = Synth.tail(~group, \mixer); - -OSCdef(\mixer, {arg msg, time, addr, port; - mixer.set((msg[1] ++ '_' ++ msg[2] ++ '_' ++ msg[3]), msg[4]) -}, \mixer); - -/* -OSCdef(\sampler, {arg msg, time, addr, port; - msg.postln; - sampler.free; - ~sBuf.free; - ~sBuf = Buffer.read(s, msg[1].asString.postln, action: {sampler = Synth.head(~group, \sampler)}); -}, \sampler); -*/ -) - -/* old something -( -SynthDef(\test, {arg freq, gate = 1, sustain, amp, dur; - var trig, exc, sig1, sig2, noHarms, freqFinal, start, end; - noHarms = 30; - freq = WhiteNoise.ar * 3 + freq; - freqFinal = Duty.ar((1/freq), 0, freq); - trig = Changed.ar(freqFinal); - start = Demand.ar(trig, 0, Dwhite(-1, -0.75)); - end = Demand.ar(trig, 0, Dwhite(0.75, 1)); - exc = Phasor.ar(trig, (end - start) * freqFinal / SampleRate.ir, start, end, 0) * 0.001 + Dust.ar(10000, 0.01); - - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(2, 3)}) ], exc) * 0.5).softclip; - sig1 = HPF.ar(sig1, 300); - Out.ar([0, 1], sig1 * EnvGen.kr(Env.adsr(0.3, 0.3, 0.9, 0.5, 0.9), gate, doneAction: 2)); -}).add; -) -*/ - diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/46985d14/46985d14_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_1/46985d14/46985d14_mus_model.json deleted file mode 100644 index de147a2..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/46985d14/46985d14_mus_model.json +++ /dev/null @@ -1,85 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ "Rest" ], [ 0, -1, 0, 0, 1, 0 ], [ "Rest" ] ], 1.75 ], - [ [ [ -1, -1, 0, 1, 1, 0 ], [ "Rest" ], [ 0, -1, 0, 0, 1, 0 ], [ "Rest" ] ], 0 ], - [ [ [ -1, -1, 0, 1, 1, 0 ], [ "Rest" ], [ 0, -1, 0, 0, 1, 0 ], [ 0, -1, 1, 0, 1, 0 ] ], 0 ], - [ [ [ -1, -1, 0, 1, 1, 0 ], [ -1, -1, 0, 0, 1, 1 ], [ 0, -1, 0, 0, 1, 0 ], [ 0, -1, 1, 0, 1, 0 ] ], 1.25 ], - [ [ [ 0, -1, -1, 0, 1, 0 ], [ -1, -1, 0, 0, 1, 1 ], [ 0, -1, 0, 0, 1, 0 ], [ 0, -1, 1, 0, 1, 0 ] ], 1.75 ], - [ [ [ -1, 0, 0, 0, 1, 0 ], [ -1, -1, 0, 0, 1, 1 ], [ 0, -1, 0, 0, 1, 0 ], [ 0, -1, 1, 0, 1, 0 ] ], 0 ], - [ [ [ -1, 0, 0, 0, 1, 0 ], [ -1, -1, 0, 0, 1, 1 ], [ 0, -1, 0, 0, 1, 0 ], [ 1, -2, 0, 0, 1, 0 ] ], 0 ], - [ [ [ -1, 0, 0, 0, 1, 0 ], [ -1, -1, 0, 1, 1, 0 ], [ 0, -1, 0, 0, 1, 0 ], [ 1, -2, 0, 0, 1, 0 ] ], 0.875 ], - [ [ [ -1, 0, 0, 0, 1, 0 ], [ 1, -1, 0, -1, 1, 0 ], [ 0, -1, 0, 0, 1, 0 ], [ 1, -2, 0, 0, 1, 0 ] ], 0 ], - [ [ [ -1, 0, 0, 0, 1, 0 ], [ 1, -1, 0, -1, 1, 0 ], [ 0, -1, 0, 0, 1, 0 ], [ 1, -1, 0, 0, 1, -1 ] ], 1.625 ], - [ [ [ -1, 0, 0, 0, 1, 0 ], [ 1, -2, 0, 0, 1, 0 ], [ 0, -1, 0, 0, 1, 0 ], [ 1, -1, 0, 0, 1, -1 ] ], 1.75 ], - [ [ [ -1, 0, 0, 0, 1, 0 ], [ 0, 0, 0, 0, 1, 0 ], [ 0, -1, 0, 0, 1, 0 ], [ 1, -1, 0, 0, 1, -1 ] ], 0 ], - [ [ [ -1, 0, 0, 0, 1, 0 ], [ 0, 0, 0, 0, 1, 0 ], [ 0, -1, 0, 0, 1, 0 ], [ 1, -1, 0, -1, 1, 0 ] ], 0.875 ] - ], - [ - [ [ [ -1, 0, 0, 0, 1, 0 ], [ 0, 0, 0, 0, 1, 0 ], [ -1, 0, 1, 0, 1, 0 ], [ 1, -1, 0, -1, 1, 0 ] ], 0.625 ], - [ [ [ -1, 0, 0, 0, 1, 0 ], [ 0, 0, 0, 0, 1, 0 ], [ 0, 0, 0, 0, 1, -1 ], [ 1, -1, 0, -1, 1, 0 ] ], 1.625 ], - [ [ [ -1, 0, 0, 0, 1, 0 ], [ 0, 0, 0, 0, 1, 0 ], [ -1, 0, 0, 0, 2, 0 ], [ 1, -1, 0, -1, 1, 0 ] ], 1.125 ], - [ [ [ -1, 0, 0, 0, 1, 0 ], [ 0, 0, 0, 0, 1, 0 ], [ 1, -1, -1, -1, 1, 0 ], [ 1, -1, 0, -1, 1, 0 ] ], 1 ], - [ [ [ -1, 0, 0, 0, 1, 0 ], [ 0, 0, 0, 0, 1, 0 ], [ 0, 0, 0, -1, 1, 0 ], [ 1, -1, 0, -1, 1, 0 ] ], 0.5 ], - [ [ [ -1, 0, 0, 0, 1, 0 ], [ 0, 0, 0, 0, 1, 0 ], [ 0, -1, 0, -1, 1, 1 ], [ 1, -1, 0, -1, 1, 0 ] ], 1.625 ], - [ [ [ -1, 0, 0, 0, 1, 0 ], [ 0, 0, 0, 0, 1, 0 ], [ 0, -1, 0, 0, 1, 0 ], [ 1, -1, 0, -1, 1, 0 ] ], 1.5 ], - [ [ [ -1, 0, 0, 0, 1, 0 ], [ 0, 0, 0, 0, 1, 0 ], [ 0, 0, 0, 0, 1, -1 ], [ 1, -1, 0, -1, 1, 0 ] ], 0.5 ] - ], - [ - [ [ [ 1, -2, 0, -1, 1, 0 ], [ 0, 0, 0, 0, 1, 0 ], [ 0, 0, 0, 0, 1, -1 ], [ 1, -1, 0, -1, 1, 0 ] ], 0.5 ], - [ [ [ 0, 0, 0, -1, 1, 0 ], [ 0, 0, 0, 0, 1, 0 ], [ 0, 0, 0, 0, 1, -1 ], [ 1, -1, 0, -1, 1, 0 ] ], 1.5 ], - [ [ [ -1, 0, 0, 1, 1, -1 ], [ 0, 0, 0, 0, 1, 0 ], [ 0, 0, 0, 0, 1, -1 ], [ 1, -1, 0, -1, 1, 0 ] ], 1.5 ], - [ [ [ 1, -1, 0, -1, 0, 0 ], [ 0, 0, 0, 0, 1, 0 ], [ 0, 0, 0, 0, 1, -1 ], [ 1, -1, 0, -1, 1, 0 ] ], 1.125 ] - ], - [ - [ [ [ 1, -1, 0, -1, 0, 0 ], [ 0, 0, 0, 0, 1, 0 ], [ 0, 0, 0, 0, 1, -1 ], [ "Rest" ] ], 0 ], - [ [ [ "Rest" ], [ 0, 0, 0, 0, 1, 0 ], [ 0, 0, 0, 0, 1, -1 ], [ "Rest" ] ], 0 ], - [ [ [ "Rest" ], [ 0, 0, 0, 0, 1, 0 ], [ 0, -1, 0, 0, 1, 0 ], [ "Rest" ] ], 1.375 ] - ], - [ - [ [ [ "Rest" ], [ 0, 0, 0, 0, 1, 0 ], [ 0, -1, 0, 0, 1, 0 ], [ 1, -1, 0, -1, 1, 0 ] ], 1.75 ], - [ [ [ 0, -1, 0, -1, 2, 0 ], [ 0, 0, 0, 0, 1, 0 ], [ 0, -1, 0, 0, 1, 0 ], [ 1, -1, 0, -1, 1, 0 ] ], 1.875 ], - [ [ [ -1, -1, 0, 0, 1, 1 ], [ 0, 0, 0, 0, 1, 0 ], [ 0, -1, 0, 0, 1, 0 ], [ 1, -1, 0, -1, 1, 0 ] ], 0.75 ], - [ [ [ 0, -1, -1, 0, 1, 0 ], [ 0, 0, 0, 0, 1, 0 ], [ 0, -1, 0, 0, 1, 0 ], [ 1, -1, 0, -1, 1, 0 ] ], 1.25 ], - [ [ [ -1, 0, 0, 0, 1, 0 ], [ 0, 0, 0, 0, 1, 0 ], [ 0, -1, 0, 0, 1, 0 ], [ 1, -1, 0, -1, 1, 0 ] ], 1 ], - [ [ [ 1, -2, 0, -1, 1, 0 ], [ 0, 0, 0, 0, 1, 0 ], [ 0, -1, 0, 0, 1, 0 ], [ 1, -1, 0, -1, 1, 0 ] ], 1.375 ], - [ [ [ 1, -1, 0, -1, 0, 0 ], [ 0, 0, 0, 0, 1, 0 ], [ 0, -1, 0, 0, 1, 0 ], [ 1, -1, 0, -1, 1, 0 ] ], 2 ], - [ [ [ 1, -1, 0, -1, 0, 0 ], [ "Rest" ], [ 0, -1, 0, 0, 1, 0 ], [ 1, -1, 0, -1, 1, 0 ] ], 0 ], - [ [ [ 1, -1, 0, -1, 0, 0 ], [ "Rest" ], [ "Rest" ], [ 1, -1, 0, -1, 1, 0 ] ], 4.75 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ 1, -1, 0, -1, 1, 0 ] ], 8.875 ] - ] - ] -], -"last_changes": -[ - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], - [ [ 1, -1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], - [ [ 0, 0, -1, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], - [ [ -1, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], - [ [ 0, -1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ] -], -"cur_uid": "46985d14", -"ref_uid": "nil", -"order_seed": 209164, -"dur_seed": 417909, -"motifs_seed": 885208, -"entrances_probs_vals": [ 0.34, 0, 10, 0.5, 2, 0, 0.5, 0.24509803921569, 0.89189189189189, 0.5, 1, 0.5, 0.5, 0.8562091503268, 0.69932432432432, 1, 0.5 ], -"passages_probs_vals": [ 0.34, 0, 10, 0.5, 2, 0, 0.5, 0.24509803921569, 0.89189189189189, 0.5, 1, 0.5, 0.5, 0.8562091503268, 0.69932432432432, 1, 0.5 ], -"exits_probs_vals": [ 0.34, 0, 10, 0.5, 2, 0, 0.5, 0.24509803921569, 0.89189189189189, 0.5, 1, 0.5, 0.5, 0.8562091503268, 0.69932432432432, 1, 0.5 ], -"ranges": [ [ -1200, 2400 ], [ -1200, 2400 ], [ -1200, 2400 ], [ -1200, 2400 ] ], -"step_probs_vals": [ 0, 1200, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_weights": [ 0.75, 0.75, 0.75, 0.75, 0.75 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 2 ], [ 0, 0, 0, 0 ], [ 1, 3 ] ] -], -"sus_weights": [ 0.75, 0.75, 0.75 ], -"order_size": [ 1, 10 ], -"passages_size": [ 0, 10 ], -"motif_edited": "true", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/46985d14/lilypond/part_I.ly b/resources/resources_bak_2024_01_03/string_quartet_1/46985d14/lilypond/part_I.ly deleted file mode 100644 index f38f2bd..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/46985d14/lilypond/part_I.ly +++ /dev/null @@ -1,50 +0,0 @@ -{ - { r2. r8[ d'8^\markup { \pad-markup #0.2 "+36"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 5↑" }}] ~ } - \bar "|" - { d'1 ~ } - \bar "|" - { d'4 ~ d'8[ dis'8^\markup { \pad-markup #0.2 "+47"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↓" }}] ~ dis'4 ~ dis'16[ d'8.^\markup { \pad-markup #0.2 "+9"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 13↓" }}] ~ } - \bar "|" - { d'1 ~ } - \bar "|" - { d'2 cis'2^\markup { \pad-markup #0.2 "-19"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 7↓" }} ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'2 r2 } - \bar "|" - { r8.[ cis'16^\markup { \pad-markup #0.2 "-19"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 7↓" }}] ~ cis'2. ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/46985d14/lilypond/part_II.ly b/resources/resources_bak_2024_01_03/string_quartet_1/46985d14/lilypond/part_II.ly deleted file mode 100644 index 2bae7a3..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/46985d14/lilypond/part_II.ly +++ /dev/null @@ -1,50 +0,0 @@ -{ - { ais1^\markup { \pad-markup #0.2 "+49"} ~ } - \bar "|" - { ais1 ~ } - \bar "|" - { ais1 ~ } - \bar "|" - { ais1 ~ } - \bar "|" - { ais2. ~ ais8.[ a16^\markup { \pad-markup #0.2 "+38"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }}] ~ } - \bar "|" - { a4 a2.^\markup { \pad-markup #0.2 "+11"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↓" }} ~ } - \bar "|" - { a16[ b8.^\markup { \pad-markup #0.2 "+3"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 11↑" }}] ~ b4 ~ b8[ a8^\markup { \pad-markup #0.2 "-6"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 5↓" }}] ~ a4 ~ } - \bar "|" - { a8[ gis8^\markup { \pad-markup #0.2 "-18"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↓" }}] ~ gis8[ a8^\markup { \pad-markup #0.2 "+21"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 13↑" }}] ~ a2 ~ } - \bar "|" - { a8.[ ais16^\markup { \pad-markup #0.2 "+49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }}] ~ ais2 ~ ais8.[ a16^\markup { \pad-markup #0.2 "+11"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↓" }}] ~ } - \bar "|" - { a1 ~ } - \bar "|" - { a1 ~ } - \bar "|" - { a2 ais2^\markup { \pad-markup #0.2 "+49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↓" }} ~ } - \bar "|" - { ais1 ~ } - \bar "|" - { ais1 ~ } - \bar "|" - { ais1 ~ } - \bar "|" - { ais1 ~ } - \bar "|" - { ais1 ~ } - \bar "|" - { ais8.[ r16] r2. } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/46985d14/lilypond/part_III.ly b/resources/resources_bak_2024_01_03/string_quartet_1/46985d14/lilypond/part_III.ly deleted file mode 100644 index 3ee54a1..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/46985d14/lilypond/part_III.ly +++ /dev/null @@ -1,50 +0,0 @@ -{ - { r2. r8[ g8^\markup { \pad-markup #0.2 "-10"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 13↑" }}] ~ } - \bar "|" - { g1 ~ } - \bar "|" - { g4 ~ g8[ gis8^\markup { \pad-markup #0.2 "+18"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 7↑" }}] ~ gis4 ~ gis16[ cis'8.^\markup { \pad-markup #0.2 "-19"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 7↓" }}] ~ } - \bar "|" - { cis'2 ~ cis'8[ dis'8^\markup { \pad-markup #0.2 "+47"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↓" }}] ~ dis'4 ~ } - \bar "|" - { dis'2 fis'2^\markup { \pad-markup #0.2 "-49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }} ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'8.[ r16] r2. } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/46985d14/lilypond/part_IV.ly b/resources/resources_bak_2024_01_03/string_quartet_1/46985d14/lilypond/part_IV.ly deleted file mode 100644 index f0e3f84..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/46985d14/lilypond/part_IV.ly +++ /dev/null @@ -1,50 +0,0 @@ -{ - { r2. r8[ gis8^\markup { \pad-markup #0.2 "+18"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 7↑" }}] ~ } - \bar "|" - { gis2 g2^\markup { \pad-markup #0.2 "-37"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 5↓" }} ~ } - \bar "|" - { g4 ~ g8[ fis8^\markup { \pad-markup #0.2 "-49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↑" }}] ~ fis2 ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis8.[ fis16^\markup { \pad-markup #0.2 "-21"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↓" }}] ~ fis8.[ gis16^\markup { \pad-markup #0.2 "-18"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 7↓" }}] ~ gis2 ~ } - \bar "|" - { gis8.[ g16^\markup { \pad-markup #0.2 "-20"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 7↑" }}] ~ g2 ~ g8.[ g16^\markup { \pad-markup #0.2 "+29"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 11↓" }}] ~ } - \bar "|" - { g2 r2 } - \bar "|" - { r1 } - \bar "|" - { r16[ fis8.^\markup { \pad-markup #0.2 "+32"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 11↑" }}] ~ fis2. } - \bar "|" - { g4^\markup { \pad-markup #0.2 "-10"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 13↑" }} ~ g8[ g8^\markup { \pad-markup #0.2 "-37"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 5↓" }}] ~ g2 } - \bar "|" - { fis2^\markup { \pad-markup #0.2 "-49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }} fis2^\markup { \pad-markup #0.2 "-21"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↓" }} ~ } - \bar "|" - { fis8.[ g16^\markup { \pad-markup #0.2 "+29"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 11↓" }}] ~ g2. ~ } - \bar "|" - { g1 ~ } - \bar "|" - { g1 ~ } - \bar "|" - { g2 ~ g16[ r8.] r4 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/490b1e6e/490b1e6e_code.scd b/resources/resources_bak_2024_01_03/string_quartet_1/490b1e6e/490b1e6e_code.scd deleted file mode 100644 index 3eb3cbd..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/490b1e6e/490b1e6e_code.scd +++ /dev/null @@ -1,1058 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance); -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file; - file = File(path, "w"); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((dir +/+ ".." +/+ "resources" +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((dir +/+ ".." +/+ "resources" +/+ curUID).standardizePath); - File.copy(exPath, (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (dir +/+ ".." +/+ "resources" +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((dir +/+ ".." +/+ "resources" +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (dir +/+ ".." +/+ "resources" +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (dir +/+ ".." +/+ "resources" +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "resources" +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "resources" +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \".." +/+ ".." +/+ "resources" +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - -~transcribe.value(~seq, dir); - -( -//synthdefs -~stringModelBusArray = 4.collect({Bus.audio(s, 1)}); -~sineBusArray = 4.collect({Bus.audio(s, 1)}); -~bassBusArray = 1.collect({Bus.audio(s, 1)}); -~hdustBusArray = 1.collect({Bus.audio(s, 1)}); -~samplerBusArray = 2.collect({Bus.audio(s, 1)}); -~sBuf = Buffer.alloc(s, 10, 2); -SynthDef(\string_model, {arg freq, gate = 1, sustain, amp, dur, attack, release = 1, busIndex = 0; - var trig, exc, sig1, sig2, noHarms; - noHarms = rrand(20, 40); - exc = Saw.ar(freq, TRand.ar(0.5, 1, Impulse.ar(freq))) * 0.001 + Dust.ar(10000, 0.01); - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(1, 2)}) ], exc) * 0.8).softclip; - //sig1 = HPF.ar(sig1, 300); - Out.ar(Select.kr(busIndex, ~stringModelBusArray), sig1 * amp * EnvGen.kr(Env.adsr(attack, 0.3, 0.9, release, 0.9, -3), gate, doneAction: 2)); - //Out.ar([0, 1], sig1 * EnvGen.kr(Env.asr(dur, 0.3, 1), gate, doneAction: 2)); -}).add; - -SynthDef(\sine, {arg freq, gate = 1, sustain, amp, dur, busIndex = 0; - var sig; - sig = SinOsc.ar(freq); - Out.ar(Select.kr(busIndex, ~sineBusArray), sig * EnvGen.kr(Env.asr(0.3, 0.4, 0.3), gate, timeScale: dur, doneAction: 2)); - //Out.ar(Select.kr(busIndex, ~sineBusArray), sig * EnvGen.kr(Env.sine(dur), gate, doneAction: 2)); -}).add; - -SynthDef(\mixer, {arg freq, gate = 1, sustain, amp, dur, out; - var nameSpaces, sigs; - - sigs = [~stringModelBusArray, ~sineBusArray/*, ~bassBusArray, ~hdustBusArray, ~samplerBusArray*/].collect({arg busArray, i; - var nameSpace, sig; - nameSpace = ['string', 'sine', 'bass', 'hdust', 'sampler'][i]; - sig = busArray.collect({arg bus, c; In.ar(bus, 1) * NamedControl.kr(\ ++ nameSpace ++ '_volume_' ++ c, 1, 0.1)}); - sig = sig.collect({arg channel, c; Pan2.ar(channel, NamedControl.kr(\ ++ nameSpace ++ '_pan_' ++ c, i / (busArray.size - 1), 0.1) * 2 - 1)}); - sig = sig.collect({arg channel, c; channel * NamedControl.kr(\ ++ nameSpace ++ '_mute_' ++ c, 1, 0.1)}); - sig = Mix.ar(sig) * pow(NamedControl.kr(\ ++ nameSpace ++ '_volume_master', 1, 0.1), 2); - }); - - sigs = Mix.ar(sigs / 4); - Out.ar(0, sigs) -}).add; - -SynthDef(\bass, { - var switches, drone; - switches = {|i| Dust.kr(0.1)} ! 9; - drone = {|i| var harm = pow(2, 2 - (i / 3).trunc), amp = (1 / pow(harm, 2)); - SinOsc.ar(60 * harm + TRand.kr(-3, 3, switches[i]), 0, amp)} ! 9; - Out.ar(~bassBusArray[0], Mix.new(drone) * 0.2); -}).add; - -SynthDef(\sampler, { - Out.ar(~samplerBusArray, PlayBuf.ar(2, ~sBuf, BufRateScale.kr(~sBuf), doneAction: 2)) -}).add; - -// main routine -SynthDef(\hdust, { - arg gate = 0; - var hierarchical_dust, low_sine, high_sine, brown_noise, white_noise; - // this triggers the combinations of sources - // it is similar to the Supercollider UGen called dust but with a hierarchical structure - hierarchical_dust = ( - TIRand.kr(0, 1, Impulse.kr(100)) * - TIRand.kr(0, 1, Impulse.kr(10)) * - TIRand.kr(0, 1, Impulse.kr(1)) * - TIRand.kr(0, 1, Impulse.kr(0.1)) - ); - // adjust the multiplier at the end of each line for adjusting levels - // note with each trigger, each source has a 1 in 3 chance of sounding - low_sine = SinOsc.ar(76.midicps / 16) * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.1; - high_sine = SinOsc.ar(76.midicps * 8) * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.01; - brown_noise = BrownNoise.ar() * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.025; - white_noise = WhiteNoise.ar() * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.02; - Out.ar(~hdustBusArray[0], - ((low_sine + high_sine + brown_noise + white_noise) ) - ); -}).add; - -) - -( -var bass, hdust, sampler, mixer; -/* -bass = Synth.tail(~group, \bass); -hdust = Synth.tail(~group, \hdust); -sampler = Synth.head(~group, \sampler); -*/ -mixer = Synth.tail(~group, \mixer); - -OSCdef(\mixer, {arg msg, time, addr, port; - mixer.set((msg[1] ++ '_' ++ msg[2] ++ '_' ++ msg[3]), msg[4]) -}, \mixer); - -/* -OSCdef(\sampler, {arg msg, time, addr, port; - msg.postln; - sampler.free; - ~sBuf.free; - ~sBuf = Buffer.read(s, msg[1].asString.postln, action: {sampler = Synth.head(~group, \sampler)}); -}, \sampler); -*/ -) - -/* old something -( -SynthDef(\test, {arg freq, gate = 1, sustain, amp, dur; - var trig, exc, sig1, sig2, noHarms, freqFinal, start, end; - noHarms = 30; - freq = WhiteNoise.ar * 3 + freq; - freqFinal = Duty.ar((1/freq), 0, freq); - trig = Changed.ar(freqFinal); - start = Demand.ar(trig, 0, Dwhite(-1, -0.75)); - end = Demand.ar(trig, 0, Dwhite(0.75, 1)); - exc = Phasor.ar(trig, (end - start) * freqFinal / SampleRate.ir, start, end, 0) * 0.001 + Dust.ar(10000, 0.01); - - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(2, 3)}) ], exc) * 0.5).softclip; - sig1 = HPF.ar(sig1, 300); - Out.ar([0, 1], sig1 * EnvGen.kr(Env.adsr(0.3, 0.3, 0.9, 0.5, 0.9), gate, doneAction: 2)); -}).add; -) -*/ - diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/490b1e6e/490b1e6e_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_1/490b1e6e/490b1e6e_mus_model.json deleted file mode 100644 index 64ab1de..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/490b1e6e/490b1e6e_mus_model.json +++ /dev/null @@ -1,63 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ -2, 0, 0, 1, 1, 0 ], [ "Rest" ], [ "Rest" ] ], 1.375 ], - [ [ [ -2, 0, 0, 1, 1, 1 ], [ -2, 0, 0, 1, 1, 0 ], [ "Rest" ], [ "Rest" ] ], 0.875 ], - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -2, 0, 0, 1, 1, 0 ], [ "Rest" ], [ "Rest" ] ], 0.875 ], - [ [ [ -2, 0, 0, 1, 2, 0 ], [ -2, 0, 0, 1, 1, 0 ], [ "Rest" ], [ "Rest" ] ], 0.75 ], - [ [ [ -1, 0, 0, 1, 0, 0 ], [ -2, 0, 0, 1, 1, 0 ], [ "Rest" ], [ "Rest" ] ], 1.5 ], - [ [ [ -1, -1, 0, 1, 1, 0 ], [ -2, 0, 0, 1, 1, 0 ], [ "Rest" ], [ "Rest" ] ], 1.125 ], - [ [ [ -2, 0, 1, 1, 1, 0 ], [ -2, 0, 0, 1, 1, 0 ], [ "Rest" ], [ "Rest" ] ], 1.625 ], - [ [ [ -1, 0, 0, 0, 1, 0 ], [ -2, 0, 0, 1, 1, 0 ], [ "Rest" ], [ "Rest" ] ], 1.625 ] - ], - [ - [ [ [ -1, 0, 0, 0, 1, 0 ], [ -2, 0, 0, 1, 1, 0 ], [ 0, -1, 0, 0, 1, 0 ], [ "Rest" ] ], 0 ], - [ [ [ -1, 0, 0, 0, 1, 0 ], [ -2, 0, 0, 1, 1, 0 ], [ 0, -1, 0, 0, 1, 0 ], [ 0, 0, 0, 0, 1, 0 ] ], 1.25 ], - [ [ [ -1, 0, 0, 0, 1, 0 ], [ -1, -1, 1, 0, 1, 0 ], [ 0, -1, 0, 0, 1, 0 ], [ 0, 0, 0, 0, 1, 0 ] ], 1.125 ], - [ [ [ -1, 0, 0, 0, 1, 0 ], [ 0, -2, 0, 0, 1, 0 ], [ 0, -1, 0, 0, 1, 0 ], [ 0, 0, 0, 0, 1, 0 ] ], 1 ], - [ [ [ -1, 0, 0, 0, 1, 0 ], [ -2, 1, 0, 0, 1, 0 ], [ 0, -1, 0, 0, 1, 0 ], [ 0, 0, 0, 0, 1, 0 ] ], 0.5 ], - [ [ [ -1, 0, 0, 0, 1, 0 ], [ -1, 0, -1, 0, 1, 0 ], [ 0, -1, 0, 0, 1, 0 ], [ 0, 0, 0, 0, 1, 0 ] ], 1.625 ], - [ [ [ -1, 0, 0, 0, 1, 0 ], [ 0, -1, 0, 0, 1, -1 ], [ 0, -1, 0, 0, 1, 0 ], [ 0, 0, 0, 0, 1, 0 ] ], 2 ], - [ [ [ -1, 0, 0, 0, 1, 0 ], [ 0, -1, 0, -1, 1, 0 ], [ 0, -1, 0, 0, 1, 0 ], [ 0, 0, 0, 0, 1, 0 ] ], 1.75 ], - [ [ [ -1, 0, 0, 0, 1, 0 ], [ -1, -1, 1, 0, 1, 0 ], [ 0, -1, 0, 0, 1, 0 ], [ 0, 0, 0, 0, 1, 0 ] ], 1.5 ], - [ [ [ -1, 0, 0, 0, 1, 0 ], [ 0, -2, 0, 0, 1, 0 ], [ 0, -1, 0, 0, 1, 0 ], [ 0, 0, 0, 0, 1, 0 ] ], 1.25 ], - [ [ [ -1, 0, 0, 0, 1, 0 ], [ 0, -2, 0, 0, 1, 0 ], [ 0, -1, 0, 0, 1, 0 ], [ "Rest" ] ], 0.875 ], - [ [ [ "Rest" ], [ 0, -2, 0, 0, 1, 0 ], [ 0, -1, 0, 0, 1, 0 ], [ "Rest" ] ], 0 ], - [ [ [ "Rest" ], [ 0, -2, 0, 0, 1, 0 ], [ "Rest" ], [ "Rest" ] ], 0 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 1.375 ] - ] - ] -], -"last_changes": -[ - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], - [ [ 1, -1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], - [ [ 0, 0, -1, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], - [ [ -1, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], - [ [ 0, -1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ] -], -"cur_uid": "490b1e6e", -"ref_uid": "nil", -"order_seed": 209164, -"dur_seed": 417909, -"motifs_seed": 885208, -"entrances_probs_vals": [ 0.34, 0, 10, 0.5, 2, 0, 0.5, 0.24509803921569, 0.89189189189189, 0.5, 1, 0.5, 0.5, 0.8562091503268, 0.69932432432432, 1, 0.5 ], -"passages_probs_vals": [ 0.34, 0, 10, 0.5, 2, 0, 0.5, 0.24509803921569, 0.89189189189189, 0.5, 1, 0.5, 0.5, 0.8562091503268, 0.69932432432432, 1, 0.5 ], -"exits_probs_vals": [ 0.34, 0, 10, 0.5, 2, 0, 0.5, 0.24509803921569, 0.89189189189189, 0.5, 1, 0.5, 0.5, 0.8562091503268, 0.69932432432432, 1, 0.5 ], -"ranges": [ [ -1200, 2400 ], [ -1200, 2400 ], [ -1200, 2400 ], [ -1200, 2400 ] ], -"step_probs_vals": [ 0, 1200, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_weights": [ 0.75, 0.75, 0.75, 0.75, 0.75 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 2 ], [ 0, 0, 0, 0 ], [ 1, 3 ] ] -], -"sus_weights": [ 0.75, 0.75, 0.75 ], -"order_size": [ 1, 10 ], -"passages_size": [ 0, 10 ], -"motif_edited": "true", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/490b1e6e/lilypond/part_I.ly b/resources/resources_bak_2024_01_03/string_quartet_1/490b1e6e/lilypond/part_I.ly deleted file mode 100644 index 57e7dcf..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/490b1e6e/lilypond/part_I.ly +++ /dev/null @@ -1,26 +0,0 @@ -{ - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r2. r8[ fis'8^\markup { \pad-markup #0.2 "-49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }}] ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'2. ~ fis'8[ r8] } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/490b1e6e/lilypond/part_II.ly b/resources/resources_bak_2024_01_03/string_quartet_1/490b1e6e/lilypond/part_II.ly deleted file mode 100644 index 72acd78..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/490b1e6e/lilypond/part_II.ly +++ /dev/null @@ -1,26 +0,0 @@ -{ - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r2. r8[ ais8^\markup { \pad-markup #0.2 "+49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }}] ~ } - \bar "|" - { ais1 ~ } - \bar "|" - { ais1 ~ } - \bar "|" - { ais1 ~ } - \bar "|" - { ais1 ~ } - \bar "|" - { ais1 ~ } - \bar "|" - { ais1 ~ } - \bar "|" - { ais4 ~ ais16[ r8.] r2 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/490b1e6e/lilypond/part_III.ly b/resources/resources_bak_2024_01_03/string_quartet_1/490b1e6e/lilypond/part_III.ly deleted file mode 100644 index c698c38..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/490b1e6e/lilypond/part_III.ly +++ /dev/null @@ -1,26 +0,0 @@ -{ - { dis1^\markup { \pad-markup #0.2 "+20"} ~ } - \bar "|" - { dis1 ~ } - \bar "|" - { dis1 ~ } - \bar "|" - { dis1 ~ } - \bar "|" - { dis1 ~ } - \bar "|" - { dis2 d2^\markup { \pad-markup #0.2 "+36"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 5↑" }} ~ } - \bar "|" - { d16[ dis8.^\markup { \pad-markup #0.2 "+47"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↓" }}] ~ dis4 ~ dis16[ cis8.^\markup { \pad-markup #0.2 "-47"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }}] ~ cis16[ d8.^\markup { \pad-markup #0.2 "-35"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↓" }}] ~ } - \bar "|" - { d2 ~ d8[ d8^\markup { \pad-markup #0.2 "+9"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 13↓" }}] ~ d4 ~ } - \bar "|" - { d2 ~ d8[ cis8^\markup { \pad-markup #0.2 "-19"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 7↓" }}] ~ cis4 ~ } - \bar "|" - { cis2 d2^\markup { \pad-markup #0.2 "+36"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 5↑" }} ~ } - \bar "|" - { d4 dis2.^\markup { \pad-markup #0.2 "+47"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↓" }} ~ } - \bar "|" - { dis4 ~ dis16[ r8.] r2 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/490b1e6e/lilypond/part_IV.ly b/resources/resources_bak_2024_01_03/string_quartet_1/490b1e6e/lilypond/part_IV.ly deleted file mode 100644 index 72aea57..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/490b1e6e/lilypond/part_IV.ly +++ /dev/null @@ -1,26 +0,0 @@ -{ - { r2 r8.[ c'16^\markup { \pad-markup #0.2 "-39"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 13↑" }}] ~ c'4 ~ } - \bar "|" - { c'8[ ais8^\markup { \pad-markup #0.2 "+22"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↑" }}] ~ ais4 ~ ais16[ a8.^\markup { \pad-markup #0.2 "-29"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 11↑" }}] ~ a8.[ ais16^\markup { \pad-markup #0.2 "-31"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 11↓" }}] ~ } - \bar "|" - { ais2 ~ ais8.[ gis16^\markup { \pad-markup #0.2 "+18"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↓" }}] ~ gis4 ~ } - \bar "|" - { gis4 g2.^\markup { \pad-markup #0.2 "+6"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 5↑" }} ~ } - \bar "|" - { g16[ fis8.^\markup { \pad-markup #0.2 "-49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 7↓" }}] ~ fis2. ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis4 ~ fis16[ r8.] r2 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/4a8a6e53/4a8a6e53_code.scd b/resources/resources_bak_2024_01_03/string_quartet_1/4a8a6e53/4a8a6e53_code.scd deleted file mode 100644 index 3eb3cbd..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/4a8a6e53/4a8a6e53_code.scd +++ /dev/null @@ -1,1058 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance); -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file; - file = File(path, "w"); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((dir +/+ ".." +/+ "resources" +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((dir +/+ ".." +/+ "resources" +/+ curUID).standardizePath); - File.copy(exPath, (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (dir +/+ ".." +/+ "resources" +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((dir +/+ ".." +/+ "resources" +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (dir +/+ ".." +/+ "resources" +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (dir +/+ ".." +/+ "resources" +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "resources" +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "resources" +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \".." +/+ ".." +/+ "resources" +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - -~transcribe.value(~seq, dir); - -( -//synthdefs -~stringModelBusArray = 4.collect({Bus.audio(s, 1)}); -~sineBusArray = 4.collect({Bus.audio(s, 1)}); -~bassBusArray = 1.collect({Bus.audio(s, 1)}); -~hdustBusArray = 1.collect({Bus.audio(s, 1)}); -~samplerBusArray = 2.collect({Bus.audio(s, 1)}); -~sBuf = Buffer.alloc(s, 10, 2); -SynthDef(\string_model, {arg freq, gate = 1, sustain, amp, dur, attack, release = 1, busIndex = 0; - var trig, exc, sig1, sig2, noHarms; - noHarms = rrand(20, 40); - exc = Saw.ar(freq, TRand.ar(0.5, 1, Impulse.ar(freq))) * 0.001 + Dust.ar(10000, 0.01); - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(1, 2)}) ], exc) * 0.8).softclip; - //sig1 = HPF.ar(sig1, 300); - Out.ar(Select.kr(busIndex, ~stringModelBusArray), sig1 * amp * EnvGen.kr(Env.adsr(attack, 0.3, 0.9, release, 0.9, -3), gate, doneAction: 2)); - //Out.ar([0, 1], sig1 * EnvGen.kr(Env.asr(dur, 0.3, 1), gate, doneAction: 2)); -}).add; - -SynthDef(\sine, {arg freq, gate = 1, sustain, amp, dur, busIndex = 0; - var sig; - sig = SinOsc.ar(freq); - Out.ar(Select.kr(busIndex, ~sineBusArray), sig * EnvGen.kr(Env.asr(0.3, 0.4, 0.3), gate, timeScale: dur, doneAction: 2)); - //Out.ar(Select.kr(busIndex, ~sineBusArray), sig * EnvGen.kr(Env.sine(dur), gate, doneAction: 2)); -}).add; - -SynthDef(\mixer, {arg freq, gate = 1, sustain, amp, dur, out; - var nameSpaces, sigs; - - sigs = [~stringModelBusArray, ~sineBusArray/*, ~bassBusArray, ~hdustBusArray, ~samplerBusArray*/].collect({arg busArray, i; - var nameSpace, sig; - nameSpace = ['string', 'sine', 'bass', 'hdust', 'sampler'][i]; - sig = busArray.collect({arg bus, c; In.ar(bus, 1) * NamedControl.kr(\ ++ nameSpace ++ '_volume_' ++ c, 1, 0.1)}); - sig = sig.collect({arg channel, c; Pan2.ar(channel, NamedControl.kr(\ ++ nameSpace ++ '_pan_' ++ c, i / (busArray.size - 1), 0.1) * 2 - 1)}); - sig = sig.collect({arg channel, c; channel * NamedControl.kr(\ ++ nameSpace ++ '_mute_' ++ c, 1, 0.1)}); - sig = Mix.ar(sig) * pow(NamedControl.kr(\ ++ nameSpace ++ '_volume_master', 1, 0.1), 2); - }); - - sigs = Mix.ar(sigs / 4); - Out.ar(0, sigs) -}).add; - -SynthDef(\bass, { - var switches, drone; - switches = {|i| Dust.kr(0.1)} ! 9; - drone = {|i| var harm = pow(2, 2 - (i / 3).trunc), amp = (1 / pow(harm, 2)); - SinOsc.ar(60 * harm + TRand.kr(-3, 3, switches[i]), 0, amp)} ! 9; - Out.ar(~bassBusArray[0], Mix.new(drone) * 0.2); -}).add; - -SynthDef(\sampler, { - Out.ar(~samplerBusArray, PlayBuf.ar(2, ~sBuf, BufRateScale.kr(~sBuf), doneAction: 2)) -}).add; - -// main routine -SynthDef(\hdust, { - arg gate = 0; - var hierarchical_dust, low_sine, high_sine, brown_noise, white_noise; - // this triggers the combinations of sources - // it is similar to the Supercollider UGen called dust but with a hierarchical structure - hierarchical_dust = ( - TIRand.kr(0, 1, Impulse.kr(100)) * - TIRand.kr(0, 1, Impulse.kr(10)) * - TIRand.kr(0, 1, Impulse.kr(1)) * - TIRand.kr(0, 1, Impulse.kr(0.1)) - ); - // adjust the multiplier at the end of each line for adjusting levels - // note with each trigger, each source has a 1 in 3 chance of sounding - low_sine = SinOsc.ar(76.midicps / 16) * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.1; - high_sine = SinOsc.ar(76.midicps * 8) * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.01; - brown_noise = BrownNoise.ar() * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.025; - white_noise = WhiteNoise.ar() * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.02; - Out.ar(~hdustBusArray[0], - ((low_sine + high_sine + brown_noise + white_noise) ) - ); -}).add; - -) - -( -var bass, hdust, sampler, mixer; -/* -bass = Synth.tail(~group, \bass); -hdust = Synth.tail(~group, \hdust); -sampler = Synth.head(~group, \sampler); -*/ -mixer = Synth.tail(~group, \mixer); - -OSCdef(\mixer, {arg msg, time, addr, port; - mixer.set((msg[1] ++ '_' ++ msg[2] ++ '_' ++ msg[3]), msg[4]) -}, \mixer); - -/* -OSCdef(\sampler, {arg msg, time, addr, port; - msg.postln; - sampler.free; - ~sBuf.free; - ~sBuf = Buffer.read(s, msg[1].asString.postln, action: {sampler = Synth.head(~group, \sampler)}); -}, \sampler); -*/ -) - -/* old something -( -SynthDef(\test, {arg freq, gate = 1, sustain, amp, dur; - var trig, exc, sig1, sig2, noHarms, freqFinal, start, end; - noHarms = 30; - freq = WhiteNoise.ar * 3 + freq; - freqFinal = Duty.ar((1/freq), 0, freq); - trig = Changed.ar(freqFinal); - start = Demand.ar(trig, 0, Dwhite(-1, -0.75)); - end = Demand.ar(trig, 0, Dwhite(0.75, 1)); - exc = Phasor.ar(trig, (end - start) * freqFinal / SampleRate.ir, start, end, 0) * 0.001 + Dust.ar(10000, 0.01); - - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(2, 3)}) ], exc) * 0.5).softclip; - sig1 = HPF.ar(sig1, 300); - Out.ar([0, 1], sig1 * EnvGen.kr(Env.adsr(0.3, 0.3, 0.9, 0.5, 0.9), gate, doneAction: 2)); -}).add; -) -*/ - diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/4a8a6e53/4a8a6e53_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_1/4a8a6e53/4a8a6e53_mus_model.json deleted file mode 100644 index 150baf5..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/4a8a6e53/4a8a6e53_mus_model.json +++ /dev/null @@ -1,97 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ] ], 0.875 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ] ], 0.625 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], 1.5 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ] ], 0.875 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ] ], 0.875 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ] ], 1 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 1, 0, 0 ] ], 1 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ] ], 1.25 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 1 ] ], 0.875 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, -1, 0, 0, 0 ] ], 0.875 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ] ], 1.25 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ] ], 0.75 ] - ], - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ] ], 0.875 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 1, 0, 0, 0, 0, -1 ], [ "Rest" ] ], 1.5 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ -1, 0, 0, 1, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ], [ "Rest" ] ], 1.25 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ -1, 0, 0, 1, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ "Rest" ] ], 1.375 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ -1, 0, 0, 1, 0, 0 ], [ 0, 0, 0, 1, 0, 0 ], [ "Rest" ] ], 0.75 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, -1, 0, 0, 0 ], [ 0, 0, 0, 1, 0, 0 ], [ "Rest" ] ], 0.625 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 0, 0, 0, 1, 0, 0 ], [ "Rest" ] ], 0.75 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 0, 0, 0, 0, 0, 1 ], [ "Rest" ] ], 1.125 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 1, 0, -1, 0, 0, 0 ], [ "Rest" ] ], 1.25 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ "Rest" ] ], 1 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ "Rest" ] ], 0.875 ] - ], - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, -1, 0, -1, 0 ] ], 0.875 ], - [ [ [ 1, -1, 0, 0, -1, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, -1, 0, -1, 0 ] ], 0.75 ], - [ [ [ 1, -1, 0, 0, -1, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 0, 0, 0, 1, -1, 0 ], [ 1, 0, -1, 0, -1, 0 ] ], 1.5 ], - [ [ [ 1, -1, 0, 0, -1, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 0, 0, 0, 1, -1, 0 ], [ 0, 0, 0, 0, -1, 1 ] ], 1.25 ], - [ [ [ 1, -1, 0, 0, -1, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 0, 0, 0, 1, -1, 0 ], [ 0, 1, 0, 0, -1, 0 ] ], 0.625 ], - [ [ [ 1, -1, 0, 0, -1, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 1, 0, 0, 0, -1, 0 ], [ 0, 1, 0, 0, -1, 0 ] ], 0.625 ], - [ [ [ 0, 0, 1, 0, -1, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 1, 0, 0, 0, -1, 0 ], [ 0, 1, 0, 0, -1, 0 ] ], 0.625 ], - [ [ [ 1, 0, 0, -1, -1, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 1, 0, 0, 0, -1, 0 ], [ 0, 1, 0, 0, -1, 0 ] ], 1.375 ], - [ [ [ 1, 0, 0, -1, -1, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 1, 0, 0, 0, -1, 0 ], [ 0, 0, 1, 0, -1, 0 ] ], 1.375 ], - [ [ [ 1, 0, 0, -1, -1, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 2, 0, 0, -1, -1, 0 ], [ 0, 0, 1, 0, -1, 0 ] ], 1.5 ], - [ [ [ 1, 0, 0, -1, -1, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 2, 0, 0, 0, -1, -1 ], [ 0, 0, 1, 0, -1, 0 ] ], 0.75 ], - [ [ [ 1, 0, 0, -1, -1, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 2, 0, 0, 0, -1, -1 ], [ 1, -1, 0, 0, -1, 0 ] ], 1 ] - ], - [ - [ [ [ 1, 0, 0, -1, -1, 0 ], [ "Rest" ], [ 2, 0, 0, 0, -1, -1 ], [ 1, -1, 0, 0, -1, 0 ] ], 0.75 ], - [ [ [ 0, -1, 0, 1, -1, 0 ], [ "Rest" ], [ 2, 0, 0, 0, -1, -1 ], [ 1, -1, 0, 0, -1, 0 ] ], 1 ], - [ [ [ 0, -1, 0, 1, -1, 0 ], [ "Rest" ], [ 2, -1, 0, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ] ], 0.875 ], - [ [ [ 0, -1, 0, 0, -1, 1 ], [ "Rest" ], [ 2, -1, 0, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ] ], 1.25 ], - [ [ [ 0, -1, 0, 0, -1, 1 ], [ "Rest" ], [ 1, -1, 0, 1, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ] ], 1.125 ], - [ [ [ 1, -1, -1, 0, -1, 0 ], [ "Rest" ], [ 1, -1, 0, 1, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ] ], 1 ], - [ [ [ 1, -1, -1, 0, -1, 0 ], [ "Rest" ], [ 1, 0, 0, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ] ], 0.75 ], - [ [ [ 1, -1, -1, 0, -1, 0 ], [ "Rest" ], [ 1, -1, 0, 0, 0, 0 ], [ 1, -1, 0, 0, -1, 0 ] ], 0.625 ], - [ [ [ 0, -1, 0, 0, 0, 0 ], [ "Rest" ], [ 1, -1, 0, 0, 0, 0 ], [ 1, -1, 0, 0, -1, 0 ] ], 0.75 ], - [ [ [ 1, -1, 0, 0, -2, 0 ], [ "Rest" ], [ 1, -1, 0, 0, 0, 0 ], [ 1, -1, 0, 0, -1, 0 ] ], 1.375 ], - [ [ [ 1, -1, 0, 0, -2, 0 ], [ "Rest" ], [ 2, -2, 0, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ] ], 0.875 ], - [ [ [ 0, -1, 0, 0, -1, 1 ], [ "Rest" ], [ 2, -2, 0, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ] ], 3.375 ], - [ [ [ 0, -1, 0, 0, -1, 1 ], [ "Rest" ], [ 2, -2, 0, 0, -1, 0 ], [ "Rest" ] ], 1.5 ], - [ [ [ 0, -1, 0, 0, -1, 1 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 1.375 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 2 ] - ] - ] -], -"last_changes": -[ - [ [ 0, 0, 0, 1, 0, -1 ], [ 0, 0, 0, 0, 0, 0 ], [ 2, 0, 0, 0, 0, -1 ], [ 1, 0, 0, 0, 0, -2 ] ], - [ [ 0, 0, 0, 1, 0, -1 ], [ 0, 0, 0, 0, 0, 0 ], [ 2, 0, 0, 0, 0, -1 ], [ -1, 0, 0, 1, 0, -1 ] ], - [ [ 0, 0, 0, 1, 0, -1 ], [ 0, 0, 0, 0, 0, 0 ], [ 2, 0, 0, 0, 0, -1 ], [ 0, 0, 0, 0, -1, 0 ] ], - [ [ 0, 0, 0, 1, 0, -1 ], [ 0, 0, 0, 0, 0, 0 ], [ 2, 0, 0, -1, 0, 0 ], [ 0, 0, 0, 0, -1, 0 ] ], - [ [ 1, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 2, 0, 0, -1, 0, 0 ], [ 0, 0, 0, 0, -1, 0 ] ] -], -"cur_uid": "4a8a6e53", -"ref_uid": "nil", -"order_seed": 320463, -"dur_seed": 903977, -"motifs_seed": 895384, -"entrances_probs_vals": [ 0.75, 0, 10, 0, 0.5, 0.26424870466321, 0.75675675675676, 0.5, 0.5, 0.58549222797927, 0.72635135135135, 1, 0.5 ], -"passages_probs_vals": [ 0.75, 0, 10, 0, 0.5, 0.20725388601036, 0.68581081081081, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"exits_probs_vals": [ 0.75, 0, 10, 0, 0.5, 0.20725388601036, 0.68581081081081, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"ranges": [ [ -384, 2400 ], [ -507, 2400 ], [ -282, 2237 ], [ -1200, 2053 ] ], -"step_probs_vals": [ 0, 1200, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_weights": [ 0.75, 0.75, 0.75, 0.75, 0.75 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 1 ], [ 0, 3, 2, 3, 3, 2 ], [ ] ], - [ [ 2, 1 ], [ 3, 0, 3 ], [ ] ], - [ [ 1 ], [ 3, 2, 0 ], [ ] ] -], -"sus_weights": [ 0.75, 0.69, 0.75 ], -"order_size": [ 2, 6 ], -"passages_size": [ 0, 10 ], -"motif_edited": "true", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/4a8a6e53/lilypond/part_I.ly b/resources/resources_bak_2024_01_03/string_quartet_1/4a8a6e53/lilypond/part_I.ly deleted file mode 100644 index e9e6601..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/4a8a6e53/lilypond/part_I.ly +++ /dev/null @@ -1,56 +0,0 @@ -{ - { r2. e'4^\markup { \pad-markup #0.2 "-41"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↓" }} ~ } - \bar "|" - { e'2 e'4^\markup { \pad-markup #0.2 "-14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }} ~ e'8.[ f'16^\markup { \pad-markup #0.2 "-2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }}] ~ } - \bar "|" - { f'4 ~ f'8[ g'8^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }}] ~ g'4 ~ g'8[ ais'8^\markup { \pad-markup #0.2 "-31"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↑" }}] ~ } - \bar "|" - { ais'4 ~ ais'8[ c''8^\markup { \pad-markup #0.2 "+0"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }}] ~ c''2 } - \bar "|" - { gis'4^\markup { \pad-markup #0.2 "+41"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↑" }} ~ gis'8.[ gis'16^\markup { \pad-markup #0.2 "+14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↓" }}] ~ gis'4 ~ gis'8[ f'8^\markup { \pad-markup #0.2 "-2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }}] ~ } - \bar "|" - { f'2 e'4^\markup { \pad-markup #0.2 "-14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }} ~ e'8[ r8] } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r2 r16[ dis'8.^\markup { \pad-markup #0.2 "-38"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 5↓" }}] ~ dis'4 ~ } - \bar "|" - { dis'1 ~ } - \bar "|" - { dis'8[ dis'8^\markup { \pad-markup #0.2 "-11"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 13↑" }}] ~ dis'2 d'4^\markup { \pad-markup #0.2 "-49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↑" }} ~ } - \bar "|" - { d'1 ~ } - \bar "|" - { d'4 ~ d'8[ ais8^\markup { \pad-markup #0.2 "+35"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 5↑" }}] ~ ais2 ~ } - \bar "|" - { ais1 ~ } - \bar "|" - { ais8.[ b16^\markup { \pad-markup #0.2 "+47"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↓" }}] ~ b2. ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b2 ~ b16[ r8.] r4 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/4a8a6e53/lilypond/part_II.ly b/resources/resources_bak_2024_01_03/string_quartet_1/4a8a6e53/lilypond/part_II.ly deleted file mode 100644 index 3c00ff8..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/4a8a6e53/lilypond/part_II.ly +++ /dev/null @@ -1,56 +0,0 @@ -{ - { c'1^\markup { \pad-markup #0.2 "+0"} ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'4 ~ c'16[ e'8.^\markup { \pad-markup #0.2 "-41"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↓" }}] ~ e'2 ~ } - \bar "|" - { e'2 ~ e'8.[ g'16^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }}] ~ g'4 ~ } - \bar "|" - { g'4 ~ g'8[ ais'8^\markup { \pad-markup #0.2 "-31"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }}] ~ ais'2 ~ } - \bar "|" - { ais'4 ~ ais'8.[ gis'16^\markup { \pad-markup #0.2 "+41"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↑" }}] ~ gis'2 } - \bar "|" - { gis'2^\markup { \pad-markup #0.2 "+14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↓" }} ~ gis'8[ g'8^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }}] ~ g'4 ~ } - \bar "|" - { g'8[ f'8^\markup { \pad-markup #0.2 "-2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }}] ~ f'2. ~ } - \bar "|" - { f'4 ~ f'8[ e'8^\markup { \pad-markup #0.2 "+18"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 7↑" }}] ~ e'2 ~ } - \bar "|" - { e'1 ~ } - \bar "|" - { e'16[ fis'8.^\markup { \pad-markup #0.2 "+49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }}] ~ fis'2. ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'16[ a'8.^\markup { \pad-markup #0.2 "-20"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }}] ~ a'2 ~ a'16[ ais'8.^\markup { \pad-markup #0.2 "+8"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 13↓" }}] ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'2 ~ ais'16[ b'8.^\markup { \pad-markup #0.2 "+47"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }}] ~ b'4 ~ } - \bar "|" - { b'2 ~ b'8[ a'8^\markup { \pad-markup #0.2 "+16"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 7↑" }}] ~ a'4 ~ } - \bar "|" - { a'2 ~ a'8.[ fis'16^\markup { \pad-markup #0.2 "+49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↑" }}] ~ fis'4 ~ } - \bar "|" - { fis'16[ f'8.^\markup { \pad-markup #0.2 "-2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 11↑" }}] ~ f'2. ~ } - \bar "|" - { f'4 ~ f'8.[ e'16^\markup { \pad-markup #0.2 "+45"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↓" }}] ~ e'2 ~ } - \bar "|" - { e'1 ~ } - \bar "|" - { e'1 ~ } - \bar "|" - { e'4 ~ e'16[ r8.] r2 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/4a8a6e53/lilypond/part_III.ly b/resources/resources_bak_2024_01_03/string_quartet_1/4a8a6e53/lilypond/part_III.ly deleted file mode 100644 index 75dcb1c..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/4a8a6e53/lilypond/part_III.ly +++ /dev/null @@ -1,56 +0,0 @@ -{ - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r16[ ais8.^\markup { \pad-markup #0.2 "-31"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↑" }}] ~ ais2. ~ } - \bar "|" - { ais2. gis4^\markup { \pad-markup #0.2 "+14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↓" }} ~ } - \bar "|" - { gis16[ fis8.^\markup { \pad-markup #0.2 "+49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 11↓" }}] ~ fis2. ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis2 ~ fis8.[ r16] r4 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/4a8a6e53/lilypond/part_IV.ly b/resources/resources_bak_2024_01_03/string_quartet_1/4a8a6e53/lilypond/part_IV.ly deleted file mode 100644 index 41471e8..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/4a8a6e53/lilypond/part_IV.ly +++ /dev/null @@ -1,56 +0,0 @@ -{ - { r4 r8.[ c'16^\markup { \pad-markup #0.2 "+0"}] ~ c'2 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 } - \bar "|" - { b1^\markup { \pad-markup #0.2 "+47"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↓" }} ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b4 ~ b8[ ais8^\markup { \pad-markup #0.2 "+35"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 5↑" }}] ~ ais8.[ a16^\markup { \pad-markup #0.2 "-20"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 7↓" }}] ~ a4 ~ } - \bar "|" - { a1 ~ } - \bar "|" - { a1 ~ } - \bar "|" - { a1 ~ } - \bar "|" - { a16[ a8.^\markup { \pad-markup #0.2 "+16"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 7↑" }}] ~ a2. } - \bar "|" - { gis1^\markup { \pad-markup #0.2 "-13"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 13↑" }} ~ } - \bar "|" - { gis8.[ gis16^\markup { \pad-markup #0.2 "-40"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 5↓" }}] ~ gis2. ~ } - \bar "|" - { gis4 ~ gis8[ f8^\markup { \pad-markup #0.2 "-2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 1↑" }}] ~ f4 fis4^\markup { \pad-markup #0.2 "-5"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 11↓" }} ~ } - \bar "|" - { fis2. ~ fis8[ gis8^\markup { \pad-markup #0.2 "-13"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 13↑" }}] ~ } - \bar "|" - { gis1 ~ } - \bar "|" - { gis1 ~ } - \bar "|" - { gis1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/4b7745df/4b7745df_code.scd b/resources/resources_bak_2024_01_03/string_quartet_1/4b7745df/4b7745df_code.scd deleted file mode 100644 index a98b916..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/4b7745df/4b7745df_code.scd +++ /dev/null @@ -1,945 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance); -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/4b7745df/4b7745df_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_1/4b7745df/4b7745df_mus_model.json deleted file mode 100644 index f30b098..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/4b7745df/4b7745df_mus_model.json +++ /dev/null @@ -1,48 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ 2, -2, 0, -1, 1, 0 ], [ "Rest" ], [ "Rest" ] ], 7.5 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ "Rest" ], [ "Rest" ] ], 3.625 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ "Rest" ], [ 3, -2, -1, -1, 1, 0 ] ], 1.875 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 2, -1, -1, -1, 1, 0 ], [ 3, -2, -1, -1, 1, 0 ] ], 1.75 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 2, -1, -1, -1, 1, 0 ], [ 3, -1, 0, -2, 1, 0 ] ], 3.375 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ "Rest" ], [ 2, -1, -1, -1, 1, 0 ], [ 3, -1, 0, -2, 1, 0 ] ], 1.75 ], - [ [ [ "Rest" ], [ "Rest" ], [ 2, -1, -1, -1, 1, 0 ], [ 3, -1, 0, -2, 1, 0 ] ], 0.75 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ 3, -1, 0, -2, 1, 0 ] ], 1.125 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 4.25 ] - ] - ] -], -"last_changes": -[ - [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 3, -2, 0, -1, 1, -1 ], [ 3, -2, 0, -1, 0, 0 ] ], - [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 3, -2, 0, -1, 1, -1 ], [ 2, -1, 0, -1, 1, 0 ] ], - [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 3, -2, 0, -1, 1, -1 ], [ 3, -2, -1, -1, 1, 0 ] ], - [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 2, -1, -1, -1, 1, 0 ], [ 3, -2, -1, -1, 1, 0 ] ], - [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 2, -1, -1, -1, 1, 0 ], [ 3, -1, 0, -2, 1, 0 ] ] -], -"cur_uid": "4b7745df", -"ref_uid": "7d3c9a80", -"order_seed": 216475, -"dur_seed": 241788, -"motifs_seed": 440693, -"entrances_probs_vals": [ 0, 1.1904761904762, 3.3333333333333, 0.71, 1.92, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 0, 1.1904761904762, 3.3333333333333, 0.71, 1.92, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 0, 1.1904761904762, 3.3333333333333, 0.71, 1.92, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -3600, -312 ], [ -1872, 1378 ], [ -145, 1583 ], [ -182, 1527 ] ], -"step_probs_vals": [ 0, 1200, 0, 0, 0.082304526748971, 0.99431818181818, 0.14197530864198, 0, 1, 0 ], -"passages_weights": [ 0.75, 0.75, 0.75, 0.75, 0.75 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 1, 0 ], [ 3, 2, 3 ], [ ] ] -], -"sus_weights": [ 0, 0.65, 0 ], -"order_size": [ 1, 2 ], -"passages_size": [ 1, 6 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/4b7745df/lilypond/part_I.ly b/resources/resources_bak_2024_01_03/string_quartet_1/4b7745df/lilypond/part_I.ly deleted file mode 100644 index d9ec1f9..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/4b7745df/lilypond/part_I.ly +++ /dev/null @@ -1,28 +0,0 @@ -{ - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r2 r16[ d''8.^\markup { \pad-markup #0.2 "-8"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 5↓" }}] ~ d''4 ~ } - \bar "|" - { d''1 ~ } - \bar "|" - { d''4 ~ d''8[ dis''8^\markup { \pad-markup #0.2 "+12"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↓" }}] ~ dis''2 ~ } - \bar "|" - { dis''1 ~ } - \bar "|" - { dis''1 ~ } - \bar "|" - { dis''2. ~ dis''8[ r8] } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/4b7745df/lilypond/part_II.ly b/resources/resources_bak_2024_01_03/string_quartet_1/4b7745df/lilypond/part_II.ly deleted file mode 100644 index 6118a4a..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/4b7745df/lilypond/part_II.ly +++ /dev/null @@ -1,28 +0,0 @@ -{ - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r2 a'2^\markup { \pad-markup #0.2 "-6"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↓" }} ~ } - \bar "|" - { a'1 ~ } - \bar "|" - { a'1 ~ } - \bar "|" - { a'1 ~ } - \bar "|" - { a'4 ~ a'16[ r8.] r2 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/4b7745df/lilypond/part_III.ly b/resources/resources_bak_2024_01_03/string_quartet_1/4b7745df/lilypond/part_III.ly deleted file mode 100644 index 80764d9..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/4b7745df/lilypond/part_III.ly +++ /dev/null @@ -1,28 +0,0 @@ -{ - { fis'1^\markup { \pad-markup #0.2 "-21"} ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'16[ r8.] r2. } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/4b7745df/lilypond/part_IV.ly b/resources/resources_bak_2024_01_03/string_quartet_1/4b7745df/lilypond/part_IV.ly deleted file mode 100644 index 8cc8f1d..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/4b7745df/lilypond/part_IV.ly +++ /dev/null @@ -1,28 +0,0 @@ -{ - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r2. cis'4^\markup { \pad-markup #0.2 "-19"} ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'2. ~ cis'8.[ r16] } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/4e7d35e5/4e7d35e5_code.scd b/resources/resources_bak_2024_01_03/string_quartet_1/4e7d35e5/4e7d35e5_code.scd deleted file mode 100644 index a98b916..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/4e7d35e5/4e7d35e5_code.scd +++ /dev/null @@ -1,945 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance); -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/4e7d35e5/4e7d35e5_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_1/4e7d35e5/4e7d35e5_mus_model.json deleted file mode 100644 index 0eebea8..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/4e7d35e5/4e7d35e5_mus_model.json +++ /dev/null @@ -1,52 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ 1, 0, 1, -2, 1, 1 ] ], 1.75 ], - [ [ [ "Rest" ], [ "Rest" ], [ 1, 0, 0, -2, 1, 1 ], [ 1, 0, 1, -2, 1, 1 ] ], 1.5 ] - ], - [ - [ [ [ "Rest" ], [ "Rest" ], [ 1, 0, 0, -2, 1, 1 ], [ "Rest" ] ], 0 ], - [ [ [ "Rest" ], [ 1, -1, 1, -2, 2, 0 ], [ 1, 0, 0, -2, 1, 1 ], [ "Rest" ] ], 1.5 ], - [ [ [ "Rest" ], [ 1, -1, 1, -2, 2, 0 ], [ 1, 0, 1, -2, 2, 0 ], [ "Rest" ] ], 0 ], - [ [ [ 0, -1, 1, -2, 2, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 1, 0, 1, -2, 2, 0 ], [ "Rest" ] ], 0.75 ], - [ [ [ 0, -1, 1, -2, 2, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 1, -1, 1, -2, 3, 0 ], [ "Rest" ] ], 1.375 ], - [ [ [ 0, -1, 1, -2, 2, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ "Rest" ], [ "Rest" ] ], 1.125 ], - [ [ [ 0, -1, 1, -2, 2, 0 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 0.625 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 3.375 ] - ] - ] -], -"last_changes": -[ - [ [ 1, -1, 1, -3, 2, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 0, 1, 1, -2, 1, 1 ], [ 1, 0, 1, -2, 1, 1 ] ], - [ [ 1, -1, 1, -3, 2, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 1, 0, 0, -2, 1, 1 ], [ 1, 0, 1, -2, 1, 1 ] ], - [ [ 1, -1, 1, -3, 2, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 1, 0, 1, -2, 2, 0 ], [ 1, 0, 1, -2, 1, 1 ] ], - [ [ 0, -1, 1, -2, 2, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 1, 0, 1, -2, 2, 0 ], [ 1, 0, 1, -2, 1, 1 ] ], - [ [ 0, -1, 1, -2, 2, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 1, -1, 1, -2, 3, 0 ], [ 1, 0, 1, -2, 1, 1 ] ] -], -"cur_uid": "4e7d35e5", -"ref_uid": "6d635e88", -"order_seed": 516056, -"dur_seed": 358555, -"motifs_seed": 595740, -"entrances_probs_vals": [ 0.18, 0.28, 1.4285714285714, 0.47, 1.62, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 0.29, 0, 1.1111111111111, 0.65934065934066, 1.37, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 0.18, 0.28, 1.4285714285714, 0.47, 1.62, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -2411.1455108359, -850.77399380805 ], [ -1872, 450 ], [ -479, 1304.0247678019 ], [ -368, 1173.9938080495 ] ], -"step_probs_vals": [ 0, 1200, 0, 0, 0.082304526748971, 0.99431818181818, 0.33950617283951, 0, 0.72839506172839, 0, 1, 0 ], -"passages_weights": [ 0.35, 0.42, 0.75, 0.9, 0.93 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 3 ], [ 2 ], [ 0, 1 ] ], - [ [ 1 ], [ 2, 0, 2 ], [ 3 ] ] -], -"sus_weights": [ 0.41, 0, 0 ], -"order_size": [ 2, 6 ], -"passages_size": [ 0, 5 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/4e7d35e5/lilypond/part_I.ly b/resources/resources_bak_2024_01_03/string_quartet_1/4e7d35e5/lilypond/part_I.ly deleted file mode 100644 index 18a5337..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/4e7d35e5/lilypond/part_I.ly +++ /dev/null @@ -1,14 +0,0 @@ -{ - { ais'1^\markup { \pad-markup #0.2 "+41"} ~ } - \bar "|" - { ais'2 ~ ais'8[ r8] r4 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/4e7d35e5/lilypond/part_II.ly b/resources/resources_bak_2024_01_03/string_quartet_1/4e7d35e5/lilypond/part_II.ly deleted file mode 100644 index 0674392..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/4e7d35e5/lilypond/part_II.ly +++ /dev/null @@ -1,14 +0,0 @@ -{ - { r2. r8[ g'8^\markup { \pad-markup #0.2 "-46"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 5↓" }}] ~ } - \bar "|" - { g'1 ~ } - \bar "|" - { g'4 ~ g'8[ gis'8^\markup { \pad-markup #0.2 "-49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↑" }}] ~ gis'4 fis'4^\markup { \pad-markup #0.2 "+1"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 11↑" }} ~ } - \bar "|" - { fis'4 ~ fis'8.[ r16] r2 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/4e7d35e5/lilypond/part_III.ly b/resources/resources_bak_2024_01_03/string_quartet_1/4e7d35e5/lilypond/part_III.ly deleted file mode 100644 index 7778860..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/4e7d35e5/lilypond/part_III.ly +++ /dev/null @@ -1,14 +0,0 @@ -{ - { r1 } - \bar "|" - { r2 r8[ c'8^\markup { \pad-markup #0.2 "+49"}] ~ c'4 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/4e7d35e5/lilypond/part_IV.ly b/resources/resources_bak_2024_01_03/string_quartet_1/4e7d35e5/lilypond/part_IV.ly deleted file mode 100644 index 0f106c9..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/4e7d35e5/lilypond/part_IV.ly +++ /dev/null @@ -1,14 +0,0 @@ -{ - { r1 } - \bar "|" - { r1 } - \bar "|" - { r4 r8[ c8^\markup { \pad-markup #0.2 "+49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }}] ~ c2 ~ } - \bar "|" - { c1 ~ } - \bar "|" - { c4 ~ c16[ r8.] r2 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/52c9a980/52c9a980_code.scd b/resources/resources_bak_2024_01_03/string_quartet_1/52c9a980/52c9a980_code.scd deleted file mode 100644 index a98b916..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/52c9a980/52c9a980_code.scd +++ /dev/null @@ -1,945 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance); -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/52c9a980/52c9a980_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_1/52c9a980/52c9a980_mus_model.json deleted file mode 100644 index f3cde46..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/52c9a980/52c9a980_mus_model.json +++ /dev/null @@ -1,55 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ 1, 0, 1, -2, 1, 1 ] ], 2 ], - [ [ [ "Rest" ], [ "Rest" ], [ 0, 0, 1, -1, 1, 1 ], [ 1, 0, 1, -2, 1, 1 ] ], 1.5 ] - ], - [ - [ [ [ "Rest" ], [ "Rest" ], [ 0, 0, 1, -1, 1, 1 ], [ "Rest" ] ], 0 ], - [ [ [ "Rest" ], [ 1, -1, 1, -2, 2, 0 ], [ 0, 0, 1, -1, 1, 1 ], [ "Rest" ] ], 1.5 ], - [ [ [ "Rest" ], [ 1, -1, 1, -2, 2, 0 ], [ 2, -1, 1, -2, 1, 0 ], [ "Rest" ] ], 0 ], - [ [ [ 0, -1, 1, -2, 2, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 2, -1, 1, -2, 1, 0 ], [ "Rest" ] ], 0.75 ], - [ [ [ 0, -1, 1, -2, 2, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 2, -2, 1, -2, 2, 0 ], [ "Rest" ] ], 0.75 ], - [ [ [ -1, -1, 1, -1, 2, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 2, -2, 1, -2, 2, 0 ], [ "Rest" ] ], 0.625 ], - [ [ [ 0, -1, 0, -2, 2, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 2, -2, 1, -2, 2, 0 ], [ "Rest" ] ], 1.25 ], - [ [ [ 0, -1, 0, -2, 2, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 2, -1, 1, -2, 2, -1 ], [ "Rest" ] ], 2.25 ], - [ [ [ 0, -1, 0, -2, 2, 0 ], [ "Rest" ], [ 2, -1, 1, -2, 2, -1 ], [ "Rest" ] ], 1.5 ], - [ [ [ 0, -1, 0, -2, 2, 0 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 0.875 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 3.0 ] - ] - ] -], -"last_changes": -[ - [ [ 0, -1, 1, -2, 2, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 2, -1, 1, -2, 1, 0 ], [ 1, 0, 1, -2, 1, 1 ] ], - [ [ 0, -1, 1, -2, 2, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 2, -2, 1, -2, 2, 0 ], [ 1, 0, 1, -2, 1, 1 ] ], - [ [ -1, -1, 1, -1, 2, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 2, -2, 1, -2, 2, 0 ], [ 1, 0, 1, -2, 1, 1 ] ], - [ [ 0, -1, 0, -2, 2, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 2, -2, 1, -2, 2, 0 ], [ 1, 0, 1, -2, 1, 1 ] ], - [ [ 0, -1, 0, -2, 2, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 2, -1, 1, -2, 2, -1 ], [ 1, 0, 1, -2, 1, 1 ] ] -], -"cur_uid": "52c9a980", -"ref_uid": "6d635e88", -"order_seed": 516056, -"dur_seed": 358555, -"motifs_seed": 210544, -"entrances_probs_vals": [ 0.18, 0.28, 1.4285714285714, 0.82, 2.0054945054945, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 0.29, 0, 1.1111111111111, 0.65934065934066, 1.37, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 0.18, 0.28, 1.4285714285714, 0.82, 2.0054945054945, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -2411.1455108359, -850.77399380805 ], [ -1872, 450 ], [ -479, 1304.0247678019 ], [ -368, 1173.9938080495 ] ], -"step_probs_vals": [ 0, 1200, 0, 0, 0.082304526748971, 0.99431818181818, 0.33950617283951, 0, 0.72839506172839, 0, 1, 0 ], -"passages_weights": [ 0.35, 0.42, 0.75, 0.9, 0.93 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 3 ], [ 2 ], [ 0, 1 ] ], - [ [ 1 ], [ 2, 0, 2, 0, 0, 2 ], [ 3 ] ] -], -"sus_weights": [ 0.41, 0, 0 ], -"order_size": [ 2, 6 ], -"passages_size": [ 0, 5 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/52c9a980/lilypond/part_I.ly b/resources/resources_bak_2024_01_03/string_quartet_1/52c9a980/lilypond/part_I.ly deleted file mode 100644 index ba446df..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/52c9a980/lilypond/part_I.ly +++ /dev/null @@ -1,18 +0,0 @@ -{ - { ais'1^\markup { \pad-markup #0.2 "+41"} ~ } - \bar "|" - { ais'2. r4 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/52c9a980/lilypond/part_II.ly b/resources/resources_bak_2024_01_03/string_quartet_1/52c9a980/lilypond/part_II.ly deleted file mode 100644 index 75eeb2b..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/52c9a980/lilypond/part_II.ly +++ /dev/null @@ -1,18 +0,0 @@ -{ - { r1 } - \bar "|" - { gis'1^\markup { \pad-markup #0.2 "+9"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 7↑" }} ~ } - \bar "|" - { gis'2 g'4^\markup { \pad-markup #0.2 "-2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 11↓" }} ~ g'8[ f'8^\markup { \pad-markup #0.2 "+47"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }}] ~ } - \bar "|" - { f'1 ~ } - \bar "|" - { f'8.[ e'16^\markup { \pad-markup #0.2 "+9"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 13↓" }}] ~ e'2. ~ } - \bar "|" - { e'1 ~ } - \bar "|" - { e'16[ r8.] r2. } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/52c9a980/lilypond/part_III.ly b/resources/resources_bak_2024_01_03/string_quartet_1/52c9a980/lilypond/part_III.ly deleted file mode 100644 index 9e681f0..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/52c9a980/lilypond/part_III.ly +++ /dev/null @@ -1,18 +0,0 @@ -{ - { r1 } - \bar "|" - { r2. c'4^\markup { \pad-markup #0.2 "+49"} ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'4 ~ c'16[ r8.] r2 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/52c9a980/lilypond/part_IV.ly b/resources/resources_bak_2024_01_03/string_quartet_1/52c9a980/lilypond/part_IV.ly deleted file mode 100644 index bb5c589..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/52c9a980/lilypond/part_IV.ly +++ /dev/null @@ -1,18 +0,0 @@ -{ - { r1 } - \bar "|" - { r1 } - \bar "|" - { r2 c2^\markup { \pad-markup #0.2 "+49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }} ~ } - \bar "|" - { c4 ais,4^\markup { \pad-markup #0.2 "+18"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 7↑" }} ~ ais,16[ a,8.^\markup { \pad-markup #0.2 "-37"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 5↓" }}] ~ a,4 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,2 r2 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/5e54c468/5e54c468_code.scd b/resources/resources_bak_2024_01_03/string_quartet_1/5e54c468/5e54c468_code.scd deleted file mode 100644 index 3eb3cbd..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/5e54c468/5e54c468_code.scd +++ /dev/null @@ -1,1058 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance); -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file; - file = File(path, "w"); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((dir +/+ ".." +/+ "resources" +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((dir +/+ ".." +/+ "resources" +/+ curUID).standardizePath); - File.copy(exPath, (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (dir +/+ ".." +/+ "resources" +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((dir +/+ ".." +/+ "resources" +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (dir +/+ ".." +/+ "resources" +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (dir +/+ ".." +/+ "resources" +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "resources" +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "resources" +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \".." +/+ ".." +/+ "resources" +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - -~transcribe.value(~seq, dir); - -( -//synthdefs -~stringModelBusArray = 4.collect({Bus.audio(s, 1)}); -~sineBusArray = 4.collect({Bus.audio(s, 1)}); -~bassBusArray = 1.collect({Bus.audio(s, 1)}); -~hdustBusArray = 1.collect({Bus.audio(s, 1)}); -~samplerBusArray = 2.collect({Bus.audio(s, 1)}); -~sBuf = Buffer.alloc(s, 10, 2); -SynthDef(\string_model, {arg freq, gate = 1, sustain, amp, dur, attack, release = 1, busIndex = 0; - var trig, exc, sig1, sig2, noHarms; - noHarms = rrand(20, 40); - exc = Saw.ar(freq, TRand.ar(0.5, 1, Impulse.ar(freq))) * 0.001 + Dust.ar(10000, 0.01); - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(1, 2)}) ], exc) * 0.8).softclip; - //sig1 = HPF.ar(sig1, 300); - Out.ar(Select.kr(busIndex, ~stringModelBusArray), sig1 * amp * EnvGen.kr(Env.adsr(attack, 0.3, 0.9, release, 0.9, -3), gate, doneAction: 2)); - //Out.ar([0, 1], sig1 * EnvGen.kr(Env.asr(dur, 0.3, 1), gate, doneAction: 2)); -}).add; - -SynthDef(\sine, {arg freq, gate = 1, sustain, amp, dur, busIndex = 0; - var sig; - sig = SinOsc.ar(freq); - Out.ar(Select.kr(busIndex, ~sineBusArray), sig * EnvGen.kr(Env.asr(0.3, 0.4, 0.3), gate, timeScale: dur, doneAction: 2)); - //Out.ar(Select.kr(busIndex, ~sineBusArray), sig * EnvGen.kr(Env.sine(dur), gate, doneAction: 2)); -}).add; - -SynthDef(\mixer, {arg freq, gate = 1, sustain, amp, dur, out; - var nameSpaces, sigs; - - sigs = [~stringModelBusArray, ~sineBusArray/*, ~bassBusArray, ~hdustBusArray, ~samplerBusArray*/].collect({arg busArray, i; - var nameSpace, sig; - nameSpace = ['string', 'sine', 'bass', 'hdust', 'sampler'][i]; - sig = busArray.collect({arg bus, c; In.ar(bus, 1) * NamedControl.kr(\ ++ nameSpace ++ '_volume_' ++ c, 1, 0.1)}); - sig = sig.collect({arg channel, c; Pan2.ar(channel, NamedControl.kr(\ ++ nameSpace ++ '_pan_' ++ c, i / (busArray.size - 1), 0.1) * 2 - 1)}); - sig = sig.collect({arg channel, c; channel * NamedControl.kr(\ ++ nameSpace ++ '_mute_' ++ c, 1, 0.1)}); - sig = Mix.ar(sig) * pow(NamedControl.kr(\ ++ nameSpace ++ '_volume_master', 1, 0.1), 2); - }); - - sigs = Mix.ar(sigs / 4); - Out.ar(0, sigs) -}).add; - -SynthDef(\bass, { - var switches, drone; - switches = {|i| Dust.kr(0.1)} ! 9; - drone = {|i| var harm = pow(2, 2 - (i / 3).trunc), amp = (1 / pow(harm, 2)); - SinOsc.ar(60 * harm + TRand.kr(-3, 3, switches[i]), 0, amp)} ! 9; - Out.ar(~bassBusArray[0], Mix.new(drone) * 0.2); -}).add; - -SynthDef(\sampler, { - Out.ar(~samplerBusArray, PlayBuf.ar(2, ~sBuf, BufRateScale.kr(~sBuf), doneAction: 2)) -}).add; - -// main routine -SynthDef(\hdust, { - arg gate = 0; - var hierarchical_dust, low_sine, high_sine, brown_noise, white_noise; - // this triggers the combinations of sources - // it is similar to the Supercollider UGen called dust but with a hierarchical structure - hierarchical_dust = ( - TIRand.kr(0, 1, Impulse.kr(100)) * - TIRand.kr(0, 1, Impulse.kr(10)) * - TIRand.kr(0, 1, Impulse.kr(1)) * - TIRand.kr(0, 1, Impulse.kr(0.1)) - ); - // adjust the multiplier at the end of each line for adjusting levels - // note with each trigger, each source has a 1 in 3 chance of sounding - low_sine = SinOsc.ar(76.midicps / 16) * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.1; - high_sine = SinOsc.ar(76.midicps * 8) * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.01; - brown_noise = BrownNoise.ar() * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.025; - white_noise = WhiteNoise.ar() * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.02; - Out.ar(~hdustBusArray[0], - ((low_sine + high_sine + brown_noise + white_noise) ) - ); -}).add; - -) - -( -var bass, hdust, sampler, mixer; -/* -bass = Synth.tail(~group, \bass); -hdust = Synth.tail(~group, \hdust); -sampler = Synth.head(~group, \sampler); -*/ -mixer = Synth.tail(~group, \mixer); - -OSCdef(\mixer, {arg msg, time, addr, port; - mixer.set((msg[1] ++ '_' ++ msg[2] ++ '_' ++ msg[3]), msg[4]) -}, \mixer); - -/* -OSCdef(\sampler, {arg msg, time, addr, port; - msg.postln; - sampler.free; - ~sBuf.free; - ~sBuf = Buffer.read(s, msg[1].asString.postln, action: {sampler = Synth.head(~group, \sampler)}); -}, \sampler); -*/ -) - -/* old something -( -SynthDef(\test, {arg freq, gate = 1, sustain, amp, dur; - var trig, exc, sig1, sig2, noHarms, freqFinal, start, end; - noHarms = 30; - freq = WhiteNoise.ar * 3 + freq; - freqFinal = Duty.ar((1/freq), 0, freq); - trig = Changed.ar(freqFinal); - start = Demand.ar(trig, 0, Dwhite(-1, -0.75)); - end = Demand.ar(trig, 0, Dwhite(0.75, 1)); - exc = Phasor.ar(trig, (end - start) * freqFinal / SampleRate.ir, start, end, 0) * 0.001 + Dust.ar(10000, 0.01); - - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(2, 3)}) ], exc) * 0.5).softclip; - sig1 = HPF.ar(sig1, 300); - Out.ar([0, 1], sig1 * EnvGen.kr(Env.adsr(0.3, 0.3, 0.9, 0.5, 0.9), gate, doneAction: 2)); -}).add; -) -*/ - diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/5e54c468/5e54c468_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_1/5e54c468/5e54c468_mus_model.json deleted file mode 100644 index f3f6493..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/5e54c468/5e54c468_mus_model.json +++ /dev/null @@ -1,70 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ "Rest" ], [ 1, -1, 0, -1, 1, -1 ], [ "Rest" ] ], 0 ], - [ [ [ "Rest" ], [ 2, -2, 0, -1, 1, 0 ], [ 1, -1, 0, -1, 1, -1 ], [ "Rest" ] ], 0.625 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 1, -1, 0, -1, 1, -1 ], [ "Rest" ] ], 2.5 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 1, -1, 0, -1, 1, -1 ], [ 2, -1, -1, -1, 1, 0 ] ], 1 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 1, -1, 0, -1, 1, -1 ], [ 2, -1, 1, -1, 1, -1 ] ], 3.875 ] - ], - [ - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ "Rest" ], [ 2, -1, 1, -1, 1, -1 ] ], 2 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -1, 0, -1, 1, -1 ], [ "Rest" ], [ 2, -1, 1, -1, 1, -1 ] ], 6.5 ] - ], - [ - [ [ [ "Rest" ], [ 2, -1, 0, -1, 1, -1 ], [ "Rest" ], [ 2, -1, 1, -1, 1, -1 ] ], 0 ], - [ [ [ "Rest" ], [ 2, -1, 0, -1, 1, -1 ], [ "Rest" ], [ "Rest" ] ], 0.75 ], - [ [ [ "Rest" ], [ 2, -1, 0, -1, 1, -1 ], [ 2, -1, 0, 0, 1, -1 ], [ "Rest" ] ], 1.125 ], - [ [ [ "Rest" ], [ 2, -1, 0, -1, 1, -1 ], [ 2, -1, 0, -1, 1, 0 ], [ "Rest" ] ], 4.5 ] - ], - [ - [ [ [ "Rest" ], [ 2, -1, 0, -1, 1, -1 ], [ 2, -1, 0, -1, 1, 0 ], [ 2, -1, 1, -1, 1, -1 ] ], 0.875 ], - [ [ [ "Rest" ], [ 2, -1, 0, -2, 1, 0 ], [ 2, -1, 0, -1, 1, 0 ], [ 2, -1, 1, -1, 1, -1 ] ], 1.25 ], - [ [ [ "Rest" ], [ 1, 0, 1, -1, 1, -1 ], [ 2, -1, 0, -1, 1, 0 ], [ 2, -1, 1, -1, 1, -1 ] ], 3.75 ] - ], - [ - [ [ [ "Rest" ], [ 1, -1, 1, -1, 1, 0 ], [ 2, -1, 0, -1, 1, 0 ], [ 2, -1, 1, -1, 1, -1 ] ], 1 ], - [ [ [ "Rest" ], [ 2, -2, 0, -1, 1, 0 ], [ 2, -1, 0, -1, 1, 0 ], [ 2, -1, 1, -1, 1, -1 ] ], 3.75 ], - [ [ [ "Rest" ], [ 2, -2, 0, -1, 1, 0 ], [ 2, -1, 0, -1, 1, 0 ], [ "Rest" ] ], 2 ], - [ [ [ "Rest" ], [ "Rest" ], [ 2, -1, 0, -1, 1, 0 ], [ "Rest" ] ], 0 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 4.5 ] - ] - ] -], -"last_changes": -[ - [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -1, 0, -1, 1, -1 ], [ 2, -1, 0, -1, 1, 0 ], [ 2, -1, 1, -1, 1, -1 ] ], - [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -1, 0, -2, 1, 0 ], [ 2, -1, 0, -1, 1, 0 ], [ 2, -1, 1, -1, 1, -1 ] ], - [ [ 1, -1, 0, -1, 1, 0 ], [ 1, 0, 1, -1, 1, -1 ], [ 2, -1, 0, -1, 1, 0 ], [ 2, -1, 1, -1, 1, -1 ] ], - [ [ 1, -1, 0, -1, 1, 0 ], [ 1, -1, 1, -1, 1, 0 ], [ 2, -1, 0, -1, 1, 0 ], [ 2, -1, 1, -1, 1, -1 ] ], - [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 2, -1, 0, -1, 1, 0 ], [ 2, -1, 1, -1, 1, -1 ] ] -], -"cur_uid": "5e54c468", -"ref_uid": "6fb60ab6", -"order_seed": 499586, -"dur_seed": 134526, -"motifs_seed": 636998, -"entrances_probs_vals": [ 0.34, 0.99, 3.1746031746032, 0.5, 2, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 0.34, 1.5873015873016, 4.7222222222222, 0.5, 2.1153846153846, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 0.34, 0.32, 1.9444444444444, 0.5, 2.12, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -3600, -312.07430340557 ], [ -1872, 1378.3281733746 ], [ -144.89164086687, 1582.6625386997 ], [ -182.04334365325, 1527 ] ], -"step_probs_vals": [ 0, 1200, 0, 0, 0.082304526748971, 0.99431818181818, 0.14197530864198, 0, 1, 0 ], -"passages_weights": [ 0.75, 0.75, 0.75, 0.75, 0.75 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 2, 1, 0 ], [ 3, 3 ], [ ] ], - [ [ 3, 0 ], [ 1 ], [ 2 ] ], - [ [ 1 ], [ 2, 2 ], [ 0, 3 ] ], - [ [ 3, 2 ], [ 1, 1 ], [ 0 ] ], - [ [ 3, 2 ], [ 1, 1 ], [ 0 ] ] -], -"sus_weights": [ 0.75, 0.25, 0.25 ], -"order_size": [ 3, 6 ], -"passages_size": [ 0, 3 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/5e54c468/lilypond/part_I.ly b/resources/resources_bak_2024_01_03/string_quartet_1/5e54c468/lilypond/part_I.ly deleted file mode 100644 index 98ddfc8..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/5e54c468/lilypond/part_I.ly +++ /dev/null @@ -1,44 +0,0 @@ -{ - { r1 } - \bar "|" - { r2 r16[ a'8.^\markup { \pad-markup #0.2 "-6"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↓" }}] ~ a'4 ~ } - \bar "|" - { a'16[ gis'8.^\markup { \pad-markup #0.2 "+26"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 5↑" }}] ~ gis'2. ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'4 r2. } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r4 r8.[ gis'16^\markup { \pad-markup #0.2 "+26"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 5↑" }}] ~ gis'2 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'2. r4 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/5e54c468/lilypond/part_II.ly b/resources/resources_bak_2024_01_03/string_quartet_1/5e54c468/lilypond/part_II.ly deleted file mode 100644 index 6b51d38..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/5e54c468/lilypond/part_II.ly +++ /dev/null @@ -1,44 +0,0 @@ -{ - { e1^\markup { \pad-markup #0.2 "+40"} ~ } - \bar "|" - { e1 ~ } - \bar "|" - { e1 ~ } - \bar "|" - { e1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r2 r8[ d''8^\markup { \pad-markup #0.2 "+9"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 7↑" }}] ~ d''4 ~ } - \bar "|" - { d''8.[ cis''16^\markup { \pad-markup #0.2 "-19"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 13↑" }}] ~ cis''2. ~ } - \bar "|" - { cis''1 ~ } - \bar "|" - { cis''1 ~ } - \bar "|" - { cis''1 ~ } - \bar "|" - { cis''1 ~ } - \bar "|" - { cis''1 ~ } - \bar "|" - { cis''1 ~ } - \bar "|" - { cis''1 ~ } - \bar "|" - { cis''2. r4 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/5e54c468/lilypond/part_III.ly b/resources/resources_bak_2024_01_03/string_quartet_1/5e54c468/lilypond/part_III.ly deleted file mode 100644 index 2632120..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/5e54c468/lilypond/part_III.ly +++ /dev/null @@ -1,44 +0,0 @@ -{ - { fis'1^\markup { \pad-markup #0.2 "-21"} ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 } - \bar "|" - { e'1^\markup { \pad-markup #0.2 "+40"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↓" }} ~ } - \bar "|" - { e'1 ~ } - \bar "|" - { e'1 ~ } - \bar "|" - { e'1 ~ } - \bar "|" - { e'1 ~ } - \bar "|" - { e'1 ~ } - \bar "|" - { e'2. ~ e'8[ dis'8^\markup { \pad-markup #0.2 "+12"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 7↓" }}] ~ } - \bar "|" - { dis'2 dis'2^\markup { \pad-markup #0.2 "+28"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↑" }} ~ } - \bar "|" - { dis'1 ~ } - \bar "|" - { dis'4 ~ dis'8[ f'8^\markup { \pad-markup #0.2 "-33"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 5↑" }}] ~ f'4 ~ f'8[ fis'8^\markup { \pad-markup #0.2 "-21"}] ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'2. r4 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/5e54c468/lilypond/part_IV.ly b/resources/resources_bak_2024_01_03/string_quartet_1/5e54c468/lilypond/part_IV.ly deleted file mode 100644 index 1f3a4d8..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/5e54c468/lilypond/part_IV.ly +++ /dev/null @@ -1,44 +0,0 @@ -{ - { r4 r16[ cis'8.^\markup { \pad-markup #0.2 "-19"}] ~ cis'2 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'4 r2. } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/61ce9067/61ce9067_code.scd b/resources/resources_bak_2024_01_03/string_quartet_1/61ce9067/61ce9067_code.scd deleted file mode 100644 index c194eef..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/61ce9067/61ce9067_code.scd +++ /dev/null @@ -1,945 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance); -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/61ce9067/61ce9067_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_1/61ce9067/61ce9067_mus_model.json deleted file mode 100644 index bdc8f6f..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/61ce9067/61ce9067_mus_model.json +++ /dev/null @@ -1,55 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ 0, -1, 1, -2, 1, 0 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 0.125 ], - [ [ [ 0, -1, 1, -2, 1, 0 ], [ 2, -1, 1, -3, 1, 0 ], [ "Rest" ], [ "Rest" ] ], 0.75 ], - [ [ [ 0, -1, 1, -2, 1, 0 ], [ 2, -1, 1, -3, 1, 0 ], [ 3, -2, 1, -2, 1, 0 ], [ "Rest" ] ], 0.75 ], - [ [ [ 0, -1, 1, -2, 1, 0 ], [ 2, -1, 1, -3, 1, 0 ], [ 3, -2, 1, -2, 1, 0 ], [ 3, -1, 1, -3, 1, 0 ] ], 0.375 ], - [ [ [ 0, -1, 1, -2, 1, 0 ], [ 1, -1, 1, -2, 1, 0 ], [ 3, -2, 1, -2, 1, 0 ], [ 3, -1, 1, -3, 1, 0 ] ], 1 ], - [ [ [ 0, -1, 1, -2, 1, 0 ], [ 1, -1, 1, -2, 1, 0 ], [ 1, -1, 1, -1, 1, 0 ], [ 3, -1, 1, -3, 1, 0 ] ], 0.5 ], - [ [ [ 0, -1, 1, -2, 1, 0 ], [ 1, -1, 1, -2, 1, 0 ], [ 1, -1, 1, -1, 1, 0 ], [ 2, -1, 1, -2, 1, 0 ] ], 0.75 ], - [ [ [ 0, -1, 1, -2, 1, 0 ], [ 1, -1, 2, -2, 1, 0 ], [ 1, -1, 1, -1, 1, 0 ], [ 2, -1, 1, -2, 1, 0 ] ], 1.125 ], - [ [ [ 0, -1, 1, -2, 1, 0 ], [ 1, -1, 2, -2, 1, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 2, -1, 1, -2, 1, 0 ] ], 0.75 ], - [ [ [ 0, -1, 1, -2, 1, 0 ], [ 1, -1, 2, -2, 1, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 2, -1, 2, -2, 1, 0 ] ], 0.25 ], - [ [ [ 0, -1, 1, -2, 1, 0 ], [ 1, -1, 1, -2, 1, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 2, -1, 2, -2, 1, 0 ] ], 0.875 ], - [ [ [ 0, -1, 1, -2, 1, 0 ], [ 1, -1, 1, -2, 1, 0 ], [ 1, -1, 1, -2, 1, 1 ], [ 2, -1, 2, -2, 1, 0 ] ], 0.875 ], - [ [ [ 0, -1, 1, -2, 1, 0 ], [ 1, -1, 1, -2, 1, 0 ], [ 1, -1, 1, -2, 1, 1 ], [ 2, -1, 1, -2, 1, 0 ] ], 0.375 ], - [ [ [ "Rest" ], [ 1, -1, 1, -2, 1, 0 ], [ 1, -1, 1, -2, 1, 1 ], [ 2, -1, 1, -2, 1, 0 ] ], 0.375 ], - [ [ [ "Rest" ], [ 1, -1, 1, -2, 1, 0 ], [ 1, -1, 1, -2, 1, 1 ], [ "Rest" ] ], 0.375 ], - [ [ [ "Rest" ], [ 1, -1, 1, -2, 1, 0 ], [ "Rest" ], [ "Rest" ] ], 0.125 ] - ] - ] -], -"last_changes": -[ - [ [ 0, -1, 1, -2, 1, 0 ], [ 1, -1, 2, -2, 1, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 2, -1, 1, -2, 1, 0 ] ], - [ [ 0, -1, 1, -2, 1, 0 ], [ 1, -1, 2, -2, 1, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 2, -1, 2, -2, 1, 0 ] ], - [ [ 0, -1, 1, -2, 1, 0 ], [ 1, -1, 1, -2, 1, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 2, -1, 2, -2, 1, 0 ] ], - [ [ 0, -1, 1, -2, 1, 0 ], [ 1, -1, 1, -2, 1, 0 ], [ 1, -1, 1, -2, 1, 1 ], [ 2, -1, 2, -2, 1, 0 ] ], - [ [ 0, -1, 1, -2, 1, 0 ], [ 1, -1, 1, -2, 1, 0 ], [ 1, -1, 1, -2, 1, 1 ], [ 2, -1, 1, -2, 1, 0 ] ] -], -"cur_uid": "61ce9067", -"ref_uid": "4200a90d", -"order_seed": 278192, -"dur_seed": 660041, -"motifs_seed": 150685, -"entrances_probs_vals": [ 0, 0, 0, 0.19, 0.93406593406593, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 0, 0.2, 2.3015873015873, 0.08, 1.2912087912088, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 0, 0.16, 1.0714285714286, 0.16, 1.510989010989, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -2411.1455108359, -850.77399380805 ], [ -1872, 450 ], [ -479, 1304.0247678019 ], [ -368, 1173.9938080495 ] ], -"step_probs_vals": [ 0, 1200, 0, 0, 0.08641975308642, 0.9375, 0.50617283950617, 0.89772727272727, 0.69135802469136, 0, 1, 0 ], -"passages_weights": [ 0.27, 0, 0.6, 0, 1 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 0 ], [ 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3 ], [ ] ] -], -"sus_weights": [ 0.62, 0.25, 0 ], -"order_size": [ 7, 10 ], -"passages_size": [ 0, 6 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/61ce9067/lilypond/part_I.ly b/resources/resources_bak_2024_01_03/string_quartet_1/61ce9067/lilypond/part_I.ly deleted file mode 100644 index 36d5c00..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/61ce9067/lilypond/part_I.ly +++ /dev/null @@ -1,10 +0,0 @@ -{ - { r2. r16[ a'8.^\markup { \pad-markup #0.2 "+29"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }}] ~ } - \bar "|" - { a'2. g'4^\markup { \pad-markup #0.2 "-2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }} ~ } - \bar "|" - { g'1 ~ } - \bar "|" - { g'16[ b'8.^\markup { \pad-markup #0.2 "-16"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }}] ~ b'2.} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/61ce9067/lilypond/part_II.ly b/resources/resources_bak_2024_01_03/string_quartet_1/61ce9067/lilypond/part_II.ly deleted file mode 100644 index 172d34d..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/61ce9067/lilypond/part_II.ly +++ /dev/null @@ -1,10 +0,0 @@ -{ - { r4 r8.[ c''16^\markup { \pad-markup #0.2 "-4"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }}] ~ c''2 ~ } - \bar "|" - { c''2 f'2^\markup { \pad-markup #0.2 "-33"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↑" }} ~ } - \bar "|" - { f'2 ~ f'8.[ c'16^\markup { \pad-markup #0.2 "+49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 11↑" }}] ~ c'4 ~ } - \bar "|" - { c'2 ~ c'8[ dis'8^\markup { \pad-markup #0.2 "+39"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↑" }}] ~ dis'4} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/61ce9067/lilypond/part_III.ly b/resources/resources_bak_2024_01_03/string_quartet_1/61ce9067/lilypond/part_III.ly deleted file mode 100644 index 80195eb..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/61ce9067/lilypond/part_III.ly +++ /dev/null @@ -1,10 +0,0 @@ -{ - { r16[ a8.^\markup { \pad-markup #0.2 "+29"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↓" }}] ~ a2. } - \bar "|" - { g1^\markup { \pad-markup #0.2 "-2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }} ~ } - \bar "|" - { g8[ b8^\markup { \pad-markup #0.2 "-16"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }}] ~ b2. ~ } - \bar "|" - { b8.[ g16^\markup { \pad-markup #0.2 "-2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }}] ~ g2.} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/61ce9067/lilypond/part_IV.ly b/resources/resources_bak_2024_01_03/string_quartet_1/61ce9067/lilypond/part_IV.ly deleted file mode 100644 index ce0c70d..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/61ce9067/lilypond/part_IV.ly +++ /dev/null @@ -1,10 +0,0 @@ -{ - { g,1^\markup { \pad-markup #0.2 "-2"} ~ } - \bar "|" - { g,1 ~ } - \bar "|" - { g,1 ~ } - \bar "|" - { g,1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/62820081/62820081_code.scd b/resources/resources_bak_2024_01_03/string_quartet_1/62820081/62820081_code.scd deleted file mode 100644 index a98b916..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/62820081/62820081_code.scd +++ /dev/null @@ -1,945 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance); -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/62820081/62820081_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_1/62820081/62820081_mus_model.json deleted file mode 100644 index ab5d8c3..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/62820081/62820081_mus_model.json +++ /dev/null @@ -1,48 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ 2, -2, 0, -1, 1, 0 ], [ "Rest" ], [ "Rest" ] ], 1.5 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ "Rest" ], [ "Rest" ] ], 4.375 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ "Rest" ], [ 1, -1, 0, 0, 1, 0 ] ], 1.625 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 2, -1, -1, -1, 1, 0 ], [ 1, -1, 0, 0, 1, 0 ] ], 1.25 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 2, -1, -1, -1, 1, 0 ], [ 2, -2, 1, -1, 1, 0 ] ], 3.375 ], - [ [ [ "Rest" ], [ 2, -2, 0, -1, 1, 0 ], [ 2, -1, -1, -1, 1, 0 ], [ 2, -2, 1, -1, 1, 0 ] ], 1.625 ], - [ [ [ "Rest" ], [ "Rest" ], [ 2, -1, -1, -1, 1, 0 ], [ 2, -2, 1, -1, 1, 0 ] ], 1.625 ], - [ [ [ "Rest" ], [ "Rest" ], [ 2, -1, -1, -1, 1, 0 ], [ "Rest" ] ], 0.875 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 10.0 ] - ] - ] -], -"last_changes": -[ - [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 1, 0, 0, -1, 1, 0 ], [ 2, -1, -1, -1, 1, 0 ] ], - [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 1, 0, 0, -1, 1, 0 ], [ 3, -2, 0, -1, 1, -1 ] ], - [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 1, 0, 0, -1, 1, 0 ], [ 1, -1, 0, 0, 1, 0 ] ], - [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 2, -1, -1, -1, 1, 0 ], [ 1, -1, 0, 0, 1, 0 ] ], - [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 2, -1, -1, -1, 1, 0 ], [ 2, -2, 1, -1, 1, 0 ] ] -], -"cur_uid": "62820081", -"ref_uid": "79e0a4a7", -"order_seed": 216475, -"dur_seed": 914627, -"motifs_seed": 252655, -"entrances_probs_vals": [ 0, 1.1904761904762, 3.3333333333333, 0.71, 1.92, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 0, 1.1904761904762, 3.3333333333333, 0.71, 1.92, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 0, 1.1904761904762, 3.3333333333333, 0.71, 1.92, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -3600, -312 ], [ -1872, 1378 ], [ -145, 1583 ], [ -182, 1527 ] ], -"step_probs_vals": [ 0, 1200, 0, 0, 0.082304526748971, 0.99431818181818, 0.14197530864198, 0, 1, 0 ], -"passages_weights": [ 0.75, 0.75, 0.75, 0.75, 0.75 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 1, 0 ], [ 3, 2, 3 ], [ ] ] -], -"sus_weights": [ 0, 0.65, 0 ], -"order_size": [ 1, 1 ], -"passages_size": [ 1, 6 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/631e2af1/631e2af1_code.scd b/resources/resources_bak_2024_01_03/string_quartet_1/631e2af1/631e2af1_code.scd deleted file mode 100644 index 8e9fe42..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/631e2af1/631e2af1_code.scd +++ /dev/null @@ -1,943 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance); -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/631e2af1/631e2af1_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_1/631e2af1/631e2af1_mus_model.json deleted file mode 100644 index 78ae751..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/631e2af1/631e2af1_mus_model.json +++ /dev/null @@ -1,48 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ 2, -2, 0, -1, 1, 0 ], [ "Rest" ], [ "Rest" ] ], 1.125 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ "Rest" ], [ "Rest" ] ], 4.375 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ "Rest" ], [ 1, -1, 0, 0, 1, 0 ] ], 1.375 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 1, -1, 0, -1, 2, 0 ], [ 1, -1, 0, 0, 1, 0 ] ], 1.25 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 1, -1, 0, -1, 2, 0 ], [ 2, -2, 0, -1, 2, 0 ] ], 2.375 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 1, -1, 0, -1, 2, 0 ], [ "Rest" ] ], 1.75 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ "Rest" ], [ "Rest" ] ], 1.125 ], - [ [ [ "Rest" ], [ 2, -2, 0, -1, 1, 0 ], [ "Rest" ], [ "Rest" ] ], 1.625 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 5.0 ] - ] - ] -], -"last_changes": -[ - [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 1, 0, 0, -1, 1, 0 ], [ 2, -1, -1, -1, 1, 0 ] ], - [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 1, 0, 0, -1, 1, 0 ], [ 3, -2, 0, -1, 1, -1 ] ], - [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 1, 0, 0, -1, 1, 0 ], [ 1, -1, 0, 0, 1, 0 ] ], - [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 1, -1, 0, -1, 2, 0 ], [ 1, -1, 0, 0, 1, 0 ] ], - [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 1, -1, 0, -1, 2, 0 ], [ 2, -2, 0, -1, 2, 0 ] ] -], -"cur_uid": "631e2af1", -"ref_uid": "79e0a4a7", -"order_seed": 216475, -"dur_seed": 698877, -"motifs_seed": 336611, -"entrances_probs_vals": [ 0, 1.1904761904762, 3.3333333333333, 0.71, 1.92, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 0, 1.1904761904762, 3.3333333333333, 0.71, 1.92, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 0, 1.1904761904762, 3.3333333333333, 0.71, 1.92, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -3600, -312 ], [ -1872, 1378 ], [ -145, 1583 ], [ -182, 1527 ] ], -"step_probs_vals": [ 0, 1200, 0, 0, 0.082304526748971, 0.99431818181818, 0.14197530864198, 0, 1, 0 ], -"passages_weights": [ 0.75, 0.75, 0.75, 0.75, 0.75 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 1, 0 ], [ 3, 2, 3 ], [ ] ] -], -"sus_weights": [ 0, 0.65, 0 ], -"order_size": [ 1, 1 ], -"passages_size": [ 1, 6 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/66f6a618/66f6a618_code.scd b/resources/resources_bak_2024_01_03/string_quartet_1/66f6a618/66f6a618_code.scd deleted file mode 100644 index 3eb3cbd..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/66f6a618/66f6a618_code.scd +++ /dev/null @@ -1,1058 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance); -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file; - file = File(path, "w"); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((dir +/+ ".." +/+ "resources" +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((dir +/+ ".." +/+ "resources" +/+ curUID).standardizePath); - File.copy(exPath, (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (dir +/+ ".." +/+ "resources" +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((dir +/+ ".." +/+ "resources" +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (dir +/+ ".." +/+ "resources" +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (dir +/+ ".." +/+ "resources" +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "resources" +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "resources" +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \".." +/+ ".." +/+ "resources" +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - -~transcribe.value(~seq, dir); - -( -//synthdefs -~stringModelBusArray = 4.collect({Bus.audio(s, 1)}); -~sineBusArray = 4.collect({Bus.audio(s, 1)}); -~bassBusArray = 1.collect({Bus.audio(s, 1)}); -~hdustBusArray = 1.collect({Bus.audio(s, 1)}); -~samplerBusArray = 2.collect({Bus.audio(s, 1)}); -~sBuf = Buffer.alloc(s, 10, 2); -SynthDef(\string_model, {arg freq, gate = 1, sustain, amp, dur, attack, release = 1, busIndex = 0; - var trig, exc, sig1, sig2, noHarms; - noHarms = rrand(20, 40); - exc = Saw.ar(freq, TRand.ar(0.5, 1, Impulse.ar(freq))) * 0.001 + Dust.ar(10000, 0.01); - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(1, 2)}) ], exc) * 0.8).softclip; - //sig1 = HPF.ar(sig1, 300); - Out.ar(Select.kr(busIndex, ~stringModelBusArray), sig1 * amp * EnvGen.kr(Env.adsr(attack, 0.3, 0.9, release, 0.9, -3), gate, doneAction: 2)); - //Out.ar([0, 1], sig1 * EnvGen.kr(Env.asr(dur, 0.3, 1), gate, doneAction: 2)); -}).add; - -SynthDef(\sine, {arg freq, gate = 1, sustain, amp, dur, busIndex = 0; - var sig; - sig = SinOsc.ar(freq); - Out.ar(Select.kr(busIndex, ~sineBusArray), sig * EnvGen.kr(Env.asr(0.3, 0.4, 0.3), gate, timeScale: dur, doneAction: 2)); - //Out.ar(Select.kr(busIndex, ~sineBusArray), sig * EnvGen.kr(Env.sine(dur), gate, doneAction: 2)); -}).add; - -SynthDef(\mixer, {arg freq, gate = 1, sustain, amp, dur, out; - var nameSpaces, sigs; - - sigs = [~stringModelBusArray, ~sineBusArray/*, ~bassBusArray, ~hdustBusArray, ~samplerBusArray*/].collect({arg busArray, i; - var nameSpace, sig; - nameSpace = ['string', 'sine', 'bass', 'hdust', 'sampler'][i]; - sig = busArray.collect({arg bus, c; In.ar(bus, 1) * NamedControl.kr(\ ++ nameSpace ++ '_volume_' ++ c, 1, 0.1)}); - sig = sig.collect({arg channel, c; Pan2.ar(channel, NamedControl.kr(\ ++ nameSpace ++ '_pan_' ++ c, i / (busArray.size - 1), 0.1) * 2 - 1)}); - sig = sig.collect({arg channel, c; channel * NamedControl.kr(\ ++ nameSpace ++ '_mute_' ++ c, 1, 0.1)}); - sig = Mix.ar(sig) * pow(NamedControl.kr(\ ++ nameSpace ++ '_volume_master', 1, 0.1), 2); - }); - - sigs = Mix.ar(sigs / 4); - Out.ar(0, sigs) -}).add; - -SynthDef(\bass, { - var switches, drone; - switches = {|i| Dust.kr(0.1)} ! 9; - drone = {|i| var harm = pow(2, 2 - (i / 3).trunc), amp = (1 / pow(harm, 2)); - SinOsc.ar(60 * harm + TRand.kr(-3, 3, switches[i]), 0, amp)} ! 9; - Out.ar(~bassBusArray[0], Mix.new(drone) * 0.2); -}).add; - -SynthDef(\sampler, { - Out.ar(~samplerBusArray, PlayBuf.ar(2, ~sBuf, BufRateScale.kr(~sBuf), doneAction: 2)) -}).add; - -// main routine -SynthDef(\hdust, { - arg gate = 0; - var hierarchical_dust, low_sine, high_sine, brown_noise, white_noise; - // this triggers the combinations of sources - // it is similar to the Supercollider UGen called dust but with a hierarchical structure - hierarchical_dust = ( - TIRand.kr(0, 1, Impulse.kr(100)) * - TIRand.kr(0, 1, Impulse.kr(10)) * - TIRand.kr(0, 1, Impulse.kr(1)) * - TIRand.kr(0, 1, Impulse.kr(0.1)) - ); - // adjust the multiplier at the end of each line for adjusting levels - // note with each trigger, each source has a 1 in 3 chance of sounding - low_sine = SinOsc.ar(76.midicps / 16) * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.1; - high_sine = SinOsc.ar(76.midicps * 8) * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.01; - brown_noise = BrownNoise.ar() * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.025; - white_noise = WhiteNoise.ar() * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.02; - Out.ar(~hdustBusArray[0], - ((low_sine + high_sine + brown_noise + white_noise) ) - ); -}).add; - -) - -( -var bass, hdust, sampler, mixer; -/* -bass = Synth.tail(~group, \bass); -hdust = Synth.tail(~group, \hdust); -sampler = Synth.head(~group, \sampler); -*/ -mixer = Synth.tail(~group, \mixer); - -OSCdef(\mixer, {arg msg, time, addr, port; - mixer.set((msg[1] ++ '_' ++ msg[2] ++ '_' ++ msg[3]), msg[4]) -}, \mixer); - -/* -OSCdef(\sampler, {arg msg, time, addr, port; - msg.postln; - sampler.free; - ~sBuf.free; - ~sBuf = Buffer.read(s, msg[1].asString.postln, action: {sampler = Synth.head(~group, \sampler)}); -}, \sampler); -*/ -) - -/* old something -( -SynthDef(\test, {arg freq, gate = 1, sustain, amp, dur; - var trig, exc, sig1, sig2, noHarms, freqFinal, start, end; - noHarms = 30; - freq = WhiteNoise.ar * 3 + freq; - freqFinal = Duty.ar((1/freq), 0, freq); - trig = Changed.ar(freqFinal); - start = Demand.ar(trig, 0, Dwhite(-1, -0.75)); - end = Demand.ar(trig, 0, Dwhite(0.75, 1)); - exc = Phasor.ar(trig, (end - start) * freqFinal / SampleRate.ir, start, end, 0) * 0.001 + Dust.ar(10000, 0.01); - - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(2, 3)}) ], exc) * 0.5).softclip; - sig1 = HPF.ar(sig1, 300); - Out.ar([0, 1], sig1 * EnvGen.kr(Env.adsr(0.3, 0.3, 0.9, 0.5, 0.9), gate, doneAction: 2)); -}).add; -) -*/ - diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/66f6a618/66f6a618_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_1/66f6a618/66f6a618_mus_model.json deleted file mode 100644 index fe45ed4..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/66f6a618/66f6a618_mus_model.json +++ /dev/null @@ -1,91 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ 1, -1, 0, 0, -1, 0 ] ], 0.75 ], - [ [ [ "Rest" ], [ 1, -1, 0, 0, -1, 0 ], [ "Rest" ], [ 1, -1, 0, 0, -1, 0 ] ], 0.5 ], - [ [ [ "Rest" ], [ 1, -1, 0, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ] ], 1.375 ], - [ [ [ 0, -1, 0, 0, -1, 1 ], [ 1, -1, 0, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ] ], 1.5 ], - [ [ [ 0, 0, 0, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ] ], 0.875 ], - [ [ [ 1, -2, 0, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ] ], 0.75 ], - [ [ [ 0, -1, 1, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ] ], 0.75 ], - [ [ [ 1, -1, 0, -1, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ] ], 8.75 ] - ], - [ - [ [ [ 1, -1, 0, -1, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ], [ 2, -1, 0, -1, -1, 0 ] ], 0.625 ], - [ [ [ 1, -1, 0, -1, -1, 0 ], [ 0, -1, 0, 1, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ], [ 2, -1, 0, -1, -1, 0 ] ], 0.625 ], - [ [ [ 0, -1, 0, 0, -1, 0 ], [ 0, -1, 0, 1, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ], [ 2, -1, 0, -1, -1, 0 ] ], 0.75 ], - [ [ [ 1, -1, 0, 0, -1, -1 ], [ 0, -1, 0, 1, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ], [ 2, -1, 0, -1, -1, 0 ] ], 0.875 ], - [ [ [ 1, -1, 0, 0, -1, -1 ], [ 0, -1, 0, 1, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ], [ 2, -1, 0, 0, -1, -1 ] ], 1.25 ], - [ [ [ 1, -1, 0, 0, -1, -1 ], [ 1, -1, -1, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ], [ 2, -1, 0, 0, -1, -1 ] ], 1.75 ], - [ [ [ 1, -1, 0, 0, -1, -1 ], [ 1, -1, -1, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ], [ 1, -1, 0, 0, 0, 0 ] ], 0 ], - [ [ [ 1, -1, 0, 0, -1, -1 ], [ 0, -1, 0, 0, -1, 1 ], [ 1, -1, 0, 0, -1, 0 ], [ 1, -1, 0, 0, 0, 0 ] ], 0 ], - [ [ [ 0, -1, 1, 0, -1, 0 ], [ 0, -1, 0, 0, -1, 1 ], [ 1, -1, 0, 0, -1, 0 ], [ 1, -1, 0, 0, 0, 0 ] ], 1.875 ], - [ [ [ 0, -1, 1, 0, -1, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ], [ 1, -1, 0, 0, 0, 0 ] ], 3 ] - ], - [ - [ [ [ 0, -1, -1, 0, 0, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ], [ 1, -1, 0, 0, 0, 0 ] ], 1 ], - [ [ [ 0, 0, -1, 0, -1, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ], [ 1, -1, 0, 0, 0, 0 ] ], 1 ], - [ [ [ 1, -1, 0, -1, -1, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ], [ 1, -1, 0, 0, 0, 0 ] ], 1.625 ], - [ [ [ -1, -1, 0, 0, 0, 1 ], [ 0, 0, 0, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ], [ 1, -1, 0, 0, 0, 0 ] ], 0.875 ], - [ [ [ 0, -1, 0, 0, -1, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ], [ 1, -1, 0, 0, 0, 0 ] ], 1.25 ], - [ [ [ -1, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ], [ 1, -1, 0, 0, 0, 0 ] ], 4.625 ] - ], - [ - [ [ [ -1, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ], [ 2, -1, -1, 0, -1, 0 ] ], 1.75 ], - [ [ [ -1, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ], [ 2, 0, 0, -1, -1, 0 ] ], 1.875 ], - [ [ [ -1, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ], [ 1, 0, -1, 0, 0, 0 ] ], 0.625 ], - [ [ [ -1, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ], [ 1, 0, 0, 0, -1, 0 ] ], 0.625 ], - [ [ [ -1, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ], [ 0, 0, 0, 0, 1, 0 ] ], 7.25 ] - ], - [ - [ [ [ -1, 0, 0, 0, 0, 0 ], [ 0, -1, 0, 0, 0, 0 ], [ 1, -1, 0, 0, -1, 0 ], [ 0, 0, 0, 0, 1, 0 ] ], 1.875 ], - [ [ [ -1, 0, 0, 0, 0, 0 ], [ 1, -1, -1, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ], [ 0, 0, 0, 0, 1, 0 ] ], 1.625 ], - [ [ [ -1, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, -2, 0 ], [ 1, -1, 0, 0, -1, 0 ], [ 0, 0, 0, 0, 1, 0 ] ], 1.625 ], - [ [ [ -1, 0, 0, 0, 0, 0 ], [ 1, -2, 0, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ], [ 0, 0, 0, 0, 1, 0 ] ], 1 ], - [ [ [ -1, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, -1 ], [ 1, -1, 0, 0, -1, 0 ], [ 0, 0, 0, 0, 1, 0 ] ], 3.75 ] - ], - [ - [ [ [ "Rest" ], [ 0, 0, 0, 0, 0, -1 ], [ 1, -1, 0, 0, -1, 0 ], [ 0, 0, 0, 0, 1, 0 ] ], 0 ], - [ [ [ "Rest" ], [ 0, 0, 0, 0, 0, -1 ], [ "Rest" ], [ 0, 0, 0, 0, 1, 0 ] ], 1.25 ], - [ [ [ "Rest" ], [ -2, 0, 0, 0, 1, 1 ], [ "Rest" ], [ 0, 0, 0, 0, 1, 0 ] ], 1.875 ], - [ [ [ "Rest" ], [ -2, 1, 0, 0, 1, 0 ], [ "Rest" ], [ 0, 0, 0, 0, 1, 0 ] ], 1.25 ], - [ [ [ "Rest" ], [ -1, 0, -1, 0, 1, 0 ], [ "Rest" ], [ 0, 0, 0, 0, 1, 0 ] ], 2 ], - [ [ [ "Rest" ], [ -2, 0, 0, 1, 1, 0 ], [ "Rest" ], [ 0, 0, 0, 0, 1, 0 ] ], 2.625 ], - [ [ [ "Rest" ], [ -2, 0, 0, 1, 1, 0 ], [ "Rest" ], [ "Rest" ] ], 0.25 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 0.375 ] - ] - ] -], -"last_changes": -[ - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], - [ [ 1, -1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], - [ [ 0, 0, -1, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], - [ [ -1, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], - [ [ 0, -1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ] -], -"cur_uid": "66f6a618", -"ref_uid": "nil", -"order_seed": 209164, -"dur_seed": 417909, -"motifs_seed": 885208, -"entrances_probs_vals": [ 0.34, 0, 10, 0.5, 2, 0, 0.5, 0.24509803921569, 0.89189189189189, 0.5, 1, 0.5, 0.5, 0.8562091503268, 0.69932432432432, 1, 0.5 ], -"passages_probs_vals": [ 0.34, 0, 10, 0.5, 2, 0, 0.5, 0.24509803921569, 0.89189189189189, 0.5, 1, 0.5, 0.5, 0.8562091503268, 0.69932432432432, 1, 0.5 ], -"exits_probs_vals": [ 0.34, 0, 10, 0.5, 2, 0, 0.5, 0.24509803921569, 0.89189189189189, 0.5, 1, 0.5, 0.5, 0.8562091503268, 0.69932432432432, 1, 0.5 ], -"ranges": [ [ -1200, 2400 ], [ -1200, 2400 ], [ -1200, 2400 ], [ -1200, 2400 ] ], -"step_probs_vals": [ 0, 1200, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_weights": [ 0.75, 0.75, 0.75, 0.75, 0.75 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 2 ], [ 0, 0, 0, 0 ], [ 1, 3 ] ] -], -"sus_weights": [ 0.75, 0.75, 0.75 ], -"order_size": [ 1, 10 ], -"passages_size": [ 0, 10 ], -"motif_edited": "true", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/66f6a618/lilypond/part_I.ly b/resources/resources_bak_2024_01_03/string_quartet_1/66f6a618/lilypond/part_I.ly deleted file mode 100644 index d05522a..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/66f6a618/lilypond/part_I.ly +++ /dev/null @@ -1,70 +0,0 @@ -{ - { b1^\markup { \pad-markup #0.2 "+47"} ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b2 ~ b8[ d'8^\markup { \pad-markup #0.2 "-22"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }}] ~ d'4 ~ } - \bar "|" - { d'1 ~ } - \bar "|" - { d'16[ dis'8.^\markup { \pad-markup #0.2 "+6"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }}] ~ dis'2. ~ } - \bar "|" - { dis'2 ~ dis'16[ f'8.^\markup { \pad-markup #0.2 "-2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 11↑" }}] ~ f'4 ~ } - \bar "|" - { f'1 ~ } - \bar "|" - { f'1 ~ } - \bar "|" - { f'1 ~ } - \bar "|" - { f'1 ~ } - \bar "|" - { f'1 ~ } - \bar "|" - { f'1 ~ } - \bar "|" - { f'1 ~ } - \bar "|" - { f'8.[ gis'16^\markup { \pad-markup #0.2 "-40"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 5↓" }}] ~ gis'2. ~ } - \bar "|" - { gis'16[ a'8.^\markup { \pad-markup #0.2 "-20"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 7↓" }}] ~ a'2. } - \bar "|" - { gis'4^\markup { \pad-markup #0.2 "+14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↓" }} ~ gis'16[ fis'8.^\markup { \pad-markup #0.2 "+49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }}] ~ fis'8[ fis'8^\markup { \pad-markup #0.2 "-49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 11↑" }}] ~ fis'4 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'2 ~ fis'8.[ r16] r4} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/66f6a618/lilypond/part_II.ly b/resources/resources_bak_2024_01_03/string_quartet_1/66f6a618/lilypond/part_II.ly deleted file mode 100644 index 602b0d6..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/66f6a618/lilypond/part_II.ly +++ /dev/null @@ -1,70 +0,0 @@ -{ - { r2 r8[ b8^\markup { \pad-markup #0.2 "+47"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }}] ~ b4 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b8.[ r16] r2. } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/66f6a618/lilypond/part_III.ly b/resources/resources_bak_2024_01_03/string_quartet_1/66f6a618/lilypond/part_III.ly deleted file mode 100644 index 6d06a75..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/66f6a618/lilypond/part_III.ly +++ /dev/null @@ -1,70 +0,0 @@ -{ - { r4 r8[ b8^\markup { \pad-markup #0.2 "+47"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }}] ~ b2 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b2. ~ b8.[ a16^\markup { \pad-markup #0.2 "+16"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 7↑" }}] ~ } - \bar "|" - { a1 ~ } - \bar "|" - { a2 ~ a8.[ gis16^\markup { \pad-markup #0.2 "-40"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 5↓" }}] ~ gis4 ~ } - \bar "|" - { gis2 ~ gis16[ gis8.^\markup { \pad-markup #0.2 "-13"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 13↑" }}] ~ gis4 ~ } - \bar "|" - { gis2 fis2^\markup { \pad-markup #0.2 "+49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↑" }} ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis4 f2.^\markup { \pad-markup #0.2 "-2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }} ~ } - \bar "|" - { f8.[ gis16^\markup { \pad-markup #0.2 "-40"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 5↓" }}] ~ gis2. } - \bar "|" - { fis2.^\markup { \pad-markup #0.2 "-5"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 11↓" }} ~ fis16[ e8.^\markup { \pad-markup #0.2 "+45"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↓" }}] ~ } - \bar "|" - { e4 ~ e16[ e8.^\markup { \pad-markup #0.2 "-41"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↓" }}] ~ e2 ~ } - \bar "|" - { e1 ~ } - \bar "|" - { e2. ~ e16[ d8.^\markup { \pad-markup #0.2 "-8"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 13↑" }}] ~ } - \bar "|" - { d2. cis4^\markup { \pad-markup #0.2 "-47"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↑" }} ~ } - \bar "|" - { cis4 ~ cis8[ d8^\markup { \pad-markup #0.2 "-35"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 5↓" }}] ~ d2 ~ } - \bar "|" - { d4 ~ d8[ dis8^\markup { \pad-markup #0.2 "+20"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 7↑" }}] ~ dis2 ~ } - \bar "|" - { dis2. ~ dis16[ r8.]} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/66f6a618/lilypond/part_IV.ly b/resources/resources_bak_2024_01_03/string_quartet_1/66f6a618/lilypond/part_IV.ly deleted file mode 100644 index bc81ade..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/66f6a618/lilypond/part_IV.ly +++ /dev/null @@ -1,70 +0,0 @@ -{ - { r1 } - \bar "|" - { r4 r16[ gis8.^\markup { \pad-markup #0.2 "-13"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 13↑" }}] ~ gis2 ~ } - \bar "|" - { gis16[ fis8.^\markup { \pad-markup #0.2 "+49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↑" }}] ~ fis4 e4^\markup { \pad-markup #0.2 "+45"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↓" }} ~ e8[ dis8^\markup { \pad-markup #0.2 "+33"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 5↑" }}] ~ } - \bar "|" - { dis4 d2.^\markup { \pad-markup #0.2 "-22"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 7↓" }} ~ } - \bar "|" - { d1 ~ } - \bar "|" - { d1 ~ } - \bar "|" - { d1 ~ } - \bar "|" - { d1 ~ } - \bar "|" - { d4 b,4^\markup { \pad-markup #0.2 "+47"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 1↑" }} ~ b,8[ dis8^\markup { \pad-markup #0.2 "+6"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 13↓" }}] ~ dis4 ~ } - \bar "|" - { dis1 ~ } - \bar "|" - { dis2 ~ dis16[ dis8.^\markup { \pad-markup #0.2 "+33"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 5↑" }}] ~ dis4 ~ } - \bar "|" - { dis1 ~ } - \bar "|" - { dis1 } - \bar "|" - { cis2^\markup { \pad-markup #0.2 "+12"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 5↓" }} dis2^\markup { \pad-markup #0.2 "-38"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 5↓" }} } - \bar "|" - { d2.^\markup { \pad-markup #0.2 "-22"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 7↓" }} ~ d16[ cis8.^\markup { \pad-markup #0.2 "+39"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 13↑" }}] ~ } - \bar "|" - { cis4 b,2^\markup { \pad-markup #0.2 "+47"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 1↑" }} ~ b,8[ c8^\markup { \pad-markup #0.2 "+0"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 11↑" }}] ~ } - \bar "|" - { c1 ~ } - \bar "|" - { c1 ~ } - \bar "|" - { c1 ~ } - \bar "|" - { c1 ~ } - \bar "|" - { c1 ~ } - \bar "|" - { c1 ~ } - \bar "|" - { c1 ~ } - \bar "|" - { c1 ~ } - \bar "|" - { c1 ~ } - \bar "|" - { c1 ~ } - \bar "|" - { c1 ~ } - \bar "|" - { c1 ~ } - \bar "|" - { c1 ~ } - \bar "|" - { c8.[ r16] r2. } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/6d635e88/6d635e88_code.scd b/resources/resources_bak_2024_01_03/string_quartet_1/6d635e88/6d635e88_code.scd deleted file mode 100644 index a98b916..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/6d635e88/6d635e88_code.scd +++ /dev/null @@ -1,945 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance); -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/6d635e88/6d635e88_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_1/6d635e88/6d635e88_mus_model.json deleted file mode 100644 index 228456c..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/6d635e88/6d635e88_mus_model.json +++ /dev/null @@ -1,95 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ 1, -2, 1, -2, 1, 0 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 1.625 ], - [ [ [ 1, -2, 1, -2, 1, 0 ], [ "Rest" ], [ 2, -1, 1, -2, 1, 0 ], [ "Rest" ] ], 3.125 ], - [ [ [ 1, -2, 1, -2, 1, 0 ], [ 3, -2, 1, -2, 0, 0 ], [ 2, -1, 1, -2, 1, 0 ], [ "Rest" ] ], 1.125 ], - [ [ [ 1, -2, 1, -2, 1, 0 ], [ 3, -2, 0, -2, 1, 0 ], [ 2, -1, 1, -2, 1, 0 ], [ "Rest" ] ], 3.5 ] - ], - [ - [ [ [ 1, -2, 1, -2, 1, 0 ], [ 3, -2, 0, -2, 1, 0 ], [ 2, -1, 1, -2, 1, 0 ], [ 2, -2, 1, -1, 1, 0 ] ], 3.25 ], - [ [ [ 1, -2, 1, -2, 1, 0 ], [ 1, -2, 1, -1, 1, 1 ], [ 2, -1, 1, -2, 1, 0 ], [ 2, -2, 1, -1, 1, 0 ] ], 1.375 ], - [ [ [ 1, -2, 1, -2, 1, 0 ], [ 1, -1, 1, -1, 1, 0 ], [ 2, -1, 1, -2, 1, 0 ], [ 2, -2, 1, -1, 1, 0 ] ], 2.75 ] - ], - [ - [ [ [ 1, -2, 1, -2, 1, 0 ], [ 3, -2, 1, -2, 1, -1 ], [ 2, -1, 1, -2, 1, 0 ], [ 2, -2, 1, -1, 1, 0 ] ], 1.875 ], - [ [ [ 1, -2, 1, -2, 1, 0 ], [ 1, 0, 1, -2, 1, 0 ], [ 2, -1, 1, -2, 1, 0 ], [ 2, -2, 1, -1, 1, 0 ] ], 2.875 ] - ], - [ - [ [ [ "Rest" ], [ 1, 0, 1, -2, 1, 0 ], [ 2, -1, 1, -2, 1, 0 ], [ 2, -2, 1, -1, 1, 0 ] ], 2 ], - [ [ [ "Rest" ], [ 1, -2, 1, -1, 2, 0 ], [ 2, -1, 1, -2, 1, 0 ], [ 2, -2, 1, -1, 1, 0 ] ], 3.125 ] - ], - [ - [ [ [ "Rest" ], [ "Rest" ], [ 2, -1, 1, -2, 1, 0 ], [ 2, -2, 1, -1, 1, 0 ] ], 1.25 ], - [ [ [ 0, 0, 1, -2, 1, 0 ], [ "Rest" ], [ 2, -1, 1, -2, 1, 0 ], [ 2, -2, 1, -1, 1, 0 ] ], 3.875 ] - ], - [ - [ [ [ 0, 0, 1, -2, 1, 0 ], [ 1, -2, 1, -1, 2, 0 ], [ 2, -1, 1, -2, 1, 0 ], [ 2, -2, 1, -1, 1, 0 ] ], 1.875 ], - [ [ [ 0, 0, 1, -2, 1, 0 ], [ 1, -2, 1, -1, 2, 0 ], [ 1, 0, 1, -2, 2, 0 ], [ 2, -2, 1, -1, 1, 0 ] ], 2 ], - [ [ [ 0, 0, 1, -2, 1, 0 ], [ 1, -2, 1, -1, 2, 0 ], [ 2, -2, 1, -2, 2, 0 ], [ 2, -2, 1, -1, 1, 0 ] ], 2.75 ] - ], - [ - [ [ [ 0, 0, 1, -2, 1, 0 ], [ 1, -2, 1, -1, 2, 0 ], [ 2, -2, 1, -2, 2, 0 ], [ 1, 0, 1, -1, 1, 0 ] ], 1.875 ], - [ [ [ 0, 0, 1, -2, 1, 0 ], [ 1, -2, 1, -1, 2, 0 ], [ 2, -2, 1, -2, 2, 0 ], [ 1, 0, 1, -2, 1, 1 ] ], 2.875 ] - ], - [ - [ [ [ 0, 0, 1, -2, 1, 0 ], [ 2, -2, 0, -2, 2, 0 ], [ 2, -2, 1, -2, 2, 0 ], [ 1, 0, 1, -2, 1, 1 ] ], 1.25 ], - [ [ [ 0, 0, 1, -2, 1, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 2, -2, 1, -2, 2, 0 ], [ 1, 0, 1, -2, 1, 1 ] ], 3.25 ] - ], - [ - [ [ [ 0, 0, 1, -2, 1, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 0, 1, 1, -2, 1, 1 ], [ 1, 0, 1, -2, 1, 1 ] ], 1.125 ], - [ [ [ 0, -1, 1, -2, 1, 1 ], [ 1, -1, 1, -2, 2, 0 ], [ 0, 1, 1, -2, 1, 1 ], [ 1, 0, 1, -2, 1, 1 ] ], 2 ], - [ [ [ -1, 1, 1, -2, 1, 1 ], [ 1, -1, 1, -2, 2, 0 ], [ 0, 1, 1, -2, 1, 1 ], [ 1, 0, 1, -2, 1, 1 ] ], 4 ] - ], - [ - [ [ [ -1, 0, 1, -2, 2, 1 ], [ 1, -1, 1, -2, 2, 0 ], [ 0, 1, 1, -2, 1, 1 ], [ 1, 0, 1, -2, 1, 1 ] ], 1.875 ], - [ [ [ 1, -1, 1, -3, 2, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 0, 1, 1, -2, 1, 1 ], [ 1, 0, 1, -2, 1, 1 ] ], 2.25 ], - [ [ [ 1, -1, 1, -3, 2, 0 ], [ "Rest" ], [ 0, 1, 1, -2, 1, 1 ], [ 1, 0, 1, -2, 1, 1 ] ], 1.75 ], - [ [ [ 1, -1, 1, -3, 2, 0 ], [ "Rest" ], [ "Rest" ], [ 1, 0, 1, -2, 1, 1 ] ], 1.75 ], - [ [ [ 1, -1, 1, -3, 2, 0 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 1.625 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 4.0 ] - ] - ] -], -"last_changes": -[ - [ [ 0, 0, 1, -2, 1, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 0, 1, 1, -2, 1, 1 ], [ 1, 0, 1, -2, 1, 1 ] ], - [ [ 0, -1, 1, -2, 1, 1 ], [ 1, -1, 1, -2, 2, 0 ], [ 0, 1, 1, -2, 1, 1 ], [ 1, 0, 1, -2, 1, 1 ] ], - [ [ -1, 1, 1, -2, 1, 1 ], [ 1, -1, 1, -2, 2, 0 ], [ 0, 1, 1, -2, 1, 1 ], [ 1, 0, 1, -2, 1, 1 ] ], - [ [ -1, 0, 1, -2, 2, 1 ], [ 1, -1, 1, -2, 2, 0 ], [ 0, 1, 1, -2, 1, 1 ], [ 1, 0, 1, -2, 1, 1 ] ], - [ [ 1, -1, 1, -3, 2, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 0, 1, 1, -2, 1, 1 ], [ 1, 0, 1, -2, 1, 1 ] ] -], -"cur_uid": "6d635e88", -"ref_uid": "6ed95c4c", -"order_seed": 526896, -"dur_seed": 815251, -"motifs_seed": 342685, -"entrances_probs_vals": [ 0, 0.91269841269841, 2.8571428571429, 0.71, 1.92, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 0, 0.63, 2.1031746031746, 0.98901098901099, 2.23, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 0, 0.91269841269841, 2.8571428571429, 0.71, 1.92, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -2894.1176470588, -312 ], [ -1872, 1378 ], [ -145, 1583 ], [ -182, 1527 ] ], -"step_probs_vals": [ 0, 1200, 0, 0, 0.082304526748971, 0.99431818181818, 0.23045267489712, 1.1102230246252e-16, 0.61522633744856, 0, 1, 0 ], -"passages_weights": [ 0.75, 0.75, 0.75, 0.75, 0.8 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 0, 2 ], [ 1, 1 ], [ 3 ] ], - [ [ 0, 2, 3 ], [ 1, 1 ], [ ] ], - [ [ 2, 0, 3 ], [ 1, 1 ], [ ] ], - [ [ 2, 3 ], [ 1 ], [ 0 ] ], - [ [ 3, 2 ], [ 0 ], [ 1 ] ], - [ [ 1, 3, 0 ], [ 2, 2 ], [ ] ], - [ [ 0, 2, 1 ], [ 3, 3 ], [ ] ], - [ [ 2, 0, 3 ], [ 1, 1 ], [ ] ], - [ [ 3, 1 ], [ 2, 0, 0 ], [ ] ], - [ [ 2, 3, 1 ], [ 0, 0 ], [ ] ] -], -"sus_weights": [ 0, 0.31, 0.55 ], -"order_size": [ 10, 10 ], -"passages_size": [ 0, 2 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/6d635e88/lilypond/part_I.ly b/resources/resources_bak_2024_01_03/string_quartet_1/6d635e88/lilypond/part_I.ly deleted file mode 100644 index ea663b7..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/6d635e88/lilypond/part_I.ly +++ /dev/null @@ -1,70 +0,0 @@ -{ - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r2 r8.[ ais'16^\markup { \pad-markup #0.2 "-35"}] ~ ais'4 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'8.[ c''16^\markup { \pad-markup #0.2 "-31"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↑" }}] ~ c''2. ~ } - \bar "|" - { c''8[ ais'8^\markup { \pad-markup #0.2 "+41"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↑" }}] ~ ais'2. ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'8.[ r16] r2. } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/6d635e88/lilypond/part_II.ly b/resources/resources_bak_2024_01_03/string_quartet_1/6d635e88/lilypond/part_II.ly deleted file mode 100644 index 8850de9..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/6d635e88/lilypond/part_II.ly +++ /dev/null @@ -1,70 +0,0 @@ -{ - { r2. r16[ g'8.^\markup { \pad-markup #0.2 "-2"}] ~ } - \bar "|" - { g'1 ~ } - \bar "|" - { g'1 ~ } - \bar "|" - { g'1 ~ } - \bar "|" - { g'1 ~ } - \bar "|" - { g'1 ~ } - \bar "|" - { g'1 ~ } - \bar "|" - { g'1 ~ } - \bar "|" - { g'1 ~ } - \bar "|" - { g'1 ~ } - \bar "|" - { g'1 ~ } - \bar "|" - { g'1 ~ } - \bar "|" - { g'1 ~ } - \bar "|" - { g'1 ~ } - \bar "|" - { g'1 ~ } - \bar "|" - { g'1 ~ } - \bar "|" - { g'2. ~ g'16[ gis'8.^\markup { \pad-markup #0.2 "-49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 11↑" }}] ~ } - \bar "|" - { gis'2. ~ gis'16[ f'8.^\markup { \pad-markup #0.2 "+47"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 7↓" }}] ~ } - \bar "|" - { f'1 ~ } - \bar "|" - { f'1 ~ } - \bar "|" - { f'1 ~ } - \bar "|" - { f'1 ~ } - \bar "|" - { f'1 ~ } - \bar "|" - { f'2. ~ f'16[ f'8.^\markup { \pad-markup #0.2 "+42"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↑" }}] ~ } - \bar "|" - { f'1 ~ } - \bar "|" - { f'1 ~ } - \bar "|" - { f'1 ~ } - \bar "|" - { f'1 ~ } - \bar "|" - { f'1 ~ } - \bar "|" - { f'1 ~ } - \bar "|" - { f'4 ~ f'16[ r8.] r2 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/6d635e88/lilypond/part_III.ly b/resources/resources_bak_2024_01_03/string_quartet_1/6d635e88/lilypond/part_III.ly deleted file mode 100644 index 710041c..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/6d635e88/lilypond/part_III.ly +++ /dev/null @@ -1,70 +0,0 @@ -{ - { r1 } - \bar "|" - { r1 } - \bar "|" - { r4 r8[ fis'8^\markup { \pad-markup #0.2 "+45"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 11↓" }}] ~ fis'4 ~ fis'8.[ gis'16^\markup { \pad-markup #0.2 "+10"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↓" }}] ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'4 ~ gis'16[ fis'8.^\markup { \pad-markup #0.2 "+5"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 13↑" }}] ~ fis'2 } - \bar "|" - { f'1^\markup { \pad-markup #0.2 "-33"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 7↑" }} ~ } - \bar "|" - { f'4 ~ f'8[ e'8^\markup { \pad-markup #0.2 "-44"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↓" }}] ~ e'2 ~ } - \bar "|" - { e'4 ~ e'16[ d'8.^\markup { \pad-markup #0.2 "+0"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↑" }}] ~ d'2 ~ } - \bar "|" - { d'1 ~ } - \bar "|" - { d'2. dis'4^\markup { \pad-markup #0.2 "+16"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 11↑" }} ~ } - \bar "|" - { dis'1 ~ } - \bar "|" - { dis'4 ~ dis'16[ r8.] r2 } - \bar "|" - { r1 } - \bar "|" - { r2. r8[ dis'8^\markup { \pad-markup #0.2 "+16"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 11↑" }}] ~ } - \bar "|" - { dis'1 ~ } - \bar "|" - { dis'1 ~ } - \bar "|" - { dis'1 ~ } - \bar "|" - { dis'1 ~ } - \bar "|" - { dis'1 ~ } - \bar "|" - { dis'2 ~ dis'16[ d'8.^\markup { \pad-markup #0.2 "-39"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 5↓" }}] ~ d'4 ~ } - \bar "|" - { d'8.[ c'16^\markup { \pad-markup #0.2 "+49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↑" }}] ~ c'2. ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'4 ~ c'8.[ r16] r2 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/6d635e88/lilypond/part_IV.ly b/resources/resources_bak_2024_01_03/string_quartet_1/6d635e88/lilypond/part_IV.ly deleted file mode 100644 index 8163bc3..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/6d635e88/lilypond/part_IV.ly +++ /dev/null @@ -1,70 +0,0 @@ -{ - { c1^\markup { \pad-markup #0.2 "-4"} ~ } - \bar "|" - { c1 ~ } - \bar "|" - { c1 ~ } - \bar "|" - { c1 ~ } - \bar "|" - { c1 ~ } - \bar "|" - { c1 ~ } - \bar "|" - { c1 ~ } - \bar "|" - { c1 ~ } - \bar "|" - { c1 ~ } - \bar "|" - { c1 ~ } - \bar "|" - { c2. r4 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r2. r8.[ d16^\markup { \pad-markup #0.2 "+0"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↑" }}] ~ } - \bar "|" - { d1 ~ } - \bar "|" - { d1 ~ } - \bar "|" - { d1 ~ } - \bar "|" - { d1 ~ } - \bar "|" - { d1 ~ } - \bar "|" - { d1 ~ } - \bar "|" - { d1 ~ } - \bar "|" - { d1 ~ } - \bar "|" - { d1 ~ } - \bar "|" - { d1 ~ } - \bar "|" - { d4 ~ d8[ dis8^\markup { \pad-markup #0.2 "+39"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↓" }}] ~ dis2 ~ } - \bar "|" - { dis4 ~ dis8[ f8^\markup { \pad-markup #0.2 "+42"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 1↑" }}] ~ f2 ~ } - \bar "|" - { f1 ~ } - \bar "|" - { f4 ~ f8[ e8^\markup { \pad-markup #0.2 "-8"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 11↑" }}] ~ e2 ~ } - \bar "|" - { e4 ~ e16[ dis8.^\markup { \pad-markup #0.2 "-19"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 7↓" }}] ~ dis2 ~ } - \bar "|" - { dis1 ~ } - \bar "|" - { dis1 ~ } - \bar "|" - { dis1 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/6ed95c4c/6ed95c4c_code.scd b/resources/resources_bak_2024_01_03/string_quartet_1/6ed95c4c/6ed95c4c_code.scd deleted file mode 100644 index a98b916..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/6ed95c4c/6ed95c4c_code.scd +++ /dev/null @@ -1,945 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance); -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/6ed95c4c/6ed95c4c_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_1/6ed95c4c/6ed95c4c_mus_model.json deleted file mode 100644 index c03359a..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/6ed95c4c/6ed95c4c_mus_model.json +++ /dev/null @@ -1,66 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ 2, -2, 0, -1, 1, 0 ], [ "Rest" ], [ "Rest" ] ], 4.125 ], - [ [ [ "Rest" ], [ 2, -2, 0, -1, 1, 0 ], [ "Rest" ], [ 2, -2, 0, -1, 1, 1 ] ], 1.375 ], - [ [ [ "Rest" ], [ 2, -2, 0, -1, 1, 0 ], [ 3, -2, 0, -2, 1, 0 ], [ 2, -2, 0, -1, 1, 1 ] ], 1.25 ], - [ [ [ "Rest" ], [ 2, -2, 0, -1, 1, 0 ], [ 3, -2, 0, -2, 1, 0 ], [ 2, -1, 0, -1, 1, 0 ] ], 1.125 ], - [ [ [ "Rest" ], [ 2, -2, 0, -1, 1, 0 ], [ 2, -2, 1, -1, 1, 0 ], [ 2, -1, 0, -1, 1, 0 ] ], 3.5 ] - ], - [ - [ [ [ "Rest" ], [ 2, -2, 0, -1, 1, 0 ], [ 2, -2, 1, -1, 1, 0 ], [ "Rest" ] ], 1.5 ], - [ [ [ 1, -3, 1, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 2, -2, 1, -1, 1, 0 ], [ "Rest" ] ], 1.625 ], - [ [ [ 1, -3, 1, -1, 1, 0 ], [ 1, -2, 1, -1, 1, 1 ], [ 2, -2, 1, -1, 1, 0 ], [ "Rest" ] ], 2.25 ], - [ [ [ 1, -3, 1, -1, 1, 0 ], [ 1, -1, 1, -1, 1, 0 ], [ 2, -2, 1, -1, 1, 0 ], [ "Rest" ] ], 1.5 ], - [ [ [ 0, -2, 2, -1, 1, 0 ], [ 1, -1, 1, -1, 1, 0 ], [ 2, -2, 1, -1, 1, 0 ], [ "Rest" ] ], 2.125 ], - [ [ [ 1, -2, 1, -2, 1, 0 ], [ 1, -1, 1, -1, 1, 0 ], [ 2, -2, 1, -1, 1, 0 ], [ "Rest" ] ], 4.25 ] - ], - [ - [ [ [ 1, -2, 1, -2, 1, 0 ], [ 1, -1, 1, -1, 1, 0 ], [ 3, -2, 0, -2, 1, 0 ], [ "Rest" ] ], 2 ], - [ [ [ 1, -2, 1, -2, 1, 0 ], [ 3, -2, 1, -2, 1, -1 ], [ 3, -2, 0, -2, 1, 0 ], [ "Rest" ] ], 1.75 ], - [ [ [ 1, -2, 1, -2, 1, 0 ], [ 3, -2, 1, -2, 1, -1 ], [ 3, -2, 0, -2, 1, 0 ], [ 3, -2, 1, -2, 1, 0 ] ], 1 ], - [ [ [ 1, -2, 1, -2, 1, 0 ], [ 3, -2, 1, -2, 1, -1 ], [ 3, -2, 0, -2, 1, 0 ], [ 2, -2, 1, -1, 1, 0 ] ], 1.125 ], - [ [ [ 1, -2, 1, -2, 1, 0 ], [ 2, -2, 2, -2, 1, 0 ], [ 3, -2, 0, -2, 1, 0 ], [ 2, -2, 1, -1, 1, 0 ] ], 1.75 ], - [ [ [ 1, -2, 1, -2, 1, 0 ], [ 3, -3, 1, -2, 1, 0 ], [ 3, -2, 0, -2, 1, 0 ], [ 2, -2, 1, -1, 1, 0 ] ], 2 ], - [ [ [ 1, -2, 1, -2, 1, 0 ], [ 3, -3, 1, -2, 1, 0 ], [ 2, -1, 1, -2, 1, 0 ], [ 2, -2, 1, -1, 1, 0 ] ], 3.625 ], - [ [ [ 1, -2, 1, -2, 1, 0 ], [ 3, -3, 1, -2, 1, 0 ], [ "Rest" ], [ 2, -2, 1, -1, 1, 0 ] ], 1 ], - [ [ [ 1, -2, 1, -2, 1, 0 ], [ 3, -3, 1, -2, 1, 0 ], [ "Rest" ], [ "Rest" ] ], 0.875 ], - [ [ [ "Rest" ], [ 3, -3, 1, -2, 1, 0 ], [ "Rest" ], [ "Rest" ] ], 0.25 ] - ] - ] -], -"last_changes": -[ - [ [ 1, -2, 1, -2, 1, 0 ], [ 3, -2, 1, -2, 1, -1 ], [ 3, -2, 0, -2, 1, 0 ], [ 3, -2, 1, -2, 1, 0 ] ], - [ [ 1, -2, 1, -2, 1, 0 ], [ 3, -2, 1, -2, 1, -1 ], [ 3, -2, 0, -2, 1, 0 ], [ 2, -2, 1, -1, 1, 0 ] ], - [ [ 1, -2, 1, -2, 1, 0 ], [ 2, -2, 2, -2, 1, 0 ], [ 3, -2, 0, -2, 1, 0 ], [ 2, -2, 1, -1, 1, 0 ] ], - [ [ 1, -2, 1, -2, 1, 0 ], [ 3, -3, 1, -2, 1, 0 ], [ 3, -2, 0, -2, 1, 0 ], [ 2, -2, 1, -1, 1, 0 ] ], - [ [ 1, -2, 1, -2, 1, 0 ], [ 3, -3, 1, -2, 1, 0 ], [ 2, -1, 1, -2, 1, 0 ], [ 2, -2, 1, -1, 1, 0 ] ] -], -"cur_uid": "6ed95c4c", -"ref_uid": "4b7745df", -"order_seed": 602538, -"dur_seed": 495773, -"motifs_seed": 128841, -"entrances_probs_vals": [ 0, 1.1904761904762, 3.3333333333333, 0.71, 1.92, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 0, 1.55, 3.452380952381, 0.98901098901099, 2.23, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 0, 1.1904761904762, 3.3333333333333, 0.71, 1.92, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -2894.1176470588, -312 ], [ -1872, 1378 ], [ -145, 1583 ], [ -182, 1527 ] ], -"step_probs_vals": [ 0, 1200, 0, 0, 0.082304526748971, 0.99431818181818, 0.14197530864198, 0, 1, 0 ], -"passages_weights": [ 0.75, 0.75, 0.75, 0.75, 0.8 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 1 ], [ 3, 2, 3, 2 ], [ 0 ] ], - [ [ 2 ], [ 0, 1, 1, 0, 0 ], [ 3 ] ], - [ [ 0 ], [ 2, 1, 3, 3, 1, 1, 2 ], [ ] ] -], -"sus_weights": [ 0.66, 0, 0 ], -"order_size": [ 1, 4 ], -"passages_size": [ 2, 5 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/6ed95c4c/lilypond/part_I.ly b/resources/resources_bak_2024_01_03/string_quartet_1/6ed95c4c/lilypond/part_I.ly deleted file mode 100644 index 4ccdb1e..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/6ed95c4c/lilypond/part_I.ly +++ /dev/null @@ -1,42 +0,0 @@ -{ - { r1 } - \bar "|" - { r1 } - \bar "|" - { r16[ d''8.^\markup { \pad-markup #0.2 "+19"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 13↑" }}] ~ d''2. ~ } - \bar "|" - { d''4 ~ d''8[ cis''8^\markup { \pad-markup #0.2 "-19"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↑" }}] ~ cis''2 ~ } - \bar "|" - { cis''1 ~ } - \bar "|" - { cis''2 ~ cis''8.[ r16] r4 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r8.[ c''16^\markup { \pad-markup #0.2 "-4"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }}] ~ c''4 ~ c''8.[ ais'16^\markup { \pad-markup #0.2 "-35"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↑" }}] ~ ais'4 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'4 ~ ais'8.[ r16] r2 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/6ed95c4c/lilypond/part_II.ly b/resources/resources_bak_2024_01_03/string_quartet_1/6ed95c4c/lilypond/part_II.ly deleted file mode 100644 index dba1611..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/6ed95c4c/lilypond/part_II.ly +++ /dev/null @@ -1,42 +0,0 @@ -{ - { r1 } - \bar "|" - { r1 } - \bar "|" - { r2. gis'4^\markup { \pad-markup #0.2 "+10"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 7↓" }} ~ } - \bar "|" - { gis'2. ~ gis'8.[ ais'16^\markup { \pad-markup #0.2 "-35"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 5↑" }}] ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'4 ~ ais'16[ gis'8.^\markup { \pad-markup #0.2 "+10"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↓" }}] ~ gis'2 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'8[ g'8^\markup { \pad-markup #0.2 "-2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }}] ~ g'2. ~ } - \bar "|" - { g'2. ~ g'8.[ r16] } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/6ed95c4c/lilypond/part_III.ly b/resources/resources_bak_2024_01_03/string_quartet_1/6ed95c4c/lilypond/part_III.ly deleted file mode 100644 index ce5e5ba..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/6ed95c4c/lilypond/part_III.ly +++ /dev/null @@ -1,42 +0,0 @@ -{ - { fis'1^\markup { \pad-markup #0.2 "-21"} ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'4 fis'2.^\markup { \pad-markup #0.2 "+5"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 13↑" }} ~ } - \bar "|" - { fis'4 ~ fis'8[ f'8^\markup { \pad-markup #0.2 "-33"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↑" }}] ~ f'2 ~ } - \bar "|" - { f'1 ~ } - \bar "|" - { f'1 ~ } - \bar "|" - { f'1 ~ } - \bar "|" - { f'1 ~ } - \bar "|" - { f'4 ~ f'16[ e'8.^\markup { \pad-markup #0.2 "-44"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↓" }}] ~ e'2 ~ } - \bar "|" - { e'1 ~ } - \bar "|" - { e'4 e'2.^\markup { \pad-markup #0.2 "-18"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }} ~ } - \bar "|" - { e'8[ f'8^\markup { \pad-markup #0.2 "-6"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }}] ~ f'2. ~ } - \bar "|" - { f'1 ~ } - \bar "|" - { f'1 ~ } - \bar "|" - { f'1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/6ed95c4c/lilypond/part_IV.ly b/resources/resources_bak_2024_01_03/string_quartet_1/6ed95c4c/lilypond/part_IV.ly deleted file mode 100644 index 18babdb..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/6ed95c4c/lilypond/part_IV.ly +++ /dev/null @@ -1,42 +0,0 @@ -{ - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r4 r8.[ dis16^\markup { \pad-markup #0.2 "-37"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↓" }}] ~ dis2 ~ } - \bar "|" - { dis1 ~ } - \bar "|" - { dis1 ~ } - \bar "|" - { dis8[ d8^\markup { \pad-markup #0.2 "-49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 5↑" }}] ~ d2. ~ } - \bar "|" - { d8.[ c16^\markup { \pad-markup #0.2 "-4"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 7↓" }}] ~ c2. ~ } - \bar "|" - { c1 ~ } - \bar "|" - { c1 ~ } - \bar "|" - { c1 ~ } - \bar "|" - { c1 ~ } - \bar "|" - { c1 ~ } - \bar "|" - { c1 ~ } - \bar "|" - { c1 ~ } - \bar "|" - { c1 ~ } - \bar "|" - { c2. ~ c8[ r8]} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/6fb60ab6/6fb60ab6_code.scd b/resources/resources_bak_2024_01_03/string_quartet_1/6fb60ab6/6fb60ab6_code.scd deleted file mode 100644 index 3eb3cbd..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/6fb60ab6/6fb60ab6_code.scd +++ /dev/null @@ -1,1058 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance); -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file; - file = File(path, "w"); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((dir +/+ ".." +/+ "resources" +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((dir +/+ ".." +/+ "resources" +/+ curUID).standardizePath); - File.copy(exPath, (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (dir +/+ ".." +/+ "resources" +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((dir +/+ ".." +/+ "resources" +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (dir +/+ ".." +/+ "resources" +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (dir +/+ ".." +/+ "resources" +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "resources" +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "resources" +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \".." +/+ ".." +/+ "resources" +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - -~transcribe.value(~seq, dir); - -( -//synthdefs -~stringModelBusArray = 4.collect({Bus.audio(s, 1)}); -~sineBusArray = 4.collect({Bus.audio(s, 1)}); -~bassBusArray = 1.collect({Bus.audio(s, 1)}); -~hdustBusArray = 1.collect({Bus.audio(s, 1)}); -~samplerBusArray = 2.collect({Bus.audio(s, 1)}); -~sBuf = Buffer.alloc(s, 10, 2); -SynthDef(\string_model, {arg freq, gate = 1, sustain, amp, dur, attack, release = 1, busIndex = 0; - var trig, exc, sig1, sig2, noHarms; - noHarms = rrand(20, 40); - exc = Saw.ar(freq, TRand.ar(0.5, 1, Impulse.ar(freq))) * 0.001 + Dust.ar(10000, 0.01); - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(1, 2)}) ], exc) * 0.8).softclip; - //sig1 = HPF.ar(sig1, 300); - Out.ar(Select.kr(busIndex, ~stringModelBusArray), sig1 * amp * EnvGen.kr(Env.adsr(attack, 0.3, 0.9, release, 0.9, -3), gate, doneAction: 2)); - //Out.ar([0, 1], sig1 * EnvGen.kr(Env.asr(dur, 0.3, 1), gate, doneAction: 2)); -}).add; - -SynthDef(\sine, {arg freq, gate = 1, sustain, amp, dur, busIndex = 0; - var sig; - sig = SinOsc.ar(freq); - Out.ar(Select.kr(busIndex, ~sineBusArray), sig * EnvGen.kr(Env.asr(0.3, 0.4, 0.3), gate, timeScale: dur, doneAction: 2)); - //Out.ar(Select.kr(busIndex, ~sineBusArray), sig * EnvGen.kr(Env.sine(dur), gate, doneAction: 2)); -}).add; - -SynthDef(\mixer, {arg freq, gate = 1, sustain, amp, dur, out; - var nameSpaces, sigs; - - sigs = [~stringModelBusArray, ~sineBusArray/*, ~bassBusArray, ~hdustBusArray, ~samplerBusArray*/].collect({arg busArray, i; - var nameSpace, sig; - nameSpace = ['string', 'sine', 'bass', 'hdust', 'sampler'][i]; - sig = busArray.collect({arg bus, c; In.ar(bus, 1) * NamedControl.kr(\ ++ nameSpace ++ '_volume_' ++ c, 1, 0.1)}); - sig = sig.collect({arg channel, c; Pan2.ar(channel, NamedControl.kr(\ ++ nameSpace ++ '_pan_' ++ c, i / (busArray.size - 1), 0.1) * 2 - 1)}); - sig = sig.collect({arg channel, c; channel * NamedControl.kr(\ ++ nameSpace ++ '_mute_' ++ c, 1, 0.1)}); - sig = Mix.ar(sig) * pow(NamedControl.kr(\ ++ nameSpace ++ '_volume_master', 1, 0.1), 2); - }); - - sigs = Mix.ar(sigs / 4); - Out.ar(0, sigs) -}).add; - -SynthDef(\bass, { - var switches, drone; - switches = {|i| Dust.kr(0.1)} ! 9; - drone = {|i| var harm = pow(2, 2 - (i / 3).trunc), amp = (1 / pow(harm, 2)); - SinOsc.ar(60 * harm + TRand.kr(-3, 3, switches[i]), 0, amp)} ! 9; - Out.ar(~bassBusArray[0], Mix.new(drone) * 0.2); -}).add; - -SynthDef(\sampler, { - Out.ar(~samplerBusArray, PlayBuf.ar(2, ~sBuf, BufRateScale.kr(~sBuf), doneAction: 2)) -}).add; - -// main routine -SynthDef(\hdust, { - arg gate = 0; - var hierarchical_dust, low_sine, high_sine, brown_noise, white_noise; - // this triggers the combinations of sources - // it is similar to the Supercollider UGen called dust but with a hierarchical structure - hierarchical_dust = ( - TIRand.kr(0, 1, Impulse.kr(100)) * - TIRand.kr(0, 1, Impulse.kr(10)) * - TIRand.kr(0, 1, Impulse.kr(1)) * - TIRand.kr(0, 1, Impulse.kr(0.1)) - ); - // adjust the multiplier at the end of each line for adjusting levels - // note with each trigger, each source has a 1 in 3 chance of sounding - low_sine = SinOsc.ar(76.midicps / 16) * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.1; - high_sine = SinOsc.ar(76.midicps * 8) * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.01; - brown_noise = BrownNoise.ar() * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.025; - white_noise = WhiteNoise.ar() * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.02; - Out.ar(~hdustBusArray[0], - ((low_sine + high_sine + brown_noise + white_noise) ) - ); -}).add; - -) - -( -var bass, hdust, sampler, mixer; -/* -bass = Synth.tail(~group, \bass); -hdust = Synth.tail(~group, \hdust); -sampler = Synth.head(~group, \sampler); -*/ -mixer = Synth.tail(~group, \mixer); - -OSCdef(\mixer, {arg msg, time, addr, port; - mixer.set((msg[1] ++ '_' ++ msg[2] ++ '_' ++ msg[3]), msg[4]) -}, \mixer); - -/* -OSCdef(\sampler, {arg msg, time, addr, port; - msg.postln; - sampler.free; - ~sBuf.free; - ~sBuf = Buffer.read(s, msg[1].asString.postln, action: {sampler = Synth.head(~group, \sampler)}); -}, \sampler); -*/ -) - -/* old something -( -SynthDef(\test, {arg freq, gate = 1, sustain, amp, dur; - var trig, exc, sig1, sig2, noHarms, freqFinal, start, end; - noHarms = 30; - freq = WhiteNoise.ar * 3 + freq; - freqFinal = Duty.ar((1/freq), 0, freq); - trig = Changed.ar(freqFinal); - start = Demand.ar(trig, 0, Dwhite(-1, -0.75)); - end = Demand.ar(trig, 0, Dwhite(0.75, 1)); - exc = Phasor.ar(trig, (end - start) * freqFinal / SampleRate.ir, start, end, 0) * 0.001 + Dust.ar(10000, 0.01); - - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(2, 3)}) ], exc) * 0.5).softclip; - sig1 = HPF.ar(sig1, 300); - Out.ar([0, 1], sig1 * EnvGen.kr(Env.adsr(0.3, 0.3, 0.9, 0.5, 0.9), gate, doneAction: 2)); -}).add; -) -*/ - diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/6fb60ab6/6fb60ab6_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_1/6fb60ab6/6fb60ab6_mus_model.json deleted file mode 100644 index 1778bf5..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/6fb60ab6/6fb60ab6_mus_model.json +++ /dev/null @@ -1,56 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ 1, -1, 0, -1, 1, 0 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 0.625 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ "Rest" ], [ "Rest" ], [ 1, 0, 0, -1, 1, 0 ] ], 0 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ "Rest" ], [ 2, -1, 0, -1, 1, -1 ], [ 1, 0, 0, -1, 1, 0 ] ], 1.75 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ "Rest" ], [ 2, -1, 0, -1, 1, -1 ], [ 2, -1, 0, -1, 0, 0 ] ], 1.875 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ "Rest" ], [ 2, -1, 0, -1, 1, -1 ], [ 1, -1, 0, -1, 2, 0 ] ], 1.5 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ "Rest" ], [ 2, -1, 0, -1, 1, -1 ], [ 1, -1, 1, -1, 1, 0 ] ], 0.75 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ "Rest" ], [ 2, -1, 0, -1, 1, -1 ], [ 2, -1, 0, -2, 1, 0 ] ], 1.25 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ "Rest" ], [ 2, -1, 0, -1, 1, -1 ], [ 0, -1, 0, 0, 1, 0 ] ], 1.625 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ "Rest" ], [ 2, -1, 0, -1, 1, -1 ], [ 1, 0, 0, -1, 1, 0 ] ], 1.875 ] - ], - [ - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 2, -1, 0, -1, 1, -1 ], [ 1, 0, 0, -1, 1, 0 ] ], 1 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 1, -1, 0, -1, 2, 0 ], [ 1, 0, 0, -1, 1, 0 ] ], 1.125 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 1, 0, -1, -1, 1, 0 ], [ 1, 0, 0, -1, 1, 0 ] ], 0.75 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ 1, 0, 0, -1, 1, 0 ] ], 1.5 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 1, -2, 0, -1, 1, 1 ], [ 1, 0, 0, -1, 1, 0 ] ], 1.5 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 1, 0, 0, -1, 1, -1 ], [ 1, 0, 0, -1, 1, 0 ] ], 1.75 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ "Rest" ], [ 1, 0, 0, -1, 1, 0 ] ], 1.125 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ "Rest" ], [ "Rest" ] ], 0.5 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 0 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 5.5 ] - ] - ] -], -"last_changes": -[ - [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 1, -1, 0, -1, 1, -1 ], [ 1, 0, 0, -1, 1, 0 ] ] -], -"cur_uid": "6fb60ab6", -"ref_uid": "nil", -"order_seed": 209164, -"dur_seed": 417909, -"motifs_seed": 885208, -"entrances_probs_vals": [ 0.34, 0, 10, 0.5, 2, 0, 0.5, 0.24509803921569, 0.89189189189189, 0.5, 1, 0.5, 0.5, 0.8562091503268, 0.69932432432432, 1, 0.5 ], -"passages_probs_vals": [ 0.34, 0, 10, 0.5, 2, 0, 0.5, 0.24509803921569, 0.89189189189189, 0.5, 1, 0.5, 0.5, 0.8562091503268, 0.69932432432432, 1, 0.5 ], -"exits_probs_vals": [ 0.34, 0, 10, 0.5, 2, 0, 0.5, 0.24509803921569, 0.89189189189189, 0.5, 1, 0.5, 0.5, 0.8562091503268, 0.69932432432432, 1, 0.5 ], -"ranges": [ [ -1200, 2400 ], [ -1200, 2400 ], [ -1200, 2400 ], [ -1200, 2400 ] ], -"step_probs_vals": [ 0, 1200, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_weights": [ 0.75, 0.75, 0.75, 0.75, 0.75 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 2 ], [ 0, 0, 0, 0 ], [ 1, 3 ] ] -], -"sus_weights": [ 0.75, 0.75, 0.75 ], -"order_size": [ 1, 10 ], -"passages_size": [ 0, 10 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/6fb60ab6/lilypond/part_I.ly b/resources/resources_bak_2024_01_03/string_quartet_1/6fb60ab6/lilypond/part_I.ly deleted file mode 100644 index 3ed19b7..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/6fb60ab6/lilypond/part_I.ly +++ /dev/null @@ -1,28 +0,0 @@ -{ - { r4 r16[ gis'8.^\markup { \pad-markup #0.2 "-18"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }}] ~ gis'2 ~ } - \bar "|" - { gis'8.[ g'16^\markup { \pad-markup #0.2 "+29"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 11↓" }}] ~ g'2. ~ } - \bar "|" - { g'8[ fis'8^\markup { \pad-markup #0.2 "+32"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 11↑" }}] ~ fis'2 ~ fis'8[ f'8^\markup { \pad-markup #0.2 "-33"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }}] ~ } - \bar "|" - { f'4 dis'2^\markup { \pad-markup #0.2 "+12"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↓" }} ~ dis'8[ ais8^\markup { \pad-markup #0.2 "+49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↑" }}] ~ } - \bar "|" - { ais2 ~ ais8.[ gis'16^\markup { \pad-markup #0.2 "-18"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }}] ~ gis'4 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/6fb60ab6/lilypond/part_II.ly b/resources/resources_bak_2024_01_03/string_quartet_1/6fb60ab6/lilypond/part_II.ly deleted file mode 100644 index af38e4d..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/6fb60ab6/lilypond/part_II.ly +++ /dev/null @@ -1,28 +0,0 @@ -{ - { r4 r16[ e'8.^\markup { \pad-markup #0.2 "+40"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↓" }}] ~ e'2 ~ } - \bar "|" - { e'1 ~ } - \bar "|" - { e'1 ~ } - \bar "|" - { e'1 ~ } - \bar "|" - { e'1 ~ } - \bar "|" - { e'1 ~ } - \bar "|" - { e'8[ fis'8^\markup { \pad-markup #0.2 "+32"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 11↑" }}] ~ fis'4 ~ fis'8.[ e'16^\markup { \pad-markup #0.2 "-4"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 5↓" }}] ~ e'4 ~ } - \bar "|" - { e'16[ d'8.^\markup { \pad-markup #0.2 "+31"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 11↓" }}] ~ d'2 ~ d'16[ d'8.^\markup { \pad-markup #0.2 "+19"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 13↑" }}] ~ } - \bar "|" - { d'2 ~ d'16[ b8.^\markup { \pad-markup #0.2 "+42"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 13↓" }}] ~ b4 ~ } - \bar "|" - { b4 ~ b8.[ r16] r2 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/6fb60ab6/lilypond/part_III.ly b/resources/resources_bak_2024_01_03/string_quartet_1/6fb60ab6/lilypond/part_III.ly deleted file mode 100644 index ff528bb..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/6fb60ab6/lilypond/part_III.ly +++ /dev/null @@ -1,28 +0,0 @@ -{ - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r2 r8[ fis'8^\markup { \pad-markup #0.2 "-21"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }}] ~ fis'4 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'4 r2. } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/6fb60ab6/lilypond/part_IV.ly b/resources/resources_bak_2024_01_03/string_quartet_1/6fb60ab6/lilypond/part_IV.ly deleted file mode 100644 index 1592265..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/6fb60ab6/lilypond/part_IV.ly +++ /dev/null @@ -1,28 +0,0 @@ -{ - { cis'1^\markup { \pad-markup #0.2 "-19"} ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'4 r2. } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/761e4585/761e4585_code.scd b/resources/resources_bak_2024_01_03/string_quartet_1/761e4585/761e4585_code.scd deleted file mode 100644 index 3eb3cbd..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/761e4585/761e4585_code.scd +++ /dev/null @@ -1,1058 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance); -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file; - file = File(path, "w"); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((dir +/+ ".." +/+ "resources" +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((dir +/+ ".." +/+ "resources" +/+ curUID).standardizePath); - File.copy(exPath, (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (dir +/+ ".." +/+ "resources" +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((dir +/+ ".." +/+ "resources" +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (dir +/+ ".." +/+ "resources" +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (dir +/+ ".." +/+ "resources" +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "resources" +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "resources" +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \".." +/+ ".." +/+ "resources" +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - -~transcribe.value(~seq, dir); - -( -//synthdefs -~stringModelBusArray = 4.collect({Bus.audio(s, 1)}); -~sineBusArray = 4.collect({Bus.audio(s, 1)}); -~bassBusArray = 1.collect({Bus.audio(s, 1)}); -~hdustBusArray = 1.collect({Bus.audio(s, 1)}); -~samplerBusArray = 2.collect({Bus.audio(s, 1)}); -~sBuf = Buffer.alloc(s, 10, 2); -SynthDef(\string_model, {arg freq, gate = 1, sustain, amp, dur, attack, release = 1, busIndex = 0; - var trig, exc, sig1, sig2, noHarms; - noHarms = rrand(20, 40); - exc = Saw.ar(freq, TRand.ar(0.5, 1, Impulse.ar(freq))) * 0.001 + Dust.ar(10000, 0.01); - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(1, 2)}) ], exc) * 0.8).softclip; - //sig1 = HPF.ar(sig1, 300); - Out.ar(Select.kr(busIndex, ~stringModelBusArray), sig1 * amp * EnvGen.kr(Env.adsr(attack, 0.3, 0.9, release, 0.9, -3), gate, doneAction: 2)); - //Out.ar([0, 1], sig1 * EnvGen.kr(Env.asr(dur, 0.3, 1), gate, doneAction: 2)); -}).add; - -SynthDef(\sine, {arg freq, gate = 1, sustain, amp, dur, busIndex = 0; - var sig; - sig = SinOsc.ar(freq); - Out.ar(Select.kr(busIndex, ~sineBusArray), sig * EnvGen.kr(Env.asr(0.3, 0.4, 0.3), gate, timeScale: dur, doneAction: 2)); - //Out.ar(Select.kr(busIndex, ~sineBusArray), sig * EnvGen.kr(Env.sine(dur), gate, doneAction: 2)); -}).add; - -SynthDef(\mixer, {arg freq, gate = 1, sustain, amp, dur, out; - var nameSpaces, sigs; - - sigs = [~stringModelBusArray, ~sineBusArray/*, ~bassBusArray, ~hdustBusArray, ~samplerBusArray*/].collect({arg busArray, i; - var nameSpace, sig; - nameSpace = ['string', 'sine', 'bass', 'hdust', 'sampler'][i]; - sig = busArray.collect({arg bus, c; In.ar(bus, 1) * NamedControl.kr(\ ++ nameSpace ++ '_volume_' ++ c, 1, 0.1)}); - sig = sig.collect({arg channel, c; Pan2.ar(channel, NamedControl.kr(\ ++ nameSpace ++ '_pan_' ++ c, i / (busArray.size - 1), 0.1) * 2 - 1)}); - sig = sig.collect({arg channel, c; channel * NamedControl.kr(\ ++ nameSpace ++ '_mute_' ++ c, 1, 0.1)}); - sig = Mix.ar(sig) * pow(NamedControl.kr(\ ++ nameSpace ++ '_volume_master', 1, 0.1), 2); - }); - - sigs = Mix.ar(sigs / 4); - Out.ar(0, sigs) -}).add; - -SynthDef(\bass, { - var switches, drone; - switches = {|i| Dust.kr(0.1)} ! 9; - drone = {|i| var harm = pow(2, 2 - (i / 3).trunc), amp = (1 / pow(harm, 2)); - SinOsc.ar(60 * harm + TRand.kr(-3, 3, switches[i]), 0, amp)} ! 9; - Out.ar(~bassBusArray[0], Mix.new(drone) * 0.2); -}).add; - -SynthDef(\sampler, { - Out.ar(~samplerBusArray, PlayBuf.ar(2, ~sBuf, BufRateScale.kr(~sBuf), doneAction: 2)) -}).add; - -// main routine -SynthDef(\hdust, { - arg gate = 0; - var hierarchical_dust, low_sine, high_sine, brown_noise, white_noise; - // this triggers the combinations of sources - // it is similar to the Supercollider UGen called dust but with a hierarchical structure - hierarchical_dust = ( - TIRand.kr(0, 1, Impulse.kr(100)) * - TIRand.kr(0, 1, Impulse.kr(10)) * - TIRand.kr(0, 1, Impulse.kr(1)) * - TIRand.kr(0, 1, Impulse.kr(0.1)) - ); - // adjust the multiplier at the end of each line for adjusting levels - // note with each trigger, each source has a 1 in 3 chance of sounding - low_sine = SinOsc.ar(76.midicps / 16) * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.1; - high_sine = SinOsc.ar(76.midicps * 8) * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.01; - brown_noise = BrownNoise.ar() * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.025; - white_noise = WhiteNoise.ar() * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.02; - Out.ar(~hdustBusArray[0], - ((low_sine + high_sine + brown_noise + white_noise) ) - ); -}).add; - -) - -( -var bass, hdust, sampler, mixer; -/* -bass = Synth.tail(~group, \bass); -hdust = Synth.tail(~group, \hdust); -sampler = Synth.head(~group, \sampler); -*/ -mixer = Synth.tail(~group, \mixer); - -OSCdef(\mixer, {arg msg, time, addr, port; - mixer.set((msg[1] ++ '_' ++ msg[2] ++ '_' ++ msg[3]), msg[4]) -}, \mixer); - -/* -OSCdef(\sampler, {arg msg, time, addr, port; - msg.postln; - sampler.free; - ~sBuf.free; - ~sBuf = Buffer.read(s, msg[1].asString.postln, action: {sampler = Synth.head(~group, \sampler)}); -}, \sampler); -*/ -) - -/* old something -( -SynthDef(\test, {arg freq, gate = 1, sustain, amp, dur; - var trig, exc, sig1, sig2, noHarms, freqFinal, start, end; - noHarms = 30; - freq = WhiteNoise.ar * 3 + freq; - freqFinal = Duty.ar((1/freq), 0, freq); - trig = Changed.ar(freqFinal); - start = Demand.ar(trig, 0, Dwhite(-1, -0.75)); - end = Demand.ar(trig, 0, Dwhite(0.75, 1)); - exc = Phasor.ar(trig, (end - start) * freqFinal / SampleRate.ir, start, end, 0) * 0.001 + Dust.ar(10000, 0.01); - - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(2, 3)}) ], exc) * 0.5).softclip; - sig1 = HPF.ar(sig1, 300); - Out.ar([0, 1], sig1 * EnvGen.kr(Env.adsr(0.3, 0.3, 0.9, 0.5, 0.9), gate, doneAction: 2)); -}).add; -) -*/ - diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/761e4585/761e4585_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_1/761e4585/761e4585_mus_model.json deleted file mode 100644 index f2ad529..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/761e4585/761e4585_mus_model.json +++ /dev/null @@ -1,80 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ 1, -1, 0, -1, 1, 0 ] ], 1.75 ], - [ [ [ "Rest" ], [ "Rest" ], [ 1, -1, 1, -1, 1, 0 ], [ 1, -1, 0, -1, 1, 0 ] ], 0 ], - [ [ [ "Rest" ], [ 0, -1, 0, 0, 1, 0 ], [ 1, -1, 1, -1, 1, 0 ], [ 1, -1, 0, -1, 1, 0 ] ], 0.625 ], - [ [ [ "Rest" ], [ 0, -1, 0, 0, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 1, -1, 0, -1, 1, 0 ] ], 0.875 ], - [ [ [ "Rest" ], [ 0, -1, 0, 0, 1, 0 ], [ 2, -1, 0, -1, 1, -1 ], [ 1, -1, 0, -1, 1, 0 ] ], 1.375 ], - [ [ [ "Rest" ], [ 0, -1, 0, 0, 1, 0 ], [ 1, -1, 0, -1, 2, 0 ], [ 1, -1, 0, -1, 1, 0 ] ], 0 ], - [ [ [ "Rest" ], [ 0, 0, 0, -1, 1, 0 ], [ 1, -1, 0, -1, 2, 0 ], [ 1, -1, 0, -1, 1, 0 ] ], 0.5 ], - [ [ [ "Rest" ], [ 0, -1, 0, -1, 1, 1 ], [ 1, -1, 0, -1, 2, 0 ], [ 1, -1, 0, -1, 1, 0 ] ], 0 ], - [ [ [ "Rest" ], [ 0, -1, 0, -1, 1, 1 ], [ 1, 0, 0, -1, 1, 0 ], [ 1, -1, 0, -1, 1, 0 ] ], 1.25 ], - [ [ [ "Rest" ], [ 0, -1, 0, -1, 1, 1 ], [ 2, -1, -1, -1, 1, 0 ], [ 1, -1, 0, -1, 1, 0 ] ], 0 ], - [ [ [ "Rest" ], [ 1, -1, -1, -1, 1, 0 ], [ 2, -1, -1, -1, 1, 0 ], [ 1, -1, 0, -1, 1, 0 ] ], 1.875 ] - ], - [ - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 1, -1, -1, -1, 1, 0 ], [ 2, -1, -1, -1, 1, 0 ], [ 1, -1, 0, -1, 1, 0 ] ], 1.625 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 0, -1, 0, 0, 1, 0 ], [ 2, -1, -1, -1, 1, 0 ], [ 1, -1, 0, -1, 1, 0 ] ], 0 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 0, -1, 0, 0, 1, 0 ], [ 2, -1, -1, -1, 1, 0 ], [ 2, -1, 0, -2, 1, 0 ] ], 0 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 0, -1, 0, 0, 1, 0 ], [ 1, -1, 0, -1, 2, 0 ], [ 2, -1, 0, -2, 1, 0 ] ], 1.75 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 0, -1, 0, 0, 1, 0 ], [ 2, -1, 0, -1, 0, 0 ], [ 2, -1, 0, -2, 1, 0 ] ], 1.75 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 0, -1, 0, -1, 1, 1 ], [ 2, -1, 0, -1, 0, 0 ], [ 2, -1, 0, -2, 1, 0 ] ], 0 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 0, -1, 0, -1, 1, 1 ], [ 1, -1, 0, -1, 1, 1 ], [ 2, -1, 0, -2, 1, 0 ] ], 1.75 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 1, -1, -1, -1, 1, 0 ], [ 1, -1, 0, -1, 1, 1 ], [ 2, -1, 0, -2, 1, 0 ] ], 1.875 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 1, -1, -1, -1, 1, 0 ], [ 2, -1, -1, -1, 1, 0 ], [ 2, -1, 0, -2, 1, 0 ] ], 1.375 ] - ], - [ - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 1, -1, -1, -1, 1, 0 ], [ 2, -1, -1, -1, 1, 0 ], [ "Rest" ] ], 1.375 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 0, 0, 0, -1, 1, 0 ], [ 2, -1, -1, -1, 1, 0 ], [ "Rest" ] ], 1 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -1, -1, -2, 1, 0 ], [ 2, -1, -1, -1, 1, 0 ], [ "Rest" ] ], 1.125 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 1, -1, -1, -1, 2, 0 ], [ 2, -1, -1, -1, 1, 0 ], [ "Rest" ] ], 1.625 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, -1, -1, 1, 0 ], [ 2, -1, -1, -1, 1, 0 ], [ "Rest" ] ], 1.75 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 1, -1, 1, -1, 1, 0 ], [ 2, -1, -1, -1, 1, 0 ], [ "Rest" ] ], 1.125 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 2, -1, -1, -1, 1, 0 ], [ "Rest" ] ], 1.25 ] - ], - [ - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 2, -1, -1, -1, 1, 0 ], [ 2, -1, 0, -2, 1, 0 ] ], 0 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 1, -1, 0, 0, 1, 0 ], [ 2, -1, 0, -2, 1, 0 ] ], 1.25 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 2, -1, 0, -1, 1, 0 ], [ 2, -1, 0, -2, 1, 0 ] ], 1.25 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 1 ], [ 2, -1, 0, -2, 1, 0 ] ], 1.5 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 3, -1, 0, -2, 1, 0 ], [ 2, -1, 0, -2, 1, 0 ] ], 2.375 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ "Rest" ], [ 2, -1, 0, -2, 1, 0 ] ], 0 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ "Rest" ], [ "Rest" ] ], 0 ], - [ [ [ "Rest" ], [ 2, -2, 0, -1, 1, 0 ], [ "Rest" ], [ "Rest" ] ], 0 ] - ] - ] -], -"last_changes": -[ - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], - [ [ 1, -1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], - [ [ 0, 0, -1, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], - [ [ -1, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], - [ [ 0, -1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ] -], -"cur_uid": "761e4585", -"ref_uid": "nil", -"order_seed": 209164, -"dur_seed": 417909, -"motifs_seed": 885208, -"entrances_probs_vals": [ 0.34, 0, 10, 0.5, 2, 0, 0.5, 0.24509803921569, 0.89189189189189, 0.5, 1, 0.5, 0.5, 0.8562091503268, 0.69932432432432, 1, 0.5 ], -"passages_probs_vals": [ 0.34, 0, 10, 0.5, 2, 0, 0.5, 0.24509803921569, 0.89189189189189, 0.5, 1, 0.5, 0.5, 0.8562091503268, 0.69932432432432, 1, 0.5 ], -"exits_probs_vals": [ 0.34, 0, 10, 0.5, 2, 0, 0.5, 0.24509803921569, 0.89189189189189, 0.5, 1, 0.5, 0.5, 0.8562091503268, 0.69932432432432, 1, 0.5 ], -"ranges": [ [ -1200, 2400 ], [ -1200, 2400 ], [ -1200, 2400 ], [ -1200, 2400 ] ], -"step_probs_vals": [ 0, 1200, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_weights": [ 0.75, 0.75, 0.75, 0.75, 0.75 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 2 ], [ 0, 0, 0, 0 ], [ 1, 3 ] ] -], -"sus_weights": [ 0.75, 0.75, 0.75 ], -"order_size": [ 1, 10 ], -"passages_size": [ 0, 10 ], -"motif_edited": "true", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/761e4585/lilypond/part_I.ly b/resources/resources_bak_2024_01_03/string_quartet_1/761e4585/lilypond/part_I.ly deleted file mode 100644 index 8f69c77..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/761e4585/lilypond/part_I.ly +++ /dev/null @@ -1,36 +0,0 @@ -{ - { cis'1^\markup { \pad-markup #0.2 "-19"} ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'2. ~ cis'8.[ dis'16^\markup { \pad-markup #0.2 "+12"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↓" }}] ~ } - \bar "|" - { dis'1 ~ } - \bar "|" - { dis'1 ~ } - \bar "|" - { dis'1 ~ } - \bar "|" - { dis'1 ~ } - \bar "|" - { dis'8.[ r16] r2. } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r2. r16[ dis'8.^\markup { \pad-markup #0.2 "+12"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↓" }}] ~ } - \bar "|" - { dis'1 ~ } - \bar "|" - { dis'1 ~ } - \bar "|" - { dis'1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/761e4585/lilypond/part_II.ly b/resources/resources_bak_2024_01_03/string_quartet_1/761e4585/lilypond/part_II.ly deleted file mode 100644 index af6a6cf..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/761e4585/lilypond/part_II.ly +++ /dev/null @@ -1,36 +0,0 @@ -{ - { r2. r8[ f'8^\markup { \pad-markup #0.2 "-33"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 5↑" }}] ~ } - \bar "|" - { f'8.[ fis'16^\markup { \pad-markup #0.2 "-21"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↓" }}] ~ fis'4 ~ fis'8[ e'8^\markup { \pad-markup #0.2 "+40"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 13↓" }}] ~ e'4 ~ } - \bar "|" - { e'4 ~ e'16[ fis'8.^\markup { \pad-markup #0.2 "+32"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 11↑" }}] ~ fis'16[ gis'8.^\markup { \pad-markup #0.2 "-18"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↑" }}] ~ gis'4 ~ } - \bar "|" - { gis'8.[ a'16^\markup { \pad-markup #0.2 "-6"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 5↓" }}] ~ a'2. ~ } - \bar "|" - { a'2. ~ a'8.[ fis'16^\markup { \pad-markup #0.2 "+32"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 11↑" }}] ~ } - \bar "|" - { fis'2. ~ fis'16[ g'8.^\markup { \pad-markup #0.2 "+29"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 11↓" }}] ~ } - \bar "|" - { g'2 ~ g'8.[ a'16^\markup { \pad-markup #0.2 "+21"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }}] ~ a'4 ~ } - \bar "|" - { a'1 ~ } - \bar "|" - { a'2 a'2^\markup { \pad-markup #0.2 "-6"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }} ~ } - \bar "|" - { a'1 ~ } - \bar "|" - { a'1 ~ } - \bar "|" - { a'1 ~ } - \bar "|" - { a'1 ~ } - \bar "|" - { a'2. ~ a'16[ ais'8.^\markup { \pad-markup #0.2 "+49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↑" }}] ~ } - \bar "|" - { ais'4 ~ ais'8.[ cis''16^\markup { \pad-markup #0.2 "-19"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }}] ~ cis''2 ~ } - \bar "|" - { cis''16[ d''8.^\markup { \pad-markup #0.2 "+19"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 13↑" }}] ~ d''2 ~ d''16[ dis''8.^\markup { \pad-markup #0.2 "+12"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }}] ~ } - \bar "|" - { dis''1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/761e4585/lilypond/part_III.ly b/resources/resources_bak_2024_01_03/string_quartet_1/761e4585/lilypond/part_III.ly deleted file mode 100644 index 144d704..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/761e4585/lilypond/part_III.ly +++ /dev/null @@ -1,36 +0,0 @@ -{ - { r2. r8[ ais8^\markup { \pad-markup #0.2 "+49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 7↑" }}] ~ } - \bar "|" - { ais1 ~ } - \bar "|" - { ais4 ~ ais16[ gis8.^\markup { \pad-markup #0.2 "-18"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↑" }}] ~ gis16[ a8.^\markup { \pad-markup #0.2 "+21"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 13↑" }}] ~ a4 ~ } - \bar "|" - { a8.[ a16^\markup { \pad-markup #0.2 "-6"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 1↑" }}] ~ a2. ~ } - \bar "|" - { a2. ~ a8.[ ais16^\markup { \pad-markup #0.2 "+49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↑" }}] ~ } - \bar "|" - { ais1 ~ } - \bar "|" - { ais2 ~ ais8.[ a16^\markup { \pad-markup #0.2 "+21"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↑" }}] ~ a4 ~ } - \bar "|" - { a2 ~ a16[ a8.^\markup { \pad-markup #0.2 "-6"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↓" }}] ~ a4 ~ } - \bar "|" - { a1 ~ } - \bar "|" - { a2. ~ a8[ gis8^\markup { \pad-markup #0.2 "-18"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }}] ~ } - \bar "|" - { gis4 ~ gis8[ b8^\markup { \pad-markup #0.2 "+25"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 7↓" }}] ~ b4 ~ b8.[ d'16^\markup { \pad-markup #0.2 "+46"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 11↑" }}] ~ } - \bar "|" - { d'2. d'4^\markup { \pad-markup #0.2 "-8"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↓" }} ~ } - \bar "|" - { d'2 ~ d'8[ f'8^\markup { \pad-markup #0.2 "-33"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }}] ~ f'4 ~ } - \bar "|" - { f'8.[ fis'16^\markup { \pad-markup #0.2 "-21"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }}] ~ fis'2. ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/761e4585/lilypond/part_IV.ly b/resources/resources_bak_2024_01_03/string_quartet_1/761e4585/lilypond/part_IV.ly deleted file mode 100644 index 89e838d..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/761e4585/lilypond/part_IV.ly +++ /dev/null @@ -1,36 +0,0 @@ -{ - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r8[ cis'8^\markup { \pad-markup #0.2 "-19"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }}] ~ cis'2. ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/774ed940/774ed940_code.scd b/resources/resources_bak_2024_01_03/string_quartet_1/774ed940/774ed940_code.scd deleted file mode 100644 index c194eef..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/774ed940/774ed940_code.scd +++ /dev/null @@ -1,945 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance); -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/774ed940/774ed940_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_1/774ed940/774ed940_mus_model.json deleted file mode 100644 index beff01e..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/774ed940/774ed940_mus_model.json +++ /dev/null @@ -1,70 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ 2, -1, 1, -2, 1, 0 ] ], 0.25 ], - [ [ [ 0, -1, 1, -2, 1, 1 ], [ "Rest" ], [ "Rest" ], [ 2, -1, 1, -2, 1, 0 ] ], 0.5 ], - [ [ [ 0, 0, 1, -2, 1, 0 ], [ "Rest" ], [ "Rest" ], [ 2, -1, 1, -2, 1, 0 ] ], 1.25 ], - [ [ [ 0, -1, 1, -2, 1, 1 ], [ "Rest" ], [ "Rest" ], [ 2, -1, 1, -2, 1, 0 ] ], 0.75 ], - [ [ [ 0, -1, 1, -1, 1, 0 ], [ "Rest" ], [ "Rest" ], [ 2, -1, 1, -2, 1, 0 ] ], 2.875 ] - ], - [ - [ [ [ 0, -1, 1, -1, 1, 0 ], [ "Rest" ], [ "Rest" ], [ 0, 0, 1, -1, 1, 0 ] ], 0 ], - [ [ [ 0, -1, 1, -1, 1, 0 ], [ "Rest" ], [ 0, -1, 1, 0, 1, 0 ], [ 0, 0, 1, -1, 1, 0 ] ], 0 ], - [ [ [ 0, -1, 1, -1, 1, 0 ], [ 0, -1, 2, -1, 1, 0 ], [ 0, -1, 1, 0, 1, 0 ], [ 0, 0, 1, -1, 1, 0 ] ], 1.5 ], - [ [ [ 0, -1, 1, -1, 1, 0 ], [ 1, -1, 1, -1, 1, -1 ], [ 0, -1, 1, 0, 1, 0 ], [ 0, 0, 1, -1, 1, 0 ] ], 1.5 ], - [ [ [ 0, -1, 1, -1, 1, 0 ], [ -1, -1, 1, 0, 1, 0 ], [ 0, -1, 1, 0, 1, 0 ], [ 0, 0, 1, -1, 1, 0 ] ], 0 ], - [ [ [ 0, -1, 1, -1, 1, 0 ], [ -1, -1, 1, 0, 1, 0 ], [ 0, -1, 1, 0, 1, 0 ], [ 2, -1, 1, -1, 1, -1 ] ], 1.5 ], - [ [ [ 0, -1, 1, -1, 1, 0 ], [ 0, -1, 1, -1, 2, 0 ], [ 0, -1, 1, 0, 1, 0 ], [ 2, -1, 1, -1, 1, -1 ] ], 0.625 ], - [ [ [ 0, -1, 1, -1, 1, 0 ], [ 1, -2, 1, -1, 1, 0 ], [ 0, -1, 1, 0, 1, 0 ], [ 2, -1, 1, -1, 1, -1 ] ], 1.25 ] - ], - [ - [ [ [ 0, -1, 1, -1, 1, 0 ], [ -1, -1, 1, 0, 1, 1 ], [ 0, -1, 1, 0, 1, 0 ], [ 2, -1, 1, -1, 1, -1 ] ], 0 ], - [ [ [ -2, 0, 1, 0, 1, 0 ], [ -1, -1, 1, 0, 1, 1 ], [ 0, -1, 1, 0, 1, 0 ], [ 2, -1, 1, -1, 1, -1 ] ], 1 ], - [ [ [ -2, 0, 1, 0, 1, 0 ], [ -1, -1, 1, 0, 1, 1 ], [ 0, -1, 1, 0, 1, 0 ], [ 0, -1, 1, 1, 1, 0 ] ], 0 ], - [ [ [ -2, 0, 1, 0, 1, 0 ], [ -1, -1, 1, 1, 1, 0 ], [ 0, -1, 1, 0, 1, 0 ], [ 0, -1, 1, 1, 1, 0 ] ], 1.25 ], - [ [ [ -2, 0, 1, 0, 1, 0 ], [ -1, -1, 2, 0, 1, 0 ], [ 0, -1, 1, 0, 1, 0 ], [ 0, -1, 1, 1, 1, 0 ] ], 0 ], - [ [ [ -2, 0, 1, 0, 1, 0 ], [ -1, -1, 2, 0, 1, 0 ], [ 0, -1, 1, 0, 1, 0 ], [ 0, -1, 1, 0, 2, 0 ] ], 1.125 ], - [ [ [ -2, 0, 1, 0, 1, 0 ], [ -1, -1, 2, 0, 1, 0 ], [ 0, -1, 1, 0, 1, 0 ], [ 1, -1, 1, 0, 1, 0 ] ], 0 ], - [ [ [ -1, -1, 1, 0, 1, 0 ], [ -1, -1, 2, 0, 1, 0 ], [ 0, -1, 1, 0, 1, 0 ], [ 1, -1, 1, 0, 1, 0 ] ], 0.875 ], - [ [ [ -1, -1, 1, 0, 1, 0 ], [ -1, -1, 2, 0, 1, 0 ], [ 0, -1, 1, 0, 1, 0 ], [ 1, -1, 1, 0, 1, 0 ] ], 2 ], - [ [ [ -1, -1, 1, 0, 1, 0 ], [ -1, -1, 2, 0, 1, 0 ], [ 0, -1, 1, 0, 1, 0 ], [ 1, -1, 1, 0, 1, 0 ] ], 0], - [ [ [ -1, -1, 1, 0, 1, 0 ], [ -1, -1, 2, 0, 1, 0 ], [ 0, -1, 1, 0, 1, 0 ], [ "Rest" ] ], 0 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 2.875 ] - ] - ] -], -"last_changes": -[ - [ [ -2, 0, 1, 0, 1, 0 ], [ -1, -1, 1, 1, 1, 0 ], [ 0, -1, 1, 0, 1, 0 ], [ 0, -1, 1, 1, 1, 0 ] ], - [ [ -2, 0, 1, 0, 1, 0 ], [ -1, -1, 2, 0, 1, 0 ], [ 0, -1, 1, 0, 1, 0 ], [ 0, -1, 1, 1, 1, 0 ] ], - [ [ -2, 0, 1, 0, 1, 0 ], [ -1, -1, 2, 0, 1, 0 ], [ 0, -1, 1, 0, 1, 0 ], [ 0, -1, 1, 0, 2, 0 ] ], - [ [ -2, 0, 1, 0, 1, 0 ], [ -1, -1, 2, 0, 1, 0 ], [ 0, -1, 1, 0, 1, 0 ], [ 1, -1, 1, 0, 1, 0 ] ], - [ [ -1, -1, 1, 0, 1, 0 ], [ -1, -1, 2, 0, 1, 0 ], [ 0, -1, 1, 0, 1, 0 ], [ 1, -1, 1, 0, 1, 0 ] ] -], -"cur_uid": "774ed940", -"ref_uid": "61ce9067", -"order_seed": 473248, -"dur_seed": 979780, -"motifs_seed": 262605, -"entrances_probs_vals": [ 1, 0, 0, 0.19, 1.7582417582418, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 0.85, 0, 1.2301587301587, 0.54945054945055, 1.79, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 1, 0.16, 1.0714285714286, 0.16, 1.510989010989, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -2560, 59.442724458204 ], [ -1074, 393.8080495356 ], [ 59.442724458205, 1638.3900928793 ], [ -52.012383900929, 1582.6625386997 ] ], -"step_probs_vals": [ 0, 1200, 0, 0, 0.092592592592593, 0.78977272727273, 0.16460905349794, 0, 0.24279835390947, 0, 0.60699588477366, 0.63636363636364, 0.73662551440329, 0, 1, 0 ], -"passages_weights": [ 1, 0, 0.6, 0, 0.54 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 3 ], [ 0, 0, 0, 0 ], [ 1, 2 ] ], - [ [ 0 ], [ 3, 2, 1, 1, 1, 3, 1, 1 ], [ ] ], - [ [ 2 ], [ 1, 0, 3, 1, 1, 3, 3, 0 ], [ ] ] -], -"sus_weights": [ 0.69, 0, 0 ], -"order_size": [ 1, 7 ], -"passages_size": [ 3, 6 ], -"motif_edited": "true", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/774ed940/lilypond/part_I.ly b/resources/resources_bak_2024_01_03/string_quartet_1/774ed940/lilypond/part_I.ly deleted file mode 100644 index 2b16ea6..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/774ed940/lilypond/part_I.ly +++ /dev/null @@ -1,22 +0,0 @@ -{ - { g'1^\markup { \pad-markup #0.2 "-2"} ~ } - \bar "|" - { g'1 ~ } - \bar "|" - { g'2. ~ g'16[ c'8.^\markup { \pad-markup #0.2 "-31"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }}] ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'4 ~ c'16[ gis'8.^\markup { \pad-markup #0.2 "+26"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↓" }}] ~ gis'2 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'2 c''2^\markup { \pad-markup #0.2 "+5"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 7↑" }} ~ } - \bar "|" - { c''8[ gis'8^\markup { \pad-markup #0.2 "-13"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 11↑" }}] ~ gis'4 ~ gis'8.[ d''16^\markup { \pad-markup #0.2 "+36"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 1↑" }}] ~ d''4 ~ } - \bar "|" - { d''1 ~ } - \bar "|" - { d''8[ r8] r2. } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/774ed940/lilypond/part_II.ly b/resources/resources_bak_2024_01_03/string_quartet_1/774ed940/lilypond/part_II.ly deleted file mode 100644 index 86115b1..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/774ed940/lilypond/part_II.ly +++ /dev/null @@ -1,22 +0,0 @@ -{ - { r1 } - \bar "|" - { r1 } - \bar "|" - { r2. r16[ d'8.^\markup { \pad-markup #0.2 "+36"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↑" }}] ~ } - \bar "|" - { d'1 ~ } - \bar "|" - { d'1 ~ } - \bar "|" - { d'1 ~ } - \bar "|" - { d'1 ~ } - \bar "|" - { d'1 ~ } - \bar "|" - { d'1 ~ } - \bar "|" - { d'8[ r8] r2. } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/774ed940/lilypond/part_III.ly b/resources/resources_bak_2024_01_03/string_quartet_1/774ed940/lilypond/part_III.ly deleted file mode 100644 index 9d65346..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/774ed940/lilypond/part_III.ly +++ /dev/null @@ -1,22 +0,0 @@ -{ - { r1 } - \bar "|" - { r1 } - \bar "|" - { r2. r16[ a8.^\markup { \pad-markup #0.2 "-47"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }}] ~ } - \bar "|" - { a2 ~ a16[ gis8.^\markup { \pad-markup #0.2 "+26"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↓" }}] ~ gis4 ~ } - \bar "|" - { gis4 ~ gis16[ d8.^\markup { \pad-markup #0.2 "+36"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 1↑" }}] ~ d2 ~ } - \bar "|" - { d16[ ais8.^\markup { \pad-markup #0.2 "+18"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 11↑" }}] ~ ais8[ ais8^\markup { \pad-markup #0.2 "-35"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }}] ~ ais2 } - \bar "|" - { b2^\markup { \pad-markup #0.2 "-24"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 13↑" }} c'2^\markup { \pad-markup #0.2 "+5"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }} ~ } - \bar "|" - { c'8[ fis8^\markup { \pad-markup #0.2 "+22"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 5↑" }}] ~ fis2. ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis8[ r8] r2. } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/774ed940/lilypond/part_IV.ly b/resources/resources_bak_2024_01_03/string_quartet_1/774ed940/lilypond/part_IV.ly deleted file mode 100644 index c7d9483..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/774ed940/lilypond/part_IV.ly +++ /dev/null @@ -1,22 +0,0 @@ -{ - { r8[ dis8^\markup { \pad-markup #0.2 "+39"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 13↑" }}] ~ dis8[ d8^\markup { \pad-markup #0.2 "+0"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↑" }}] ~ d2 } - \bar "|" - { dis4^\markup { \pad-markup #0.2 "+39"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 13↑" }} ~ dis8[ f8^\markup { \pad-markup #0.2 "-33"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 7↑" }}] ~ f2 ~ } - \bar "|" - { f1 ~ } - \bar "|" - { f1 ~ } - \bar "|" - { f1 ~ } - \bar "|" - { f1 } - \bar "|" - { a,1^\markup { \pad-markup #0.2 "+38"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↑" }} ~ } - \bar "|" - { a,2 ~ a,8.[ d16^\markup { \pad-markup #0.2 "+36"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 1↑" }}] ~ d4 ~ } - \bar "|" - { d1 ~ } - \bar "|" - { d8[ r8] r2. } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/784130cc/784130cc_code.scd b/resources/resources_bak_2024_01_03/string_quartet_1/784130cc/784130cc_code.scd deleted file mode 100644 index a98b916..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/784130cc/784130cc_code.scd +++ /dev/null @@ -1,945 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance); -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/784130cc/784130cc_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_1/784130cc/784130cc_mus_model.json deleted file mode 100644 index 697284e..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/784130cc/784130cc_mus_model.json +++ /dev/null @@ -1,53 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ 1, 0, 1, -2, 1, 1 ] ], 1.75 ], - [ [ [ "Rest" ], [ "Rest" ], [ 1, -1, 1, -2, 1, 1 ], [ 1, 0, 1, -2, 1, 1 ] ], 1.5 ] - ], - [ - [ [ [ "Rest" ], [ "Rest" ], [ 1, -1, 1, -2, 1, 1 ], [ "Rest" ] ], 0 ], - [ [ [ "Rest" ], [ 1, -1, 1, -2, 2, 0 ], [ 1, -1, 1, -2, 1, 1 ], [ "Rest" ] ], 1.5 ], - [ [ [ "Rest" ], [ 1, -1, 1, -2, 2, 0 ], [ 2, -1, 1, -2, 2, -1 ], [ "Rest" ] ], 0 ], - [ [ [ 0, -1, 1, -2, 2, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 2, -1, 1, -2, 2, -1 ], [ "Rest" ] ], 0.75 ], - [ [ [ 0, -1, 1, -2, 2, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 1, 0, 1, -2, 2, 0 ], [ "Rest" ] ], 0.75 ], - [ [ [ -1, -1, 1, -2, 2, 1 ], [ 1, -1, 1, -2, 2, 0 ], [ 1, 0, 1, -2, 2, 0 ], [ "Rest" ] ], 1.625 ], - [ [ [ -1, -1, 1, -2, 2, 1 ], [ 1, -1, 1, -2, 2, 0 ], [ "Rest" ], [ "Rest" ] ], 1.125 ], - [ [ [ -1, -1, 1, -2, 2, 1 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 0.625 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 2.375 ] - ] - ] -], -"last_changes": -[ - [ [ 1, -1, 1, -3, 2, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 1, -1, 1, -2, 1, 1 ], [ 1, 0, 1, -2, 1, 1 ] ], - [ [ 1, -1, 1, -3, 2, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 2, -1, 1, -2, 2, -1 ], [ 1, 0, 1, -2, 1, 1 ] ], - [ [ 0, -1, 1, -2, 2, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 2, -1, 1, -2, 2, -1 ], [ 1, 0, 1, -2, 1, 1 ] ], - [ [ 0, -1, 1, -2, 2, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 1, 0, 1, -2, 2, 0 ], [ 1, 0, 1, -2, 1, 1 ] ], - [ [ -1, -1, 1, -2, 2, 1 ], [ 1, -1, 1, -2, 2, 0 ], [ 1, 0, 1, -2, 2, 0 ], [ 1, 0, 1, -2, 1, 1 ] ] -], -"cur_uid": "784130cc", -"ref_uid": "6d635e88", -"order_seed": 516056, -"dur_seed": 358555, -"motifs_seed": 830376, -"entrances_probs_vals": [ 0.18, 0.28, 1.4285714285714, 0.47, 1.62, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 0.29, 0, 1.1111111111111, 0.65934065934066, 1.37, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 0.18, 0.28, 1.4285714285714, 0.47, 1.62, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -2411.1455108359, -850.77399380805 ], [ -1872, 450 ], [ -479, 1304.0247678019 ], [ -368, 1173.9938080495 ] ], -"step_probs_vals": [ 0, 1200, 0, 0, 0.082304526748971, 0.99431818181818, 0.33950617283951, 0, 0.72839506172839, 0, 1, 0 ], -"passages_weights": [ 0.35, 0.42, 0.75, 0.9, 0.93 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 3 ], [ 2 ], [ 0, 1 ] ], - [ [ 1 ], [ 2, 0, 2, 0 ], [ 3 ] ] -], -"sus_weights": [ 0.41, 0, 0 ], -"order_size": [ 2, 6 ], -"passages_size": [ 0, 5 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/784130cc/lilypond/part_I.ly b/resources/resources_bak_2024_01_03/string_quartet_1/784130cc/lilypond/part_I.ly deleted file mode 100644 index 18a5337..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/784130cc/lilypond/part_I.ly +++ /dev/null @@ -1,14 +0,0 @@ -{ - { ais'1^\markup { \pad-markup #0.2 "+41"} ~ } - \bar "|" - { ais'2 ~ ais'8[ r8] r4 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/784130cc/lilypond/part_II.ly b/resources/resources_bak_2024_01_03/string_quartet_1/784130cc/lilypond/part_II.ly deleted file mode 100644 index 3a20dd1..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/784130cc/lilypond/part_II.ly +++ /dev/null @@ -1,14 +0,0 @@ -{ - { r2. r8[ dis'8^\markup { \pad-markup #0.2 "+39"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↓" }}] ~ } - \bar "|" - { dis'1 ~ } - \bar "|" - { dis'4 ~ dis'8[ e'8^\markup { \pad-markup #0.2 "+9"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 13↓" }}] ~ e'4 gis'4^\markup { \pad-markup #0.2 "-49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }} ~ } - \bar "|" - { gis'2. ~ gis'8.[ r16] } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/784130cc/lilypond/part_III.ly b/resources/resources_bak_2024_01_03/string_quartet_1/784130cc/lilypond/part_III.ly deleted file mode 100644 index 6d5d2d3..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/784130cc/lilypond/part_III.ly +++ /dev/null @@ -1,14 +0,0 @@ -{ - { r1 } - \bar "|" - { r2 r8[ c'8^\markup { \pad-markup #0.2 "+49"}] ~ c'4 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'2 r2 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/784130cc/lilypond/part_IV.ly b/resources/resources_bak_2024_01_03/string_quartet_1/784130cc/lilypond/part_IV.ly deleted file mode 100644 index ed76315..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/784130cc/lilypond/part_IV.ly +++ /dev/null @@ -1,14 +0,0 @@ -{ - { r1 } - \bar "|" - { r1 } - \bar "|" - { r4 r8[ c8^\markup { \pad-markup #0.2 "+49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }}] ~ c2 ~ } - \bar "|" - { c8[ a,8^\markup { \pad-markup #0.2 "-10"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 13↑" }}] ~ a,2. ~ } - \bar "|" - { a,2. ~ a,16[ r8.] } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/79e0a4a7/79e0a4a7_code.scd b/resources/resources_bak_2024_01_03/string_quartet_1/79e0a4a7/79e0a4a7_code.scd deleted file mode 100644 index 8e9fe42..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/79e0a4a7/79e0a4a7_code.scd +++ /dev/null @@ -1,943 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance); -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/79e0a4a7/79e0a4a7_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_1/79e0a4a7/79e0a4a7_mus_model.json deleted file mode 100644 index 4a70a1c..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/79e0a4a7/79e0a4a7_mus_model.json +++ /dev/null @@ -1,47 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ 2, -2, 0, -1, 1, 0 ], [ "Rest" ], [ "Rest" ] ], 4.75 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ "Rest" ], [ "Rest" ] ], 4.25 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ "Rest" ], [ 2, -1, -1, -1, 1, 0 ] ], 1.75 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 1, 0, 0, -1, 1, 0 ], [ 2, -1, -1, -1, 1, 0 ] ], 1.5 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 1, 0, 0, -1, 1, 0 ], [ 3, -2, 0, -1, 1, -1 ] ], 4.375 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ "Rest" ], [ 1, 0, 0, -1, 1, 0 ], [ 3, -2, 0, -1, 1, -1 ] ], 1.125 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ "Rest" ], [ "Rest" ], [ 3, -2, 0, -1, 1, -1 ] ], 1.5 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 0.75 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 6.0 ] - ] - ] -], -"last_changes": -[ - [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 1, -1, 0, -1, 1, -1 ], [ 1, 0, 0, -1, 1, 0 ] ], - [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 1, -1, 0, -1, 1, -1 ], [ 2, -1, -1, -1, 1, 0 ] ], - [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 1, 0, 0, -1, 1, 0 ], [ 2, -1, -1, -1, 1, 0 ] ], - [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 1, 0, 0, -1, 1, 0 ], [ 3, -2, 0, -1, 1, -1 ] ] -], -"cur_uid": "79e0a4a7", -"ref_uid": "6fb60ab6", -"order_seed": 216475, -"dur_seed": 359011, -"motifs_seed": 501751, -"entrances_probs_vals": [ 0, 1.1904761904762, 3.3333333333333, 0.71, 1.9230769230769, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 0, 1.1904761904762, 3.3333333333333, 0.71, 1.9230769230769, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 0, 1.1904761904762, 3.3333333333333, 0.71, 1.9230769230769, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -3600, -312 ], [ -1872, 1378 ], [ -145, 1583 ], [ -182, 1527 ] ], -"step_probs_vals": [ 0, 1200, 0, 0, 0.082304526748971, 0.99431818181818, 0.14197530864198, 0, 1, 0 ], -"passages_weights": [ 0.75, 0.75, 0.75, 0.75, 0.75 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 1, 0 ], [ 3, 2, 3 ], [ ] ] -], -"sus_weights": [ 0, 0.65, 0 ], -"order_size": [ 1, 1 ], -"passages_size": [ 1, 6 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/79e0a4a7/lilypond/part_I.ly b/resources/resources_bak_2024_01_03/string_quartet_1/79e0a4a7/lilypond/part_I.ly deleted file mode 100644 index 3d68499..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/79e0a4a7/lilypond/part_I.ly +++ /dev/null @@ -1,28 +0,0 @@ -{ - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r2 a'2^\markup { \pad-markup #0.2 "-6"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↓" }} ~ } - \bar "|" - { a'1 ~ } - \bar "|" - { a'8[ a'8^\markup { \pad-markup #0.2 "+38"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 13↓" }}] ~ a'2. ~ } - \bar "|" - { a'1 ~ } - \bar "|" - { a'1 ~ } - \bar "|" - { a'2 ~ a'8[ r8] r4 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/79e0a4a7/lilypond/part_II.ly b/resources/resources_bak_2024_01_03/string_quartet_1/79e0a4a7/lilypond/part_II.ly deleted file mode 100644 index 771f45e..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/79e0a4a7/lilypond/part_II.ly +++ /dev/null @@ -1,28 +0,0 @@ -{ - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r4 r8[ gis'8^\markup { \pad-markup #0.2 "-18"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }}] ~ gis'2 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'2. ~ gis'8[ r8] } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/79e0a4a7/lilypond/part_III.ly b/resources/resources_bak_2024_01_03/string_quartet_1/79e0a4a7/lilypond/part_III.ly deleted file mode 100644 index c1f7fda..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/79e0a4a7/lilypond/part_III.ly +++ /dev/null @@ -1,28 +0,0 @@ -{ - { fis'1^\markup { \pad-markup #0.2 "-21"} ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'4 ~ fis'16[ r8.] r2 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/79e0a4a7/lilypond/part_IV.ly b/resources/resources_bak_2024_01_03/string_quartet_1/79e0a4a7/lilypond/part_IV.ly deleted file mode 100644 index 5984926..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/79e0a4a7/lilypond/part_IV.ly +++ /dev/null @@ -1,28 +0,0 @@ -{ - { r1 } - \bar "|" - { r1 } - \bar "|" - { r4 r8[ cis'8^\markup { \pad-markup #0.2 "-19"}] ~ cis'2 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/7d3c9a80/7d3c9a80_code.scd b/resources/resources_bak_2024_01_03/string_quartet_1/7d3c9a80/7d3c9a80_code.scd deleted file mode 100644 index a98b916..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/7d3c9a80/7d3c9a80_code.scd +++ /dev/null @@ -1,945 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance); -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/7d3c9a80/7d3c9a80_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_1/7d3c9a80/7d3c9a80_mus_model.json deleted file mode 100644 index e6e1f1a..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/7d3c9a80/7d3c9a80_mus_model.json +++ /dev/null @@ -1,48 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ 2, -2, 0, -1, 1, 0 ], [ "Rest" ], [ "Rest" ] ], 6.25 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ "Rest" ], [ "Rest" ] ], 4.25 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ "Rest" ], [ 3, -2, 0, -1, 0, 0 ] ], 1.75 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 3, -2, 0, -1, 1, -1 ], [ 3, -2, 0, -1, 0, 0 ] ], 2.75 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 3, -2, 0, -1, 1, -1 ], [ 2, -1, 0, -1, 1, 0 ] ], 3.875 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ "Rest" ], [ 3, -2, 0, -1, 1, -1 ], [ 2, -1, 0, -1, 1, 0 ] ], 1.75 ], - [ [ [ 1, -1, 0, -1, 1, 0 ], [ "Rest" ], [ "Rest" ], [ 2, -1, 0, -1, 1, 0 ] ], 0.75 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ 2, -1, 0, -1, 1, 0 ] ], 1.25 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 5.375 ] - ] - ] -], -"last_changes": -[ - [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 3, -2, 0, -2, 1, 0 ], [ 3, -3, 0, -1, 1, 0 ] ], - [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 3, -2, 0, -2, 1, 0 ], [ 2, -2, 0, -1, 2, 0 ] ], - [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 3, -2, 0, -2, 1, 0 ], [ 3, -2, 0, -1, 0, 0 ] ], - [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 3, -2, 0, -1, 1, -1 ], [ 3, -2, 0, -1, 0, 0 ] ], - [ [ 1, -1, 0, -1, 1, 0 ], [ 2, -2, 0, -1, 1, 0 ], [ 3, -2, 0, -1, 1, -1 ], [ 2, -1, 0, -1, 1, 0 ] ] -], -"cur_uid": "7d3c9a80", -"ref_uid": "43b009ff", -"order_seed": 216475, -"dur_seed": 155918, -"motifs_seed": 903149, -"entrances_probs_vals": [ 0, 1.1904761904762, 3.3333333333333, 0.71, 1.92, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 0, 1.1904761904762, 3.3333333333333, 0.71, 1.92, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 0, 1.1904761904762, 3.3333333333333, 0.71, 1.92, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -3600, -312 ], [ -1872, 1378 ], [ -145, 1583 ], [ -182, 1527 ] ], -"step_probs_vals": [ 0, 1200, 0, 0, 0.082304526748971, 0.99431818181818, 0.14197530864198, 0, 1, 0 ], -"passages_weights": [ 0.75, 0.75, 0.75, 0.75, 0.75 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 1, 0 ], [ 3, 2, 3 ], [ ] ] -], -"sus_weights": [ 0, 0.65, 0 ], -"order_size": [ 1, 1 ], -"passages_size": [ 1, 6 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/7d3c9a80/lilypond/part_I.ly b/resources/resources_bak_2024_01_03/string_quartet_1/7d3c9a80/lilypond/part_I.ly deleted file mode 100644 index e9da74f..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/7d3c9a80/lilypond/part_I.ly +++ /dev/null @@ -1,30 +0,0 @@ -{ - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r4 c''2.^\markup { \pad-markup #0.2 "+27"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 11↓" }} ~ } - \bar "|" - { c''1 ~ } - \bar "|" - { c''2 cis''2^\markup { \pad-markup #0.2 "-19"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }} ~ } - \bar "|" - { cis''1 ~ } - \bar "|" - { cis''1 ~ } - \bar "|" - { cis''1 ~ } - \bar "|" - { cis''4 ~ cis''16[ r8.] r2 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/7d3c9a80/lilypond/part_II.ly b/resources/resources_bak_2024_01_03/string_quartet_1/7d3c9a80/lilypond/part_II.ly deleted file mode 100644 index 544ce2c..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/7d3c9a80/lilypond/part_II.ly +++ /dev/null @@ -1,30 +0,0 @@ -{ - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r8[ a'8^\markup { \pad-markup #0.2 "+38"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 13↓" }}] ~ a'2. ~ } - \bar "|" - { a'1 ~ } - \bar "|" - { a'1 ~ } - \bar "|" - { a'1 ~ } - \bar "|" - { a'4 ~ a'16[ r8.] r2 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/7d3c9a80/lilypond/part_III.ly b/resources/resources_bak_2024_01_03/string_quartet_1/7d3c9a80/lilypond/part_III.ly deleted file mode 100644 index 924f946..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/7d3c9a80/lilypond/part_III.ly +++ /dev/null @@ -1,30 +0,0 @@ -{ - { fis'1^\markup { \pad-markup #0.2 "-21"} ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'4 ~ fis'8.[ r16] r2 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/7d3c9a80/lilypond/part_IV.ly b/resources/resources_bak_2024_01_03/string_quartet_1/7d3c9a80/lilypond/part_IV.ly deleted file mode 100644 index 91a8502..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/7d3c9a80/lilypond/part_IV.ly +++ /dev/null @@ -1,30 +0,0 @@ -{ - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r8[ cis'8^\markup { \pad-markup #0.2 "-19"}] ~ cis'2. ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'2 ~ cis'8.[ r16] r4 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/7edbdceb/7edbdceb_code.scd b/resources/resources_bak_2024_01_03/string_quartet_1/7edbdceb/7edbdceb_code.scd deleted file mode 100644 index a98b916..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/7edbdceb/7edbdceb_code.scd +++ /dev/null @@ -1,945 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance); -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/7edbdceb/7edbdceb_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_1/7edbdceb/7edbdceb_mus_model.json deleted file mode 100644 index fe59e9c..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/7edbdceb/7edbdceb_mus_model.json +++ /dev/null @@ -1,53 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ 1, 0, 1, -2, 1, 1 ] ], 1.75 ], - [ [ [ "Rest" ], [ "Rest" ], [ 1, 0, 1, -2, 0, 1 ], [ 1, 0, 1, -2, 1, 1 ] ], 1.5 ] - ], - [ - [ [ [ "Rest" ], [ "Rest" ], [ 1, 0, 1, -2, 0, 1 ], [ "Rest" ] ], 0 ], - [ [ [ "Rest" ], [ 1, -1, 1, -2, 2, 0 ], [ 1, 0, 1, -2, 0, 1 ], [ "Rest" ] ], 1.5 ], - [ [ [ "Rest" ], [ 1, -1, 1, -2, 2, 0 ], [ 1, -1, 2, -2, 2, 0 ], [ "Rest" ] ], 0 ], - [ [ [ 0, -1, 1, -2, 2, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 1, -1, 2, -2, 2, 0 ], [ "Rest" ] ], 0.75 ], - [ [ [ 0, -1, 1, -2, 2, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 2, -2, 1, -2, 2, 0 ], [ "Rest" ] ], 0.75 ], - [ [ [ -1, -1, 1, -1, 2, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 2, -2, 1, -2, 2, 0 ], [ "Rest" ] ], 1.625 ], - [ [ [ -1, -1, 1, -1, 2, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ "Rest" ], [ "Rest" ] ], 1.125 ], - [ [ [ -1, -1, 1, -1, 2, 0 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 0.625 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 2.375 ] - ] - ] -], -"last_changes": -[ - [ [ 1, -1, 1, -3, 2, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 1, 0, 1, -2, 0, 1 ], [ 1, 0, 1, -2, 1, 1 ] ], - [ [ 1, -1, 1, -3, 2, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 1, -1, 2, -2, 2, 0 ], [ 1, 0, 1, -2, 1, 1 ] ], - [ [ 0, -1, 1, -2, 2, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 1, -1, 2, -2, 2, 0 ], [ 1, 0, 1, -2, 1, 1 ] ], - [ [ 0, -1, 1, -2, 2, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 2, -2, 1, -2, 2, 0 ], [ 1, 0, 1, -2, 1, 1 ] ], - [ [ -1, -1, 1, -1, 2, 0 ], [ 1, -1, 1, -2, 2, 0 ], [ 2, -2, 1, -2, 2, 0 ], [ 1, 0, 1, -2, 1, 1 ] ] -], -"cur_uid": "7edbdceb", -"ref_uid": "6d635e88", -"order_seed": 516056, -"dur_seed": 358555, -"motifs_seed": 481455, -"entrances_probs_vals": [ 0.18, 0.28, 1.4285714285714, 0.47, 1.62, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 0.29, 0, 1.1111111111111, 0.65934065934066, 1.37, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 0.18, 0.28, 1.4285714285714, 0.47, 1.62, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -2411.1455108359, -850.77399380805 ], [ -1872, 450 ], [ -479, 1304.0247678019 ], [ -368, 1173.9938080495 ] ], -"step_probs_vals": [ 0, 1200, 0, 0, 0.082304526748971, 0.99431818181818, 0.33950617283951, 0, 0.72839506172839, 0, 1, 0 ], -"passages_weights": [ 0.35, 0.42, 0.75, 0.9, 0.93 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 3 ], [ 2 ], [ 0, 1 ] ], - [ [ 1 ], [ 2, 0, 2, 0 ], [ 3 ] ] -], -"sus_weights": [ 0.41, 0, 0 ], -"order_size": [ 2, 6 ], -"passages_size": [ 0, 5 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/7edbdceb/lilypond/part_I.ly b/resources/resources_bak_2024_01_03/string_quartet_1/7edbdceb/lilypond/part_I.ly deleted file mode 100644 index 18a5337..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/7edbdceb/lilypond/part_I.ly +++ /dev/null @@ -1,14 +0,0 @@ -{ - { ais'1^\markup { \pad-markup #0.2 "+41"} ~ } - \bar "|" - { ais'2 ~ ais'8[ r8] r4 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/7edbdceb/lilypond/part_II.ly b/resources/resources_bak_2024_01_03/string_quartet_1/7edbdceb/lilypond/part_II.ly deleted file mode 100644 index d0647dd..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/7edbdceb/lilypond/part_II.ly +++ /dev/null @@ -1,14 +0,0 @@ -{ - { r2. r8[ f'8^\markup { \pad-markup #0.2 "-11"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 11↓" }}] ~ } - \bar "|" - { f'1 ~ } - \bar "|" - { f'4 ~ f'8[ e'8^\markup { \pad-markup #0.2 "+36"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 5↑" }}] ~ e'4 f'4^\markup { \pad-markup #0.2 "+47"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }} ~ } - \bar "|" - { f'2. ~ f'8.[ r16] } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/7edbdceb/lilypond/part_III.ly b/resources/resources_bak_2024_01_03/string_quartet_1/7edbdceb/lilypond/part_III.ly deleted file mode 100644 index 6d5d2d3..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/7edbdceb/lilypond/part_III.ly +++ /dev/null @@ -1,14 +0,0 @@ -{ - { r1 } - \bar "|" - { r2 r8[ c'8^\markup { \pad-markup #0.2 "+49"}] ~ c'4 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'2 r2 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/7edbdceb/lilypond/part_IV.ly b/resources/resources_bak_2024_01_03/string_quartet_1/7edbdceb/lilypond/part_IV.ly deleted file mode 100644 index a86ce2c..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/7edbdceb/lilypond/part_IV.ly +++ /dev/null @@ -1,14 +0,0 @@ -{ - { r1 } - \bar "|" - { r1 } - \bar "|" - { r4 r8[ c8^\markup { \pad-markup #0.2 "+49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }}] ~ c2 ~ } - \bar "|" - { c8[ ais,8^\markup { \pad-markup #0.2 "+18"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 7↑" }}] ~ ais,2. ~ } - \bar "|" - { ais,2. ~ ais,16[ r8.] } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_1/tmp/tmp_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_1/tmp/tmp_mus_model.json deleted file mode 100644 index 1beabb8..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_1/tmp/tmp_mus_model.json +++ /dev/null @@ -1,78 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ "Rest" ], [ 2, -1, 1, -2, 1, 0 ], [ "Rest" ] ], 2.75 ], - [ [ [ 2, -1, 1, -2, 0, 0 ], [ "Rest" ], [ 2, -1, 1, -2, 1, 0 ], [ "Rest" ] ], 0.375 ], - [ [ [ 1, -1, 2, -2, 1, 0 ], [ "Rest" ], [ 2, -1, 1, -2, 1, 0 ], [ "Rest" ] ], 3.75 ] - ], - [ - [ [ [ 1, -1, 2, -2, 1, 0 ], [ "Rest" ], [ 2, -1, 1, -2, 1, 0 ], [ 2, -2, 1, -1, 1, 0 ] ], 0 ], - [ [ [ 1, -1, 2, -2, 1, 0 ], [ 3, -3, 1, -2, 1, 0 ], [ 2, -1, 1, -2, 1, 0 ], [ 2, -2, 1, -1, 1, 0 ] ], 3.375 ], - [ [ [ 1, -1, 2, -2, 1, 0 ], [ 3, -3, 1, -2, 1, 0 ], [ 3, -3, 1, -2, 0, 0 ], [ 2, -2, 1, -1, 1, 0 ] ], 1 ], - [ [ [ 1, -1, 2, -2, 1, 0 ], [ 3, -3, 1, -2, 1, 0 ], [ 0, 0, 2, -2, 1, 0 ], [ 2, -2, 1, -1, 1, 0 ] ], 2 ] - ], - [ - [ [ [ 0, 1, 2, -2, 1, 0 ], [ 3, -3, 1, -2, 1, 0 ], [ 0, 0, 2, -2, 1, 0 ], [ 2, -2, 1, -1, 1, 0 ] ], 1.125 ], - [ [ [ 2, -3, 1, -1, 1, 0 ], [ 3, -3, 1, -2, 1, 0 ], [ 0, 0, 2, -2, 1, 0 ], [ 2, -2, 1, -1, 1, 0 ] ], 3 ] - ], - [ - [ [ [ 2, -3, 1, -1, 1, 0 ], [ 3, -3, 1, -2, 1, 0 ], [ 0, 0, 2, -2, 1, 0 ], [ 2, -3, 0, -1, 1, 0 ] ], 0.875 ], - [ [ [ 2, -3, 1, -1, 1, 0 ], [ 3, -3, 1, -2, 1, 0 ], [ 0, 0, 2, -2, 1, 0 ], [ 1, -3, 1, 0, 1, 0 ] ], 1.375 ] - ], - [ - [ [ [ 1, -3, 1, 0, 0, 0 ], [ 3, -3, 1, -2, 1, 0 ], [ 0, 0, 2, -2, 1, 0 ], [ 1, -3, 1, 0, 1, 0 ] ], 1.125 ], - [ [ [ 3, -3, 1, -2, 1, -1 ], [ 3, -3, 1, -2, 1, 0 ], [ 0, 0, 2, -2, 1, 0 ], [ 1, -3, 1, 0, 1, 0 ] ], 1.875 ] - ], - [ - [ [ [ 3, -3, 1, -2, 1, -1 ], [ 3, -3, 1, -2, 1, 0 ], [ 0, 0, 2, -2, 1, 0 ], [ 1, 0, 1, -2, 1, 0 ] ], 0.875 ], - [ [ [ 3, -3, 1, -2, 1, -1 ], [ 3, -3, 1, -2, 1, 0 ], [ 0, 0, 2, -2, 1, 0 ], [ 0, 0, 2, -2, 2, 0 ] ], 2.125 ] - ], - [ - [ [ [ 3, -4, 1, -2, 1, 0 ], [ 3, -3, 1, -2, 1, 0 ], [ 0, 0, 2, -2, 1, 0 ], [ 0, 0, 2, -2, 2, 0 ] ], 0.875 ], - [ [ [ 3, -3, 1, -2, 0, 0 ], [ 3, -3, 1, -2, 1, 0 ], [ 0, 0, 2, -2, 1, 0 ], [ 0, 0, 2, -2, 2, 0 ] ], 1.625 ], - [ [ [ 3, -3, 1, -2, 0, 0 ], [ 3, -3, 1, -2, 1, 0 ], [ "Rest" ], [ 0, 0, 2, -2, 2, 0 ] ], 0.75 ], - [ [ [ "Rest" ], [ 3, -3, 1, -2, 1, 0 ], [ "Rest" ], [ 0, 0, 2, -2, 2, 0 ] ], 1.125 ], - [ [ [ "Rest" ], [ 3, -3, 1, -2, 1, 0 ], [ "Rest" ], [ "Rest" ] ], 1.25 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 4.75 ] - ] - ] -], -"last_changes": -[ - [ [ 3, -3, 1, -2, 1, -1 ], [ 3, -3, 1, -2, 1, 0 ], [ 0, 0, 2, -2, 1, 0 ], [ 1, -3, 1, 0, 1, 0 ] ], - [ [ 3, -3, 1, -2, 1, -1 ], [ 3, -3, 1, -2, 1, 0 ], [ 0, 0, 2, -2, 1, 0 ], [ 1, 0, 1, -2, 1, 0 ] ], - [ [ 3, -3, 1, -2, 1, -1 ], [ 3, -3, 1, -2, 1, 0 ], [ 0, 0, 2, -2, 1, 0 ], [ 0, 0, 2, -2, 2, 0 ] ], - [ [ 3, -4, 1, -2, 1, 0 ], [ 3, -3, 1, -2, 1, 0 ], [ 0, 0, 2, -2, 1, 0 ], [ 0, 0, 2, -2, 2, 0 ] ], - [ [ 3, -3, 1, -2, 0, 0 ], [ 3, -3, 1, -2, 1, 0 ], [ 0, 0, 2, -2, 1, 0 ], [ 0, 0, 2, -2, 2, 0 ] ] -], -"cur_uid": "tmp", -"ref_uid": "6ed95c4c", -"order_seed": 290117, -"dur_seed": 200959, -"motifs_seed": 970117, -"entrances_probs_vals": [ 0.75, 0, 5.0793650793651, 0, 0.5, 0.26424870466321, 0.75675675675676, 0.5, 0.5, 0.58549222797927, 0.72635135135135, 1, 0.5 ], -"passages_probs_vals": [ 0.27, 0, 2.7380952380952, 0.24725274725275, 1.48, 0.20725388601036, 0.68581081081081, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"exits_probs_vals": [ 0.27, 0, 2.7380952380952, 0.24725274725275, 1.48, 0.20725388601036, 0.68581081081081, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"ranges": [ [ -1482.3529411765, 542 ], [ -1129.4117647059, 1378 ], [ -256.34674922601, 1601 ], [ -238, 1712.693498452 ] ], -"step_probs_vals": [ -1200, 1200, 0, 0, 0.19135802469136, 0.27272727272727, 0.2962962962963, 0, 0.33539094650206, 0, 0.34362139917695, 0, 0.38271604938272, 0.15340909090909, 0.39711934156379, 0.56818181818182, 0.43415637860082, 0, 0.51028806584362, 0, 0.56172839506173, 0.84090909090909, 0.61316872427984, 0, 0.69135802469136, 0.28977272727273, 0.73662551440329, 0, 0.97736625514403, 0 ], -"passages_weights": [ 0.75, 0.75, 0.75, 0.75, 0.75 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 2 ], [ 0, 0 ], [ 3, 1 ] ], - [ [ 0, 3, 1 ], [ 2, 2 ], [ ] ], - [ [ 1, 3, 2 ], [ 0, 0 ], [ ] ], - [ [ 2, 0, 1 ], [ 3, 3 ], [ ] ], - [ [ 3, 1, 2 ], [ 0, 0 ], [ ] ], - [ [ 0, 2, 1 ], [ 3, 3 ], [ ] ], - [ [ 2, 3, 1 ], [ 0, 0 ], [ ] ] -], -"sus_weights": [ 0.45, 0.3, 0.38 ], -"order_size": [ 6.0510204081633, 15.142857142857 ], -"passages_size": [ 1, 1 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2.json b/resources/resources_bak_2024_01_03/string_quartet_2.json deleted file mode 100644 index 56e0507..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2.json +++ /dev/null @@ -1,16 +0,0 @@ -{ -"ledger": -[ - "5201b8af", - "525274f2", - "41e447bc", - "74307bb4", - "628706ec", - "4c059f33", - "60adbbef", - "74b8f8d9", - "62300302", - "72dc057f", - "76e45e56" -] -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2.json_bak b/resources/resources_bak_2024_01_03/string_quartet_2.json_bak deleted file mode 100644 index d5a6964..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2.json_bak +++ /dev/null @@ -1,15 +0,0 @@ -{ -"ledger": -[ - "5201b8af", - "525274f2", - "41e447bc", - "74307bb4", - "628706ec", - "4c059f33", - "60adbbef", - "74b8f8d9", - "62300302", - "72dc057f" -] -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/40119c5a/40119c5a_code.scd b/resources/resources_bak_2024_01_03/string_quartet_2/40119c5a/40119c5a_code.scd deleted file mode 100644 index c194eef..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/40119c5a/40119c5a_code.scd +++ /dev/null @@ -1,945 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance); -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/40119c5a/40119c5a_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_2/40119c5a/40119c5a_mus_model.json deleted file mode 100644 index 776b240..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/40119c5a/40119c5a_mus_model.json +++ /dev/null @@ -1,58 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 3.875 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ], [ 1, 0, 0, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 1, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, 0, -1, 0 ], [ 0, 0, 1, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ] ], 4.875 ] - ], - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, 0, -1, 0 ], [ 1, 0, 0, 0, 0, -1 ], [ 1, 0, 0, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ], [ 1, 0, 0, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ], [ 0, 0, 1, 0, 0, 0 ] ], 4.75 ] - ], - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, -1, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], 4.125 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, -1, 0, 0, 0 ], [ "Rest" ], [ 1, 0, 0, 0, 0, -1 ] ], 0 ], - [ [ [ "Rest" ], [ 1, 0, -1, 0, 0, 0 ], [ "Rest" ], [ 1, 0, 0, 0, 0, -1 ] ], 0 ], - [ [ [ "Rest" ], [ 1, 0, -1, 0, 0, 0 ], [ "Rest" ], [ "Rest" ] ], 0 ] - ] - ] -], -"last_changes": -[ - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 1, 0, 0 ], [ 0, 0, 0, 0, 1, 0 ], [ 1, 0, 0, -1, 0, 0 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 1, 0, 0 ], [ 0, 0, 0, 0, 1, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 1, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 1, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ] ] -], -"cur_uid": "40119c5a", -"ref_uid": "77b0d2dc", -"order_seed": 921767, -"dur_seed": 954688, -"motifs_seed": 995213, -"entrances_probs_vals": [ 1, 0, 0, 3.68, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 1, 0, 0, 3.68, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 1, 0, 0, 3.68, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -1315.1702786378, 338.08049535604 ], [ -200.61919504644, 1452.6315789474 ], [ -386, 1675.5417956656 ], [ -219, 1694.1176470588 ] ], -"step_probs_vals": [ 0, 1200, 0, 0, 0.063786008230453, 0.92613636363636, 0.12757201646091, 0, 0.54732510288066, 0, 0.71604938271605, 0, 1, 0 ], -"passages_weights": [ 0.7, 0.29, 0.66, 0.74, 0.68 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 0 ], [ 3, 2, 1 ], [ ] ], - [ [ 0 ], [ 2, 1, 3 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ] -], -"sus_weights": [ 1, 0, 0 ], -"order_size": [ 8, 10 ], -"passages_size": [ 0, 10 ], -"motif_edited": "true", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/41e447bc/41e447bc_code.scd b/resources/resources_bak_2024_01_03/string_quartet_2/41e447bc/41e447bc_code.scd deleted file mode 100644 index c194eef..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/41e447bc/41e447bc_code.scd +++ /dev/null @@ -1,945 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance); -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/41e447bc/41e447bc_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_2/41e447bc/41e447bc_mus_model.json deleted file mode 100644 index 105ee42..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/41e447bc/41e447bc_mus_model.json +++ /dev/null @@ -1,64 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 2.125 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ], [ 1, 0, 0, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 1, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, 0, -1, 0 ], [ 0, 0, 1, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ] ], 4.75 ] - ], - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, 0, -1, 0 ], [ 1, 0, 0, 0, 0, -1 ], [ 1, 0, 0, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ], [ 1, 0, 0, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ], [ 0, 0, 1, 0, 0, 0 ] ], 2.875 ] - ], - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, -1, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], 3.375 ] - ], - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, -1, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 0, 1, -1, 0, 0, 0 ] ], 1.375 ] - ], - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, -1, 1, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 0, 1, -1, 0, 0, 0 ] ], 4.625 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, -1, 1, 0, 0, 0 ], [ "Rest" ], [ 0, 1, -1, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, -1, 1, 0, 0, 0 ], [ "Rest" ], [ "Rest" ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 0 ] - ] - ] -], -"last_changes": -[ - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 1, 0, 0 ], [ 0, 0, 0, 0, 1, 0 ], [ 1, 0, 0, -1, 0, 0 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 1, 0, 0 ], [ 0, 0, 0, 0, 1, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 1, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 1, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ] ] -], -"cur_uid": "41e447bc", -"ref_uid": "77b0d2dc", -"order_seed": 921767, -"dur_seed": 954688, -"motifs_seed": 995213, -"entrances_probs_vals": [ 1, 0, 0, 3.68, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 1, 0, 0, 3.68, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 1, 0, 0, 3.68, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -1315.1702786378, 338.08049535604 ], [ -200.61919504644, 1452.6315789474 ], [ -386, 1675.5417956656 ], [ -219, 1694.1176470588 ] ], -"step_probs_vals": [ 0, 1200, 0, 0, 0.063786008230453, 0.92613636363636, 0.12757201646091, 0, 0.54732510288066, 0, 0.71604938271605, 0, 1, 0 ], -"passages_weights": [ 0.7, 0.29, 0.66, 0.74, 0.68 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 0 ], [ 3, 2, 1 ], [ ] ], - [ [ 0 ], [ 2, 1, 3 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ] -], -"sus_weights": [ 1, 0, 0 ], -"order_size": [ 8, 10 ], -"passages_size": [ 0, 10 ], -"motif_edited": "true", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/41e447bc/lilypond/part_I.ly b/resources/resources_bak_2024_01_03/string_quartet_2/41e447bc/lilypond/part_I.ly deleted file mode 100644 index 9aaa7f4..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/41e447bc/lilypond/part_I.ly +++ /dev/null @@ -1,20 +0,0 @@ -{ - { r1 } - \bar "|" - { r16[ c''8.^\markup { \pad-markup #0.2 "+0"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }}] ~ c''2. ~ } - \bar "|" - { c''1 ~ } - \bar "|" - { c''4 ~ c''8.[ e'16^\markup { \pad-markup #0.2 "-14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }}] ~ e'2 ~ } - \bar "|" - { e'2. ~ e'8[ e'8^\markup { \pad-markup #0.2 "-41"}] ~ } - \bar "|" - { e'1 ~ } - \bar "|" - { e'2 ~ e'16[ dis'8.^\markup { \pad-markup #0.2 "+16"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↑" }}] ~ dis'4 ~ } - \bar "|" - { dis'1 ~ } - \bar "|" - { dis'1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/41e447bc/lilypond/part_II.ly b/resources/resources_bak_2024_01_03/string_quartet_2/41e447bc/lilypond/part_II.ly deleted file mode 100644 index 2fe1107..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/41e447bc/lilypond/part_II.ly +++ /dev/null @@ -1,20 +0,0 @@ -{ - { r1 } - \bar "|" - { r16[ e'8.^\markup { \pad-markup #0.2 "-14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }}] ~ e'2. ~ } - \bar "|" - { e'1 ~ } - \bar "|" - { e'4 ~ e'8.[ e'16^\markup { \pad-markup #0.2 "-41"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↓" }}] ~ e'2 ~ } - \bar "|" - { e'2. ~ e'8[ f'8^\markup { \pad-markup #0.2 "-2"}] ~ } - \bar "|" - { f'1 ~ } - \bar "|" - { f'1 ~ } - \bar "|" - { f'1 ~ } - \bar "|" - { f'1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/41e447bc/lilypond/part_III.ly b/resources/resources_bak_2024_01_03/string_quartet_2/41e447bc/lilypond/part_III.ly deleted file mode 100644 index bfe5f3a..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/41e447bc/lilypond/part_III.ly +++ /dev/null @@ -1,20 +0,0 @@ -{ - { r1 } - \bar "|" - { r16[ fis'8.^\markup { \pad-markup #0.2 "+49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 11↓" }}] ~ fis'2. ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'4 ~ fis'8.[ g'16^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }}] ~ g'2 ~ } - \bar "|" - { g'2. ~ g'8[ gis'8^\markup { \pad-markup #0.2 "+14"}] ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'4 a'2.^\markup { \pad-markup #0.2 "-16"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 5↑" }} ~ } - \bar "|" - { a'1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/41e447bc/lilypond/part_IV.ly b/resources/resources_bak_2024_01_03/string_quartet_2/41e447bc/lilypond/part_IV.ly deleted file mode 100644 index 0787499..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/41e447bc/lilypond/part_IV.ly +++ /dev/null @@ -1,20 +0,0 @@ -{ - { c'1^\markup { \pad-markup #0.2 "+0"} ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/42c3365b/42c3365b_code.scd b/resources/resources_bak_2024_01_03/string_quartet_2/42c3365b/42c3365b_code.scd deleted file mode 100644 index c194eef..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/42c3365b/42c3365b_code.scd +++ /dev/null @@ -1,945 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance); -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/42c3365b/42c3365b_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_2/42c3365b/42c3365b_mus_model.json deleted file mode 100644 index 710f1b3..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/42c3365b/42c3365b_mus_model.json +++ /dev/null @@ -1,123 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ] ], 1.5 ], - [ [ [ -1, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ] ], 1.25 ], - [ [ [ -1, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 1, 0, 0, 0, 0, 0 ] ], 0.5 ], - [ [ [ 1, 0, 0, -1, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 1, 0, 0, 0, 0, 0 ] ], 0.875 ], - [ [ [ 1, 0, 0, -1, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 0, 0, 0, 1 ] ], 1.25 ], - [ [ [ -1, 1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 0, 0, 0, 1 ] ], 0 ] - ], - [ - [ [ [ -1, 1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ] ], 0.75 ], - [ [ [ -1, 1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ] ], 1.375 ], - [ [ [ 0, 0, 0, 0, -1, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ] ], 0.5 ], - [ [ [ 0, 0, 0, 0, -1, 0 ], [ 1, 0, 0, 0, -1, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ] ], 1.375 ], - [ [ [ 0, 0, 0, 0, -1, 0 ], [ 0, 0, 0, 0, 1, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ] ], 0.75 ], - [ [ [ 0, 0, 0, 0, -1, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ] ], 0.125 ], - [ [ [ -1, 0, 0, 0, 1, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ] ], 1 ], - [ [ [ 0, -1, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ] ], 1.375 ], - [ [ [ -1, 0, 1, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ] ], 0.5 ] - ], - [ - [ [ [ -1, 0, 1, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ] ], 0.75 ], - [ [ [ -1, 0, 1, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ "Rest" ], [ 2, -1, 0, 0, 0, -1 ] ], 0.125 ], - [ [ [ -1, -1, 0, 1, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ "Rest" ], [ 2, -1, 0, 0, 0, -1 ] ], 1.375 ], - [ [ [ -1, -1, 0, 1, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ "Rest" ], [ 2, -1, 0, -1, 0, 0 ] ], 0.125 ] - ], - [ - [ [ [ -1, -1, 0, 1, 0, 0 ], [ 1, -1, 0, -1, 0, 1 ], [ "Rest" ], [ 2, -1, 0, -1, 0, 0 ] ], 0.75 ], - [ [ [ 0, -1, 0, -1, 0, 1 ], [ 1, -1, 0, -1, 0, 1 ], [ "Rest" ], [ 2, -1, 0, -1, 0, 0 ] ], 0 ], - [ [ [ 0, -1, 0, -1, 0, 1 ], [ 2, -1, -1, -1, 0, 0 ], [ "Rest" ], [ 2, -1, 0, -1, 0, 0 ] ], 0.875 ], - [ [ [ 0, 0, 0, -1, 0, 0 ], [ 2, -1, -1, -1, 0, 0 ], [ "Rest" ], [ 2, -1, 0, -1, 0, 0 ] ], 0.125 ], - [ [ [ 0, 0, 0, -1, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ "Rest" ], [ 2, -1, 0, -1, 0, 0 ] ], 0.75 ], - [ [ [ 1, -1, 0, -1, -1, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ "Rest" ], [ 2, -1, 0, -1, 0, 0 ] ], 1.375 ], - [ [ [ 0, -1, 0, -1, 1, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ "Rest" ], [ 2, -1, 0, -1, 0, 0 ] ], 0.25 ] - ], - [ - [ [ [ 0, -1, 0, -1, 1, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ "Rest" ], [ 1, 0, 1, -1, 0, 0 ] ], 1.125 ], - [ [ [ -1, 0, 0, 0, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ "Rest" ], [ 1, 0, 1, -1, 0, 0 ] ], 1.375 ], - [ [ [ -1, 0, 0, 0, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ 0, 0, 0, -1, 0, 1 ], [ 1, 0, 1, -1, 0, 0 ] ], 0.25 ], - [ [ [ -1, 0, 0, 0, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ 1, 0, -1, -1, 0, 0 ], [ 1, 0, 1, -1, 0, 0 ] ], 0.625 ], - [ [ [ -1, 0, 0, 0, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ 1, 0, -1, -1, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ] ], 0.375 ], - [ [ [ -1, 0, 0, 0, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ 1, 0, -1, -1, 0, 0 ], [ 1, 0, 0, -1, 0, 1 ] ], 0.125 ], - [ [ [ 1, 0, 0, -1, -1, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ 1, 0, -1, -1, 0, 0 ], [ 1, 0, 0, -1, 0, 1 ] ], 1.5 ], - [ [ [ 1, 0, 0, -1, -1, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ 0, 1, 0, -1, 0, 0 ], [ 1, 0, 0, -1, 0, 1 ] ], 0.875 ] - ], - [ - [ [ [ -1, 2, 0, -1, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ 0, 1, 0, -1, 0, 0 ], [ 1, 0, 0, -1, 0, 1 ] ], 0.625 ], - [ [ [ -1, 2, 0, -1, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ 0, 1, 0, -1, 0, 0 ], [ 1, 1, 0, -1, 0, 0 ] ], 0.125 ], - [ [ [ -1, 2, 0, -1, 0, 0 ], [ 0, 1, 1, -1, 0, 0 ], [ 0, 1, 0, -1, 0, 0 ], [ 1, 1, 0, -1, 0, 0 ] ], 0.125 ] - ], - [ - [ [ [ -1, 2, 0, -1, 0, 0 ], [ 0, 1, 1, -1, 0, 0 ], [ 0, 1, 0, -1, 0, 0 ], [ 1, 2, 0, -1, 0, 0 ] ], 0.375 ], - [ [ [ -1, 2, 0, -1, 0, 0 ], [ 1, 1, 0, -1, 0, -1 ], [ 0, 1, 0, -1, 0, 0 ], [ 1, 2, 0, -1, 0, 0 ] ], 0.25 ], - [ [ [ 0, 1, 0, -1, -1, 0 ], [ 1, 1, 0, -1, 0, -1 ], [ 0, 1, 0, -1, 0, 0 ], [ 1, 2, 0, -1, 0, 0 ] ], 1 ], - [ [ [ 0, 1, 0, -1, -1, 0 ], [ 1, 1, 0, -1, 0, -1 ], [ 0, 1, 0, -1, 0, 0 ], [ 2, 1, 0, -1, -1, 0 ] ], 1 ], - [ [ [ 0, 1, 0, -1, -1, 0 ], [ 1, 1, 0, -1, 0, -1 ], [ 0, 1, 0, -1, 0, 0 ], [ 1, 1, 0, -1, 1, 0 ] ], 0.875 ], - [ [ [ -1, 1, 0, -1, 1, 0 ], [ 1, 1, 0, -1, 0, -1 ], [ 0, 1, 0, -1, 0, 0 ], [ 1, 1, 0, -1, 1, 0 ] ], 0.875 ], - [ [ [ 0, 0, 0, -1, 0, 0 ], [ 1, 1, 0, -1, 0, -1 ], [ 0, 1, 0, -1, 0, 0 ], [ 1, 1, 0, -1, 1, 0 ] ], 1.25 ], - [ [ [ 0, 1, 0, -1, 0, -1 ], [ 1, 1, 0, -1, 0, -1 ], [ 0, 1, 0, -1, 0, 0 ], [ 1, 1, 0, -1, 1, 0 ] ], 0.375 ], - [ [ [ 0, 1, 0, -1, 0, -1 ], [ 0, 1, 1, -1, 0, 0 ], [ 0, 1, 0, -1, 0, 0 ], [ 1, 1, 0, -1, 1, 0 ] ], 1.5 ], - [ [ [ 0, 1, 0, -2, 0, 0 ], [ 0, 1, 1, -1, 0, 0 ], [ 0, 1, 0, -1, 0, 0 ], [ 1, 1, 0, -1, 1, 0 ] ], 0.375 ], - [ [ [ 0, 1, 0, -2, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ 0, 1, 0, -1, 0, 0 ], [ 1, 1, 0, -1, 1, 0 ] ], 0.25 ], - [ [ [ 0, 1, 0, -2, 0, 0 ], [ 0, 1, 0, -1, 1, 0 ], [ 0, 1, 0, -1, 0, 0 ], [ 1, 1, 0, -1, 1, 0 ] ], 0.875 ] - ], - [ - [ [ [ "Rest" ], [ 0, 1, 0, -1, 1, 0 ], [ 0, 1, 0, -1, 0, 0 ], [ 1, 1, 0, -1, 1, 0 ] ], 0.625 ], - [ [ [ "Rest" ], [ 0, 1, 0, -1, 1, 0 ], [ 0, 1, 0, -1, 0, 0 ], [ 1, 1, 0, -1, 1, -1 ] ], 0.5 ], - [ [ [ "Rest" ], [ 0, 1, 0, -1, 1, 0 ], [ -1, 2, 0, -1, 1, 0 ], [ 1, 1, 0, -1, 1, -1 ] ], 1 ], - [ [ [ "Rest" ], [ 0, 1, 0, -1, 1, 0 ], [ 0, 1, -1, -1, 1, 0 ], [ 1, 1, 0, -1, 1, -1 ] ], 1.125 ], - [ [ [ "Rest" ], [ 0, 1, 0, -1, 1, 0 ], [ -1, 1, 0, -1, 1, 1 ], [ 1, 1, 0, -1, 1, -1 ] ], 1.375 ], - [ [ [ "Rest" ], [ 0, 1, 0, -1, 1, 0 ], [ -1, 1, 0, 0, 1, 0 ], [ 1, 1, 0, -1, 1, -1 ] ], 0 ], - [ [ [ "Rest" ], [ 0, 1, 0, -1, 1, 0 ], [ -1, 1, 0, 0, 1, 0 ], [ 0, 1, 1, -1, 1, 0 ] ], 0.125 ], - [ [ [ "Rest" ], [ 0, 1, 0, -1, 1, 0 ], [ -1, 1, 0, 0, 1, 0 ], [ 1, 0, 0, -1, 1, 0 ] ], 1.375 ], - [ [ [ "Rest" ], [ 0, 1, 0, -1, 1, 0 ], [ -1, 2, 0, -1, 1, 0 ], [ 1, 0, 0, -1, 1, 0 ] ], 0.875 ], - [ [ [ "Rest" ], [ 0, 1, 0, -1, 1, 0 ], [ 0, 1, -1, -1, 1, 0 ], [ 1, 0, 0, -1, 1, 0 ] ], 0.375 ], - [ [ [ "Rest" ], [ 0, 1, 0, -1, 1, 0 ], [ 0, 1, -1, -1, 1, 0 ], [ 0, 1, 0, -1, 2, 0 ] ], 0.625 ], - [ [ [ "Rest" ], [ 0, 1, 0, -1, 1, 0 ], [ 0, 1, -1, -1, 1, 0 ], [ "Rest" ] ], 0.5 ], - [ [ [ "Rest" ], [ "Rest" ], [ 0, 1, -1, -1, 1, 0 ], [ "Rest" ] ], 0.625 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 5.125 ] - ] - ] -], -"last_changes": -[ - [ [ 0, 1, 0, -2, 0, 0 ], [ 0, 1, 0, -1, 1, 0 ], [ -1, 1, 0, 0, 1, 0 ], [ 0, 1, 1, -1, 1, 0 ] ], - [ [ 0, 1, 0, -2, 0, 0 ], [ 0, 1, 0, -1, 1, 0 ], [ -1, 1, 0, 0, 1, 0 ], [ 1, 0, 0, -1, 1, 0 ] ], - [ [ 0, 1, 0, -2, 0, 0 ], [ 0, 1, 0, -1, 1, 0 ], [ -1, 2, 0, -1, 1, 0 ], [ 1, 0, 0, -1, 1, 0 ] ], - [ [ 0, 1, 0, -2, 0, 0 ], [ 0, 1, 0, -1, 1, 0 ], [ 0, 1, -1, -1, 1, 0 ], [ 1, 0, 0, -1, 1, 0 ] ], - [ [ 0, 1, 0, -2, 0, 0 ], [ 0, 1, 0, -1, 1, 0 ], [ 0, 1, -1, -1, 1, 0 ], [ 0, 1, 0, -1, 2, 0 ] ] -], -"cur_uid": "42c3365b", -"ref_uid": "nil", -"order_seed": 921767, -"dur_seed": 787806, -"motifs_seed": 995213, -"entrances_probs_vals": [ 0, 0, 0, 0, 1.6208791208791, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 0, 0, 0, 0, 1.6208791208791, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 0, 0, 0, 0, 1.6208791208791, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -1315.1702786378, 338.08049535604 ], [ -200.61919504644, 1452.6315789474 ], [ -386, 1675.5417956656 ], [ -219, 1694.1176470588 ] ], -"step_probs_vals": [ 0, 1200, 0, 0, 0.063786008230453, 0.92613636363636, 0.12757201646091, 0, 0.54732510288066, 0, 0.71604938271605, 0, 1, 0 ], -"passages_weights": [ 0.7, 0.29, 0.66, 0.74, 0.68 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 1 ], [ 0, 3, 0, 3, 0 ], [ 2 ] ], - [ [ 2 ], [ 0, 1, 1, 1, 0, 0, 0 ], [ 3 ] ], - [ [ 1 ], [ 3, 0, 3 ], [ 2 ] ], - [ [ 3 ], [ 1, 0, 1, 0, 1, 0, 0 ], [ 2 ] ], - [ [ 1 ], [ 3, 0, 2, 2, 3, 3, 0, 2 ], [ ] ], - [ [ 2 ], [ 0, 3, 1 ], [ ] ], - [ [ 2 ], [ 3, 1, 0, 3, 3, 0, 0, 0, 1, 0, 1, 1 ], [ ] ], - [ [ 1 ], [ 3, 2, 2, 2, 2, 3, 3, 2, 2, 3 ], [ 0 ] ] -], -"sus_weights": [ 1, 0, 0 ], -"order_size": [ 8, 10 ], -"passages_size": [ 0, 10 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/4660b5c4/4660b5c4_code.scd b/resources/resources_bak_2024_01_03/string_quartet_2/4660b5c4/4660b5c4_code.scd deleted file mode 100644 index 57e638d..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/4660b5c4/4660b5c4_code.scd +++ /dev/null @@ -1,945 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array2) - hsArrayToCents.value(array1); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = true; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance); -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength.asInteger - minMotifLength.asInteger).rand + minMotifLength.asInteger).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength.asInteger - minProgLength.asInteger).rand + minProgLength.asInteger).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/4660b5c4/4660b5c4_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_2/4660b5c4/4660b5c4_mus_model.json deleted file mode 100644 index fba5fcb..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/4660b5c4/4660b5c4_mus_model.json +++ /dev/null @@ -1,59 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ 0, 3, -2, -1, 1, 0 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 4.625 ], - [ [ [ 0, 3, -2, -1, 1, 0 ], [ "Rest" ], [ "Rest" ], [ -1, 3, -2, -2, 1, 0 ] ], 0 ], - [ [ [ 0, 3, -2, -1, 1, 0 ], [ "Rest" ], [ -1, 3, -2, -1, 1, 0 ], [ -1, 3, -2, -2, 1, 0 ] ], 0 ], - [ [ [ 0, 3, -2, -1, 1, 0 ], [ -2, 4, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 1, 0 ], [ -1, 3, -2, -2, 1, 0 ] ], 5.875 ] - ], - [ - [ [ [ 0, 3, -2, -1, 1, 0 ], [ -2, 4, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 2, 0 ], [ -1, 3, -2, -2, 1, 0 ] ], 0 ], - [ [ [ 0, 3, -2, -1, 1, 0 ], [ -2, 3, -2, -1, 1, 1 ], [ -1, 3, -2, -1, 2, 0 ], [ -1, 3, -2, -2, 1, 0 ] ], 0 ], - [ [ [ 0, 3, -2, -1, 1, 0 ], [ -2, 3, -2, -1, 1, 1 ], [ -1, 3, -2, -1, 2, 0 ], [ -1, 3, -2, -1, 1, -1 ] ], 6.625 ] - ], - [ - [ [ [ 0, 3, -2, -1, 1, 0 ], [ -2, 3, -2, -1, 1, 1 ], [ 0, 3, -2, -1, 0, 0 ], [ -1, 3, -2, -1, 1, -1 ] ], 0 ], - [ [ [ 0, 3, -2, -1, 1, 0 ], [ -2, 3, -2, -1, 1, 1 ], [ 0, 3, -2, -1, 0, 0 ], [ -2, 3, -1, -1, 1, 0 ] ], 0 ], - [ [ [ 0, 3, -2, -1, 1, 0 ], [ -2, 3, -2, 0, 1, 0 ], [ 0, 3, -2, -1, 0, 0 ], [ -2, 3, -1, -1, 1, 0 ] ], 4.875 ], - [ [ [ 0, 3, -2, -1, 1, 0 ], [ -2, 3, -2, 0, 1, 0 ], [ "Rest" ], [ -2, 3, -1, -1, 1, 0 ] ], 0 ], - [ [ [ 0, 3, -2, -1, 1, 0 ], [ "Rest" ], [ "Rest" ], [ -2, 3, -1, -1, 1, 0 ] ], 0 ], - [ [ [ 0, 3, -2, -1, 1, 0 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 0 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 6.0 ] - ] - ] -], -"last_changes": -[ - [ [ 0, 3, -2, -1, 1, 0 ], [ -2, 3, -2, -1, 1, 1 ], [ -1, 3, -2, -1, 2, 0 ], [ -1, 3, -2, -2, 1, 0 ] ], - [ [ 0, 3, -2, -1, 1, 0 ], [ -2, 3, -2, -1, 1, 1 ], [ -1, 3, -2, -1, 2, 0 ], [ -1, 3, -2, -1, 1, -1 ] ], - [ [ 0, 3, -2, -1, 1, 0 ], [ -2, 3, -2, -1, 1, 1 ], [ 0, 3, -2, -1, 0, 0 ], [ -1, 3, -2, -1, 1, -1 ] ], - [ [ 0, 3, -2, -1, 1, 0 ], [ -2, 3, -2, -1, 1, 1 ], [ 0, 3, -2, -1, 0, 0 ], [ -2, 3, -1, -1, 1, 0 ] ], - [ [ 0, 3, -2, -1, 1, 0 ], [ -2, 3, -2, 0, 1, 0 ], [ 0, 3, -2, -1, 0, 0 ], [ -2, 3, -1, -1, 1, 0 ] ] -], -"cur_uid": "4660b5c4", -"ref_uid": "4c059f33", -"order_seed": 706160, -"dur_seed": 659279, -"motifs_seed": 885545, -"entrances_probs_vals": [ 1, 0, 5.0793650793651, 0.47, 2.8021978021978, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 1, 0, 2.7380952380952, 3.68, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 1, 0, 2.7380952380952, 3.68, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -1315.1702786378, 338.08049535604 ], [ -200.61919504644, 1452.6315789474 ], [ -386, 1675.5417956656 ], [ -219, 1694.1176470588 ] ], -"step_probs_vals": [ 0, 1200, 0, 0, 0.063786008230453, 0.92613636363636, 0.12757201646091, 0, 0.54732510288066, 0, 0.71604938271605, 0, 1, 0 ], -"passages_weights": [ 0.7, 0.29, 0.66, 0.74, 0.68 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 0 ], [ 3, 2, 1 ], [ ] ], - [ [ 0 ], [ 2, 1, 3 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ] -], -"sus_weights": [ 1, 0, 0 ], -"order_size": [ 8.0714285714286, 10.091836734694 ], -"passages_size": [ 0, 10 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/4a8a6e53/4a8a6e53_code.scd b/resources/resources_bak_2024_01_03/string_quartet_2/4a8a6e53/4a8a6e53_code.scd deleted file mode 100644 index 3eb3cbd..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/4a8a6e53/4a8a6e53_code.scd +++ /dev/null @@ -1,1058 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance); -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file; - file = File(path, "w"); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((dir +/+ ".." +/+ "resources" +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((dir +/+ ".." +/+ "resources" +/+ curUID).standardizePath); - File.copy(exPath, (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (dir +/+ ".." +/+ "resources" +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (dir +/+ ".." +/+ "resources" +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((dir +/+ ".." +/+ "resources" +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (dir +/+ ".." +/+ "resources" +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (dir +/+ ".." +/+ "resources" +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "resources" +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "resources" +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \".." +/+ ".." +/+ "resources" +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - -~transcribe.value(~seq, dir); - -( -//synthdefs -~stringModelBusArray = 4.collect({Bus.audio(s, 1)}); -~sineBusArray = 4.collect({Bus.audio(s, 1)}); -~bassBusArray = 1.collect({Bus.audio(s, 1)}); -~hdustBusArray = 1.collect({Bus.audio(s, 1)}); -~samplerBusArray = 2.collect({Bus.audio(s, 1)}); -~sBuf = Buffer.alloc(s, 10, 2); -SynthDef(\string_model, {arg freq, gate = 1, sustain, amp, dur, attack, release = 1, busIndex = 0; - var trig, exc, sig1, sig2, noHarms; - noHarms = rrand(20, 40); - exc = Saw.ar(freq, TRand.ar(0.5, 1, Impulse.ar(freq))) * 0.001 + Dust.ar(10000, 0.01); - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(1, 2)}) ], exc) * 0.8).softclip; - //sig1 = HPF.ar(sig1, 300); - Out.ar(Select.kr(busIndex, ~stringModelBusArray), sig1 * amp * EnvGen.kr(Env.adsr(attack, 0.3, 0.9, release, 0.9, -3), gate, doneAction: 2)); - //Out.ar([0, 1], sig1 * EnvGen.kr(Env.asr(dur, 0.3, 1), gate, doneAction: 2)); -}).add; - -SynthDef(\sine, {arg freq, gate = 1, sustain, amp, dur, busIndex = 0; - var sig; - sig = SinOsc.ar(freq); - Out.ar(Select.kr(busIndex, ~sineBusArray), sig * EnvGen.kr(Env.asr(0.3, 0.4, 0.3), gate, timeScale: dur, doneAction: 2)); - //Out.ar(Select.kr(busIndex, ~sineBusArray), sig * EnvGen.kr(Env.sine(dur), gate, doneAction: 2)); -}).add; - -SynthDef(\mixer, {arg freq, gate = 1, sustain, amp, dur, out; - var nameSpaces, sigs; - - sigs = [~stringModelBusArray, ~sineBusArray/*, ~bassBusArray, ~hdustBusArray, ~samplerBusArray*/].collect({arg busArray, i; - var nameSpace, sig; - nameSpace = ['string', 'sine', 'bass', 'hdust', 'sampler'][i]; - sig = busArray.collect({arg bus, c; In.ar(bus, 1) * NamedControl.kr(\ ++ nameSpace ++ '_volume_' ++ c, 1, 0.1)}); - sig = sig.collect({arg channel, c; Pan2.ar(channel, NamedControl.kr(\ ++ nameSpace ++ '_pan_' ++ c, i / (busArray.size - 1), 0.1) * 2 - 1)}); - sig = sig.collect({arg channel, c; channel * NamedControl.kr(\ ++ nameSpace ++ '_mute_' ++ c, 1, 0.1)}); - sig = Mix.ar(sig) * pow(NamedControl.kr(\ ++ nameSpace ++ '_volume_master', 1, 0.1), 2); - }); - - sigs = Mix.ar(sigs / 4); - Out.ar(0, sigs) -}).add; - -SynthDef(\bass, { - var switches, drone; - switches = {|i| Dust.kr(0.1)} ! 9; - drone = {|i| var harm = pow(2, 2 - (i / 3).trunc), amp = (1 / pow(harm, 2)); - SinOsc.ar(60 * harm + TRand.kr(-3, 3, switches[i]), 0, amp)} ! 9; - Out.ar(~bassBusArray[0], Mix.new(drone) * 0.2); -}).add; - -SynthDef(\sampler, { - Out.ar(~samplerBusArray, PlayBuf.ar(2, ~sBuf, BufRateScale.kr(~sBuf), doneAction: 2)) -}).add; - -// main routine -SynthDef(\hdust, { - arg gate = 0; - var hierarchical_dust, low_sine, high_sine, brown_noise, white_noise; - // this triggers the combinations of sources - // it is similar to the Supercollider UGen called dust but with a hierarchical structure - hierarchical_dust = ( - TIRand.kr(0, 1, Impulse.kr(100)) * - TIRand.kr(0, 1, Impulse.kr(10)) * - TIRand.kr(0, 1, Impulse.kr(1)) * - TIRand.kr(0, 1, Impulse.kr(0.1)) - ); - // adjust the multiplier at the end of each line for adjusting levels - // note with each trigger, each source has a 1 in 3 chance of sounding - low_sine = SinOsc.ar(76.midicps / 16) * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.1; - high_sine = SinOsc.ar(76.midicps * 8) * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.01; - brown_noise = BrownNoise.ar() * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.025; - white_noise = WhiteNoise.ar() * (TIRand.kr(0, 2, hierarchical_dust) < 1) * 0.02; - Out.ar(~hdustBusArray[0], - ((low_sine + high_sine + brown_noise + white_noise) ) - ); -}).add; - -) - -( -var bass, hdust, sampler, mixer; -/* -bass = Synth.tail(~group, \bass); -hdust = Synth.tail(~group, \hdust); -sampler = Synth.head(~group, \sampler); -*/ -mixer = Synth.tail(~group, \mixer); - -OSCdef(\mixer, {arg msg, time, addr, port; - mixer.set((msg[1] ++ '_' ++ msg[2] ++ '_' ++ msg[3]), msg[4]) -}, \mixer); - -/* -OSCdef(\sampler, {arg msg, time, addr, port; - msg.postln; - sampler.free; - ~sBuf.free; - ~sBuf = Buffer.read(s, msg[1].asString.postln, action: {sampler = Synth.head(~group, \sampler)}); -}, \sampler); -*/ -) - -/* old something -( -SynthDef(\test, {arg freq, gate = 1, sustain, amp, dur; - var trig, exc, sig1, sig2, noHarms, freqFinal, start, end; - noHarms = 30; - freq = WhiteNoise.ar * 3 + freq; - freqFinal = Duty.ar((1/freq), 0, freq); - trig = Changed.ar(freqFinal); - start = Demand.ar(trig, 0, Dwhite(-1, -0.75)); - end = Demand.ar(trig, 0, Dwhite(0.75, 1)); - exc = Phasor.ar(trig, (end - start) * freqFinal / SampleRate.ir, start, end, 0) * 0.001 + Dust.ar(10000, 0.01); - - sig1 = (Klank.ar(`[ Array.series(noHarms, freq, freq), - Array.geom(noHarms, 1, 0.2) + Array.fill(noHarms, {rrand(0.01, 0.03)}), - Array.fill(noHarms, {rrand(2, 3)}) ], exc) * 0.5).softclip; - sig1 = HPF.ar(sig1, 300); - Out.ar([0, 1], sig1 * EnvGen.kr(Env.adsr(0.3, 0.3, 0.9, 0.5, 0.9), gate, doneAction: 2)); -}).add; -) -*/ - diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/4a8a6e53/4a8a6e53_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_2/4a8a6e53/4a8a6e53_mus_model.json deleted file mode 100644 index 150baf5..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/4a8a6e53/4a8a6e53_mus_model.json +++ /dev/null @@ -1,97 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ] ], 0.875 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ] ], 0.625 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], 1.5 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ] ], 0.875 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ] ], 0.875 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ] ], 1 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 1, 0, 0 ] ], 1 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ] ], 1.25 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 1 ] ], 0.875 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, -1, 0, 0, 0 ] ], 0.875 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ] ], 1.25 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ] ], 0.75 ] - ], - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ] ], 0.875 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 1, 0, 0, 0, 0, -1 ], [ "Rest" ] ], 1.5 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ -1, 0, 0, 1, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ], [ "Rest" ] ], 1.25 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ -1, 0, 0, 1, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ "Rest" ] ], 1.375 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ -1, 0, 0, 1, 0, 0 ], [ 0, 0, 0, 1, 0, 0 ], [ "Rest" ] ], 0.75 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, -1, 0, 0, 0 ], [ 0, 0, 0, 1, 0, 0 ], [ "Rest" ] ], 0.625 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 0, 0, 0, 1, 0, 0 ], [ "Rest" ] ], 0.75 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 0, 0, 0, 0, 0, 1 ], [ "Rest" ] ], 1.125 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 1, 0, -1, 0, 0, 0 ], [ "Rest" ] ], 1.25 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ "Rest" ] ], 1 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ "Rest" ] ], 0.875 ] - ], - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, -1, 0, -1, 0 ] ], 0.875 ], - [ [ [ 1, -1, 0, 0, -1, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, -1, 0, -1, 0 ] ], 0.75 ], - [ [ [ 1, -1, 0, 0, -1, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 0, 0, 0, 1, -1, 0 ], [ 1, 0, -1, 0, -1, 0 ] ], 1.5 ], - [ [ [ 1, -1, 0, 0, -1, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 0, 0, 0, 1, -1, 0 ], [ 0, 0, 0, 0, -1, 1 ] ], 1.25 ], - [ [ [ 1, -1, 0, 0, -1, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 0, 0, 0, 1, -1, 0 ], [ 0, 1, 0, 0, -1, 0 ] ], 0.625 ], - [ [ [ 1, -1, 0, 0, -1, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 1, 0, 0, 0, -1, 0 ], [ 0, 1, 0, 0, -1, 0 ] ], 0.625 ], - [ [ [ 0, 0, 1, 0, -1, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 1, 0, 0, 0, -1, 0 ], [ 0, 1, 0, 0, -1, 0 ] ], 0.625 ], - [ [ [ 1, 0, 0, -1, -1, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 1, 0, 0, 0, -1, 0 ], [ 0, 1, 0, 0, -1, 0 ] ], 1.375 ], - [ [ [ 1, 0, 0, -1, -1, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 1, 0, 0, 0, -1, 0 ], [ 0, 0, 1, 0, -1, 0 ] ], 1.375 ], - [ [ [ 1, 0, 0, -1, -1, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 2, 0, 0, -1, -1, 0 ], [ 0, 0, 1, 0, -1, 0 ] ], 1.5 ], - [ [ [ 1, 0, 0, -1, -1, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 2, 0, 0, 0, -1, -1 ], [ 0, 0, 1, 0, -1, 0 ] ], 0.75 ], - [ [ [ 1, 0, 0, -1, -1, 0 ], [ 0, 0, 0, 0, -1, 0 ], [ 2, 0, 0, 0, -1, -1 ], [ 1, -1, 0, 0, -1, 0 ] ], 1 ] - ], - [ - [ [ [ 1, 0, 0, -1, -1, 0 ], [ "Rest" ], [ 2, 0, 0, 0, -1, -1 ], [ 1, -1, 0, 0, -1, 0 ] ], 0.75 ], - [ [ [ 0, -1, 0, 1, -1, 0 ], [ "Rest" ], [ 2, 0, 0, 0, -1, -1 ], [ 1, -1, 0, 0, -1, 0 ] ], 1 ], - [ [ [ 0, -1, 0, 1, -1, 0 ], [ "Rest" ], [ 2, -1, 0, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ] ], 0.875 ], - [ [ [ 0, -1, 0, 0, -1, 1 ], [ "Rest" ], [ 2, -1, 0, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ] ], 1.25 ], - [ [ [ 0, -1, 0, 0, -1, 1 ], [ "Rest" ], [ 1, -1, 0, 1, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ] ], 1.125 ], - [ [ [ 1, -1, -1, 0, -1, 0 ], [ "Rest" ], [ 1, -1, 0, 1, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ] ], 1 ], - [ [ [ 1, -1, -1, 0, -1, 0 ], [ "Rest" ], [ 1, 0, 0, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ] ], 0.75 ], - [ [ [ 1, -1, -1, 0, -1, 0 ], [ "Rest" ], [ 1, -1, 0, 0, 0, 0 ], [ 1, -1, 0, 0, -1, 0 ] ], 0.625 ], - [ [ [ 0, -1, 0, 0, 0, 0 ], [ "Rest" ], [ 1, -1, 0, 0, 0, 0 ], [ 1, -1, 0, 0, -1, 0 ] ], 0.75 ], - [ [ [ 1, -1, 0, 0, -2, 0 ], [ "Rest" ], [ 1, -1, 0, 0, 0, 0 ], [ 1, -1, 0, 0, -1, 0 ] ], 1.375 ], - [ [ [ 1, -1, 0, 0, -2, 0 ], [ "Rest" ], [ 2, -2, 0, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ] ], 0.875 ], - [ [ [ 0, -1, 0, 0, -1, 1 ], [ "Rest" ], [ 2, -2, 0, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ] ], 3.375 ], - [ [ [ 0, -1, 0, 0, -1, 1 ], [ "Rest" ], [ 2, -2, 0, 0, -1, 0 ], [ "Rest" ] ], 1.5 ], - [ [ [ 0, -1, 0, 0, -1, 1 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 1.375 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 2 ] - ] - ] -], -"last_changes": -[ - [ [ 0, 0, 0, 1, 0, -1 ], [ 0, 0, 0, 0, 0, 0 ], [ 2, 0, 0, 0, 0, -1 ], [ 1, 0, 0, 0, 0, -2 ] ], - [ [ 0, 0, 0, 1, 0, -1 ], [ 0, 0, 0, 0, 0, 0 ], [ 2, 0, 0, 0, 0, -1 ], [ -1, 0, 0, 1, 0, -1 ] ], - [ [ 0, 0, 0, 1, 0, -1 ], [ 0, 0, 0, 0, 0, 0 ], [ 2, 0, 0, 0, 0, -1 ], [ 0, 0, 0, 0, -1, 0 ] ], - [ [ 0, 0, 0, 1, 0, -1 ], [ 0, 0, 0, 0, 0, 0 ], [ 2, 0, 0, -1, 0, 0 ], [ 0, 0, 0, 0, -1, 0 ] ], - [ [ 1, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 2, 0, 0, -1, 0, 0 ], [ 0, 0, 0, 0, -1, 0 ] ] -], -"cur_uid": "4a8a6e53", -"ref_uid": "nil", -"order_seed": 320463, -"dur_seed": 903977, -"motifs_seed": 895384, -"entrances_probs_vals": [ 0.75, 0, 10, 0, 0.5, 0.26424870466321, 0.75675675675676, 0.5, 0.5, 0.58549222797927, 0.72635135135135, 1, 0.5 ], -"passages_probs_vals": [ 0.75, 0, 10, 0, 0.5, 0.20725388601036, 0.68581081081081, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"exits_probs_vals": [ 0.75, 0, 10, 0, 0.5, 0.20725388601036, 0.68581081081081, 0.24093264248705, 0.34121621621622, 0.5, 0.5, 0.67616580310881, 0.81081081081081, 1, 0.5 ], -"ranges": [ [ -384, 2400 ], [ -507, 2400 ], [ -282, 2237 ], [ -1200, 2053 ] ], -"step_probs_vals": [ 0, 1200, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_weights": [ 0.75, 0.75, 0.75, 0.75, 0.75 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 1 ], [ 0, 3, 2, 3, 3, 2 ], [ ] ], - [ [ 2, 1 ], [ 3, 0, 3 ], [ ] ], - [ [ 1 ], [ 3, 2, 0 ], [ ] ] -], -"sus_weights": [ 0.75, 0.69, 0.75 ], -"order_size": [ 2, 6 ], -"passages_size": [ 0, 10 ], -"motif_edited": "true", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/4a8a6e53/lilypond/part_I.ly b/resources/resources_bak_2024_01_03/string_quartet_2/4a8a6e53/lilypond/part_I.ly deleted file mode 100644 index ce99136..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/4a8a6e53/lilypond/part_I.ly +++ /dev/null @@ -1,56 +0,0 @@ -{ \numericTimeSignature - { r2. e'4^\markup { \pad-markup #0.2 "-41"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↓" }} ~ } - \bar "|" - { e'2 e'4^\markup { \pad-markup #0.2 "-14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }} ~ e'8.[ f'16^\markup { \pad-markup #0.2 "-2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }}] ~ } - \bar "|" - { f'4 ~ f'8[ g'8^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }}] ~ g'4 ~ g'8[ ais'8^\markup { \pad-markup #0.2 "-31"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↑" }}] ~ } - \bar "|" - { ais'4 ~ ais'8[ c''8^\markup { \pad-markup #0.2 "+0"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }}] ~ c''2 } - \bar "|" - { gis'4^\markup { \pad-markup #0.2 "+41"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↑" }} ~ gis'8.[ gis'16^\markup { \pad-markup #0.2 "+14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↓" }}] ~ gis'4 ~ gis'8[ f'8^\markup { \pad-markup #0.2 "-2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }}] ~ } - \bar "|" - { f'2 e'4^\markup { \pad-markup #0.2 "-14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }} ~ e'8[ r8] } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r2 r16[ dis'8.^\markup { \pad-markup #0.2 "-38"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 5↓" }}] ~ dis'4 ~ } - \bar "|" - { dis'1 ~ } - \bar "|" - { dis'8[ dis'8^\markup { \pad-markup #0.2 "-11"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 13↑" }}] ~ dis'2 d'4^\markup { \pad-markup #0.2 "-49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↑" }} ~ } - \bar "|" - { d'1 ~ } - \bar "|" - { d'4 ~ d'8[ ais8^\markup { \pad-markup #0.2 "+35"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 5↑" }}] ~ ais2 ~ } - \bar "|" - { ais1 ~ } - \bar "|" - { ais8.[ b16^\markup { \pad-markup #0.2 "+47"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↓" }}] ~ b2. ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b2 ~ b16[ r8.] r4 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/4a8a6e53/lilypond/part_II.ly b/resources/resources_bak_2024_01_03/string_quartet_2/4a8a6e53/lilypond/part_II.ly deleted file mode 100644 index 3c00ff8..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/4a8a6e53/lilypond/part_II.ly +++ /dev/null @@ -1,56 +0,0 @@ -{ - { c'1^\markup { \pad-markup #0.2 "+0"} ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'4 ~ c'16[ e'8.^\markup { \pad-markup #0.2 "-41"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↓" }}] ~ e'2 ~ } - \bar "|" - { e'2 ~ e'8.[ g'16^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }}] ~ g'4 ~ } - \bar "|" - { g'4 ~ g'8[ ais'8^\markup { \pad-markup #0.2 "-31"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }}] ~ ais'2 ~ } - \bar "|" - { ais'4 ~ ais'8.[ gis'16^\markup { \pad-markup #0.2 "+41"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↑" }}] ~ gis'2 } - \bar "|" - { gis'2^\markup { \pad-markup #0.2 "+14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↓" }} ~ gis'8[ g'8^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }}] ~ g'4 ~ } - \bar "|" - { g'8[ f'8^\markup { \pad-markup #0.2 "-2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }}] ~ f'2. ~ } - \bar "|" - { f'4 ~ f'8[ e'8^\markup { \pad-markup #0.2 "+18"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 7↑" }}] ~ e'2 ~ } - \bar "|" - { e'1 ~ } - \bar "|" - { e'16[ fis'8.^\markup { \pad-markup #0.2 "+49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }}] ~ fis'2. ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'16[ a'8.^\markup { \pad-markup #0.2 "-20"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }}] ~ a'2 ~ a'16[ ais'8.^\markup { \pad-markup #0.2 "+8"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 13↓" }}] ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'2 ~ ais'16[ b'8.^\markup { \pad-markup #0.2 "+47"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }}] ~ b'4 ~ } - \bar "|" - { b'2 ~ b'8[ a'8^\markup { \pad-markup #0.2 "+16"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 7↑" }}] ~ a'4 ~ } - \bar "|" - { a'2 ~ a'8.[ fis'16^\markup { \pad-markup #0.2 "+49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↑" }}] ~ fis'4 ~ } - \bar "|" - { fis'16[ f'8.^\markup { \pad-markup #0.2 "-2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 11↑" }}] ~ f'2. ~ } - \bar "|" - { f'4 ~ f'8.[ e'16^\markup { \pad-markup #0.2 "+45"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↓" }}] ~ e'2 ~ } - \bar "|" - { e'1 ~ } - \bar "|" - { e'1 ~ } - \bar "|" - { e'4 ~ e'16[ r8.] r2 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/4a8a6e53/lilypond/part_III.ly b/resources/resources_bak_2024_01_03/string_quartet_2/4a8a6e53/lilypond/part_III.ly deleted file mode 100644 index 75dcb1c..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/4a8a6e53/lilypond/part_III.ly +++ /dev/null @@ -1,56 +0,0 @@ -{ - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r16[ ais8.^\markup { \pad-markup #0.2 "-31"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↑" }}] ~ ais2. ~ } - \bar "|" - { ais2. gis4^\markup { \pad-markup #0.2 "+14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↓" }} ~ } - \bar "|" - { gis16[ fis8.^\markup { \pad-markup #0.2 "+49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 11↓" }}] ~ fis2. ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis2 ~ fis8.[ r16] r4 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/4a8a6e53/lilypond/part_IV.ly b/resources/resources_bak_2024_01_03/string_quartet_2/4a8a6e53/lilypond/part_IV.ly deleted file mode 100644 index 41471e8..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/4a8a6e53/lilypond/part_IV.ly +++ /dev/null @@ -1,56 +0,0 @@ -{ - { r4 r8.[ c'16^\markup { \pad-markup #0.2 "+0"}] ~ c'2 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 } - \bar "|" - { b1^\markup { \pad-markup #0.2 "+47"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↓" }} ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b4 ~ b8[ ais8^\markup { \pad-markup #0.2 "+35"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 5↑" }}] ~ ais8.[ a16^\markup { \pad-markup #0.2 "-20"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 7↓" }}] ~ a4 ~ } - \bar "|" - { a1 ~ } - \bar "|" - { a1 ~ } - \bar "|" - { a1 ~ } - \bar "|" - { a16[ a8.^\markup { \pad-markup #0.2 "+16"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 7↑" }}] ~ a2. } - \bar "|" - { gis1^\markup { \pad-markup #0.2 "-13"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 13↑" }} ~ } - \bar "|" - { gis8.[ gis16^\markup { \pad-markup #0.2 "-40"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 5↓" }}] ~ gis2. ~ } - \bar "|" - { gis4 ~ gis8[ f8^\markup { \pad-markup #0.2 "-2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 1↑" }}] ~ f4 fis4^\markup { \pad-markup #0.2 "-5"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 11↓" }} ~ } - \bar "|" - { fis2. ~ fis8[ gis8^\markup { \pad-markup #0.2 "-13"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 13↑" }}] ~ } - \bar "|" - { gis1 ~ } - \bar "|" - { gis1 ~ } - \bar "|" - { gis1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/4c059f33/4c059f33_code.scd b/resources/resources_bak_2024_01_03/string_quartet_2/4c059f33/4c059f33_code.scd deleted file mode 100644 index c194eef..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/4c059f33/4c059f33_code.scd +++ /dev/null @@ -1,945 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance); -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/4c059f33/4c059f33_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_2/4c059f33/4c059f33_mus_model.json deleted file mode 100644 index fd5c9df..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/4c059f33/4c059f33_mus_model.json +++ /dev/null @@ -1,58 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ -2, 3, -2, -1, 1, 0 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 1 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ "Rest" ], [ "Rest" ], [ -1, 3, -2, -1, 1, 0 ] ], 0 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ "Rest" ], [ -2, 3, -1, -1, 1, 0 ], [ -1, 3, -2, -1, 1, 0 ] ], 0 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 0, 0 ], [ -2, 3, -1, -1, 1, 0 ], [ -1, 3, -2, -1, 1, 0 ] ], 4.875 ] - ], - [ - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 0, 0 ], [ -1, 3, -2, -1, 1, -1 ], [ -1, 3, -2, -1, 1, 0 ] ], 0 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 4, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 1, -1 ], [ -1, 3, -2, -1, 1, 0 ] ], 0 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 4, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 1, -1 ], [ -2, 3, -1, -1, 1, 0 ] ], 4.75 ] - ], - [ - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 4, -2, -1, 1, 0 ], [ -1, 2, -2, -1, 1, 0 ], [ -2, 3, -1, -1, 1, 0 ] ], 0 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 4, -2, -1, 1, 0 ], [ -1, 2, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 1, -1 ] ], 0 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -1, 3, -3, -1, 1, 0 ], [ -1, 2, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 1, -1 ] ], 4.125 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -1, 3, -3, -1, 1, 0 ], [ "Rest" ], [ -1, 3, -2, -1, 1, -1 ] ], 0 ], - [ [ [ "Rest" ], [ -1, 3, -3, -1, 1, 0 ], [ "Rest" ], [ -1, 3, -2, -1, 1, -1 ] ], 0 ], - [ [ [ "Rest" ], [ -1, 3, -3, -1, 1, 0 ], [ "Rest" ], [ "Rest" ] ], 0 ] - ] - ] -], -"last_changes": -[ - [ [ 0, 3, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 2, 0 ], [ 0, 3, -1, -1, 1, 0 ], [ -1, 4, -2, -1, 1, 0 ] ], - [ [ 0, 3, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 2, 0 ], [ 0, 3, -1, -1, 1, 0 ], [ 0, 3, -3, -1, 1, 0 ] ], - [ [ 0, 3, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 2, 0 ], [ 1, 3, -2, -1, 1, -1 ], [ 0, 3, -3, -1, 1, 0 ] ], - [ [ 0, 3, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 2, 0 ], [ 1, 3, -2, -1, 1, -1 ], [ -1, 3, -2, -1, 1, 1 ] ], - [ [ -2, 3, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 0, 0 ], [ -1, 3, -2, -1, 1, -1 ], [ -1, 3, -2, -1, 1, 1 ] ] -], -"cur_uid": "4c059f33", -"ref_uid": "628706ec", -"order_seed": 706160, -"dur_seed": 146047, -"motifs_seed": 575591, -"entrances_probs_vals": [ 1, 0, 0, 0.47, 2.8021978021978, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 1, 0, 0, 3.68, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 0.77, 0, 0, 0, 1.6208791208791, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -1315.1702786378, 338.08049535604 ], [ -200.61919504644, 1452.6315789474 ], [ -386, 1675.5417956656 ], [ -219, 1694.1176470588 ] ], -"step_probs_vals": [ 0, 1200, 0, 0, 0.063786008230453, 0.92613636363636, 0.12757201646091, 0, 0.54732510288066, 0, 0.71604938271605, 0, 1, 0 ], -"passages_weights": [ 0.7, 0.29, 0.66, 0.74, 0.68 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 0 ], [ 3, 2, 1 ], [ ] ], - [ [ 0 ], [ 2, 1, 3 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ] -], -"sus_weights": [ 1, 0, 0 ], -"order_size": [ 8, 10 ], -"passages_size": [ 0, 10 ], -"motif_edited": "true", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/4c059f33/lilypond/part_I.ly b/resources/resources_bak_2024_01_03/string_quartet_2/4c059f33/lilypond/part_I.ly deleted file mode 100644 index e46bd01..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/4c059f33/lilypond/part_I.ly +++ /dev/null @@ -1,16 +0,0 @@ -{ - { r2 a2^\markup { \pad-markup #0.2 "+16"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }} ~ } - \bar "|" - { a1 ~ } - \bar "|" - { a2. ~ a8.[ cis16^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }}] ~ } - \bar "|" - { cis1 ~ } - \bar "|" - { cis1 ~ } - \bar "|" - { cis4 ~ cis16[ cis8.^\markup { \pad-markup #0.2 "-25"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↓" }}] ~ cis2 ~ } - \bar "|" - { cis1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/4c059f33/lilypond/part_II.ly b/resources/resources_bak_2024_01_03/string_quartet_2/4c059f33/lilypond/part_II.ly deleted file mode 100644 index c17645f..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/4c059f33/lilypond/part_II.ly +++ /dev/null @@ -1,16 +0,0 @@ -{ - { r2 cis2^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }} ~ } - \bar "|" - { cis1 ~ } - \bar "|" - { cis2. ~ cis8.[ cis16^\markup { \pad-markup #0.2 "-25"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↓" }}] ~ } - \bar "|" - { cis1 ~ } - \bar "|" - { cis1 ~ } - \bar "|" - { cis4 ~ cis16[ d8.^\markup { \pad-markup #0.2 "+14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }}] ~ d2 ~ } - \bar "|" - { d1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/4c059f33/lilypond/part_III.ly b/resources/resources_bak_2024_01_03/string_quartet_2/4c059f33/lilypond/part_III.ly deleted file mode 100644 index f07edd8..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/4c059f33/lilypond/part_III.ly +++ /dev/null @@ -1,16 +0,0 @@ -{ - { r2 e2^\markup { \pad-markup #0.2 "-36"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 11↓" }} ~ } - \bar "|" - { e1 ~ } - \bar "|" - { e2. ~ e8.[ e16^\markup { \pad-markup #0.2 "+18"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }}] ~ } - \bar "|" - { e1 ~ } - \bar "|" - { e1 ~ } - \bar "|" - { e4 ~ e16[ f8.^\markup { \pad-markup #0.2 "+29"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↓" }}] ~ f2 ~ } - \bar "|" - { f1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/4c059f33/lilypond/part_IV.ly b/resources/resources_bak_2024_01_03/string_quartet_2/4c059f33/lilypond/part_IV.ly deleted file mode 100644 index 4db8109..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/4c059f33/lilypond/part_IV.ly +++ /dev/null @@ -1,16 +0,0 @@ -{ - { a,1^\markup { \pad-markup #0.2 "+16"} ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/5201b8af/5201b8af_code.scd b/resources/resources_bak_2024_01_03/string_quartet_2/5201b8af/5201b8af_code.scd deleted file mode 100644 index c194eef..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/5201b8af/5201b8af_code.scd +++ /dev/null @@ -1,945 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance); -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/5201b8af/5201b8af_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_2/5201b8af/5201b8af_mus_model.json deleted file mode 100644 index aa90760..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/5201b8af/5201b8af_mus_model.json +++ /dev/null @@ -1,58 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 1 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ], [ 1, 0, 0, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 1, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, 0, -1, 0 ], [ 0, 0, 1, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ] ], 4.875 ] - ], - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, 0, -1, 0 ], [ 1, 0, 0, 0, 0, -1 ], [ 1, 0, 0, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ], [ 1, 0, 0, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ], [ 0, 0, 1, 0, 0, 0 ] ], 4.75 ] - ], - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, -1, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], 4.125 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, -1, 0, 0, 0 ], [ "Rest" ], [ 1, 0, 0, 0, 0, -1 ] ], 0 ], - [ [ [ "Rest" ], [ 1, 0, -1, 0, 0, 0 ], [ "Rest" ], [ 1, 0, 0, 0, 0, -1 ] ], 0 ], - [ [ [ "Rest" ], [ 1, 0, -1, 0, 0, 0 ], [ "Rest" ], [ "Rest" ] ], 0 ] - ] - ] -], -"last_changes": -[ - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 1, 0, 0 ], [ 0, 0, 0, 0, 1, 0 ], [ 1, 0, 0, -1, 0, 0 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 1, 0, 0 ], [ 0, 0, 0, 0, 1, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 1, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 1, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ] ] -], -"cur_uid": "5201b8af", -"ref_uid": "77b0d2dc", -"order_seed": 921767, -"dur_seed": 954688, -"motifs_seed": 995213, -"entrances_probs_vals": [ 1, 0, 0, 3.68, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 1, 0, 0, 3.68, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 1, 0, 0, 3.68, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -1315.1702786378, 338.08049535604 ], [ -200.61919504644, 1452.6315789474 ], [ -386, 1675.5417956656 ], [ -219, 1694.1176470588 ] ], -"step_probs_vals": [ 0, 1200, 0, 0, 0.063786008230453, 0.92613636363636, 0.12757201646091, 0, 0.54732510288066, 0, 0.71604938271605, 0, 1, 0 ], -"passages_weights": [ 0.7, 0.29, 0.66, 0.74, 0.68 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 0 ], [ 3, 2, 1 ], [ ] ], - [ [ 0 ], [ 2, 1, 3 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ] -], -"sus_weights": [ 1, 0, 0 ], -"order_size": [ 8, 10 ], -"passages_size": [ 0, 10 ], -"motif_edited": "true", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/5201b8af/lilypond/part_I.ly b/resources/resources_bak_2024_01_03/string_quartet_2/5201b8af/lilypond/part_I.ly deleted file mode 100644 index 01ab702..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/5201b8af/lilypond/part_I.ly +++ /dev/null @@ -1,16 +0,0 @@ -{ - { r2 c''2^\markup { \pad-markup #0.2 "+0"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }} ~ } - \bar "|" - { c''1 ~ } - \bar "|" - { c''2. ~ c''8.[ e'16^\markup { \pad-markup #0.2 "-14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }}] ~ } - \bar "|" - { e'1 ~ } - \bar "|" - { e'1 ~ } - \bar "|" - { e'4 ~ e'16[ e'8.^\markup { \pad-markup #0.2 "-41"}] ~ e'2 ~ } - \bar "|" - { e'1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/5201b8af/lilypond/part_II.ly b/resources/resources_bak_2024_01_03/string_quartet_2/5201b8af/lilypond/part_II.ly deleted file mode 100644 index f176e75..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/5201b8af/lilypond/part_II.ly +++ /dev/null @@ -1,16 +0,0 @@ -{ - { r2 e'2^\markup { \pad-markup #0.2 "-14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }} ~ } - \bar "|" - { e'1 ~ } - \bar "|" - { e'2. ~ e'8.[ e'16^\markup { \pad-markup #0.2 "-41"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↓" }}] ~ } - \bar "|" - { e'1 ~ } - \bar "|" - { e'1 ~ } - \bar "|" - { e'4 ~ e'16[ f'8.^\markup { \pad-markup #0.2 "-2"}] ~ f'2 ~ } - \bar "|" - { f'1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/5201b8af/lilypond/part_III.ly b/resources/resources_bak_2024_01_03/string_quartet_2/5201b8af/lilypond/part_III.ly deleted file mode 100644 index 5f83063..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/5201b8af/lilypond/part_III.ly +++ /dev/null @@ -1,16 +0,0 @@ -{ - { r2 fis'2^\markup { \pad-markup #0.2 "+49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 11↓" }} ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'2. ~ fis'8.[ g'16^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }}] ~ } - \bar "|" - { g'1 ~ } - \bar "|" - { g'1 ~ } - \bar "|" - { g'4 ~ g'16[ gis'8.^\markup { \pad-markup #0.2 "+14"}] ~ gis'2 ~ } - \bar "|" - { gis'1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/5201b8af/lilypond/part_IV.ly b/resources/resources_bak_2024_01_03/string_quartet_2/5201b8af/lilypond/part_IV.ly deleted file mode 100644 index 67fc5d0..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/5201b8af/lilypond/part_IV.ly +++ /dev/null @@ -1,16 +0,0 @@ -{ - { c'1^\markup { \pad-markup #0.2 "+0"} ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/525274f2/525274f2_code.scd b/resources/resources_bak_2024_01_03/string_quartet_2/525274f2/525274f2_code.scd deleted file mode 100644 index c194eef..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/525274f2/525274f2_code.scd +++ /dev/null @@ -1,945 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance); -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/525274f2/525274f2_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_2/525274f2/525274f2_mus_model.json deleted file mode 100644 index a8be70b..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/525274f2/525274f2_mus_model.json +++ /dev/null @@ -1,66 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 1 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ], [ 1, 0, 0, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 1, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, 0, -1, 0 ], [ 0, 0, 1, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ] ], 3.375 ] - ], - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, 0, -1, 0 ], [ 1, 0, 0, 0, 0, -1 ], [ 1, 0, 0, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ], [ 1, 0, 0, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ], [ 0, 0, 1, 0, 0, 0 ] ], 1.25 ] - ], - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, -1, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], 3.125 ] - ], - [ - [ [ [ 1, 0, -1, 0, 0, -1 ], [ 1, 0, -1, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], 0 ], - [ [ [ 1, 0, -1, 0, 0, -1 ], [ 1, 0, 1, 0, 0, -1 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], 2.25 ] - ], - [ - [ [ [ 1, -1, 0, 0, -1, 0 ], [ 1, 0, 1, 0, 0, -1 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], 0 ], - [ [ [ 1, -1, 0, 0, -1, 0 ], [ 2, -1, 0, -1, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], 2.625 ], - [ [ [ 1, -1, 0, 0, -1, 0 ], [ 2, -1, 0, -1, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ "Rest" ] ], 0 ], - [ [ [ 1, -1, 0, 0, -1, 0 ], [ 2, -1, 0, -1, 0, 0 ], [ "Rest" ], [ "Rest" ] ], 0 ], - [ [ [ "Rest" ], [ 2, -1, 0, -1, 0, 0 ], [ "Rest" ], [ "Rest" ] ], 0 ] - ] - ] -], -"last_changes": -[ - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 1, 0, 0 ], [ 0, 0, 0, 0, 1, 0 ], [ 1, 0, 0, -1, 0, 0 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 1, 0, 0 ], [ 0, 0, 0, 0, 1, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 1, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 1, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ] ] -], -"cur_uid": "525274f2", -"ref_uid": "77b0d2dc", -"order_seed": 921767, -"dur_seed": 954688, -"motifs_seed": 995213, -"entrances_probs_vals": [ 1, 0, 0, 3.68, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 1, 0, 0, 3.68, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 1, 0, 0, 3.68, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -1315.1702786378, 338.08049535604 ], [ -200.61919504644, 1452.6315789474 ], [ -386, 1675.5417956656 ], [ -219, 1694.1176470588 ] ], -"step_probs_vals": [ 0, 1200, 0, 0, 0.063786008230453, 0.92613636363636, 0.12757201646091, 0, 0.54732510288066, 0, 0.71604938271605, 0, 1, 0 ], -"passages_weights": [ 0.7, 0.29, 0.66, 0.74, 0.68 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 0 ], [ 3, 2, 1 ], [ ] ], - [ [ 0 ], [ 2, 1, 3 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ] -], -"sus_weights": [ 1, 0, 0 ], -"order_size": [ 8, 10 ], -"passages_size": [ 0, 10 ], -"motif_edited": "true", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/525274f2/lilypond/part_I.ly b/resources/resources_bak_2024_01_03/string_quartet_2/525274f2/lilypond/part_I.ly deleted file mode 100644 index a568867..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/525274f2/lilypond/part_I.ly +++ /dev/null @@ -1,14 +0,0 @@ -{ - { r2 c''2^\markup { \pad-markup #0.2 "+0"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }} ~ } - \bar "|" - { c''1 ~ } - \bar "|" - { c''8.[ e'16^\markup { \pad-markup #0.2 "-14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }}] ~ e'2 ~ e'16[ e'8.^\markup { \pad-markup #0.2 "-41"}] ~ } - \bar "|" - { e'1 ~ } - \bar "|" - { e'1 ~ } - \bar "|" - { e'1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/525274f2/lilypond/part_II.ly b/resources/resources_bak_2024_01_03/string_quartet_2/525274f2/lilypond/part_II.ly deleted file mode 100644 index 9a7f7ed..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/525274f2/lilypond/part_II.ly +++ /dev/null @@ -1,14 +0,0 @@ -{ - { r2 e'2^\markup { \pad-markup #0.2 "-14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }} ~ } - \bar "|" - { e'1 ~ } - \bar "|" - { e'8.[ e'16^\markup { \pad-markup #0.2 "-41"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↓" }}] ~ e'2 ~ e'16[ f'8.^\markup { \pad-markup #0.2 "-2"}] ~ } - \bar "|" - { f'1 ~ } - \bar "|" - { f'1 ~ } - \bar "|" - { f'1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/525274f2/lilypond/part_III.ly b/resources/resources_bak_2024_01_03/string_quartet_2/525274f2/lilypond/part_III.ly deleted file mode 100644 index ac151b0..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/525274f2/lilypond/part_III.ly +++ /dev/null @@ -1,14 +0,0 @@ -{ - { r2 fis'2^\markup { \pad-markup #0.2 "+49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 11↓" }} ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'8.[ g'16^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }}] ~ g'2 ~ g'16[ gis'8.^\markup { \pad-markup #0.2 "+14"}] ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'4 ~ gis'8[ g'8^\markup { \pad-markup #0.2 "+46"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 5↑" }}] ~ g'2 ~ } - \bar "|" - { g'2 g'2^\markup { \pad-markup #0.2 "+29"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 7↓" }}} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/525274f2/lilypond/part_IV.ly b/resources/resources_bak_2024_01_03/string_quartet_2/525274f2/lilypond/part_IV.ly deleted file mode 100644 index e646018..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/525274f2/lilypond/part_IV.ly +++ /dev/null @@ -1,14 +0,0 @@ -{ - { c'1^\markup { \pad-markup #0.2 "+0"} ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'4 ~ c'8[ c'8^\markup { \pad-markup #0.2 "-27"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 13↓" }}] ~ c'2 ~ } - \bar "|" - { c'2 b2^\markup { \pad-markup #0.2 "+47"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 11↓" }}} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/60adbbef/60adbbef_code.scd b/resources/resources_bak_2024_01_03/string_quartet_2/60adbbef/60adbbef_code.scd deleted file mode 100644 index 57e638d..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/60adbbef/60adbbef_code.scd +++ /dev/null @@ -1,945 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array2) - hsArrayToCents.value(array1); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = true; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance); -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength.asInteger - minMotifLength.asInteger).rand + minMotifLength.asInteger).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength.asInteger - minProgLength.asInteger).rand + minProgLength.asInteger).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/60adbbef/60adbbef_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_2/60adbbef/60adbbef_mus_model.json deleted file mode 100644 index 748c135..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/60adbbef/60adbbef_mus_model.json +++ /dev/null @@ -1,65 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ -2, 3, -2, -1, 1, 0 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 3.75 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ "Rest" ], [ "Rest" ], [ -2, 4, -2, -1, 1, 0 ] ], 0 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ "Rest" ], [ -2, 3, -1, -1, 1, 0 ], [ -2, 4, -2, -1, 1, 0 ] ], 0 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 1, 0 ], [ -2, 3, -1, -1, 1, 0 ], [ -2, 4, -2, -1, 1, 0 ] ], 4.75 ] - ], - [ - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 1, 0 ], [ -1, 2, -2, -1, 1, 0 ], [ -2, 4, -2, -1, 1, 0 ] ], 0 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -2, -1, 1, 1 ], [ -1, 2, -2, -1, 1, 0 ], [ -2, 4, -2, -1, 1, 0 ] ], 0 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -2, -1, 1, 1 ], [ -1, 2, -2, -1, 1, 0 ], [ -1, 3, -3, -1, 1, 0 ] ], 7.125 ] - ], - [ - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -2, -1, 1, 1 ], [ -2, 3, -2, -1, 2, 0 ], [ -1, 3, -3, -1, 1, 0 ] ], 0 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -2, -1, 1, 1 ], [ -2, 3, -2, -1, 2, 0 ], [ 0, 3, -2, -1, 1, -1 ] ], 0 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -2, 0, 1, 0 ], [ -2, 3, -2, -1, 2, 0 ], [ 0, 3, -2, -1, 1, -1 ] ], 4.5 ] - ], - [ - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -2, 0, 1, 0 ], [ -1, 3, -2, -1, 0, 0 ], [ 0, 3, -2, -1, 1, -1 ] ], 0 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -2, 0, 1, 0 ], [ -1, 3, -2, -1, 0, 0 ], [ -1, 3, -1, -1, 1, 0 ] ], 0 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 0, 0 ], [ -1, 3, -1, -1, 1, 0 ] ], 6.875 ], - [ [ [ "Rest" ], [ -1, 3, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 0, 0 ], [ -1, 3, -1, -1, 1, 0 ] ], 0 ], - [ [ [ "Rest" ], [ -1, 3, -2, -1, 1, 0 ], [ "Rest" ], [ -1, 3, -1, -1, 1, 0 ] ], 0 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ -1, 3, -1, -1, 1, 0 ] ], 0 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 10.75 ] - ] - ] -], -"last_changes": -[ - [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -2, -1, 1, 1 ], [ -2, 3, -2, -1, 2, 0 ], [ 0, 3, -2, -1, 1, -1 ] ], - [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -2, 0, 1, 0 ], [ -2, 3, -2, -1, 2, 0 ], [ 0, 3, -2, -1, 1, -1 ] ], - [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -2, 0, 1, 0 ], [ -1, 3, -2, -1, 0, 0 ], [ 0, 3, -2, -1, 1, -1 ] ], - [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -2, 0, 1, 0 ], [ -1, 3, -2, -1, 0, 0 ], [ -1, 3, -1, -1, 1, 0 ] ], - [ [ -2, 3, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 0, 0 ], [ -1, 3, -1, -1, 1, 0 ] ] -], -"cur_uid": "60adbbef", -"ref_uid": "4c059f33", -"order_seed": 824152, -"dur_seed": 266394, -"motifs_seed": 206072, -"entrances_probs_vals": [ 1, 0, 5.0793650793651, 0.47, 2.8021978021978, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 1, 0, 2.7380952380952, 3.68, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 1, 0, 2.7380952380952, 3.68, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -1315.1702786378, 338.08049535604 ], [ -200.61919504644, 1452.6315789474 ], [ -386, 1675.5417956656 ], [ -219, 1694.1176470588 ] ], -"step_probs_vals": [ 0, 1200, 0, 0, 0.063786008230453, 0.92613636363636, 0.12757201646091, 0, 0.54732510288066, 0, 0.71604938271605, 0, 1, 0 ], -"passages_weights": [ 0.7, 0.29, 0.66, 0.74, 0.68 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 0 ], [ 3, 2, 1 ], [ ] ], - [ [ 0 ], [ 2, 1, 3 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ] -], -"sus_weights": [ 1, 0, 0 ], -"order_size": [ 8.0714285714286, 10.091836734694 ], -"passages_size": [ 0, 10 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/60adbbef/lilypond/part_I.ly b/resources/resources_bak_2024_01_03/string_quartet_2/60adbbef/lilypond/part_I.ly deleted file mode 100644 index 708ce11..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/60adbbef/lilypond/part_I.ly +++ /dev/null @@ -1,38 +0,0 @@ -{ - { r1 } - \bar "|" - { r2. r8[ e8^\markup { \pad-markup #0.2 "+18"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }}] ~ } - \bar "|" - { e1 ~ } - \bar "|" - { e1 ~ } - \bar "|" - { e4 f2.^\markup { \pad-markup #0.2 "+29"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↓" }} ~ } - \bar "|" - { f1 ~ } - \bar "|" - { f1 ~ } - \bar "|" - { f2. ~ f16[ cis'8.^\markup { \pad-markup #0.2 "-25"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↓" }}] ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'16[ cis'8.^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }}] ~ cis'2. ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'2 r2 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/60adbbef/lilypond/part_II.ly b/resources/resources_bak_2024_01_03/string_quartet_2/60adbbef/lilypond/part_II.ly deleted file mode 100644 index 7fea40e..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/60adbbef/lilypond/part_II.ly +++ /dev/null @@ -1,38 +0,0 @@ -{ - { r1 } - \bar "|" - { r2. r8[ cis8^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }}] ~ } - \bar "|" - { cis1 ~ } - \bar "|" - { cis1 ~ } - \bar "|" - { cis4 d2.^\markup { \pad-markup #0.2 "+14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }} ~ } - \bar "|" - { d1 ~ } - \bar "|" - { d1 ~ } - \bar "|" - { d2. ~ d16[ dis8.^\markup { \pad-markup #0.2 "-33"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 11↑" }}] ~ } - \bar "|" - { dis1 ~ } - \bar "|" - { dis1 ~ } - \bar "|" - { dis16[ e8.^\markup { \pad-markup #0.2 "-36"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 11↓" }}] ~ e2. ~ } - \bar "|" - { e1 ~ } - \bar "|" - { e1 ~ } - \bar "|" - { e2 r2 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/60adbbef/lilypond/part_III.ly b/resources/resources_bak_2024_01_03/string_quartet_2/60adbbef/lilypond/part_III.ly deleted file mode 100644 index dde5fb8..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/60adbbef/lilypond/part_III.ly +++ /dev/null @@ -1,38 +0,0 @@ -{ - { r1 } - \bar "|" - { r2. r8[ a8^\markup { \pad-markup #0.2 "+16"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }}] ~ } - \bar "|" - { a1 ~ } - \bar "|" - { a1 ~ } - \bar "|" - { a4 fis2.^\markup { \pad-markup #0.2 "-44"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↑" }} ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis2. ~ fis16[ g8.^\markup { \pad-markup #0.2 "-15"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↑" }}] ~ } - \bar "|" - { g1 ~ } - \bar "|" - { g1 ~ } - \bar "|" - { g16[ a8.^\markup { \pad-markup #0.2 "+16"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }}] ~ a2. ~ } - \bar "|" - { a1 ~ } - \bar "|" - { a1 ~ } - \bar "|" - { a2 r2 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/60adbbef/lilypond/part_IV.ly b/resources/resources_bak_2024_01_03/string_quartet_2/60adbbef/lilypond/part_IV.ly deleted file mode 100644 index 98319b9..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/60adbbef/lilypond/part_IV.ly +++ /dev/null @@ -1,38 +0,0 @@ -{ - { a,1^\markup { \pad-markup #0.2 "+16"} ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,2 r2 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/61e92979/61e92979_code.scd b/resources/resources_bak_2024_01_03/string_quartet_2/61e92979/61e92979_code.scd deleted file mode 100644 index c194eef..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/61e92979/61e92979_code.scd +++ /dev/null @@ -1,945 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance); -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/61e92979/61e92979_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_2/61e92979/61e92979_mus_model.json deleted file mode 100644 index 413129a..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/61e92979/61e92979_mus_model.json +++ /dev/null @@ -1,67 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 3.875 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ], [ 1, 0, 0, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 1, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, 0, -1, 0 ], [ 0, 0, 1, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ] ], 3.375 ] - ], - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, 0, -1, 0 ], [ 1, 0, 0, 0, 0, -1 ], [ 1, 0, 0, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ], [ 1, 0, 0, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ], [ 0, 0, 1, 0, 0, 0 ] ], 1.25 ] - ], - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, -1, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], 3.125 ] - ], - [ - [ [ [ 1, 0, -1, 0, 0, -1 ], [ 1, 0, -1, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], 0 ], - [ [ [ 1, 0, -1, 0, 0, -1 ], [ 1, 0, 1, 0, 0, -1 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], 2.25 ] - ], - [ - [ [ [ 1, -1, 0, 0, -1, 0 ], [ 1, 0, 1, 0, 0, -1 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], 0 ], - [ [ [ 1, -1, 0, 0, -1, 0 ], [ 2, -1, 0, -1, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], 2.625 ], - [ [ [ 1, -1, 0, 0, -1, 0 ], [ 2, -1, 0, -1, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ "Rest" ] ], 0 ], - [ [ [ 1, -1, 0, 0, -1, 0 ], [ 2, -1, 0, -1, 0, 0 ], [ "Rest" ], [ "Rest" ] ], 0 ], - [ [ [ "Rest" ], [ 2, -1, 0, -1, 0, 0 ], [ "Rest" ], [ "Rest" ] ], 0 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 10 ] - ] - ] -], -"last_changes": -[ - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ], [ 1, 0, 0, 0, 0, 0 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ], [ 0, 0, 1, 0, 0, 0 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, -1, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ] -], -"cur_uid": "61e92979", -"ref_uid": "nil", -"order_seed": 921767, -"dur_seed": 954688, -"motifs_seed": 995213, -"entrances_probs_vals": [ 1, 0, 0, 3.68, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 1, 0, 0, 3.68, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 1, 0, 0, 3.68, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -1315.1702786378, 338.08049535604 ], [ -200.61919504644, 1452.6315789474 ], [ -386, 1675.5417956656 ], [ -219, 1694.1176470588 ] ], -"step_probs_vals": [ 0, 1200, 0, 0, 0.063786008230453, 0.92613636363636, 0.12757201646091, 0, 0.54732510288066, 0, 0.71604938271605, 0, 1, 0 ], -"passages_weights": [ 0.7, 0.29, 0.66, 0.74, 0.68 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 0 ], [ 3, 2, 1 ], [ ] ], - [ [ 0 ], [ 2, 1, 3 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ] -], -"sus_weights": [ 1, 0, 0 ], -"order_size": [ 8, 10 ], -"passages_size": [ 0, 10 ], -"motif_edited": "true", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/62300302/62300302_code.scd b/resources/resources_bak_2024_01_03/string_quartet_2/62300302/62300302_code.scd deleted file mode 100644 index 57e638d..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/62300302/62300302_code.scd +++ /dev/null @@ -1,945 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array2) - hsArrayToCents.value(array1); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = true; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance); -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength.asInteger - minMotifLength.asInteger).rand + minMotifLength.asInteger).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength.asInteger - minProgLength.asInteger).rand + minProgLength.asInteger).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/62300302/62300302_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_2/62300302/62300302_mus_model.json deleted file mode 100644 index dfaef7d..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/62300302/62300302_mus_model.json +++ /dev/null @@ -1,77 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ -2, 3, -2, -1, 1, 0 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 2.25 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ "Rest" ], [ "Rest" ], [ -2, 3, -2, 0, 1, 0 ] ], 1.5 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ "Rest" ], [ 0, 2, -2, -1, 1, 0 ], [ -2, 3, -2, 0, 1, 0 ] ], 1.875 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -2, -1, 2, 0 ], [ 0, 2, -2, -1, 1, 0 ], [ -2, 3, -2, 0, 1, 0 ] ], 2.625 ] - ], - [ - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -2, -1, 2, 0 ], [ -1, 3, -2, -1, 2, 0 ], [ -2, 3, -2, 0, 1, 0 ] ], 1.25 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 0, 0 ], [ -1, 3, -2, -1, 2, 0 ], [ -2, 3, -2, 0, 1, 0 ] ], 1.5 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 0, 0 ], [ -1, 3, -2, -1, 2, 0 ], [ -1, 3, -2, -2, 1, 0 ] ], 2.25 ] - ], - [ - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 0, 0 ], [ 0, 3, -2, -1, 0, 0 ], [ -1, 3, -2, -2, 1, 0 ] ], 1.5 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 0, 0 ], [ 0, 3, -2, -1, 0, 0 ], [ -1, 3, -2, -1, 1, -1 ] ], 2 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 4, -2, -1, 1, 0 ], [ 0, 3, -2, -1, 0, 0 ], [ -1, 3, -2, -1, 1, -1 ] ], 1.75 ] - ], - [ - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 4, -2, -1, 1, 0 ], [ 0, 3, -2, -2, 1, 0 ], [ -1, 3, -2, -1, 1, -1 ] ], 1.375 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 4, -2, -1, 1, 0 ], [ 0, 3, -2, -2, 1, 0 ], [ -1, 2, -2, -1, 1, 0 ] ], 2.125 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -2, -1, 1, 1 ], [ 0, 3, -2, -2, 1, 0 ], [ -1, 2, -2, -1, 1, 0 ] ], 1.125 ] - ], - [ - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -2, -1, 1, 1 ], [ 0, 3, -2, -1, 1, -1 ], [ -1, 2, -2, -1, 1, 0 ] ], 2.125 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -2, 0, 1, 0 ], [ 0, 3, -2, -1, 1, -1 ], [ -1, 2, -2, -1, 1, 0 ] ], 1.75 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -2, 0, 1, 0 ], [ 0, 3, -2, -1, 1, -1 ], [ -2, 3, -2, -1, 2, 0 ] ], 2 ] - ], - [ - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -2, 0, 1, 0 ], [ 0, 3, -2, -1, 1, -1 ], [ -1, 3, -2, -1, 0, 0 ] ], 1 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -2, 0, 1, 0 ], [ 0, 2, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 0, 0 ] ], 1 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 1, 0 ], [ 0, 2, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 0, 0 ] ], 1.5 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 1, 0 ], [ "Rest" ], [ -1, 3, -2, -1, 0, 0 ] ], 1 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 1, 0 ], [ "Rest" ], [ "Rest" ] ], 1.375 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 0 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 0 ] - ] - ] -], -"last_changes": -[ - [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -2, 0, 1, 0 ], [ 0, 3, -2, -1, 1, -1 ], [ -1, 2, -2, -1, 1, 0 ] ], - [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -2, 0, 1, 0 ], [ 0, 3, -2, -1, 1, -1 ], [ -2, 3, -2, -1, 2, 0 ] ], - [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -2, 0, 1, 0 ], [ 0, 3, -2, -1, 1, -1 ], [ -1, 3, -2, -1, 0, 0 ] ], - [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -2, 0, 1, 0 ], [ 0, 2, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 0, 0 ] ], - [ [ -2, 3, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 1, 0 ], [ 0, 2, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 0, 0 ] ] -], -"cur_uid": "62300302", -"ref_uid": "74b8f8d9", -"order_seed": 799630, -"dur_seed": 442647, -"motifs_seed": 452591, -"entrances_probs_vals": [ 1, 0, 2.9365079365079, 0.47, 2.8021978021978, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 0, 0, 2.7380952380952, 0.96, 2.4725274725275, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 0, 0, 2.7380952380952, 0.96, 2.4725274725275, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -1315.1702786378, 338.08049535604 ], [ -200.61919504644, 1452.6315789474 ], [ -386, 1675.5417956656 ], [ -219, 1694.1176470588 ] ], -"step_probs_vals": [ 0, 1200, 0, 0, 0.063786008230453, 0.92613636363636, 0.12757201646091, 0, 0.54732510288066, 0, 0.71604938271605, 0, 1, 0 ], -"passages_weights": [ 0.7, 0.29, 0.66, 0.74, 0.68 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 0 ], [ 3, 2, 1 ], [ ] ], - [ [ 0 ], [ 2, 1, 3 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ], - [ [ 0 ], [ 2, 1, 3 ], [ ] ], - [ [ 0 ], [ 3, 2, 1 ], [ ] ] -], -"sus_weights": [ 1, 0, 0 ], -"order_size": [ 8.0714285714286, 10.091836734694 ], -"passages_size": [ 0, 10 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/62300302/lilypond/part_I.ly b/resources/resources_bak_2024_01_03/string_quartet_2/62300302/lilypond/part_I.ly deleted file mode 100644 index f4f96ba..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/62300302/lilypond/part_I.ly +++ /dev/null @@ -1,36 +0,0 @@ -{ - { r1 } - \bar "|" - { r8[ g8^\markup { \pad-markup #0.2 "-15"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↑" }}] ~ g2. ~ } - \bar "|" - { g1 ~ } - \bar "|" - { g1 ~ } - \bar "|" - { g1 ~ } - \bar "|" - { g2 b,2^\markup { \pad-markup #0.2 "+47"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↓" }} ~ } - \bar "|" - { b,1 ~ } - \bar "|" - { b,4 ~ b,8[ cis8^\markup { \pad-markup #0.2 "-25"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↓" }}] ~ cis2 ~ } - \bar "|" - { cis1 ~ } - \bar "|" - { cis2. ~ cis8.[ d16^\markup { \pad-markup #0.2 "+14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }}] ~ } - \bar "|" - { d1 ~ } - \bar "|" - { d1 ~ } - \bar "|" - { d1 ~ } - \bar "|" - { d2 dis2^\markup { \pad-markup #0.2 "-33"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 11↑" }} ~ } - \bar "|" - { dis2 e2^\markup { \pad-markup #0.2 "-36"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 11↓" }} ~ } - \bar "|" - { e1 ~ } - \bar "|" - { e2. r4} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/62300302/lilypond/part_II.ly b/resources/resources_bak_2024_01_03/string_quartet_2/62300302/lilypond/part_II.ly deleted file mode 100644 index 158f676..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/62300302/lilypond/part_II.ly +++ /dev/null @@ -1,36 +0,0 @@ -{ - { r1 } - \bar "|" - { r2. r8[ d'8^\markup { \pad-markup #0.2 "+14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }}] ~ } - \bar "|" - { d'1 ~ } - \bar "|" - { d'1 ~ } - \bar "|" - { d'8[ dis'8^\markup { \pad-markup #0.2 "-33"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }}] ~ dis'2. ~ } - \bar "|" - { dis'1 ~ } - \bar "|" - { dis'2 ~ dis'8[ e'8^\markup { \pad-markup #0.2 "-36"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }}] ~ e'4 ~ } - \bar "|" - { e'1 ~ } - \bar "|" - { e'1 ~ } - \bar "|" - { e'4 b2.^\markup { \pad-markup #0.2 "+47"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↓" }} ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b2 ~ b16[ cis'8.^\markup { \pad-markup #0.2 "-25"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↓" }}] ~ cis'4 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 } - \bar "|" - { d'1^\markup { \pad-markup #0.2 "+14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }} ~ } - \bar "|" - { d'4 r2. } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/62300302/lilypond/part_III.ly b/resources/resources_bak_2024_01_03/string_quartet_2/62300302/lilypond/part_III.ly deleted file mode 100644 index cebac3f..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/62300302/lilypond/part_III.ly +++ /dev/null @@ -1,36 +0,0 @@ -{ - { r1 } - \bar "|" - { r1 } - \bar "|" - { r2. r16[ dis8.^\markup { \pad-markup #0.2 "-33"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 11↑" }}] ~ } - \bar "|" - { dis1 ~ } - \bar "|" - { dis2. e4^\markup { \pad-markup #0.2 "-36"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 11↓" }} ~ } - \bar "|" - { e1 ~ } - \bar "|" - { e1 ~ } - \bar "|" - { e1 ~ } - \bar "|" - { e4 ~ e8[ e8^\markup { \pad-markup #0.2 "+18"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }}] ~ e2 ~ } - \bar "|" - { e1 ~ } - \bar "|" - { e1 } - \bar "|" - { fis1^\markup { \pad-markup #0.2 "-44"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↑" }} ~ } - \bar "|" - { fis2 ~ fis8[ g8^\markup { \pad-markup #0.2 "-15"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↑" }}] ~ g4 ~ } - \bar "|" - { g1 ~ } - \bar "|" - { g1 ~ } - \bar "|" - { g2 a2^\markup { \pad-markup #0.2 "+16"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }} ~ } - \bar "|" - { a1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/62300302/lilypond/part_IV.ly b/resources/resources_bak_2024_01_03/string_quartet_2/62300302/lilypond/part_IV.ly deleted file mode 100644 index 19d2217..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/62300302/lilypond/part_IV.ly +++ /dev/null @@ -1,36 +0,0 @@ -{ - { a,1^\markup { \pad-markup #0.2 "+16"} ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/628706ec/628706ec_code.scd b/resources/resources_bak_2024_01_03/string_quartet_2/628706ec/628706ec_code.scd deleted file mode 100644 index c194eef..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/628706ec/628706ec_code.scd +++ /dev/null @@ -1,945 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance); -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/628706ec/628706ec_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_2/628706ec/628706ec_mus_model.json deleted file mode 100644 index 7226160..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/628706ec/628706ec_mus_model.json +++ /dev/null @@ -1,117 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ 0, 2, -1, 0, 0, 0 ], [ "Rest" ], [ "Rest" ] ], 1.5 ], - [ [ [ -1, 2, -1, 0, 0, 0 ], [ 0, 2, -1, 0, 0, 0 ], [ "Rest" ], [ "Rest" ] ], 1.25 ], - [ [ [ -1, 2, -1, 0, 0, 0 ], [ 0, 2, -1, 0, 0, 0 ], [ "Rest" ], [ 1, 2, -1, 0, 0, 0 ] ], 0.5 ], - [ [ [ 1, 2, -1, -1, 0, 0 ], [ 0, 2, -1, 0, 0, 0 ], [ "Rest" ], [ 1, 2, -1, 0, 0, 0 ] ], 0.875 ], - [ [ [ 1, 2, -1, -1, 0, 0 ], [ 0, 2, -1, 0, 0, 0 ], [ "Rest" ], [ 0, 2, -1, 0, 0, 1 ] ], 1.25 ], - [ [ [ -1, 3, -1, 0, 0, 0 ], [ 0, 2, -1, 0, 0, 0 ], [ "Rest" ], [ 0, 2, -1, 0, 0, 1 ] ], 0 ] - ], - [ - [ [ [ -1, 3, -1, 0, 0, 0 ], [ 0, 2, -1, 0, 0, 0 ], [ "Rest" ], [ "Rest" ] ], 0.75 ], - [ [ [ -1, 3, -1, 0, 0, 0 ], [ 0, 2, -1, 0, 0, 0 ], [ 0, 2, -1, 0, 0, 0 ], [ "Rest" ] ], 1.375 ], - [ [ [ 0, 2, -1, 0, -1, 0 ], [ 0, 2, -1, 0, 0, 0 ], [ 0, 2, -1, 0, 0, 0 ], [ "Rest" ] ], 0.5 ], - [ [ [ 0, 2, -1, 0, -1, 0 ], [ 1, 2, -1, 0, -1, 0 ], [ 0, 2, -1, 0, 0, 0 ], [ "Rest" ] ], 1.375 ], - [ [ [ 0, 2, -1, 0, -1, 0 ], [ 0, 2, -1, 0, 1, 0 ], [ 0, 2, -1, 0, 0, 0 ], [ "Rest" ] ], 0.75 ], - [ [ [ 0, 2, -1, 0, -1, 0 ], [ 1, 1, -1, 0, 0, 0 ], [ 0, 2, -1, 0, 0, 0 ], [ "Rest" ] ], 0.125 ], - [ [ [ -1, 2, -1, 0, 1, 0 ], [ 1, 1, -1, 0, 0, 0 ], [ 0, 2, -1, 0, 0, 0 ], [ "Rest" ] ], 1 ], - [ [ [ 0, 1, -1, 0, 0, 0 ], [ 1, 1, -1, 0, 0, 0 ], [ 0, 2, -1, 0, 0, 0 ], [ "Rest" ] ], 1.375 ], - [ [ [ -1, 2, 0, 0, 0, 0 ], [ 1, 1, -1, 0, 0, 0 ], [ 0, 2, -1, 0, 0, 0 ], [ "Rest" ] ], 0.5 ] - ], - [ - [ [ [ -1, 2, 0, 0, 0, 0 ], [ 1, 1, -1, 0, 0, 0 ], [ "Rest" ], [ "Rest" ] ], 0.75 ], - [ [ [ -1, 2, 0, 0, 0, 0 ], [ 1, 1, -1, 0, 0, 0 ], [ "Rest" ], [ 2, 1, -1, 0, 0, -1 ] ], 0.125 ], - [ [ [ -1, 1, -1, 1, 0, 0 ], [ 1, 1, -1, 0, 0, 0 ], [ "Rest" ], [ 2, 1, -1, 0, 0, -1 ] ], 1.375 ], - [ [ [ -1, 1, -1, 1, 0, 0 ], [ 1, 1, -1, 0, 0, 0 ], [ "Rest" ], [ 2, 1, -1, -1, 0, 0 ] ], 0.125 ] - ], - [ - [ [ [ -1, 1, -1, 1, 0, 0 ], [ 1, 1, -1, -1, 0, 1 ], [ "Rest" ], [ 2, 1, -1, -1, 0, 0 ] ], 0.75 ], - [ [ [ 0, 1, -1, -1, 0, 1 ], [ 1, 1, -1, -1, 0, 1 ], [ "Rest" ], [ 2, 1, -1, -1, 0, 0 ] ], 0 ], - [ [ [ 0, 1, -1, -1, 0, 1 ], [ 2, 1, -2, -1, 0, 0 ], [ "Rest" ], [ 2, 1, -1, -1, 0, 0 ] ], 0.875 ], - [ [ [ 0, 2, -1, -1, 0, 0 ], [ 2, 1, -2, -1, 0, 0 ], [ "Rest" ], [ 2, 1, -1, -1, 0, 0 ] ], 0.125 ], - [ [ [ 0, 2, -1, -1, 0, 0 ], [ 1, 2, -1, -1, 0, 0 ], [ "Rest" ], [ 2, 1, -1, -1, 0, 0 ] ], 0.75 ], - [ [ [ 1, 1, -1, -1, -1, 0 ], [ 1, 2, -1, -1, 0, 0 ], [ "Rest" ], [ 2, 1, -1, -1, 0, 0 ] ], 1.375 ], - [ [ [ 0, 1, -1, -1, 1, 0 ], [ 1, 2, -1, -1, 0, 0 ], [ "Rest" ], [ 2, 1, -1, -1, 0, 0 ] ], 0.25 ] - ], - [ - [ [ [ 0, 1, -1, -1, 1, 0 ], [ 1, 2, -1, -1, 0, 0 ], [ "Rest" ], [ 1, 2, 0, -1, 0, 0 ] ], 1.125 ], - [ [ [ -1, 2, -1, 0, 0, 0 ], [ 1, 2, -1, -1, 0, 0 ], [ "Rest" ], [ 1, 2, 0, -1, 0, 0 ] ], 1.375 ], - [ [ [ -1, 2, -1, 0, 0, 0 ], [ 1, 2, -1, -1, 0, 0 ], [ 0, 2, -1, -1, 0, 1 ], [ 1, 2, 0, -1, 0, 0 ] ], 0.25 ], - [ [ [ -1, 2, -1, 0, 0, 0 ], [ 1, 2, -1, -1, 0, 0 ], [ 1, 2, -2, -1, 0, 0 ], [ 1, 2, 0, -1, 0, 0 ] ], 0.625 ], - [ [ [ -1, 2, -1, 0, 0, 0 ], [ 1, 2, -1, -1, 0, 0 ], [ 1, 2, -2, -1, 0, 0 ], [ 1, 2, -1, 0, 0, 0 ] ], 0.375 ], - [ [ [ -1, 2, -1, 0, 0, 0 ], [ 1, 2, -1, -1, 0, 0 ], [ 1, 2, -2, -1, 0, 0 ], [ 1, 2, -1, -1, 0, 1 ] ], 0.125 ], - [ [ [ 1, 2, -1, -1, -1, 0 ], [ 1, 2, -1, -1, 0, 0 ], [ 1, 2, -2, -1, 0, 0 ], [ 1, 2, -1, -1, 0, 1 ] ], 1.5 ], - [ [ [ 1, 2, -1, -1, -1, 0 ], [ 1, 2, -1, -1, 0, 0 ], [ 0, 3, -1, -1, 0, 0 ], [ 1, 2, -1, -1, 0, 1 ] ], 0.875 ] - ], - [ - [ [ [ -1, 4, -1, -1, 0, 0 ], [ 1, 2, -1, -1, 0, 0 ], [ 0, 3, -1, -1, 0, 0 ], [ 1, 2, -1, -1, 0, 1 ] ], 0.625 ], - [ [ [ -1, 4, -1, -1, 0, 0 ], [ 1, 2, -1, -1, 0, 0 ], [ 0, 3, -1, -1, 0, 0 ], [ 1, 3, -1, -1, 0, 0 ] ], 0.125 ], - [ [ [ -1, 4, -1, -1, 0, 0 ], [ 0, 3, 0, -1, 0, 0 ], [ 0, 3, -1, -1, 0, 0 ], [ 1, 3, -1, -1, 0, 0 ] ], 0.125 ] - ], - [ - [ [ [ -1, 4, -1, -1, 0, 0 ], [ 0, 3, 0, -1, 0, 0 ], [ 0, 3, -1, -1, 0, 0 ], [ 1, 4, -1, -1, 0, 0 ] ], 0.375 ], - [ [ [ -1, 4, -1, -1, 0, 0 ], [ 1, 3, -1, -1, 0, -1 ], [ 0, 3, -1, -1, 0, 0 ], [ 1, 4, -1, -1, 0, 0 ] ], 0.25 ], - [ [ [ 0, 3, -1, -1, -1, 0 ], [ 1, 3, -1, -1, 0, -1 ], [ 0, 3, -1, -1, 0, 0 ], [ 1, 4, -1, -1, 0, 0 ] ], 1 ], - [ [ [ 0, 3, -1, -1, -1, 0 ], [ 1, 3, -1, -1, 0, -1 ], [ 0, 3, -1, -1, 0, 0 ], [ 2, 3, -1, -1, -1, 0 ] ], 1 ], - [ [ [ 0, 3, -1, -1, -1, 0 ], [ 1, 3, -1, -1, 0, -1 ], [ 0, 3, -1, -1, 0, 0 ], [ 1, 3, -1, -1, 1, 0 ] ], 0.875 ], - [ [ [ -1, 3, -1, -1, 1, 0 ], [ 1, 3, -1, -1, 0, -1 ], [ 0, 3, -1, -1, 0, 0 ], [ 1, 3, -1, -1, 1, 0 ] ], 0.875 ], - [ [ [ 0, 2, -1, -1, 0, 0 ], [ 1, 3, -1, -1, 0, -1 ], [ 0, 3, -1, -1, 0, 0 ], [ 1, 3, -1, -1, 1, 0 ] ], 1.25 ], - [ [ [ 0, 3, -1, -1, 0, -1 ], [ 1, 3, -1, -1, 0, -1 ], [ 0, 3, -1, -1, 0, 0 ], [ 1, 3, -1, -1, 1, 0 ] ], 0.375 ], - [ [ [ 0, 3, -1, -1, 0, -1 ], [ 0, 3, 0, -1, 0, 0 ], [ 0, 3, -1, -1, 0, 0 ], [ 1, 3, -1, -1, 1, 0 ] ], 1.5 ], - [ [ [ 0, 3, -1, -2, 0, 0 ], [ 0, 3, 0, -1, 0, 0 ], [ 0, 3, -1, -1, 0, 0 ], [ 1, 3, -1, -1, 1, 0 ] ], 0.375 ], - [ [ [ 0, 3, -1, -2, 0, 0 ], [ 1, 2, -1, -1, 0, 0 ], [ 0, 3, -1, -1, 0, 0 ], [ 1, 3, -1, -1, 1, 0 ] ], 0.25 ], - [ [ [ 0, 3, -1, -2, 0, 0 ], [ 0, 3, -1, -1, 1, 0 ], [ 0, 3, -1, -1, 0, 0 ], [ 1, 3, -1, -1, 1, 0 ] ], 0.875 ] - ], - [ - [ [ [ "Rest" ], [ 0, 3, -1, -1, 1, 0 ], [ 0, 3, -1, -1, 0, 0 ], [ 1, 3, -1, -1, 1, 0 ] ], 0.625 ], - [ [ [ "Rest" ], [ 0, 3, -1, -1, 1, 0 ], [ 0, 3, -1, -1, 0, 0 ], [ 1, 3, -1, -1, 1, -1 ] ], 0.5 ], - [ [ [ "Rest" ], [ 0, 3, -1, -1, 1, 0 ], [ -1, 4, -1, -1, 1, 0 ], [ 1, 3, -1, -1, 1, -1 ] ], 1 ], - [ [ [ "Rest" ], [ 0, 3, -1, -1, 1, 0 ], [ 0, 3, -2, -1, 1, 0 ], [ 1, 3, -1, -1, 1, -1 ] ], 1.125 ], - [ [ [ "Rest" ], [ 0, 3, -1, -1, 1, 0 ], [ -1, 3, -1, -1, 1, 1 ], [ 1, 3, -1, -1, 1, -1 ] ], 1.375 ], - [ [ [ "Rest" ], [ 0, 3, -1, -1, 1, 0 ], [ -1, 3, -1, 0, 1, 0 ], [ 1, 3, -1, -1, 1, -1 ] ], 0 ], - [ [ [ "Rest" ], [ 0, 3, -1, -1, 1, 0 ], [ -1, 3, -1, 0, 1, 0 ], [ 0, 3, 0, -1, 1, 0 ] ], 0.125 ], - [ [ [ "Rest" ], [ 0, 3, -1, -1, 1, 0 ], [ -1, 3, -1, 0, 1, 0 ], [ 1, 2, -1, -1, 1, 0 ] ], 1.375 ], - [ [ [ "Rest" ], [ 0, 3, -1, -1, 1, 0 ], [ -1, 4, -1, -1, 1, 0 ], [ 1, 2, -1, -1, 1, 0 ] ], 0.875 ], - [ [ [ "Rest" ], [ 0, 3, -1, -1, 1, 0 ], [ 0, 3, -2, -1, 1, 0 ], [ 1, 2, -1, -1, 1, 0 ] ], 0.375 ], - [ [ [ "Rest" ], [ 0, 3, -1, -1, 1, 0 ], [ 0, 3, -2, -1, 1, 0 ], [ 0, 3, -1, -1, 2, 0 ] ], 0.625 ], - [ [ [ "Rest" ], [ 0, 3, -1, -1, 1, 0 ], [ 0, 3, -2, -1, 1, 0 ], [ "Rest" ] ], 0.5 ], - [ [ [ "Rest" ], [ "Rest" ], [ 0, 3, -2, -1, 1, 0 ], [ "Rest" ] ], 0.625 ] - ] - ] -], -"last_changes": -[ - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 1, 0, 0 ], [ 0, 0, 0, 0, 1, 0 ], [ 1, 0, 0, -1, 0, 0 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 1, 0, 0 ], [ 0, 0, 0, 0, 1, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 1, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 1, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ] ], - [ [ 0, 3, -2, -1, 1, 0 ], [ 0, 3, -2, -1, 1, 0 ], [ 0, 3, -2, -1, 1, 0 ], [ 0, 3, -2, -1, 1, 0 ] ] -], -"cur_uid": "628706ec", -"ref_uid": "77b0d2dc", -"order_seed": 921767, -"dur_seed": 954688, -"motifs_seed": 995213, -"entrances_probs_vals": [ 1, 0, 0, 3.68, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 1, 0, 0, 3.68, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 1, 0, 0, 3.68, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -1315.1702786378, 338.08049535604 ], [ -200.61919504644, 1452.6315789474 ], [ -386, 1675.5417956656 ], [ -219, 1694.1176470588 ] ], -"step_probs_vals": [ 0, 1200, 0, 0, 0.063786008230453, 0.92613636363636, 0.12757201646091, 0, 0.54732510288066, 0, 0.71604938271605, 0, 1, 0 ], -"passages_weights": [ 0.7, 0.29, 0.66, 0.74, 0.68 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 0 ], [ 3, 2, 1 ], [ ] ], - [ [ 0 ], [ 2, 1, 3 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ] -], -"sus_weights": [ 1, 0, 0 ], -"order_size": [ 8, 10 ], -"passages_size": [ 0, 10 ], -"motif_edited": "true", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/628706ec/lilypond/part_I.ly b/resources/resources_bak_2024_01_03/string_quartet_2/628706ec/lilypond/part_I.ly deleted file mode 100644 index 5057e30..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/628706ec/lilypond/part_I.ly +++ /dev/null @@ -1,46 +0,0 @@ -{ - { r1 } - \bar "|" - { r4 r8[ ais''8^\markup { \pad-markup #0.2 "+18"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }}] ~ ais''2 ~ } - \bar "|" - { ais''16[ g''8.^\markup { \pad-markup #0.2 "-42"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 13↑" }}] ~ g''4 ~ g''8.[ r16] r4 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r2. r8.[ g''16^\markup { \pad-markup #0.2 "-25"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 13↓" }}] ~ } - \bar "|" - { g''2 ~ g''8.[ f''16^\markup { \pad-markup #0.2 "+47"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 7↓" }}] ~ f''4 ~ } - \bar "|" - { f''1 ~ } - \bar "|" - { f''2. ~ f''16[ e''8.^\markup { \pad-markup #0.2 "+35"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 5↑" }}] ~ } - \bar "|" - { e''1 ~ } - \bar "|" - { e''2 ais''8.^\markup { \pad-markup #0.2 "+18"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }}[ a''16^\markup { \pad-markup #0.2 "-11"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 13↑" }}] ~ a''4 ~ } - \bar "|" - { a''1 ~ } - \bar "|" - { a''4 gis''8^\markup { \pad-markup #0.2 "-49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 1↑" }}[ dis'''8^\markup { \pad-markup #0.2 "-47"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }}] ~ dis'''2 ~ } - \bar "|" - { dis'''8.[ d'''16^\markup { \pad-markup #0.2 "-1"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }}] ~ d'''4 ~ d'''8.[ cis'''16^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 11↑" }}] ~ cis'''4 ~ } - \bar "|" - { cis'''1 ~ } - \bar "|" - { cis'''1 ~ } - \bar "|" - { cis'''1 ~ } - \bar "|" - { cis'''8.[ f''16^\markup { \pad-markup #0.2 "-38"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 13↓" }}] ~ f''2. ~ } - \bar "|" - { f''1 ~ } - \bar "|" - { f''8.[ f''16^\markup { \pad-markup #0.2 "-12"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 5↑" }}] fis''2.^\markup { \pad-markup #0.2 "+0"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↓" }} ~ } - \bar "|" - { fis''2 ~ fis''16[ g''8.^\markup { \pad-markup #0.2 "-47"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 11↑" }}] ~ g''8[ r8]} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/628706ec/lilypond/part_II.ly b/resources/resources_bak_2024_01_03/string_quartet_2/628706ec/lilypond/part_II.ly deleted file mode 100644 index 488d911..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/628706ec/lilypond/part_II.ly +++ /dev/null @@ -1,46 +0,0 @@ -{ - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r16[ ais'8.^\markup { \pad-markup #0.2 "+18"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }}] ~ ais'2. ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'2 ~ ais'16[ r8.] r4 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r16[ a'8^\markup { \pad-markup #0.2 "-11"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 13↑" }} a'16^\markup { \pad-markup #0.2 "-38"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 5↓" }}] ~ a'2. ~ } - \bar "|" - { a'2 gis'2^\markup { \pad-markup #0.2 "-49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↑" }} ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'4 ~ gis'8.[ gis'16^\markup { \pad-markup #0.2 "+4"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↑" }}] ~ gis'4 ~ gis'8.[ a'16^\markup { \pad-markup #0.2 "+16"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 5↓" }}] ~ } - \bar "|" - { a'2 a'2^\markup { \pad-markup #0.2 "+43"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 13↑" }} ~ } - \bar "|" - { a'8.[ b'16^\markup { \pad-markup #0.2 "-29"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 7↑" }}] ~ b'2 ~ b'8.[ gis'16^\markup { \pad-markup #0.2 "+4"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↑" }}] ~ } - \bar "|" - { gis'4 ~ gis'8[ a'8^\markup { \pad-markup #0.2 "+16"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 5↓" }}] ~ a'2} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/628706ec/lilypond/part_III.ly b/resources/resources_bak_2024_01_03/string_quartet_2/628706ec/lilypond/part_III.ly deleted file mode 100644 index e86a63f..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/628706ec/lilypond/part_III.ly +++ /dev/null @@ -1,46 +0,0 @@ -{ - { ais'1^\markup { \pad-markup #0.2 "+18"} ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 } - \bar "|" - { f''2^\markup { \pad-markup #0.2 "-34"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }} ~ f''8.[ e''16^\markup { \pad-markup #0.2 "-31"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 11↑" }}] ~ e''4 ~ } - \bar "|" - { e''16[ dis''8.^\markup { \pad-markup #0.2 "+16"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↓" }}] ~ dis''2. ~ } - \bar "|" - { dis''1 ~ } - \bar "|" - { dis''2. d''4^\markup { \pad-markup #0.2 "-13"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 13↑" }} ~ } - \bar "|" - { d''8[ d''8^\markup { \pad-markup #0.2 "-39"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 5↓" }}] ~ d''4 ~ d''8[ c''8^\markup { \pad-markup #0.2 "+49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }}] ~ c''4 ~ } - \bar "|" - { c''1 ~ } - \bar "|" - { c''1 ~ } - \bar "|" - { c''1 ~ } - \bar "|" - { c''1 ~ } - \bar "|" - { c''4 ~ c''16[ b'8.^\markup { \pad-markup #0.2 "+37"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 5↑" }}] ~ b'16[ b'8.^\markup { \pad-markup #0.2 "+10"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 13↓" }}] ~ b'4 ~ } - \bar "|" - { b'1 ~ } - \bar "|" - { b'1 ~ } - \bar "|" - { b'4 ~ b'8[ b'8^\markup { \pad-markup #0.2 "+37"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 5↑" }}] ~ b'2 ~ } - \bar "|" - { b'4 ~ b'16[ c''8^\markup { \pad-markup #0.2 "+49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↓" }} cis''16^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }}] ~ cis''2 ~ } - \bar "|" - { cis''1 ~ } - \bar "|" - { cis''1 ~ } - \bar "|" - { cis''1 ~ } - \bar "|" - { cis''1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/628706ec/lilypond/part_IV.ly b/resources/resources_bak_2024_01_03/string_quartet_2/628706ec/lilypond/part_IV.ly deleted file mode 100644 index ce23b81..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/628706ec/lilypond/part_IV.ly +++ /dev/null @@ -1,46 +0,0 @@ -{ - { r2. ais4^\markup { \pad-markup #0.2 "+18"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }} ~ } - \bar "|" - { ais2 ~ ais8[ c''8^\markup { \pad-markup #0.2 "+49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 7↓" }}] ~ c''4 ~ } - \bar "|" - { c''2 ~ c''8.[ f'16^\markup { \pad-markup #0.2 "+20"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↑" }}] ~ f'4 ~ } - \bar "|" - { f'2. f'4^\markup { \pad-markup #0.2 "-34"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 11↓" }} ~ } - \bar "|" - { f'1 ~ } - \bar "|" - { f'8[ e'8^\markup { \pad-markup #0.2 "-31"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 11↑" }}] ~ e'4 ~ e'8[ dis'8^\markup { \pad-markup #0.2 "+16"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }}] ~ dis'4 ~ } - \bar "|" - { dis'4 ~ dis'16[ d'8.^\markup { \pad-markup #0.2 "+4"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 5↑" }}] ~ d'2 } - \bar "|" - { cis'1^\markup { \pad-markup #0.2 "-16"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 7↑" }} ~ } - \bar "|" - { cis'8[ d'8^\markup { \pad-markup #0.2 "-13"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }}] ~ d'4 ~ d'16[ c'8.^\markup { \pad-markup #0.2 "+49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↑" }}] ~ c'4 } - \bar "|" - { c'2^\markup { \pad-markup #0.2 "-5"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 11↓" }} ~ c'8.[ b16^\markup { \pad-markup #0.2 "-2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 11↑" }}] ~ b4 ~ } - \bar "|" - { b4 ~ b8[ ais8^\markup { \pad-markup #0.2 "+18"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 7↑" }}] ~ ais2 ~ } - \bar "|" - { ais2. g'4^\markup { \pad-markup #0.2 "-3"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 11↓" }} ~ } - \bar "|" - { g'2. ~ g'8.[ dis'16^\markup { \pad-markup #0.2 "-47"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↑" }}] ~ } - \bar "|" - { dis'2 ~ dis'8.[ d'16^\markup { \pad-markup #0.2 "-1"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 11↓" }}] ~ d'4 ~ } - \bar "|" - { d'1 ~ } - \bar "|" - { d'8[ cis'8^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }}] ~ cis'4 ~ cis'16[ c'8.^\markup { \pad-markup #0.2 "+49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↓" }}] ~ c'4 ~ } - \bar "|" - { c'8.[ b16^\markup { \pad-markup #0.2 "+10"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }}] ~ b2. ~ } - \bar "|" - { b8[ ais8^\markup { \pad-markup #0.2 "-18"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 7↓" }}] ~ ais2 ~ ais8[ r8] } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/63bf7942/63bf7942_code.scd b/resources/resources_bak_2024_01_03/string_quartet_2/63bf7942/63bf7942_code.scd deleted file mode 100644 index c194eef..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/63bf7942/63bf7942_code.scd +++ /dev/null @@ -1,945 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance); -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/63bf7942/63bf7942_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_2/63bf7942/63bf7942_mus_model.json deleted file mode 100644 index 792f760..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/63bf7942/63bf7942_mus_model.json +++ /dev/null @@ -1,67 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 2.125 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ], [ 1, 0, 0, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 1, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, 0, -1, 0 ], [ 0, 0, 1, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ] ], 4.75 ] - ], - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, 0, -1, 0 ], [ 1, 0, 0, 0, 0, -1 ], [ 1, 0, 0, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ], [ 1, 0, 0, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ], [ 0, 0, 1, 0, 0, 0 ] ], 2.875 ] - ], - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, -1, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], 3.375 ] - ], - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, -1, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 0, 1, -1, 0, 0, 0 ] ], 1.375 ] - ], - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, -1, 1, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 0, 1, -1, 0, 0, 0 ] ], 4.625 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, -1, 1, 0, 0, 0 ], [ "Rest" ], [ 0, 1, -1, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, -1, 1, 0, 0, 0 ], [ "Rest" ], [ "Rest" ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 0 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 9.125 ] - ] - ] -], -"last_changes": -[ - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, -1, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, -1, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 0, 1, -1, 0, 0, 0 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 1, -1, 1, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 0, 1, -1, 0, 0, 0 ] ] -], -"cur_uid": "63bf7942", -"ref_uid": "nil", -"order_seed": 921767, -"dur_seed": 345812, -"motifs_seed": 995213, -"entrances_probs_vals": [ 1, 0, 0, 0.88, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 1, 0, 0, 0.88, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 1, 0, 0, 0.88, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -1315.1702786378, 338.08049535604 ], [ -200.61919504644, 1452.6315789474 ], [ -386, 1675.5417956656 ], [ -219, 1694.1176470588 ] ], -"step_probs_vals": [ 0, 1200, 0, 0, 0.063786008230453, 0.92613636363636, 0.12757201646091, 0, 0.54732510288066, 0, 0.71604938271605, 0, 1, 0 ], -"passages_weights": [ 0.7, 0.29, 0.66, 0.74, 0.68 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 0 ], [ 3, 2, 1 ], [ ] ], - [ [ 0 ], [ 2, 1, 3 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ], - [ [ 0, 1, 2 ], [ 3 ], [ ] ], - [ [ 0, 2, 3 ], [ 1 ], [ ] ] -], -"sus_weights": [ 1, 0, 0 ], -"order_size": [ 8, 10 ], -"passages_size": [ 0, 10 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/6a7a8dd9/6a7a8dd9_code.scd b/resources/resources_bak_2024_01_03/string_quartet_2/6a7a8dd9/6a7a8dd9_code.scd deleted file mode 100644 index c194eef..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/6a7a8dd9/6a7a8dd9_code.scd +++ /dev/null @@ -1,945 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance); -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/6a7a8dd9/6a7a8dd9_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_2/6a7a8dd9/6a7a8dd9_mus_model.json deleted file mode 100644 index bc3aae4..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/6a7a8dd9/6a7a8dd9_mus_model.json +++ /dev/null @@ -1,126 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ 0, 1, -1, 0, 0, 0 ] ], 3.875 ], - [ [ [ "Rest" ], [ "Rest" ], [ 1, 1, -1, -1, 0, 0 ], [ 0, 1, -1, 0, 0, 0 ] ], 0 ], - [ [ [ -1, 1, -1, 0, 0, 1 ], [ "Rest" ], [ 1, 1, -1, -1, 0, 0 ], [ 0, 1, -1, 0, 0, 0 ] ], 0 ], - [ [ [ -1, 1, -1, 0, 0, 1 ], [ 1, 1, -1, 0, -1, 0 ], [ 1, 1, -1, -1, 0, 0 ], [ 0, 1, -1, 0, 0, 0 ] ], 4.25 ], - [ [ [ -1, 1, -1, 0, 0, 1 ], [ 1, 1, -1, 0, -1, 0 ], [ 1, 1, -1, 0, 0, -1 ], [ 0, 1, -1, 0, 0, 0 ] ], 4.375 ], - [ [ [ -1, 1, -1, 0, 0, 1 ], [ 1, 1, -1, 0, -1, 0 ], [ 1, 0, -1, 0, 0, 0 ], [ 0, 1, -1, 0, 0, 0 ] ], 4 ], - [ [ [ -1, 1, -1, 0, 0, 1 ], [ 1, 1, -1, 0, -1, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 0, 1, -1, 0, 0, 0 ] ], 0 ], - [ [ [ -1, 1, -1, 0, 0, 1 ], [ 0, 2, -1, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 0, 1, -1, 0, 0, 0 ] ], 1 ], - [ [ [ -1, 1, -1, 0, 0, 1 ], [ 0, 2, -1, 0, 0, 0 ], [ 1, 1, -1, 0, 0, 0 ], [ 0, 1, -1, 0, 0, 0 ] ], 3.75 ], - [ [ [ -1, 1, -1, 0, 0, 1 ], [ 0, 2, -1, 0, 0, 0 ], [ 0, 1, -1, 1, 0, 0 ], [ 0, 1, -1, 0, 0, 0 ] ], 2.25 ] - ], - [ - [ [ [ -1, 1, -1, 0, 0, 1 ], [ "Rest" ], [ 0, 1, -1, 1, 0, 0 ], [ 0, 1, -1, 0, 0, 0 ] ], 0 ], - [ [ [ "Rest" ], [ "Rest" ], [ 0, 1, -1, 1, 0, 0 ], [ 0, 1, -1, 0, 0, 0 ] ], 0 ], - [ [ [ "Rest" ], [ "Rest" ], [ 0, 1, -1, 1, 0, 0 ], [ 0, 1, -1, 1, 0, -1 ] ], 4.375 ], - [ [ [ "Rest" ], [ "Rest" ], [ 0, 1, -1, 1, 0, 0 ], [ -1, 1, 0, 1, 0, 0 ] ], 2.5 ], - [ [ [ "Rest" ], [ "Rest" ], [ 0, 1, -1, 1, 0, 0 ], [ 0, 0, -1, 1, 0, 0 ] ], 1.375 ], - [ [ [ "Rest" ], [ "Rest" ], [ 0, 1, -1, 1, 0, 0 ], [ -1, 1, -1, 1, 1, 0 ] ], 3.75 ], - [ [ [ "Rest" ], [ "Rest" ], [ 0, 1, -1, 1, 0, 0 ], [ 0, 1, -1, 1, -1, 0 ] ], 1.625 ], - [ [ [ "Rest" ], [ "Rest" ], [ 0, 1, -1, 1, 0, 0 ], [ -1, 2, -1, 1, 0, 0 ] ], 1.125 ], - [ [ [ "Rest" ], [ "Rest" ], [ 0, 1, -1, 1, 0, 0 ], [ 0, 1, -2, 1, 0, 0 ] ], 5 ], - [ [ [ "Rest" ], [ "Rest" ], [ 0, 1, -1, 1, 0, 0 ], [ -1, 1, -1, 1, 0, 1 ] ], 1.625 ] - ], - [ - [ [ [ -2, 1, -1, 2, 0, 0 ], [ "Rest" ], [ 0, 1, -1, 1, 0, 0 ], [ -1, 1, -1, 1, 0, 1 ] ], 0 ], - [ [ [ -2, 1, -1, 2, 0, 0 ], [ "Rest" ], [ 0, 1, -1, 1, 0, 0 ], [ -1, 1, -1, 2, 0, 0 ] ], 5 ], - [ [ [ -2, 1, -1, 2, 0, 0 ], [ "Rest" ], [ 0, 1, -1, 1, 0, 0 ], [ 0, 1, -1, 1, 0, -1 ] ], 2.125 ], - [ [ [ -2, 1, -1, 2, 0, 0 ], [ "Rest" ], [ 0, 1, -1, 1, 0, 0 ], [ 0, 0, -1, 1, 0, 0 ] ], 1.625 ] - ], - [ - [ [ [ -2, 1, -1, 2, 0, 0 ], [ 0, 2, -1, 0, 0, 0 ], [ 0, 1, -1, 1, 0, 0 ], [ 0, 0, -1, 1, 0, 0 ] ], 4.75 ], - [ [ [ -2, 1, -1, 2, 0, 0 ], [ 0, 2, -1, 0, 0, 0 ], [ 0, 1, -1, 1, 0, 0 ], [ -1, 3, -1, 0, 0, 0 ] ], 0 ], - [ [ [ -1, 2, -1, 0, 0, 0 ], [ 0, 2, -1, 0, 0, 0 ], [ 0, 1, -1, 1, 0, 0 ], [ -1, 3, -1, 0, 0, 0 ] ], 0 ], - [ [ [ -1, 2, -1, 0, 0, 0 ], [ 0, 2, -1, 0, 0, 0 ], [ 1, 2, -1, 0, 0, -1 ], [ -1, 3, -1, 0, 0, 0 ] ], 4 ], - [ [ [ -1, 2, -1, 0, 0, 0 ], [ 0, 2, -1, 0, 0, 0 ], [ 1, 2, -1, 0, 0, -1 ], [ 0, 2, -2, 0, 0, 0 ] ], 4 ], - [ [ [ -1, 2, -1, 0, 0, 0 ], [ 0, 2, -1, 0, 0, 0 ], [ 1, 2, -1, 0, 0, -1 ], [ -1, 2, -1, 0, 0, 1 ] ], 0 ], - [ [ [ -1, 2, -1, 0, 0, 0 ], [ 0, 2, -1, 0, 0, 0 ], [ 1, 1, -1, 0, 0, 0 ], [ -1, 2, -1, 0, 0, 1 ] ], 2.75 ], - [ [ [ -1, 2, -1, 0, 0, 0 ], [ 0, 2, -1, 0, 0, 0 ], [ 1, 1, -1, 0, 0, 0 ], [ -1, 2, -1, 1, 0, 0 ] ], 4.625 ] - ], - [ - [ [ [ -1, 2, -1, 0, 0, 0 ], [ "Rest" ], [ 1, 1, -1, 0, 0, 0 ], [ -1, 2, -1, 1, 0, 0 ] ], 0 ], - [ [ [ -1, 2, -1, 0, 0, 0 ], [ "Rest" ], [ "Rest" ], [ -1, 2, -1, 1, 0, 0 ] ], 0 ], - [ [ [ -1, 2, -1, 1, 0, -1 ], [ "Rest" ], [ "Rest" ], [ -1, 2, -1, 1, 0, 0 ] ], 4 ], - [ [ [ -2, 2, 0, 1, 0, 0 ], [ "Rest" ], [ "Rest" ], [ -1, 2, -1, 1, 0, 0 ] ], 4.75 ], - [ [ [ -1, 1, -1, 1, 0, 0 ], [ "Rest" ], [ "Rest" ], [ -1, 2, -1, 1, 0, 0 ] ], 3.25 ], - [ [ [ -2, 2, -1, 1, 1, 0 ], [ "Rest" ], [ "Rest" ], [ -1, 2, -1, 1, 0, 0 ] ], 3.75 ], - [ [ [ -1, 2, -1, 1, -1, 0 ], [ "Rest" ], [ "Rest" ], [ -1, 2, -1, 1, 0, 0 ] ], 4.125 ], - [ [ [ -2, 3, -1, 1, 0, 0 ], [ "Rest" ], [ "Rest" ], [ -1, 2, -1, 1, 0, 0 ] ], 2.625 ], - [ [ [ -3, 2, -1, 1, 0, 1 ], [ "Rest" ], [ "Rest" ], [ -1, 2, -1, 1, 0, 0 ] ], 4.5 ], - [ [ [ -2, 2, -2, 1, 0, 0 ], [ "Rest" ], [ "Rest" ], [ -1, 2, -1, 1, 0, 0 ] ], 2.625 ], - [ [ [ -3, 3, -1, 1, 0, 0 ], [ "Rest" ], [ "Rest" ], [ -1, 2, -1, 1, 0, 0 ] ], 3.375 ] - ], - [ - [ [ [ -3, 3, -1, 1, 0, 0 ], [ -1, 3, -1, 1, -1, 0 ], [ "Rest" ], [ -1, 2, -1, 1, 0, 0 ] ], 0 ], - [ [ [ -3, 3, -1, 1, 0, 0 ], [ -1, 3, -1, 1, -1, 0 ], [ -1, 3, -1, 1, 0, 0 ], [ -1, 2, -1, 1, 0, 0 ] ], 0 ], - [ [ [ -3, 3, -1, 1, 0, 0 ], [ -1, 3, -1, 1, -1, 0 ], [ -1, 3, -1, 1, 0, 0 ], [ -2, 3, 0, 1, 0, 0 ] ], 4.5 ], - [ [ [ -3, 3, -1, 1, 0, 0 ], [ -1, 3, -1, 1, -1, 0 ], [ -1, 3, -1, 1, 0, 0 ], [ -1, 3, -1, 1, 0, -1 ] ], 0 ], - [ [ [ -3, 3, -1, 1, 0, 0 ], [ -1, 3, -1, 1, -1, 0 ], [ -1, 2, -1, 1, 0, 0 ], [ -1, 3, -1, 1, 0, -1 ] ], 0 ], - [ [ [ -3, 3, -1, 1, 0, 0 ], [ -2, 4, -1, 1, 0, 0 ], [ -1, 2, -1, 1, 0, 0 ], [ -1, 3, -1, 1, 0, -1 ] ], 4.5 ], - [ [ [ -3, 3, -1, 1, 0, 0 ], [ -2, 4, -1, 1, 0, 0 ], [ -1, 2, -1, 1, 0, 0 ], [ -2, 3, -1, 2, 0, 0 ] ], 4.875 ], - [ [ [ -3, 3, -1, 1, 0, 0 ], [ -2, 4, -1, 1, 0, 0 ], [ -1, 2, -1, 1, 0, 0 ], [ -3, 3, -1, 2, 0, 0 ] ], 4.25 ] - ], - [ - [ [ [ -3, 3, -1, 1, 0, 0 ], [ "Rest" ], [ -1, 2, -1, 1, 0, 0 ], [ -3, 3, -1, 2, 0, 0 ] ], 0 ], - [ [ [ -3, 3, -1, 1, 0, 0 ], [ "Rest" ], [ "Rest" ], [ -3, 3, -1, 2, 0, 0 ] ], 0 ], - [ [ [ -3, 3, -1, 1, 0, 0 ], [ "Rest" ], [ "Rest" ], [ -3, 3, -1, 1, 0, 1 ] ], 2.125 ], - [ [ [ -3, 3, -1, 1, 0, 0 ], [ "Rest" ], [ "Rest" ], [ -3, 4, -1, 1, 0, 0 ] ], 2 ], - [ [ [ -3, 3, -1, 1, 0, 0 ], [ "Rest" ], [ "Rest" ], [ -2, 3, -2, 1, 0, 0 ] ], 1.125 ], - [ [ [ -3, 3, -1, 1, 0, 0 ], [ "Rest" ], [ "Rest" ], [ -2, 3, -1, 1, 0, 0 ] ], 0.875 ] - ], - [ - [ [ [ -3, 3, -1, 1, 0, 0 ], [ "Rest" ], [ -1, 2, -1, 1, 0, 0 ], [ -2, 3, -1, 1, 0, 0 ] ], 1.875 ], - [ [ [ -3, 3, -1, 1, 0, 0 ], [ "Rest" ], [ -1, 2, -1, 1, 0, 0 ], [ -1, 2, -2, 1, 0, 0 ] ], 0 ], - [ [ [ -3, 3, -1, 1, 0, 0 ], [ 0, 2, -1, 0, 0, 0 ], [ -1, 2, -1, 1, 0, 0 ], [ -1, 2, -2, 1, 0, 0 ] ], 0 ], - [ [ [ -2, 2, -2, 1, 0, 0 ], [ 0, 2, -1, 0, 0, 0 ], [ -1, 2, -1, 1, 0, 0 ], [ -1, 2, -2, 1, 0, 0 ] ], 4.375 ], - [ [ [ -3, 2, -1, 1, 0, 1 ], [ 0, 2, -1, 0, 0, 0 ], [ -1, 2, -1, 1, 0, 0 ], [ -1, 2, -2, 1, 0, 0 ] ], 4.375 ], - [ [ [ -3, 2, -1, 1, 0, 1 ], [ 0, 2, -1, 0, 0, 0 ], [ -1, 2, -1, 1, 0, 0 ], [ "Rest" ] ], 0 ], - [ [ [ "Rest" ], [ 0, 2, -1, 0, 0, 0 ], [ -1, 2, -1, 1, 0, 0 ], [ "Rest" ] ], 0 ], - [ [ [ "Rest" ], [ 0, 2, -1, 0, 0, 0 ], [ "Rest" ], [ "Rest" ] ], 0 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 9.625 ] - ] - ] -], -"last_changes": -[ - [ [ -3, 3, -1, 1, 0, 0 ], [ -2, 4, -1, 1, 0, 0 ], [ -1, 2, -1, 1, 0, 0 ], [ -2, 3, -1, 1, 0, 0 ] ], - [ [ -3, 3, -1, 1, 0, 0 ], [ -2, 4, -1, 1, 0, 0 ], [ -1, 2, -1, 1, 0, 0 ], [ -1, 2, -2, 1, 0, 0 ] ], - [ [ -3, 3, -1, 1, 0, 0 ], [ 0, 2, -1, 0, 0, 0 ], [ -1, 2, -1, 1, 0, 0 ], [ -1, 2, -2, 1, 0, 0 ] ], - [ [ -2, 2, -2, 1, 0, 0 ], [ 0, 2, -1, 0, 0, 0 ], [ -1, 2, -1, 1, 0, 0 ], [ -1, 2, -2, 1, 0, 0 ] ], - [ [ -3, 2, -1, 1, 0, 1 ], [ 0, 2, -1, 0, 0, 0 ], [ -1, 2, -1, 1, 0, 0 ], [ -1, 2, -2, 1, 0, 0 ] ] -], -"cur_uid": "6a7a8dd9", -"ref_uid": "63bf7942", -"order_seed": 327691, -"dur_seed": 667550, -"motifs_seed": 549585, -"entrances_probs_vals": [ 1, 0, 0, 0.88, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 1, 0, 0, 0.88, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 1, 0, 0, 0.88, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -1315.1702786378, 338.08049535604 ], [ -200.61919504644, 1452.6315789474 ], [ -386, 1675.5417956656 ], [ -219, 1694.1176470588 ] ], -"step_probs_vals": [ 0, 1200, 0, 0, 0.063786008230453, 0.92613636363636, 0.12757201646091, 0, 0.54732510288066, 0, 0.71604938271605, 0, 1, 0 ], -"passages_weights": [ 0.7, 0.29, 0.66, 0.74, 0.68 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 3 ], [ 2, 0, 1, 2, 2, 2, 1, 2, 2 ], [ ] ], - [ [ 2 ], [ 3, 3, 3, 3, 3, 3, 3, 3 ], [ 1, 0 ] ], - [ [ 2 ], [ 0, 3, 3, 3 ], [ 1 ] ], - [ [ 1 ], [ 3, 0, 2, 3, 3, 2, 3 ], [ ] ], - [ [ 3 ], [ 0, 0, 0, 0, 0, 0, 0, 0, 0 ], [ 1, 2 ] ], - [ [ 0 ], [ 1, 2, 3, 3, 2, 1, 3, 3 ], [ ] ], - [ [ 0 ], [ 3, 3, 3, 3 ], [ 1, 2 ] ], - [ [ 2 ], [ 3, 1, 0, 0 ], [ ] ] -], -"sus_weights": [ 1, 0, 0 ], -"order_size": [ 8, 10 ], -"passages_size": [ 0, 10 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/71add9fc/71add9fc_code.scd b/resources/resources_bak_2024_01_03/string_quartet_2/71add9fc/71add9fc_code.scd deleted file mode 100644 index c194eef..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/71add9fc/71add9fc_code.scd +++ /dev/null @@ -1,945 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance); -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/71add9fc/71add9fc_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_2/71add9fc/71add9fc_mus_model.json deleted file mode 100644 index ab65a8d..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/71add9fc/71add9fc_mus_model.json +++ /dev/null @@ -1,210 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 3.875 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ], [ 1, 0, 0, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 1, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, 0, -1, 0 ], [ 0, 0, 1, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ] ], 4.875 ] - ], - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, 0, -1, 0 ], [ 1, 0, 0, 0, 0, -1 ], [ 1, 0, 0, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ], [ 1, 0, 0, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ], [ 0, 0, 1, 0, 0, 0 ] ], 4.75 ] - ], - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, -1, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], 4.125 ] - ], - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, -1, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, -1, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 1 ], [ 0, 0, 1, 0, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ] ], 4.875 ] - ], - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 1 ], [ 1, 0, 0, 0, 0, -1 ], [ 1, 0, 0, -1, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 1 ], [ 1, 0, 0, 0, 0, -1 ], [ 1, 0, -1, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ], [ 1, 0, -1, 0, 0, 0 ] ], 4.125 ] - ], - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ], [ -1, 1, 0, 0, 0, 1 ] ], 0 ], - [ [ [ -1, 1, 1, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ], [ -1, 1, 0, 0, 0, 1 ] ], 0 ], - [ [ [ -1, 1, 1, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 0, 1, -1, 0, 0, 0 ], [ -1, 1, 0, 0, 0, 1 ] ], 4.875 ] - ], - [ - [ [ [ -1, 1, 1, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 0, 1, -1, 0, 0, 0 ], [ -1, 1, 0, 1, 0, 0 ] ], 0 ], - [ [ [ 0, 1, 0, 0, 0, -1 ], [ 0, 1, 0, 0, 0, 0 ], [ 0, 1, -1, 0, 0, 0 ], [ -1, 1, 0, 1, 0, 0 ] ], 0 ], - [ [ [ 0, 1, 0, 0, 0, -1 ], [ 0, 1, 0, 0, 0, 0 ], [ -1, 1, 0, 0, 0, 1 ], [ -1, 1, 0, 1, 0, 0 ] ], 4 ] - ], - [ - [ [ [ 0, 1, 0, 0, 0, -1 ], [ 0, 1, 0, 0, 1, 0 ], [ -1, 1, 0, 0, 0, 1 ], [ -1, 1, 0, 1, 0, 0 ] ], 3.75 ], - [ [ [ 0, 1, 0, 0, 0, -1 ], [ 0, 1, 0, 0, 1, 0 ], [ -1, 1, 0, 0, 0, 1 ], [ 0, 1, 0, 0, 1, -1 ] ], 0 ], - [ [ [ 0, 1, 0, 0, 0, -1 ], [ 0, 1, 0, 0, 1, 0 ], [ -1, 1, 1, 0, 1, 0 ], [ 0, 1, 0, 0, 1, -1 ] ], 0 ], - [ [ [ 0, 1, 0, 0, 0, -1 ], [ -1, 1, 0, 1, 1, 0 ], [ -1, 1, 1, 0, 1, 0 ], [ 0, 1, 0, 0, 1, -1 ] ], 4.25 ] - ], - [ - [ [ [ 0, 1, 0, 0, 0, -1 ], [ -1, 1, 0, 1, 1, 0 ], [ -1, 1, 1, 0, 1, 0 ], [ -2, 2, 0, 1, 1, 0 ] ], 0 ], - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -1, 1, 0, 1, 1, 0 ], [ -1, 1, 1, 0, 1, 0 ], [ -2, 2, 0, 1, 1, 0 ] ], 0 ], - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -1, 1, 0, 1, 1, 0 ], [ -2, 1, 0, 1, 2, 0 ], [ -2, 2, 0, 1, 1, 0 ] ], 4.625 ] - ], - [ - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -1, 1, 0, 1, 1, 0 ], [ -2, 1, 0, 1, 2, 0 ], [ -1, 1, 0, 1, 0, 0 ] ], 0 ], - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -1, 1, 0, 1, 1, 0 ], [ -1, 0, 0, 1, 1, 0 ], [ -1, 1, 0, 1, 0, 0 ] ], 0 ], - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -2, 1, 0, 2, 1, 0 ], [ -1, 0, 0, 1, 1, 0 ], [ -1, 1, 0, 1, 0, 0 ] ], 4.625 ] - ], - [ - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -2, 1, 0, 2, 1, 0 ], [ -1, 0, 0, 1, 1, 0 ], [ -2, 1, 0, 1, 2, 0 ] ], 0 ], - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -2, 1, 0, 2, 1, 0 ], [ -1, 1, 0, 1, 1, -1 ], [ -2, 1, 0, 1, 2, 0 ] ], 0 ], - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -2, 1, 0, 1, 1, 1 ], [ -1, 1, 0, 1, 1, -1 ], [ -2, 1, 0, 1, 2, 0 ] ], 4.875 ] - ], - [ - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -2, 1, 0, 1, 1, 1 ], [ -1, 1, 0, 0, 1, 0 ], [ -2, 1, 0, 1, 2, 0 ] ], 0 ], - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -2, 1, 0, 1, 1, 1 ], [ -1, 1, 0, 0, 1, 0 ], [ -1, 0, 0, 1, 1, 0 ] ], 0 ], - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -1, 1, -1, 1, 1, 0 ], [ -1, 1, 0, 0, 1, 0 ], [ -1, 0, 0, 1, 1, 0 ] ], 4.125 ] - ], - [ - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -1, 1, -1, 1, 1, 0 ], [ 0, 1, 0, 1, 0, 0 ], [ -1, 0, 0, 1, 1, 0 ] ], 0 ], - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -1, 1, -1, 1, 1, 0 ], [ 0, 1, 0, 1, 0, 0 ], [ -2, 1, 1, 1, 1, 0 ] ], 0 ], - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -2, 2, 0, 1, 1, 0 ], [ 0, 1, 0, 1, 0, 0 ], [ -2, 1, 1, 1, 1, 0 ] ], 4 ] - ], - [ - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -1, 1, 0, 1, 0, 0 ], [ 0, 1, 0, 1, 0, 0 ], [ -2, 1, 1, 1, 1, 0 ] ], 0 ], - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -1, 1, 0, 1, 0, 0 ], [ 0, 1, 0, 1, 0, 0 ], [ -1, 1, 0, 1, 1, -1 ] ], 0 ], - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -1, 1, 0, 1, 0, 0 ], [ -1, 1, 0, 1, 2, 0 ], [ -1, 1, 0, 1, 1, -1 ] ], 4.25 ] - ], - [ - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -1, 1, 0, 1, 0, 0 ], [ 0, 0, 0, 1, 1, 0 ], [ -1, 1, 0, 1, 1, -1 ] ], 0 ], - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -1, 1, 0, 1, 0, 0 ], [ 0, 0, 0, 1, 1, 0 ], [ -1, 1, 0, 0, 1, 0 ] ], 0 ], - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -2, 2, 0, 1, 1, 0 ], [ 0, 0, 0, 1, 1, 0 ], [ -1, 1, 0, 0, 1, 0 ] ], 4 ] - ], - [ - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -2, 2, 0, 1, 1, 0 ], [ 0, 1, 0, 1, 1, -1 ], [ -1, 1, 0, 0, 1, 0 ] ], 0 ], - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -2, 2, 0, 1, 1, 0 ], [ 0, 1, 0, 1, 1, -1 ], [ -2, 1, 0, 2, 1, 0 ] ], 0 ], - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -1, 1, -1, 1, 1, 0 ], [ 0, 1, 0, 1, 1, -1 ], [ -2, 1, 0, 2, 1, 0 ] ], 4.375 ] - ], - [ - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -2, 1, 0, 1, 1, 1 ], [ 0, 1, 0, 1, 1, -1 ], [ -2, 1, 0, 2, 1, 0 ] ], 0 ], - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -2, 1, 0, 1, 1, 1 ], [ -1, 1, 1, 1, 1, 0 ], [ -2, 1, 0, 2, 1, 0 ] ], 0 ], - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -2, 1, 0, 1, 1, 1 ], [ -1, 1, 1, 1, 1, 0 ], [ -1, 1, 0, 1, 1, -1 ] ], 4 ] - ], - [ - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -2, 1, 0, 1, 1, 1 ], [ 0, 0, 0, 1, 1, 0 ], [ -1, 1, 0, 1, 1, -1 ] ], 0 ], - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -2, 1, 0, 1, 1, 1 ], [ 0, 0, 0, 1, 1, 0 ], [ -2, 1, 1, 1, 1, 0 ] ], 0 ], - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -2, 2, 0, 1, 1, 0 ], [ 0, 0, 0, 1, 1, 0 ], [ -2, 1, 1, 1, 1, 0 ] ], 4.625 ] - ], - [ - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -2, 2, 0, 1, 1, 0 ], [ 0, 0, 0, 1, 1, 0 ], [ -1, 0, 0, 1, 1, 0 ] ], 0 ], - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -1, 1, -1, 1, 1, 0 ], [ 0, 0, 0, 1, 1, 0 ], [ -1, 0, 0, 1, 1, 0 ] ], 0 ], - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -1, 1, -1, 1, 1, 0 ], [ -1, 1, 0, 1, 2, 0 ], [ -1, 0, 0, 1, 1, 0 ] ], 4.625 ] - ], - [ - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -1, 1, -1, 1, 1, 0 ], [ 0, 1, 0, 1, 0, 0 ], [ -1, 0, 0, 1, 1, 0 ] ], 0 ], - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -2, 1, 0, 1, 1, 1 ], [ 0, 1, 0, 1, 0, 0 ], [ -1, 0, 0, 1, 1, 0 ] ], 0 ], - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -2, 1, 0, 1, 1, 1 ], [ 0, 1, 0, 1, 0, 0 ], [ -2, 1, 0, 1, 2, 0 ] ], 4.5 ] - ], - [ - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -2, 1, 0, 2, 1, 0 ], [ 0, 1, 0, 1, 0, 0 ], [ -2, 1, 0, 1, 2, 0 ] ], 0 ], - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -2, 1, 0, 2, 1, 0 ], [ 0, 0, 0, 1, 1, 0 ], [ -2, 1, 0, 1, 2, 0 ] ], 0 ], - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -2, 1, 0, 2, 1, 0 ], [ 0, 0, 0, 1, 1, 0 ], [ -2, 2, 0, 1, 1, 0 ] ], 4.375 ] - ], - [ - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -2, 1, 0, 2, 1, 0 ], [ 0, 0, 0, 1, 1, 0 ], [ -1, 1, -1, 1, 1, 0 ] ], 0 ], - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -1, 1, 0, 1, 1, -1 ], [ 0, 0, 0, 1, 1, 0 ], [ -1, 1, -1, 1, 1, 0 ] ], 0 ], - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -1, 1, 0, 1, 1, -1 ], [ -1, 1, 1, 1, 1, 0 ], [ -1, 1, -1, 1, 1, 0 ] ], 4.125 ] - ], - [ - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -1, 1, 0, 1, 1, -1 ], [ -1, 1, 1, 1, 1, 0 ], [ -2, 1, 0, 1, 1, 1 ] ], 0 ], - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -1, 1, 0, 0, 1, 0 ], [ -1, 1, 1, 1, 1, 0 ], [ -2, 1, 0, 1, 1, 1 ] ], 0 ], - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -1, 1, 0, 0, 1, 0 ], [ 0, 1, 0, 1, 1, -1 ], [ -2, 1, 0, 1, 1, 1 ] ], 4.5 ] - ], - [ - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -1, 1, 0, 0, 1, 0 ], [ 0, 1, 0, 1, 1, -1 ], [ -2, 2, 0, 1, 1, 0 ] ], 0 ], - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -1, 1, 0, 0, 1, 0 ], [ -1, 1, 0, 1, 2, 0 ], [ -2, 2, 0, 1, 1, 0 ] ], 0 ], - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -1, 1, 0, 1, 1, 0 ], [ -1, 1, 0, 1, 2, 0 ], [ -2, 2, 0, 1, 1, 0 ] ], 3.875 ] - ], - [ - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -1, 1, 0, 1, 0, 0 ], [ -1, 1, 0, 1, 2, 0 ], [ -2, 2, 0, 1, 1, 0 ] ], 0 ], - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -1, 1, 0, 1, 0, 0 ], [ -1, 1, 0, 1, 2, 0 ], [ -1, 1, -1, 1, 1, 0 ] ], 0 ], - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -1, 1, 0, 1, 0, 0 ], [ 0, 0, 0, 1, 1, 0 ], [ -1, 1, -1, 1, 1, 0 ] ], 3.75 ] - ], - [ - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -1, 1, 0, 1, 0, 0 ], [ 0, 1, 0, 1, 1, -1 ], [ -1, 1, -1, 1, 1, 0 ] ], 0 ], - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -1, 1, 0, 1, 0, 0 ], [ 0, 1, 0, 1, 1, -1 ], [ -2, 1, 0, 1, 1, 1 ] ], 0 ], - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -2, 2, 0, 1, 1, 0 ], [ 0, 1, 0, 1, 1, -1 ], [ -2, 1, 0, 1, 1, 1 ] ], 4.5 ] - ], - [ - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -2, 2, 0, 1, 1, 0 ], [ -1, 1, 1, 1, 1, 0 ], [ -2, 1, 0, 1, 1, 1 ] ], 0 ], - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -2, 1, 1, 1, 1, 0 ], [ -1, 1, 1, 1, 1, 0 ], [ -2, 1, 0, 1, 1, 1 ] ], 0 ], - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -2, 1, 1, 1, 1, 0 ], [ -1, 1, 1, 1, 1, 0 ], [ -2, 1, 0, 2, 1, 0 ] ], 4.75 ] - ], - [ - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -1, 0, 0, 1, 1, 0 ], [ -1, 1, 1, 1, 1, 0 ], [ -2, 1, 0, 2, 1, 0 ] ], 0 ], - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -1, 0, 0, 1, 1, 0 ], [ -1, 1, 1, 1, 1, 0 ], [ 0, 0, 0, 1, 1, 0 ] ], 0 ], - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -1, 0, 0, 1, 1, 0 ], [ 0, 1, 0, 1, 1, -1 ], [ 0, 0, 0, 1, 1, 0 ] ], 4.75 ], - [ [ [ -2, 1, 0, 1, 1, 0 ], [ -1, 0, 0, 1, 1, 0 ], [ 0, 1, 0, 1, 1, -1 ], [ "Rest" ] ], 0 ], - [ [ [ -2, 1, 0, 1, 1, 0 ], [ "Rest" ], [ 0, 1, 0, 1, 1, -1 ], [ "Rest" ] ], 0 ], - [ [ [ -2, 1, 0, 1, 1, 0 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 0 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 5.25 ] - ] - ] -], -"last_changes": -[ - [ [ -2, 1, 0, 1, 1, 0 ], [ -2, 1, 1, 1, 1, 0 ], [ -1, 1, 1, 1, 1, 0 ], [ -2, 1, 0, 1, 1, 1 ] ], - [ [ -2, 1, 0, 1, 1, 0 ], [ -2, 1, 1, 1, 1, 0 ], [ -1, 1, 1, 1, 1, 0 ], [ -2, 1, 0, 2, 1, 0 ] ], - [ [ -2, 1, 0, 1, 1, 0 ], [ -1, 0, 0, 1, 1, 0 ], [ -1, 1, 1, 1, 1, 0 ], [ -2, 1, 0, 2, 1, 0 ] ], - [ [ -2, 1, 0, 1, 1, 0 ], [ -1, 0, 0, 1, 1, 0 ], [ -1, 1, 1, 1, 1, 0 ], [ 0, 0, 0, 1, 1, 0 ] ], - [ [ -2, 1, 0, 1, 1, 0 ], [ -1, 0, 0, 1, 1, 0 ], [ 0, 1, 0, 1, 1, -1 ], [ 0, 0, 0, 1, 1, 0 ] ] -], -"cur_uid": "71add9fc", -"ref_uid": "nil", -"order_seed": 921767, -"dur_seed": 954688, -"motifs_seed": 995213, -"entrances_probs_vals": [ 1, 0, 0, 3.68, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 1, 0, 0, 3.68, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 1, 0, 0, 3.68, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -1315.1702786378, 338.08049535604 ], [ -200.61919504644, 1452.6315789474 ], [ -386, 1675.5417956656 ], [ -219, 1694.1176470588 ] ], -"step_probs_vals": [ 0, 1200, 0, 0, 0.063786008230453, 0.92613636363636, 0.12757201646091, 0, 0.54732510288066, 0, 0.71604938271605, 0, 1, 0 ], -"passages_weights": [ 0.7, 0.29, 0.66, 0.74, 0.68 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 0 ], [ 3, 2, 1 ], [ ] ], - [ [ 0 ], [ 2, 1, 3 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ], - [ [ 1 ], [ 3, 0, 2 ], [ ] ], - [ [ 1 ], [ 3, 0, 2 ], [ ] ], - [ [ 1 ], [ 3, 2, 1 ], [ ] ], - [ [ 1 ], [ 3, 0, 2 ], [ ] ], - [ [ 0 ], [ 3, 2, 1 ], [ ] ], - [ [ 0 ], [ 3, 2, 1 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ], - [ [ 0 ], [ 1, 3, 2 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ], - [ [ 0 ], [ 1, 2, 3 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ], - [ [ 0 ], [ 3, 1, 2 ], [ ] ], - [ [ 0 ], [ 2, 1, 3 ], [ ] ], - [ [ 0 ], [ 1, 2, 3 ], [ ] ], - [ [ 0 ], [ 3, 1, 2 ], [ ] ], - [ [ 0 ], [ 3, 1, 2 ], [ ] ], - [ [ 0 ], [ 3, 2, 1 ], [ ] ], - [ [ 0 ], [ 1, 3, 2 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ], - [ [ 0 ], [ 2, 1, 3 ], [ ] ], - [ [ 0 ], [ 1, 3, 2 ], [ ] ] -], -"sus_weights": [ 1, 0, 0 ], -"order_size": [ 8, 10 ], -"passages_size": [ 0, 10 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/72dc057f/72dc057f_code.scd b/resources/resources_bak_2024_01_03/string_quartet_2/72dc057f/72dc057f_code.scd deleted file mode 100644 index 57e638d..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/72dc057f/72dc057f_code.scd +++ /dev/null @@ -1,945 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array2) - hsArrayToCents.value(array1); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = true; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance); -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength.asInteger - minMotifLength.asInteger).rand + minMotifLength.asInteger).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength.asInteger - minProgLength.asInteger).rand + minProgLength.asInteger).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/72dc057f/72dc057f_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_2/72dc057f/72dc057f_mus_model.json deleted file mode 100644 index 5541d17..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/72dc057f/72dc057f_mus_model.json +++ /dev/null @@ -1,59 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ -2, 3, -2, -1, 1, 0 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 5 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ "Rest" ], [ "Rest" ], [ -2, 4, -2, -1, 1, 0 ] ], 0 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ "Rest" ], [ -1, 3, -2, -1, 2, 0 ], [ -2, 4, -2, -1, 1, 0 ] ], 0 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -1, -1, 1, 0 ], [ -1, 3, -2, -1, 2, 0 ], [ -2, 4, -2, -1, 1, 0 ] ], 6.875 ] - ], - [ - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -1, -1, 1, 0 ], [ -1, 3, -1, -1, 1, 0 ], [ -2, 4, -2, -1, 1, 0 ] ], 0 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 1, -1 ], [ -1, 3, -1, -1, 1, 0 ], [ -2, 4, -2, -1, 1, 0 ] ], 0 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 1, -1 ], [ -1, 3, -1, -1, 1, 0 ], [ -1, 3, -2, -1, 0, 0 ] ], 3.875 ] - ], - [ - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 1, -1 ], [ 0, 2, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 0, 0 ] ], 0 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 1, -1 ], [ 0, 2, -2, -1, 1, 0 ], [ -1, 2, -2, -1, 1, 0 ] ], 0 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -1, 3, -3, -1, 1, 0 ], [ 0, 2, -2, -1, 1, 0 ], [ -1, 2, -2, -1, 1, 0 ] ], 6.125 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ "Rest" ], [ 0, 2, -2, -1, 1, 0 ], [ -1, 2, -2, -1, 1, 0 ] ], 0 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ "Rest" ], [ "Rest" ], [ -1, 2, -2, -1, 1, 0 ] ], 0 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 0 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 6.125 ] - ] - ] -], -"last_changes": -[ - [ [ -2, 3, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 1, -1 ], [ -1, 3, -1, -1, 1, 0 ], [ -2, 4, -2, -1, 1, 0 ] ], - [ [ -2, 3, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 1, -1 ], [ -1, 3, -1, -1, 1, 0 ], [ -1, 3, -2, -1, 0, 0 ] ], - [ [ -2, 3, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 1, -1 ], [ 0, 2, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 0, 0 ] ], - [ [ -2, 3, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 1, -1 ], [ 0, 2, -2, -1, 1, 0 ], [ -1, 2, -2, -1, 1, 0 ] ], - [ [ -2, 3, -2, -1, 1, 0 ], [ -1, 3, -3, -1, 1, 0 ], [ 0, 2, -2, -1, 1, 0 ], [ -1, 2, -2, -1, 1, 0 ] ] -], -"cur_uid": "72dc057f", -"ref_uid": 62300302, -"order_seed": 209649, -"dur_seed": 795391, -"motifs_seed": 821280, -"entrances_probs_vals": [ 1, 0, 2.9365079365079, 0.47, 2.8021978021978, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 1, 0, 2.7380952380952, 3.68, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 1, 0, 2.7380952380952, 3.68, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -1315.1702786378, 338.08049535604 ], [ -200.61919504644, 1452.6315789474 ], [ -386, 1675.5417956656 ], [ -219, 1694.1176470588 ] ], -"step_probs_vals": [ -1200, 1200, 0, 0, 0.35390946502058, 0, 0.5, 0.5, 0.62139917695473, 0, 1, 0 ], -"passages_weights": [ 0.7, 0.29, 0.66, 0.74, 0.68 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 0 ], [ 3, 2, 1 ], [ ] ], - [ [ 0 ], [ 2, 1, 3 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ] -], -"sus_weights": [ 1, 0, 0 ], -"order_size": [ 8.0714285714286, 10.091836734694 ], -"passages_size": [ 0, 10 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/72dc057f/lilypond/part_I.ly b/resources/resources_bak_2024_01_03/string_quartet_2/72dc057f/lilypond/part_I.ly deleted file mode 100644 index 91049e5..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/72dc057f/lilypond/part_I.ly +++ /dev/null @@ -1,30 +0,0 @@ -{ - { r1 } - \bar "|" - { r1 } - \bar "|" - { r2 e2^\markup { \pad-markup #0.2 "+18"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }} ~ } - \bar "|" - { e1 ~ } - \bar "|" - { e1 ~ } - \bar "|" - { e2. ~ e8.[ e16^\markup { \pad-markup #0.2 "-36"}] ~ } - \bar "|" - { e1 ~ } - \bar "|" - { e2. ~ e8[ d8^\markup { \pad-markup #0.2 "+14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 1↑" }}] ~ } - \bar "|" - { d1 ~ } - \bar "|" - { d1 ~ } - \bar "|" - { d2. ~ d8.[ r16] } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/72dc057f/lilypond/part_II.ly b/resources/resources_bak_2024_01_03/string_quartet_2/72dc057f/lilypond/part_II.ly deleted file mode 100644 index 80a76d1..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/72dc057f/lilypond/part_II.ly +++ /dev/null @@ -1,30 +0,0 @@ -{ - { r1 } - \bar "|" - { r1 } - \bar "|" - { r2 dis'2^\markup { \pad-markup #0.2 "-33"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 11↑" }} ~ } - \bar "|" - { dis'1 ~ } - \bar "|" - { dis'1 ~ } - \bar "|" - { dis'2. ~ dis'8.[ cis'16^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }}] ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'2. ~ cis'8[ d'8^\markup { \pad-markup #0.2 "+14"}] ~ } - \bar "|" - { d'1 ~ } - \bar "|" - { d'1 ~ } - \bar "|" - { d'2. ~ d'8.[ r16] } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/72dc057f/lilypond/part_III.ly b/resources/resources_bak_2024_01_03/string_quartet_2/72dc057f/lilypond/part_III.ly deleted file mode 100644 index 0b76537..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/72dc057f/lilypond/part_III.ly +++ /dev/null @@ -1,30 +0,0 @@ -{ - { r1 } - \bar "|" - { r1 } - \bar "|" - { r2 cis2^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }} ~ } - \bar "|" - { cis1 ~ } - \bar "|" - { cis1 ~ } - \bar "|" - { cis2. ~ cis8.[ cis16^\markup { \pad-markup #0.2 "-25"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↓" }}] ~ } - \bar "|" - { cis1 ~ } - \bar "|" - { cis2. ~ cis8[ f8^\markup { \pad-markup #0.2 "+29"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↓" }}] ~ } - \bar "|" - { f1 ~ } - \bar "|" - { f1 ~ } - \bar "|" - { f2. ~ f8.[ r16] } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/72dc057f/lilypond/part_IV.ly b/resources/resources_bak_2024_01_03/string_quartet_2/72dc057f/lilypond/part_IV.ly deleted file mode 100644 index e37440b..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/72dc057f/lilypond/part_IV.ly +++ /dev/null @@ -1,30 +0,0 @@ -{ - { a,1^\markup { \pad-markup #0.2 "+16"} ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,2. ~ a,8.[ r16] } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/74307bb4/74307bb4_code.scd b/resources/resources_bak_2024_01_03/string_quartet_2/74307bb4/74307bb4_code.scd deleted file mode 100644 index c194eef..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/74307bb4/74307bb4_code.scd +++ /dev/null @@ -1,945 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance); -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/74307bb4/74307bb4_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_2/74307bb4/74307bb4_mus_model.json deleted file mode 100644 index 6d6bd44..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/74307bb4/74307bb4_mus_model.json +++ /dev/null @@ -1,120 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ 0, 1, -1, 0, 0, 0 ] ], 3.875 ], - [ [ [ "Rest" ], [ "Rest" ], [ 1, 1, -1, -1, 0, 0 ], [ 0, 1, -1, 0, 0, 0 ] ], 0 ], - [ [ [ -1, 1, -1, 0, 0, 1 ], [ "Rest" ], [ 1, 1, -1, -1, 0, 0 ], [ 0, 1, -1, 0, 0, 0 ] ], 0 ], - [ [ [ -1, 1, -1, 0, 0, 1 ], [ 1, 1, -1, 0, -1, 0 ], [ 1, 1, -1, -1, 0, 0 ], [ 0, 1, -1, 0, 0, 0 ] ], 4.25 ], - [ [ [ -1, 1, -1, 0, 0, 1 ], [ 1, 1, -1, 0, -1, 0 ], [ 1, 1, -1, 0, 0, -1 ], [ 0, 1, -1, 0, 0, 0 ] ], 4.375 ], - [ [ [ -1, 1, -1, 0, 0, 1 ], [ 1, 1, -1, 0, -1, 0 ], [ 1, 0, -1, 0, 0, 0 ], [ 0, 1, -1, 0, 0, 0 ] ], 4 ], - [ [ [ -1, 1, -1, 0, 0, 1 ], [ 1, 1, -1, 0, -1, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 0, 1, -1, 0, 0, 0 ] ], 0 ], - [ [ [ -1, 1, -1, 0, 0, 1 ], [ 0, 2, -1, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 0, 1, -1, 0, 0, 0 ] ], 1 ], - [ [ [ -1, 1, -1, 0, 0, 1 ], [ 0, 2, -1, 0, 0, 0 ], [ 1, 1, -1, 0, 0, 0 ], [ 0, 1, -1, 0, 0, 0 ] ], 3.75 ], - [ [ [ -1, 1, -1, 0, 0, 1 ], [ 0, 2, -1, 0, 0, 0 ], [ 0, 1, -1, 1, 0, 0 ], [ 0, 1, -1, 0, 0, 0 ] ], 2.25 ] - ], - [ - [ [ [ -1, 1, -1, 0, 0, 1 ], [ "Rest" ], [ 0, 1, -1, 1, 0, 0 ], [ 0, 1, -1, 0, 0, 0 ] ], 0 ], - [ [ [ "Rest" ], [ "Rest" ], [ 0, 1, -1, 1, 0, 0 ], [ 0, 1, -1, 0, 0, 0 ] ], 0 ], - [ [ [ "Rest" ], [ "Rest" ], [ 0, 1, -1, 1, 0, 0 ], [ 0, 1, -1, 1, 0, -1 ] ], 4.375 ], - [ [ [ "Rest" ], [ "Rest" ], [ 0, 1, -1, 1, 0, 0 ], [ -1, 1, 0, 1, 0, 0 ] ], 2.5 ], - [ [ [ "Rest" ], [ "Rest" ], [ 0, 1, -1, 1, 0, 0 ], [ 0, 0, -1, 1, 0, 0 ] ], 1.375 ], - [ [ [ "Rest" ], [ "Rest" ], [ 0, 1, -1, 1, 0, 0 ], [ -1, 1, -1, 1, 1, 0 ] ], 3.75 ], - [ [ [ "Rest" ], [ "Rest" ], [ 0, 1, -1, 1, 0, 0 ], [ 0, 1, -1, 1, -1, 0 ] ], 1.625 ], - [ [ [ "Rest" ], [ "Rest" ], [ 0, 1, -1, 1, 0, 0 ], [ -1, 2, -1, 1, 0, 0 ] ], 1.125 ], - [ [ [ "Rest" ], [ "Rest" ], [ 0, 1, -1, 1, 0, 0 ], [ 0, 1, -2, 1, 0, 0 ] ], 5 ], - [ [ [ "Rest" ], [ "Rest" ], [ 0, 1, -1, 1, 0, 0 ], [ -1, 1, -1, 1, 0, 1 ] ], 1.625 ] - ], - [ - [ [ [ -2, 1, -1, 2, 0, 0 ], [ "Rest" ], [ 0, 1, -1, 1, 0, 0 ], [ -1, 1, -1, 1, 0, 1 ] ], 0 ], - [ [ [ -2, 1, -1, 2, 0, 0 ], [ "Rest" ], [ 0, 1, -1, 1, 0, 0 ], [ -1, 1, -1, 2, 0, 0 ] ], 5 ], - [ [ [ -2, 1, -1, 2, 0, 0 ], [ "Rest" ], [ 0, 1, -1, 1, 0, 0 ], [ 0, 1, -1, 1, 0, -1 ] ], 2.125 ], - [ [ [ -2, 1, -1, 2, 0, 0 ], [ "Rest" ], [ 0, 1, -1, 1, 0, 0 ], [ 0, 0, -1, 1, 0, 0 ] ], 1.625 ] - ], - [ - [ [ [ -2, 1, -1, 2, 0, 0 ], [ 0, 2, -1, 0, 0, 0 ], [ 0, 1, -1, 1, 0, 0 ], [ 0, 0, -1, 1, 0, 0 ] ], 4.75 ], - [ [ [ -2, 1, -1, 2, 0, 0 ], [ 0, 2, -1, 0, 0, 0 ], [ 0, 1, -1, 1, 0, 0 ], [ -1, 3, -1, 0, 0, 0 ] ], 0 ], - [ [ [ -1, 2, -1, 0, 0, 0 ], [ 0, 2, -1, 0, 0, 0 ], [ 0, 1, -1, 1, 0, 0 ], [ -1, 3, -1, 0, 0, 0 ] ], 0 ], - [ [ [ -1, 2, -1, 0, 0, 0 ], [ 0, 2, -1, 0, 0, 0 ], [ 1, 2, -1, 0, 0, -1 ], [ -1, 3, -1, 0, 0, 0 ] ], 4 ], - [ [ [ -1, 2, -1, 0, 0, 0 ], [ 0, 2, -1, 0, 0, 0 ], [ 1, 2, -1, 0, 0, -1 ], [ 0, 2, -2, 0, 0, 0 ] ], 4 ], - [ [ [ -1, 2, -1, 0, 0, 0 ], [ 0, 2, -1, 0, 0, 0 ], [ 1, 2, -1, 0, 0, -1 ], [ -1, 2, -1, 0, 0, 1 ] ], 0 ], - [ [ [ -1, 2, -1, 0, 0, 0 ], [ 0, 2, -1, 0, 0, 0 ], [ 1, 1, -1, 0, 0, 0 ], [ -1, 2, -1, 0, 0, 1 ] ], 2.75 ], - [ [ [ -1, 2, -1, 0, 0, 0 ], [ 0, 2, -1, 0, 0, 0 ], [ 1, 1, -1, 0, 0, 0 ], [ -1, 2, -1, 1, 0, 0 ] ], 4.625 ] - ], - [ - [ [ [ -1, 2, -1, 0, 0, 0 ], [ "Rest" ], [ 1, 1, -1, 0, 0, 0 ], [ -1, 2, -1, 1, 0, 0 ] ], 0 ], - [ [ [ -1, 2, -1, 0, 0, 0 ], [ "Rest" ], [ "Rest" ], [ -1, 2, -1, 1, 0, 0 ] ], 0 ], - [ [ [ -1, 2, -1, 1, 0, -1 ], [ "Rest" ], [ "Rest" ], [ -1, 2, -1, 1, 0, 0 ] ], 4 ], - [ [ [ -2, 2, 0, 1, 0, 0 ], [ "Rest" ], [ "Rest" ], [ -1, 2, -1, 1, 0, 0 ] ], 4.75 ], - [ [ [ -1, 1, -1, 1, 0, 0 ], [ "Rest" ], [ "Rest" ], [ -1, 2, -1, 1, 0, 0 ] ], 3.25 ], - [ [ [ -2, 2, -1, 1, 1, 0 ], [ "Rest" ], [ "Rest" ], [ -1, 2, -1, 1, 0, 0 ] ], 3.75 ], - [ [ [ -1, 2, -1, 1, -1, 0 ], [ "Rest" ], [ "Rest" ], [ -1, 2, -1, 1, 0, 0 ] ], 4.125 ], - [ [ [ -2, 3, -1, 1, 0, 0 ], [ "Rest" ], [ "Rest" ], [ -1, 2, -1, 1, 0, 0 ] ], 2.625 ], - [ [ [ -3, 2, -1, 1, 0, 1 ], [ "Rest" ], [ "Rest" ], [ -1, 2, -1, 1, 0, 0 ] ], 4.5 ], - [ [ [ -2, 2, -2, 1, 0, 0 ], [ "Rest" ], [ "Rest" ], [ -1, 2, -1, 1, 0, 0 ] ], 2.625 ], - [ [ [ -3, 3, -1, 1, 0, 0 ], [ "Rest" ], [ "Rest" ], [ -1, 2, -1, 1, 0, 0 ] ], 3.375 ] - ], - [ - [ [ [ -3, 3, -1, 1, 0, 0 ], [ -1, 3, -1, 1, -1, 0 ], [ "Rest" ], [ -1, 2, -1, 1, 0, 0 ] ], 0 ], - [ [ [ -3, 3, -1, 1, 0, 0 ], [ -1, 3, -1, 1, -1, 0 ], [ -1, 3, -1, 1, 0, 0 ], [ -1, 2, -1, 1, 0, 0 ] ], 0 ], - [ [ [ -3, 3, -1, 1, 0, 0 ], [ -1, 3, -1, 1, -1, 0 ], [ -1, 3, -1, 1, 0, 0 ], [ -2, 3, 0, 1, 0, 0 ] ], 4.5 ], - [ [ [ -3, 3, -1, 1, 0, 0 ], [ -1, 3, -1, 1, -1, 0 ], [ -1, 3, -1, 1, 0, 0 ], [ -1, 3, -1, 1, 0, -1 ] ], 0 ], - [ [ [ -3, 3, -1, 1, 0, 0 ], [ -1, 3, -1, 1, -1, 0 ], [ -1, 2, -1, 1, 0, 0 ], [ -1, 3, -1, 1, 0, -1 ] ], 0 ], - [ [ [ -3, 3, -1, 1, 0, 0 ], [ -2, 4, -1, 1, 0, 0 ], [ -1, 2, -1, 1, 0, 0 ], [ -1, 3, -1, 1, 0, -1 ] ], 4.5 ], - [ [ [ -3, 3, -1, 1, 0, 0 ], [ -2, 4, -1, 1, 0, 0 ], [ -1, 2, -1, 1, 0, 0 ], [ -2, 3, -1, 2, 0, 0 ] ], 4.875 ], - [ [ [ -3, 3, -1, 1, 0, 0 ], [ -2, 4, -1, 1, 0, 0 ], [ -1, 2, -1, 1, 0, 0 ], [ -3, 3, -1, 2, 0, 0 ] ], 4.25 ] - ], - [ - [ [ [ -3, 3, -1, 1, 0, 0 ], [ "Rest" ], [ -1, 2, -1, 1, 0, 0 ], [ -3, 3, -1, 2, 0, 0 ] ], 0 ], - [ [ [ -3, 3, -1, 1, 0, 0 ], [ "Rest" ], [ "Rest" ], [ -3, 3, -1, 2, 0, 0 ] ], 0 ], - [ [ [ -3, 3, -1, 1, 0, 0 ], [ "Rest" ], [ "Rest" ], [ -3, 3, -1, 1, 0, 1 ] ], 2.125 ], - [ [ [ -3, 3, -1, 1, 0, 0 ], [ "Rest" ], [ "Rest" ], [ -3, 4, -1, 1, 0, 0 ] ], 2 ], - [ [ [ -3, 3, -1, 1, 0, 0 ], [ "Rest" ], [ "Rest" ], [ -2, 3, -2, 1, 0, 0 ] ], 1.125 ], - [ [ [ -3, 3, -1, 1, 0, 0 ], [ "Rest" ], [ "Rest" ], [ -2, 3, -1, 1, 0, 0 ] ], 0.875 ] - ], - [ - [ [ [ -3, 3, -1, 1, 0, 0 ], [ "Rest" ], [ -1, 2, -1, 1, 0, 0 ], [ -2, 3, -1, 1, 0, 0 ] ], 1.875 ], - [ [ [ -3, 3, -1, 1, 0, 0 ], [ "Rest" ], [ -1, 2, -1, 1, 0, 0 ], [ -1, 2, -2, 1, 0, 0 ] ], 0 ], - [ [ [ -3, 3, -1, 1, 0, 0 ], [ 0, 2, -1, 0, 0, 0 ], [ -1, 2, -1, 1, 0, 0 ], [ -1, 2, -2, 1, 0, 0 ] ], 0 ], - [ [ [ -2, 2, -2, 1, 0, 0 ], [ 0, 2, -1, 0, 0, 0 ], [ -1, 2, -1, 1, 0, 0 ], [ -1, 2, -2, 1, 0, 0 ] ], 4.375 ], - [ [ [ -3, 2, -1, 1, 0, 1 ], [ 0, 2, -1, 0, 0, 0 ], [ -1, 2, -1, 1, 0, 0 ], [ -1, 2, -2, 1, 0, 0 ] ], 4.375 ], - [ [ [ -3, 2, -1, 1, 0, 1 ], [ 0, 2, -1, 0, 0, 0 ], [ -1, 2, -1, 1, 0, 0 ], [ "Rest" ] ], 0 ], - [ [ [ "Rest" ], [ 0, 2, -1, 0, 0, 0 ], [ -1, 2, -1, 1, 0, 0 ], [ "Rest" ] ], 0 ], - [ [ [ "Rest" ], [ 0, 2, -1, 0, 0, 0 ], [ "Rest" ], [ "Rest" ] ], 0 ] - ] - ] -], -"last_changes": -[ - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 1, 0, 0 ], [ 0, 0, 0, 0, 1, 0 ], [ 1, 0, 0, -1, 0, 0 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 1, 0, 0 ], [ 0, 0, 0, 0, 1, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 1, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 1, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ] ] -], -"cur_uid": "74307bb4", -"ref_uid": "77b0d2dc", -"order_seed": 921767, -"dur_seed": 954688, -"motifs_seed": 995213, -"entrances_probs_vals": [ 1, 0, 0, 3.68, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 1, 0, 0, 3.68, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 1, 0, 0, 3.68, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -1315.1702786378, 338.08049535604 ], [ -200.61919504644, 1452.6315789474 ], [ -386, 1675.5417956656 ], [ -219, 1694.1176470588 ] ], -"step_probs_vals": [ 0, 1200, 0, 0, 0.063786008230453, 0.92613636363636, 0.12757201646091, 0, 0.54732510288066, 0, 0.71604938271605, 0, 1, 0 ], -"passages_weights": [ 0.7, 0.29, 0.66, 0.74, 0.68 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 0 ], [ 3, 2, 1 ], [ ] ], - [ [ 0 ], [ 2, 1, 3 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ] -], -"sus_weights": [ 1, 0, 0 ], -"order_size": [ 8, 10 ], -"passages_size": [ 0, 10 ], -"motif_edited": "true", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/74307bb4/lilypond/part_I.ly b/resources/resources_bak_2024_01_03/string_quartet_2/74307bb4/lilypond/part_I.ly deleted file mode 100644 index 8b64a06..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/74307bb4/lilypond/part_I.ly +++ /dev/null @@ -1,142 +0,0 @@ -{ - { dis'1^\markup { \pad-markup #0.2 "+16"} ~ } - \bar "|" - { dis'1 ~ } - \bar "|" - { dis'1 ~ } - \bar "|" - { dis'1 ~ } - \bar "|" - { dis'1 ~ } - \bar "|" - { dis'1 ~ } - \bar "|" - { dis'1 ~ } - \bar "|" - { dis'1 ~ } - \bar "|" - { dis'1 ~ } - \bar "|" - { dis'1 ~ } - \bar "|" - { dis'1 ~ } - \bar "|" - { dis'2. e'4^\markup { \pad-markup #0.2 "+44"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 13↓" }} ~ } - \bar "|" - { e'1 ~ } - \bar "|" - { e'2. ~ e'8.[ f'16^\markup { \pad-markup #0.2 "-29"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 5↑" }}] ~ } - \bar "|" - { f'1 ~ } - \bar "|" - { f'8.[ fis'16^\markup { \pad-markup #0.2 "-17"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↓" }}] ~ fis'2 ~ fis'8[ fis'8^\markup { \pad-markup #0.2 "+36"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 11↑" }}] ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'2. g'4^\markup { \pad-markup #0.2 "+33"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 11↓" }} ~ } - \bar "|" - { g'2 ~ g'16[ gis'8.^\markup { \pad-markup #0.2 "-14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↑" }}] ~ gis'4 ~ } - \bar "|" - { gis'8[ a'8^\markup { \pad-markup #0.2 "-2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 5↓" }}] ~ a'2. ~ } - \bar "|" - { a'1 ~ } - \bar "|" - { a'2 ~ a'8[ a'8^\markup { \pad-markup #0.2 "+25"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 13↑" }}] ~ a'4 ~ } - \bar "|" - { a'4 ~ a'8.[ b'16^\markup { \pad-markup #0.2 "-47"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }}] ~ b'2 ~ } - \bar "|" - { b'1 ~ } - \bar "|" - { b'2. ~ b'8.[ e'16^\markup { \pad-markup #0.2 "+44"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 13↓" }}] ~ } - \bar "|" - { e'1 } - \bar "|" - { fis'1^\markup { \pad-markup #0.2 "-17"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↓" }} ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'8.[ f'16^\markup { \pad-markup #0.2 "+20"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↑" }}] ~ f'2. ~ } - \bar "|" - { f'1 ~ } - \bar "|" - { f'8.[ fis'16^\markup { \pad-markup #0.2 "+31"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↓" }}] ~ fis'2. ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'8.[ g'16^\markup { \pad-markup #0.2 "-42"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↑" }}] ~ g'2. ~ } - \bar "|" - { g'2 ~ g'16[ gis'8.^\markup { \pad-markup #0.2 "-14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↑" }}] ~ gis'4 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'4 ~ gis'8[ g'8^\markup { \pad-markup #0.2 "-25"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }}] ~ g'2 ~ } - \bar "|" - { g'1 ~ } - \bar "|" - { g'2 ~ g'8[ fis'8^\markup { \pad-markup #0.2 "+48"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↓" }}] ~ fis'4 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'2. ~ fis'8[ cis''8^\markup { \pad-markup #0.2 "-43"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↑" }}] ~ } - \bar "|" - { cis''1 ~ } - \bar "|" - { cis''1 ~ } - \bar "|" - { cis''4 ~ cis''16[ cis'8.^\markup { \pad-markup #0.2 "-43"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↑" }}] ~ cis'2 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'4 ~ cis'8.[ b16^\markup { \pad-markup #0.2 "+29"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↑" }}] ~ b2 ~ } - \bar "|" - { b2 ais2^\markup { \pad-markup #0.2 "-10"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }} ~ } - \bar "|" - { ais2 b2^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↓" }} ~ } - \bar "|" - { b16[ dis'8.^\markup { \pad-markup #0.2 "-12"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }}] ~ dis'2. ~ } - \bar "|" - { dis'4 ~ dis'8.[ e'16^\markup { \pad-markup #0.2 "+0"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 5↓" }}] ~ e'2 ~ } - \bar "|" - { e'1 ~ } - \bar "|" - { e'1 ~ } - \bar "|" - { e'1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/74307bb4/lilypond/part_II.ly b/resources/resources_bak_2024_01_03/string_quartet_2/74307bb4/lilypond/part_II.ly deleted file mode 100644 index 222dcb4..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/74307bb4/lilypond/part_II.ly +++ /dev/null @@ -1,142 +0,0 @@ -{ - { r1 } - \bar "|" - { r2. r8.[ f'16^\markup { \pad-markup #0.2 "+47"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 7↓" }}] ~ } - \bar "|" - { f'1 ~ } - \bar "|" - { f'1 ~ } - \bar "|" - { f'16[ g'8.^\markup { \pad-markup #0.2 "-25"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 13↓" }}] ~ g'2. ~ } - \bar "|" - { g'1 ~ } - \bar "|" - { g'4 gis'2.^\markup { \pad-markup #0.2 "+14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↓" }} ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'4 g'2^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 5↑" }} dis''4^\markup { \pad-markup #0.2 "+16"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }} ~ } - \bar "|" - { dis''1 ~ } - \bar "|" - { dis''2 ~ dis''8[ cis''8^\markup { \pad-markup #0.2 "-16"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 7↑" }}] ~ cis''4 ~ } - \bar "|" - { cis''1 ~ } - \bar "|" - { cis''1 ~ } - \bar "|" - { cis''1 ~ } - \bar "|" - { cis''1 ~ } - \bar "|" - { cis''1 ~ } - \bar "|" - { cis''1 ~ } - \bar "|" - { cis''1 ~ } - \bar "|" - { cis''1 ~ } - \bar "|" - { cis''1 ~ } - \bar "|" - { cis''1 ~ } - \bar "|" - { cis''1 ~ } - \bar "|" - { cis''1 ~ } - \bar "|" - { cis''1 ~ } - \bar "|" - { cis''1 ~ } - \bar "|" - { cis''1 ~ } - \bar "|" - { cis''1 ~ } - \bar "|" - { cis''1 ~ } - \bar "|" - { cis''1 ~ } - \bar "|" - { cis''8.[ d''16^\markup { \pad-markup #0.2 "-23"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↓" }}] ~ d''2. ~ } - \bar "|" - { d''1 ~ } - \bar "|" - { d''1 ~ } - \bar "|" - { d''1 ~ } - \bar "|" - { d''8.[ dis''16^\markup { \pad-markup #0.2 "+16"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }}] ~ dis''2. ~ } - \bar "|" - { dis''1 ~ } - \bar "|" - { dis''1 ~ } - \bar "|" - { dis''2. ~ dis''8[ r8] } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r4 r8[ dis''8^\markup { \pad-markup #0.2 "-12"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }}] ~ dis''2 ~ } - \bar "|" - { dis''1 ~ } - \bar "|" - { dis''2 ~ dis''8[ gis'8^\markup { \pad-markup #0.2 "-14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }}] ~ gis'4 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'4 ~ gis'8.[ r16] r2 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r2 gis'2^\markup { \pad-markup #0.2 "-14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }} ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/74307bb4/lilypond/part_III.ly b/resources/resources_bak_2024_01_03/string_quartet_2/74307bb4/lilypond/part_III.ly deleted file mode 100644 index 0991a78..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/74307bb4/lilypond/part_III.ly +++ /dev/null @@ -1,142 +0,0 @@ -{ - { r1 } - \bar "|" - { r2. r8.[ ais'16^\markup { \pad-markup #0.2 "-36"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 11↓" }}] ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'4 ais'2.^\markup { \pad-markup #0.2 "+18"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↑" }} ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'2. r4 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r2. r16[ ais'8.^\markup { \pad-markup #0.2 "+18"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 1↑" }}] ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'2. ~ ais'8[ r8] } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r4 r8[ a'8^\markup { \pad-markup #0.2 "+37"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 11↓" }}] ~ a'2 ~ } - \bar "|" - { a'1 ~ } - \bar "|" - { a'2 ~ a'8[ ais'8^\markup { \pad-markup #0.2 "-10"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }}] ~ ais'4 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'4 ~ ais'8.[ r16] r2 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r4 r8.[ ais'16^\markup { \pad-markup #0.2 "+18"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 7↓" }}] ~ ais'2 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/74307bb4/lilypond/part_IV.ly b/resources/resources_bak_2024_01_03/string_quartet_2/74307bb4/lilypond/part_IV.ly deleted file mode 100644 index 0d3677b..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/74307bb4/lilypond/part_IV.ly +++ /dev/null @@ -1,142 +0,0 @@ -{ - { r1 } - \bar "|" - { r2. r8.[ c'16^\markup { \pad-markup #0.2 "-44"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 13↑" }}] ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'2. r4 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r4 r8.[ b16^\markup { \pad-markup #0.2 "-47"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 7↑" }}] ~ b2 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b8.[ ais16^\markup { \pad-markup #0.2 "+18"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }}] ~ ais2. ~ } - \bar "|" - { ais1 ~ } - \bar "|" - { ais1 ~ } - \bar "|" - { ais1 ~ } - \bar "|" - { ais1 ~ } - \bar "|" - { ais1 ~ } - \bar "|" - { ais1 ~ } - \bar "|" - { ais2. ~ ais8[ b8^\markup { \pad-markup #0.2 "+46"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 13↓" }}] ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b2. ~ b8[ c'8^\markup { \pad-markup #0.2 "-27"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 5↑" }}] ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'4 cis'2.^\markup { \pad-markup #0.2 "-16"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↓" }} ~ } - \bar "|" - { cis'2. ~ cis'8[ cis'8^\markup { \pad-markup #0.2 "+38"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 11↑" }}] ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'2. d'4^\markup { \pad-markup #0.2 "+35"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 11↓" }} ~ } - \bar "|" - { d'1 ~ } - \bar "|" - { d'2. ~ d'16[ dis'8.^\markup { \pad-markup #0.2 "-12"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↑" }}] ~ } - \bar "|" - { dis'1 ~ } - \bar "|" - { dis'8[ e8^\markup { \pad-markup #0.2 "+27"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 13↑" }}] ~ e2. ~ } - \bar "|" - { e1 ~ } - \bar "|" - { e4 ~ e8[ e8^\markup { \pad-markup #0.2 "+0"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 5↓" }}] ~ e2 ~ } - \bar "|" - { e2 ~ e8.[ dis16^\markup { \pad-markup #0.2 "-12"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↑" }}] ~ dis4 ~ } - \bar "|" - { dis1 ~ } - \bar "|" - { dis1 ~ } - \bar "|" - { dis1 ~ } - \bar "|" - { dis1 ~ } - \bar "|" - { dis1 ~ } - \bar "|" - { dis1 ~ } - \bar "|" - { dis1 ~ } - \bar "|" - { dis1 ~ } - \bar "|" - { dis1 ~ } - \bar "|" - { dis1 ~ } - \bar "|" - { dis1 ~ } - \bar "|" - { dis1 ~ } - \bar "|" - { dis1 ~ } - \bar "|" - { dis1 ~ } - \bar "|" - { dis4 ~ dis8.[ e16^\markup { \pad-markup #0.2 "+0"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }}] ~ e2 ~ } - \bar "|" - { e1 ~ } - \bar "|" - { e2 ~ e8[ e8^\markup { \pad-markup #0.2 "+27"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 13↑" }}] ~ e4 ~ } - \bar "|" - { e1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/74b8f8d9/74b8f8d9_code.scd b/resources/resources_bak_2024_01_03/string_quartet_2/74b8f8d9/74b8f8d9_code.scd deleted file mode 100644 index 57e638d..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/74b8f8d9/74b8f8d9_code.scd +++ /dev/null @@ -1,945 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array2) - hsArrayToCents.value(array1); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = true; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance); -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength.asInteger - minMotifLength.asInteger).rand + minMotifLength.asInteger).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength.asInteger - minProgLength.asInteger).rand + minProgLength.asInteger).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/74b8f8d9/74b8f8d9_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_2/74b8f8d9/74b8f8d9_mus_model.json deleted file mode 100644 index c472d47..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/74b8f8d9/74b8f8d9_mus_model.json +++ /dev/null @@ -1,77 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ -2, 3, -2, -1, 1, 0 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 3.75 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ "Rest" ], [ "Rest" ], [ -2, 4, -2, -1, 1, 0 ] ], 0 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ "Rest" ], [ -2, 3, -1, -1, 1, 0 ], [ -2, 4, -2, -1, 1, 0 ] ], 0 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 1, 0 ], [ -2, 3, -1, -1, 1, 0 ], [ -2, 4, -2, -1, 1, 0 ] ], 4.75 ] - ], - [ - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 1, 0 ], [ -1, 2, -2, -1, 1, 0 ], [ -2, 4, -2, -1, 1, 0 ] ], 0 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -2, -1, 1, 1 ], [ -1, 2, -2, -1, 1, 0 ], [ -2, 4, -2, -1, 1, 0 ] ], 0 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -2, -1, 1, 1 ], [ -1, 2, -2, -1, 1, 0 ], [ -1, 3, -3, -1, 1, 0 ] ], 7.125 ] - ], - [ - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -2, -1, 1, 1 ], [ -2, 3, -2, -1, 2, 0 ], [ -1, 3, -3, -1, 1, 0 ] ], 0 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -2, -1, 1, 1 ], [ -2, 3, -2, -1, 2, 0 ], [ 0, 3, -2, -1, 1, -1 ] ], 0 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -2, 0, 1, 0 ], [ -2, 3, -2, -1, 2, 0 ], [ 0, 3, -2, -1, 1, -1 ] ], 4.5 ] - ], - [ - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -2, 0, 1, 0 ], [ -1, 3, -2, -1, 0, 0 ], [ 0, 3, -2, -1, 1, -1 ] ], 0 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -2, 0, 1, 0 ], [ -1, 3, -2, -1, 0, 0 ], [ -1, 3, -1, -1, 1, 0 ] ], 0 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 0, 0 ], [ -1, 3, -1, -1, 1, 0 ] ], 6.875 ] - ], - [ - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 1, 0 ], [ -2, 4, -2, -1, 1, 0 ], [ -1, 3, -1, -1, 1, 0 ] ], 0 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -1, -1, 1, 0 ], [ -2, 4, -2, -1, 1, 0 ], [ -1, 3, -1, -1, 1, 0 ] ], 0 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -1, -1, 1, 0 ], [ -2, 4, -2, -1, 1, 0 ], [ 0, 2, -2, -1, 1, 0 ] ], 5.25 ] - ], - [ - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -1, -1, 1, 0 ], [ -2, 4, -2, -1, 1, 0 ], [ -1, 3, -3, -1, 1, 0 ] ], 0 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -1, -1, 1, 0 ], [ -2, 3, -2, -1, 1, 1 ], [ -1, 3, -3, -1, 1, 0 ] ], 0 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -1, 2, -2, -1, 1, 0 ], [ -2, 3, -2, -1, 1, 1 ], [ -1, 3, -3, -1, 1, 0 ] ], 6.125 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -1, 2, -2, -1, 1, 0 ], [ -2, 3, -2, -1, 1, 1 ], [ "Rest" ] ], 0 ], - [ [ [ "Rest" ], [ -1, 2, -2, -1, 1, 0 ], [ -2, 3, -2, -1, 1, 1 ], [ "Rest" ] ], 0 ], - [ [ [ "Rest" ], [ -1, 2, -2, -1, 1, 0 ], [ "Rest" ], [ "Rest" ] ], 0 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 10.125 ] - ] - ] -], -"last_changes": -[ - [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -1, -1, 1, 0 ], [ -2, 4, -2, -1, 1, 0 ], [ -1, 3, -1, -1, 1, 0 ] ], - [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -1, -1, 1, 0 ], [ -2, 4, -2, -1, 1, 0 ], [ 0, 2, -2, -1, 1, 0 ] ], - [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -1, -1, 1, 0 ], [ -2, 4, -2, -1, 1, 0 ], [ -1, 3, -3, -1, 1, 0 ] ], - [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -1, -1, 1, 0 ], [ -2, 3, -2, -1, 1, 1 ], [ -1, 3, -3, -1, 1, 0 ] ], - [ [ -2, 3, -2, -1, 1, 0 ], [ -1, 2, -2, -1, 1, 0 ], [ -2, 3, -2, -1, 1, 1 ], [ -1, 3, -3, -1, 1, 0 ] ] -], -"cur_uid": "74b8f8d9", -"ref_uid": "4c059f33", -"order_seed": 824152, -"dur_seed": 266394, -"motifs_seed": 206072, -"entrances_probs_vals": [ 1, 0, 5.0793650793651, 0.47, 2.8021978021978, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 1, 0, 2.7380952380952, 3.68, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 1, 0, 2.7380952380952, 3.68, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -1315.1702786378, 338.08049535604 ], [ -200.61919504644, 1452.6315789474 ], [ -386, 1675.5417956656 ], [ -219, 1694.1176470588 ] ], -"step_probs_vals": [ 0, 1200, 0, 0, 0.063786008230453, 0.92613636363636, 0.12757201646091, 0, 0.54732510288066, 0, 0.71604938271605, 0, 1, 0 ], -"passages_weights": [ 0.7, 0.29, 0.66, 0.74, 0.68 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 0 ], [ 3, 2, 1 ], [ ] ], - [ [ 0 ], [ 2, 1, 3 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ], - [ [ 0 ], [ 2, 1, 3 ], [ ] ], - [ [ 0 ], [ 3, 2, 1 ], [ ] ] -], -"sus_weights": [ 1, 0, 0 ], -"order_size": [ 8.0714285714286, 10.091836734694 ], -"passages_size": [ 0, 10 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/74b8f8d9/lilypond/part_I.ly b/resources/resources_bak_2024_01_03/string_quartet_2/74b8f8d9/lilypond/part_I.ly deleted file mode 100644 index 2d48723..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/74b8f8d9/lilypond/part_I.ly +++ /dev/null @@ -1,50 +0,0 @@ -{ - { r1 } - \bar "|" - { r2. r8[ e8^\markup { \pad-markup #0.2 "+18"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }}] ~ } - \bar "|" - { e1 ~ } - \bar "|" - { e1 ~ } - \bar "|" - { e4 f2.^\markup { \pad-markup #0.2 "+29"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↓" }} ~ } - \bar "|" - { f1 ~ } - \bar "|" - { f1 ~ } - \bar "|" - { f2. ~ f16[ cis'8.^\markup { \pad-markup #0.2 "-25"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↓" }}] ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'16[ cis'8.^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }}] ~ cis'2. ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'2 d'2^\markup { \pad-markup #0.2 "+14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }} ~ } - \bar "|" - { d'1 ~ } - \bar "|" - { d'1 ~ } - \bar "|" - { d'8[ f8^\markup { \pad-markup #0.2 "+29"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↓" }}] ~ f2. ~ } - \bar "|" - { f1 ~ } - \bar "|" - { f1 ~ } - \bar "|" - { f8.[ r16] r2. } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/74b8f8d9/lilypond/part_II.ly b/resources/resources_bak_2024_01_03/string_quartet_2/74b8f8d9/lilypond/part_II.ly deleted file mode 100644 index 1c284cd..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/74b8f8d9/lilypond/part_II.ly +++ /dev/null @@ -1,50 +0,0 @@ -{ - { r1 } - \bar "|" - { r2. r8[ cis8^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }}] ~ } - \bar "|" - { cis1 ~ } - \bar "|" - { cis1 ~ } - \bar "|" - { cis4 d2.^\markup { \pad-markup #0.2 "+14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }} ~ } - \bar "|" - { d1 ~ } - \bar "|" - { d1 ~ } - \bar "|" - { d2. ~ d16[ dis8.^\markup { \pad-markup #0.2 "-33"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 11↑" }}] ~ } - \bar "|" - { dis1 ~ } - \bar "|" - { dis1 ~ } - \bar "|" - { dis16[ e8.^\markup { \pad-markup #0.2 "-36"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 11↓" }}] ~ e2. ~ } - \bar "|" - { e1 ~ } - \bar "|" - { e1 ~ } - \bar "|" - { e2 e2^\markup { \pad-markup #0.2 "+18"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }} ~ } - \bar "|" - { e1 ~ } - \bar "|" - { e1 ~ } - \bar "|" - { e8[ fis8^\markup { \pad-markup #0.2 "-44"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↑" }}] ~ fis2. ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis8.[ r16] r2. } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/74b8f8d9/lilypond/part_III.ly b/resources/resources_bak_2024_01_03/string_quartet_2/74b8f8d9/lilypond/part_III.ly deleted file mode 100644 index ecf1ce2..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/74b8f8d9/lilypond/part_III.ly +++ /dev/null @@ -1,50 +0,0 @@ -{ - { r1 } - \bar "|" - { r2. r8[ a8^\markup { \pad-markup #0.2 "+16"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }}] ~ } - \bar "|" - { a1 ~ } - \bar "|" - { a1 ~ } - \bar "|" - { a4 fis2.^\markup { \pad-markup #0.2 "-44"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↑" }} ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis2. ~ fis16[ g8.^\markup { \pad-markup #0.2 "-15"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↑" }}] ~ } - \bar "|" - { g1 ~ } - \bar "|" - { g1 ~ } - \bar "|" - { g16[ a8.^\markup { \pad-markup #0.2 "+16"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }}] ~ a2. ~ } - \bar "|" - { a1 ~ } - \bar "|" - { a1 ~ } - \bar "|" - { a2 cis2^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }} ~ } - \bar "|" - { cis1 ~ } - \bar "|" - { cis1 ~ } - \bar "|" - { cis8[ d8^\markup { \pad-markup #0.2 "+14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }}] ~ d2. ~ } - \bar "|" - { d1 ~ } - \bar "|" - { d1 ~ } - \bar "|" - { d8.[ r16] r2. } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/74b8f8d9/lilypond/part_IV.ly b/resources/resources_bak_2024_01_03/string_quartet_2/74b8f8d9/lilypond/part_IV.ly deleted file mode 100644 index eca3efa..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/74b8f8d9/lilypond/part_IV.ly +++ /dev/null @@ -1,50 +0,0 @@ -{ - { a,1^\markup { \pad-markup #0.2 "+16"} ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,8.[ r16] r2. } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/76e45e56/76e45e56_code.scd b/resources/resources_bak_2024_01_03/string_quartet_2/76e45e56/76e45e56_code.scd deleted file mode 100644 index 57e638d..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/76e45e56/76e45e56_code.scd +++ /dev/null @@ -1,945 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array2) - hsArrayToCents.value(array1); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = true; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance); -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength.asInteger - minMotifLength.asInteger).rand + minMotifLength.asInteger).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength.asInteger - minProgLength.asInteger).rand + minProgLength.asInteger).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/76e45e56/76e45e56_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_2/76e45e56/76e45e56_mus_model.json deleted file mode 100644 index e1d66b2..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/76e45e56/76e45e56_mus_model.json +++ /dev/null @@ -1,71 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ -2, 3, -2, -1, 1, 0 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 1 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ "Rest" ], [ "Rest" ], [ -2, 4, -2, -1, 1, 0 ] ], 0 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ "Rest" ], [ -1, 3, -2, -1, 2, 0 ], [ -2, 4, -2, -1, 1, 0 ] ], 0 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -1, -1, 1, 0 ], [ -1, 3, -2, -1, 2, 0 ], [ -2, 4, -2, -1, 1, 0 ] ], 7 ] - ], - [ - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -1, -1, 1, 0 ], [ -1, 3, -1, -1, 1, 0 ], [ -2, 4, -2, -1, 1, 0 ] ], 0 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 1, -1 ], [ -1, 3, -1, -1, 1, 0 ], [ -2, 4, -2, -1, 1, 0 ] ], 0 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 1, -1 ], [ -1, 3, -1, -1, 1, 0 ], [ -1, 3, -2, -1, 0, 0 ] ], 5.5 ] - ], - [ - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 1, -1 ], [ 0, 2, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 0, 0 ] ], 0 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 1, -1 ], [ 0, 2, -2, -1, 1, 0 ], [ -1, 2, -2, -1, 1, 0 ] ], 0 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -1, 3, -3, -1, 1, 0 ], [ 0, 2, -2, -1, 1, 0 ], [ -1, 2, -2, -1, 1, 0 ] ], 4 ] - ], - [ - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -1, 3, -3, -1, 1, 0 ], [ 0, 3, -2, -2, 1, 0 ], [ -1, 2, -2, -1, 1, 0 ] ], 0 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -1, 3, -3, -1, 1, 0 ], [ 0, 3, -2, -2, 1, 0 ], [ -2, 3, -1, -1, 1, 0 ] ], 0 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -2, -1, 1, 1 ], [ 0, 3, -2, -2, 1, 0 ], [ -2, 3, -1, -1, 1, 0 ] ], 5.625 ] - ], - [ - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -2, -1, 1, 1 ], [ -1, 3, -2, -1, 1, 0 ], [ -2, 3, -1, -1, 1, 0 ] ], 0 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -2, -1, 1, 1 ], [ -1, 3, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 1, -1 ] ], 0 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -2, 0, 1, 0 ], [ -1, 3, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 1, -1 ] ], 6.5 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -2, 0, 1, 0 ], [ "Rest" ], [ -1, 3, -2, -1, 1, -1 ] ], 0 ], - [ [ [ "Rest" ], [ -2, 3, -2, 0, 1, 0 ], [ "Rest" ], [ -1, 3, -2, -1, 1, -1 ] ], 0 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ -1, 3, -2, -1, 1, -1 ] ], 0 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 6.375 ] - ] - ] -], -"last_changes": -[ - [ [ -2, 3, -2, -1, 1, 0 ], [ -1, 3, -3, -1, 1, 0 ], [ 0, 3, -2, -2, 1, 0 ], [ -2, 3, -1, -1, 1, 0 ] ], - [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -2, -1, 1, 1 ], [ 0, 3, -2, -2, 1, 0 ], [ -2, 3, -1, -1, 1, 0 ] ], - [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -2, -1, 1, 1 ], [ -1, 3, -2, -1, 1, 0 ], [ -2, 3, -1, -1, 1, 0 ] ], - [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -2, -1, 1, 1 ], [ -1, 3, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 1, -1 ] ], - [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -2, 0, 1, 0 ], [ -1, 3, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 1, -1 ] ] -], -"cur_uid": "76e45e56", -"ref_uid": 62300302, -"order_seed": 209649, -"dur_seed": 306774, -"motifs_seed": 821280, -"entrances_probs_vals": [ 1, 0, 2.9365079365079, 0.47, 2.8021978021978, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 1, 0, 2.7380952380952, 3.68, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 1, 0, 2.7380952380952, 3.68, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -1315.1702786378, 338.08049535604 ], [ -200.61919504644, 1452.6315789474 ], [ -386, 1675.5417956656 ], [ -219, 1694.1176470588 ] ], -"step_probs_vals": [ -1200, 1200, 0, 0, 0.35390946502058, 0, 0.5, 0.5, 0.62139917695473, 0, 1, 0 ], -"passages_weights": [ 0.7, 0.29, 0.66, 0.74, 0.68 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 0 ], [ 3, 2, 1 ], [ ] ], - [ [ 0 ], [ 2, 1, 3 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ] -], -"sus_weights": [ 1, 0, 0 ], -"order_size": [ 8.0714285714286, 10.091836734694 ], -"passages_size": [ 0, 10 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/76e45e56/lilypond/part_I.ly b/resources/resources_bak_2024_01_03/string_quartet_2/76e45e56/lilypond/part_I.ly deleted file mode 100644 index 7efbb7f..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/76e45e56/lilypond/part_I.ly +++ /dev/null @@ -1,38 +0,0 @@ -{ - { r2 e2^\markup { \pad-markup #0.2 "+18"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }} ~ } - \bar "|" - { e1 ~ } - \bar "|" - { e1 ~ } - \bar "|" - { e1 } - \bar "|" - { e1^\markup { \pad-markup #0.2 "-36"} ~ } - \bar "|" - { e1 ~ } - \bar "|" - { e2. d4^\markup { \pad-markup #0.2 "+14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 1↑" }} ~ } - \bar "|" - { d1 ~ } - \bar "|" - { d2. cis4^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }} ~ } - \bar "|" - { cis1 ~ } - \bar "|" - { cis1 ~ } - \bar "|" - { cis2 ~ cis16[ cis8.^\markup { \pad-markup #0.2 "-25"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↓" }}] ~ cis4 ~ } - \bar "|" - { cis1 ~ } - \bar "|" - { cis1 ~ } - \bar "|" - { cis2. ~ cis16[ r8.] } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/76e45e56/lilypond/part_II.ly b/resources/resources_bak_2024_01_03/string_quartet_2/76e45e56/lilypond/part_II.ly deleted file mode 100644 index 36f4169..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/76e45e56/lilypond/part_II.ly +++ /dev/null @@ -1,38 +0,0 @@ -{ - { r2 dis'2^\markup { \pad-markup #0.2 "-33"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 11↑" }} ~ } - \bar "|" - { dis'1 ~ } - \bar "|" - { dis'1 ~ } - \bar "|" - { dis'1 } - \bar "|" - { cis'1^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }} ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'2. d'4^\markup { \pad-markup #0.2 "+14"} ~ } - \bar "|" - { d'1 ~ } - \bar "|" - { d'2. b4^\markup { \pad-markup #0.2 "+47"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↓" }} ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b2 ~ b16[ a8.^\markup { \pad-markup #0.2 "+16"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }}] ~ a4 ~ } - \bar "|" - { a1 ~ } - \bar "|" - { a1 ~ } - \bar "|" - { a2. ~ a16[ r8.] } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/76e45e56/lilypond/part_III.ly b/resources/resources_bak_2024_01_03/string_quartet_2/76e45e56/lilypond/part_III.ly deleted file mode 100644 index 9a96093..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/76e45e56/lilypond/part_III.ly +++ /dev/null @@ -1,38 +0,0 @@ -{ - { r2 cis2^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }} ~ } - \bar "|" - { cis1 ~ } - \bar "|" - { cis1 ~ } - \bar "|" - { cis1 } - \bar "|" - { cis1^\markup { \pad-markup #0.2 "-25"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↓" }} ~ } - \bar "|" - { cis1 ~ } - \bar "|" - { cis2. f4^\markup { \pad-markup #0.2 "+29"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↓" }} ~ } - \bar "|" - { f1 ~ } - \bar "|" - { f2. fis4^\markup { \pad-markup #0.2 "-44"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↑" }} ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis2 ~ fis16[ g8.^\markup { \pad-markup #0.2 "-15"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↑" }}] ~ g4 ~ } - \bar "|" - { g1 ~ } - \bar "|" - { g1 ~ } - \bar "|" - { g2. ~ g16[ r8.] } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/76e45e56/lilypond/part_IV.ly b/resources/resources_bak_2024_01_03/string_quartet_2/76e45e56/lilypond/part_IV.ly deleted file mode 100644 index c9189fc..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/76e45e56/lilypond/part_IV.ly +++ /dev/null @@ -1,38 +0,0 @@ -{ - { a,1^\markup { \pad-markup #0.2 "+16"} ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,2. ~ a,16[ r8.] } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/77b0d2dc/77b0d2dc_code.scd b/resources/resources_bak_2024_01_03/string_quartet_2/77b0d2dc/77b0d2dc_code.scd deleted file mode 100644 index c194eef..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/77b0d2dc/77b0d2dc_code.scd +++ /dev/null @@ -1,945 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance); -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/77b0d2dc/77b0d2dc_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_2/77b0d2dc/77b0d2dc_mus_model.json deleted file mode 100644 index 6f0561e..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/77b0d2dc/77b0d2dc_mus_model.json +++ /dev/null @@ -1,59 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 3.875 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ], [ 1, 0, 0, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 1, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, 0, -1, 0 ], [ 0, 0, 1, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ] ], 4.875 ] - ], - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, 0, -1, 0 ], [ 1, 0, 0, 0, 0, -1 ], [ 1, 0, 0, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ], [ 1, 0, 0, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ], [ 0, 0, 1, 0, 0, 0 ] ], 4.75 ] - ], - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, -1, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], 4.125 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, -1, 0, 0, 0 ], [ "Rest" ], [ 1, 0, 0, 0, 0, -1 ] ], 0 ], - [ [ [ "Rest" ], [ 1, 0, -1, 0, 0, 0 ], [ "Rest" ], [ 1, 0, 0, 0, 0, -1 ] ], 0 ], - [ [ [ "Rest" ], [ 1, 0, -1, 0, 0, 0 ], [ "Rest" ], [ "Rest" ] ], 0 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 9.625 ] - ] - ] -], -"last_changes": -[ - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ], [ 1, 0, 0, 0, 0, 0 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ], [ 0, 0, 1, 0, 0, 0 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, -1, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ] -], -"cur_uid": "77b0d2dc", -"ref_uid": "nil", -"order_seed": 921767, -"dur_seed": 954688, -"motifs_seed": 995213, -"entrances_probs_vals": [ 1, 0, 0, 3.68, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 1, 0, 0, 3.68, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 1, 0, 0, 3.68, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -1315.1702786378, 338.08049535604 ], [ -200.61919504644, 1452.6315789474 ], [ -386, 1675.5417956656 ], [ -219, 1694.1176470588 ] ], -"step_probs_vals": [ 0, 1200, 0, 0, 0.063786008230453, 0.92613636363636, 0.12757201646091, 0, 0.54732510288066, 0, 0.71604938271605, 0, 1, 0 ], -"passages_weights": [ 0.7, 0.29, 0.66, 0.74, 0.68 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 0 ], [ 3, 2, 1 ], [ ] ], - [ [ 0 ], [ 2, 1, 3 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ] -], -"sus_weights": [ 1, 0, 0 ], -"order_size": [ 8, 10 ], -"passages_size": [ 0, 10 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/7bb0e931/7bb0e931_code.scd b/resources/resources_bak_2024_01_03/string_quartet_2/7bb0e931/7bb0e931_code.scd deleted file mode 100644 index c194eef..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/7bb0e931/7bb0e931_code.scd +++ /dev/null @@ -1,945 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance); -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/7bb0e931/7bb0e931_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_2/7bb0e931/7bb0e931_mus_model.json deleted file mode 100644 index 97c68b2..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/7bb0e931/7bb0e931_mus_model.json +++ /dev/null @@ -1,69 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 3.875 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ], [ 1, 0, 0, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 1, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, 0, -1, 0 ], [ 0, 0, 1, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ] ], 3.375 ] - ], - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, 0, -1, 0 ], [ 1, 0, 0, 0, 0, -1 ], [ 1, 0, 0, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ], [ 1, 0, 0, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ], [ 0, 0, 1, 0, 0, 0 ] ], 1.25 ] - ], - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, -1, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], 3.125 ] - ], - [ - [ [ [ 1, 0, -1, 0, 0, -1 ], [ 1, 0, -1, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], 0 ], - [ [ [ 1, 0, -1, 0, 0, -1 ], [ 1, 0, 1, 0, 0, -1 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], 2.25 ] - ], - [ - [ [ [ 1, -1, 0, 0, -1, 0 ], [ 1, 0, 1, 0, 0, -1 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], 0 ], - [ [ [ 1, -1, 0, 0, -1, 0 ], [ 2, -1, 0, -1, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], 2.625 ], - [ [ [ 1, -1, 0, 0, -1, 0 ], [ 2, -1, 0, -1, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ "Rest" ] ], 0 ], - [ [ [ 1, -1, 0, 0, -1, 0 ], [ 2, -1, 0, -1, 0, 0 ], [ "Rest" ], [ "Rest" ] ], 0 ], - [ [ [ "Rest" ], [ 2, -1, 0, -1, 0, 0 ], [ "Rest" ], [ "Rest" ] ], 0 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 10.0 ] - ] - ] -], -"last_changes": -[ - [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, -1, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], - [ [ 1, 0, -1, 0, 0, -1 ], [ 1, 0, -1, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], - [ [ 1, 0, -1, 0, 0, -1 ], [ 1, 0, 1, 0, 0, -1 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], - [ [ 1, -1, 0, 0, -1, 0 ], [ 1, 0, 1, 0, 0, -1 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], - [ [ 1, -1, 0, 0, -1, 0 ], [ 2, -1, 0, -1, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ] -], -"cur_uid": "7bb0e931", -"ref_uid": "nil", -"order_seed": 921767, -"dur_seed": 233566, -"motifs_seed": 995213, -"entrances_probs_vals": [ 1, 0, 0, 0.88, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 1, 0, 0, 0.88, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 1, 0, 0, 0.88, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -1315.1702786378, 338.08049535604 ], [ -200.61919504644, 1452.6315789474 ], [ -386, 1675.5417956656 ], [ -219, 1694.1176470588 ] ], -"step_probs_vals": [ 0, 1200, 0, 0, 0.063786008230453, 0.92613636363636, 0.12757201646091, 0, 0.54732510288066, 0, 0.71604938271605, 0, 1, 0 ], -"passages_weights": [ 0.7, 0.29, 0.66, 0.74, 0.68 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 0 ], [ 3, 2, 1 ], [ ] ], - [ [ 0 ], [ 2, 1, 3 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ], - [ [ 3, 2 ], [ 0, 1 ], [ ] ], - [ [ 3, 2 ], [ 0, 1 ], [ ] ] -], -"sus_weights": [ 1, 0, 0 ], -"order_size": [ 8, 10 ], -"passages_size": [ 0, 10 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/7df3df4c/7df3df4c_code.scd b/resources/resources_bak_2024_01_03/string_quartet_2/7df3df4c/7df3df4c_code.scd deleted file mode 100644 index c194eef..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/7df3df4c/7df3df4c_code.scd +++ /dev/null @@ -1,945 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance); -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/7df3df4c/7df3df4c_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_2/7df3df4c/7df3df4c_mus_model.json deleted file mode 100644 index e06a740..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/7df3df4c/7df3df4c_mus_model.json +++ /dev/null @@ -1,59 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 3.875 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ], [ 1, 0, 0, -1, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 1, 0, 0, 0, -1, 0 ], [ 1, 0, 0, -1, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 1 ], [ 1, 0, 0, 0, -1, 0 ], [ 1, 0, 0, -1, 0, 0 ] ], 4.875 ] - ], - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 1 ], [ 0, 0, 0, 0, 1, 0 ], [ 1, 0, 0, -1, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 1, 0, 0 ], [ 0, 0, 0, 0, 1, 0 ], [ 1, 0, 0, -1, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 1, 0, 0 ], [ 0, 0, 0, 0, 1, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], 4.75 ] - ], - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 1, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 1, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ] ], 4.125 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 1, 0, 0, 0 ] ], 0 ], - [ [ [ "Rest" ], [ 1, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 1, 0, 0, 0 ] ], 0 ], - [ [ [ "Rest" ], [ 1, 0, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ] ], 0 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 9.625 ] - ] - ] -], -"last_changes": -[ - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 1, 0, 0 ], [ 0, 0, 0, 0, 1, 0 ], [ 1, 0, 0, -1, 0, 0 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 1, 0, 0 ], [ 0, 0, 0, 0, 1, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 1, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 1, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ] ] -], -"cur_uid": "7df3df4c", -"ref_uid": "77b0d2dc", -"order_seed": 921767, -"dur_seed": 954688, -"motifs_seed": 995213, -"entrances_probs_vals": [ 1, 0, 0, 3.68, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 1, 0, 0, 3.68, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 1, 0, 0, 3.68, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -1315.1702786378, 338.08049535604 ], [ -200.61919504644, 1452.6315789474 ], [ -386, 1675.5417956656 ], [ -219, 1694.1176470588 ] ], -"step_probs_vals": [ 0, 1200, 0, 0, 0.063786008230453, 0.92613636363636, 0.12757201646091, 0, 0.54732510288066, 0, 0.71604938271605, 0, 1, 0 ], -"passages_weights": [ 0.7, 0.29, 0.66, 0.74, 0.68 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 0 ], [ 3, 2, 1 ], [ ] ], - [ [ 0 ], [ 2, 1, 3 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ] -], -"sus_weights": [ 1, 0, 0 ], -"order_size": [ 8, 10 ], -"passages_size": [ 0, 10 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/7fe1da13/7fe1da13_code.scd b/resources/resources_bak_2024_01_03/string_quartet_2/7fe1da13/7fe1da13_code.scd deleted file mode 100644 index c194eef..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/7fe1da13/7fe1da13_code.scd +++ /dev/null @@ -1,945 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance); -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/7fe1da13/7fe1da13_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_2/7fe1da13/7fe1da13_mus_model.json deleted file mode 100644 index 61971c6..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/7fe1da13/7fe1da13_mus_model.json +++ /dev/null @@ -1,198 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 4.25 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ], [ 1, 0, 0, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 1, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 2, 0, 0, -1, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ] ], 4.25 ] - ], - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 2, 0, 0, -1, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, -1, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, -1, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ] ], 4.875 ] - ], - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, -1, 0, 0, 0 ], [ 0, 0, 0, 0, 1, 0 ], [ 0, 0, 1, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, -1, 0, 0, 0 ], [ 0, 0, 0, 0, 1, 0 ], [ 1, -1, 0, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 1 ], [ 0, 0, 0, 0, 1, 0 ], [ 1, -1, 0, 0, 0, 0 ] ], 4.875 ] - ], - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 1 ], [ 0, 0, 0, 0, 1, 0 ], [ -1, 0, 0, 1, 0, 1 ] ], 0 ], - [ [ [ 0, -1, 0, 0, 0, 1 ], [ 0, 0, 0, 0, 0, 1 ], [ 0, 0, 0, 0, 1, 0 ], [ -1, 0, 0, 1, 0, 1 ] ], 0 ], - [ [ [ 0, -1, 0, 0, 0, 1 ], [ 0, 0, 0, 0, 0, 1 ], [ -1, 0, 0, 0, 0, 2 ], [ -1, 0, 0, 1, 0, 1 ] ], 3.875 ] - ], - [ - [ [ [ 0, -1, 0, 0, 0, 1 ], [ 0, 0, 0, 0, 0, 1 ], [ -1, 0, 0, 0, 0, 2 ], [ 0, 0, 0, 0, 1, 1 ] ], 0 ], - [ [ [ -1, 0, 1, 0, 0, 1 ], [ 0, 0, 0, 0, 0, 1 ], [ -1, 0, 0, 0, 0, 2 ], [ 0, 0, 0, 0, 1, 1 ] ], 0 ], - [ [ [ -1, 0, 1, 0, 0, 1 ], [ 0, 0, 0, 0, 0, 1 ], [ -1, 1, 0, 0, 0, 1 ], [ 0, 0, 0, 0, 1, 1 ] ], 4.125 ] - ], - [ - [ [ [ -1, 0, 1, 0, 0, 1 ], [ -1, 0, 0, 1, 0, 1 ], [ -1, 1, 0, 0, 0, 1 ], [ 0, 0, 0, 0, 1, 1 ] ], 4.875 ], - [ [ [ -1, 0, 1, 0, 0, 1 ], [ -1, 0, 0, 1, 0, 1 ], [ -1, 1, 0, 0, 0, 1 ], [ -1, 0, 0, 1, 0, 2 ] ], 0 ], - [ [ [ -1, 0, 1, 0, 0, 1 ], [ -1, 0, 0, 1, 0, 1 ], [ -2, 0, 0, 1, 0, 2 ], [ -1, 0, 0, 1, 0, 2 ] ], 0 ], - [ [ [ -1, 0, 1, 0, 0, 1 ], [ 0, 0, -1, 1, 0, 1 ], [ -2, 0, 0, 1, 0, 2 ], [ -1, 0, 0, 1, 0, 2 ] ], 4.375 ] - ], - [ - [ [ [ -1, 0, 1, 0, 0, 1 ], [ 0, 0, -1, 1, 0, 1 ], [ -2, 0, 0, 1, 0, 2 ], [ 0, -1, -1, 1, 0, 1 ] ], 0 ], - [ [ [ -2, 0, -1, 2, 0, 1 ], [ 0, 0, -1, 1, 0, 1 ], [ -2, 0, 0, 1, 0, 2 ], [ 0, -1, -1, 1, 0, 1 ] ], 0 ], - [ [ [ -2, 0, -1, 2, 0, 1 ], [ 0, 0, -1, 1, 0, 1 ], [ -1, 0, -1, 1, 0, 1 ], [ 0, -1, -1, 1, 0, 1 ] ], 3.875 ] - ], - [ - [ [ [ -2, 0, -1, 2, 0, 1 ], [ 0, 0, -1, 1, 0, 1 ], [ -1, 0, -1, 1, 0, 1 ], [ -2, 0, -1, 2, 0, 2 ] ], 0 ], - [ [ [ -2, 0, -1, 2, 0, 1 ], [ 0, 0, -1, 1, 0, 1 ], [ -1, 0, -1, 2, 0, 0 ], [ -2, 0, -1, 2, 0, 2 ] ], 0 ], - [ [ [ -2, 0, -1, 2, 0, 1 ], [ -2, 1, -1, 2, 0, 1 ], [ -1, 0, -1, 2, 0, 0 ], [ -2, 0, -1, 2, 0, 2 ] ], 4.875 ] - ], - [ - [ [ [ -2, 0, -1, 2, 0, 1 ], [ -2, 1, -1, 2, 0, 1 ], [ -1, 0, -1, 2, 0, 0 ], [ -1, 0, -2, 2, 0, 1 ] ], 0 ], - [ [ [ -2, 0, -1, 2, 0, 1 ], [ -2, 1, -1, 2, 0, 1 ], [ -2, 0, 0, 2, 0, 1 ], [ -1, 0, -2, 2, 0, 1 ] ], 0 ], - [ [ [ -2, 0, -1, 2, 0, 1 ], [ -1, 0, -1, 2, -1, 1 ], [ -2, 0, 0, 2, 0, 1 ], [ -1, 0, -2, 2, 0, 1 ] ], 4.125 ] - ], - [ - [ [ [ -2, 0, -1, 2, 0, 1 ], [ -1, 0, -1, 2, -1, 1 ], [ -1, -1, -1, 2, 0, 1 ], [ -1, 0, -2, 2, 0, 1 ] ], 0 ], - [ [ [ -2, 0, -1, 2, 0, 1 ], [ -1, 0, -1, 2, -1, 1 ], [ -1, -1, -1, 2, 0, 1 ], [ -2, 1, -1, 2, 0, 1 ] ], 0 ], - [ [ [ -2, 0, -1, 2, 0, 1 ], [ -2, 0, -1, 2, 1, 1 ], [ -1, -1, -1, 2, 0, 1 ], [ -2, 1, -1, 2, 0, 1 ] ], 4.75 ] - ], - [ - [ [ [ -2, 0, -1, 2, 0, 1 ], [ -2, 0, -1, 2, 1, 1 ], [ -1, 0, -1, 2, 0, 0 ], [ -2, 1, -1, 2, 0, 1 ] ], 0 ], - [ [ [ -2, 0, -1, 2, 0, 1 ], [ -2, 0, -1, 2, 1, 1 ], [ -1, 0, -1, 2, 0, 0 ], [ -1, 0, -1, 2, -1, 1 ] ], 0 ], - [ [ [ -2, 0, -1, 2, 0, 1 ], [ -1, -1, -1, 2, 0, 1 ], [ -1, 0, -1, 2, 0, 0 ], [ -1, 0, -1, 2, -1, 1 ] ], 4.875 ] - ], - [ - [ [ [ -2, 0, -1, 2, 0, 1 ], [ -2, 0, 0, 2, 0, 1 ], [ -1, 0, -1, 2, 0, 0 ], [ -1, 0, -1, 2, -1, 1 ] ], 0 ], - [ [ [ -2, 0, -1, 2, 0, 1 ], [ -2, 0, 0, 2, 0, 1 ], [ -1, 0, -1, 2, 0, 0 ], [ -2, 0, -1, 2, 1, 1 ] ], 0 ], - [ [ [ -2, 0, -1, 2, 0, 1 ], [ -2, 0, 0, 2, 0, 1 ], [ -1, -1, -1, 2, 0, 1 ], [ -2, 0, -1, 2, 1, 1 ] ], 4.375 ] - ], - [ - [ [ [ -2, 0, -1, 2, 0, 1 ], [ -2, 0, 0, 2, 0, 1 ], [ -1, 0, -1, 2, -1, 1 ], [ -2, 0, -1, 2, 1, 1 ] ], 0 ], - [ [ [ -2, 0, -1, 2, 0, 1 ], [ -2, 0, 0, 2, 0, 1 ], [ -1, 0, -1, 2, -1, 1 ], [ -1, -1, -1, 2, 0, 1 ] ], 0 ], - [ [ [ -2, 0, -1, 2, 0, 1 ], [ -1, 0, -1, 2, 0, 0 ], [ -1, 0, -1, 2, -1, 1 ], [ -1, -1, -1, 2, 0, 1 ] ], 5 ] - ], - [ - [ [ [ -2, 0, -1, 2, 0, 1 ], [ -1, 0, -1, 2, 0, 0 ], [ -2, 1, -1, 2, 0, 1 ], [ -1, -1, -1, 2, 0, 1 ] ], 0 ], - [ [ [ -2, 0, -1, 2, 0, 1 ], [ -1, 0, -1, 2, 0, 0 ], [ -2, 1, -1, 2, 0, 1 ], [ -2, 0, 0, 2, 0, 1 ] ], 0 ], - [ [ [ -2, 0, -1, 2, 0, 1 ], [ -1, -1, -1, 2, 0, 1 ], [ -2, 1, -1, 2, 0, 1 ], [ -2, 0, 0, 2, 0, 1 ] ], 4.25 ] - ], - [ - [ [ [ -2, 0, -1, 2, 0, 1 ], [ -2, 0, -1, 2, 1, 1 ], [ -2, 1, -1, 2, 0, 1 ], [ -2, 0, 0, 2, 0, 1 ] ], 0 ], - [ [ [ -2, 0, -1, 2, 0, 1 ], [ -2, 0, -1, 2, 1, 1 ], [ -1, 0, -2, 2, 0, 1 ], [ -2, 0, 0, 2, 0, 1 ] ], 0 ], - [ [ [ -2, 0, -1, 2, 0, 1 ], [ -2, 0, -1, 2, 1, 1 ], [ -1, 0, -2, 2, 0, 1 ], [ -1, 0, -1, 2, 0, 0 ] ], 3.875 ] - ], - [ - [ [ [ -2, 0, -1, 2, 0, 1 ], [ -2, 0, -1, 2, 1, 1 ], [ -2, 0, -1, 2, 0, 2 ], [ -1, 0, -1, 2, 0, 0 ] ], 0 ], - [ [ [ -2, 0, -1, 2, 0, 1 ], [ -2, 0, -1, 2, 1, 1 ], [ -2, 0, -1, 2, 0, 2 ], [ -1, 0, -1, 1, 0, 1 ] ], 0 ], - [ [ [ -2, 0, -1, 2, 0, 1 ], [ -1, -1, -1, 2, 0, 1 ], [ -2, 0, -1, 2, 0, 2 ], [ -1, 0, -1, 1, 0, 1 ] ], 4.375 ] - ], - [ - [ [ [ -2, 0, -1, 2, 0, 1 ], [ -1, -1, -1, 2, 0, 1 ], [ -2, 0, -1, 2, 0, 2 ], [ -1, 0, -2, 2, 0, 1 ] ], 0 ], - [ [ [ -2, 0, -1, 2, 0, 1 ], [ -1, 0, -1, 2, 0, 0 ], [ -2, 0, -1, 2, 0, 2 ], [ -1, 0, -2, 2, 0, 1 ] ], 0 ], - [ [ [ -2, 0, -1, 2, 0, 1 ], [ -1, 0, -1, 2, 0, 0 ], [ -2, 1, -1, 2, 0, 1 ], [ -1, 0, -2, 2, 0, 1 ] ], 4.375 ] - ], - [ - [ [ [ -2, 0, -1, 2, 0, 1 ], [ -1, 0, -1, 2, 0, 0 ], [ -1, 0, -1, 2, -1, 1 ], [ -1, 0, -2, 2, 0, 1 ] ], 0 ], - [ [ [ -2, 0, -1, 2, 0, 1 ], [ -1, 0, -1, 1, 0, 1 ], [ -1, 0, -1, 2, -1, 1 ], [ -1, 0, -2, 2, 0, 1 ] ], 0 ], - [ [ [ -2, 0, -1, 2, 0, 1 ], [ -1, 0, -1, 1, 0, 1 ], [ -1, 0, -1, 2, -1, 1 ], [ -2, 1, -1, 2, 0, 1 ] ], 4.125 ] - ], - [ - [ [ [ -2, 0, -1, 2, 0, 1 ], [ -2, 0, 0, 2, 0, 1 ], [ -1, 0, -1, 2, -1, 1 ], [ -2, 1, -1, 2, 0, 1 ] ], 0 ], - [ [ [ -2, 0, -1, 2, 0, 1 ], [ -2, 0, 0, 2, 0, 1 ], [ -2, 0, -1, 2, 1, 1 ], [ -2, 1, -1, 2, 0, 1 ] ], 0 ], - [ [ [ -2, 0, -1, 2, 0, 1 ], [ -2, 0, 0, 2, 0, 1 ], [ -2, 0, -1, 2, 1, 1 ], [ -1, 0, -1, 2, -1, 1 ] ], 3.875 ] - ], - [ - [ [ [ -2, 0, -1, 2, 0, 1 ], [ -2, 0, 0, 2, 0, 1 ], [ -2, 0, -1, 2, 1, 1 ], [ 0, 0, -1, 1, 0, 1 ] ], 0 ], - [ [ [ -2, 0, -1, 2, 0, 1 ], [ -1, 0, -1, 2, 0, 0 ], [ -2, 0, -1, 2, 1, 1 ], [ 0, 0, -1, 1, 0, 1 ] ], 0 ], - [ [ [ -2, 0, -1, 2, 0, 1 ], [ -1, 0, -1, 2, 0, 0 ], [ -1, -1, -1, 2, 0, 1 ], [ 0, 0, -1, 1, 0, 1 ] ], 4.5 ] - ], - [ - [ [ [ -2, 0, -1, 2, 0, 1 ], [ -1, 0, -1, 2, 0, 0 ], [ -1, -1, -1, 2, 0, 1 ], [ 0, 0, -1, 2, 0, 0 ] ], 0 ], - [ [ [ -2, 0, -1, 2, 0, 1 ], [ -1, 0, -1, 1, 0, 1 ], [ -1, -1, -1, 2, 0, 1 ], [ 0, 0, -1, 2, 0, 0 ] ], 0 ], - [ [ [ -2, 0, -1, 2, 0, 1 ], [ -1, 0, -1, 1, 0, 1 ], [ -2, 0, 0, 2, 0, 1 ], [ 0, 0, -1, 2, 0, 0 ] ], 4.625 ] - ], - [ - [ [ [ -2, 0, -1, 2, 0, 1 ], [ -1, 0, -1, 1, 0, 1 ], [ -2, 0, 0, 2, 0, 1 ], [ 0, -1, -1, 2, 0, 1 ] ], 0 ], - [ [ [ -2, 0, -1, 2, 0, 1 ], [ -1, 0, -1, 1, 0, 1 ], [ -1, 0, -1, 2, 0, 0 ], [ 0, -1, -1, 2, 0, 1 ] ], 0 ], - [ [ [ -2, 0, -1, 2, 0, 1 ], [ -2, 0, -1, 2, 0, 2 ], [ -1, 0, -1, 2, 0, 0 ], [ 0, -1, -1, 2, 0, 1 ] ], 4.875 ] - ], - [ - [ [ [ -2, 0, -1, 2, 0, 1 ], [ -1, 0, -2, 2, 0, 1 ], [ -1, 0, -1, 2, 0, 0 ], [ 0, -1, -1, 2, 0, 1 ] ], 0 ], - [ [ [ -2, 0, -1, 2, 0, 1 ], [ -1, 0, -2, 2, 0, 1 ], [ -1, 0, -1, 2, 0, 0 ], [ -1, 0, 0, 2, 0, 1 ] ], 0 ], - [ [ [ -2, 0, -1, 2, 0, 1 ], [ -1, 0, -2, 2, 0, 1 ], [ -1, -1, -1, 2, 0, 1 ], [ -1, 0, 0, 2, 0, 1 ] ], 4.25 ] - ], - [ - [ [ [ -2, 0, -1, 2, 0, 1 ], [ -1, 0, -2, 2, 0, 1 ], [ -2, 0, -1, 2, 1, 1 ], [ -1, 0, 0, 2, 0, 1 ] ], 0 ], - [ [ [ -2, 0, -1, 2, 0, 1 ], [ -1, 0, -2, 2, 0, 1 ], [ -2, 0, -1, 2, 1, 1 ], [ 0, 0, -1, 2, 0, 0 ] ], 0 ], - [ [ [ -2, 0, -1, 2, 0, 1 ], [ -2, 1, -1, 2, 0, 1 ], [ -2, 0, -1, 2, 1, 1 ], [ 0, 0, -1, 2, 0, 0 ] ], 4.875 ] - ], - [ - [ [ [ -2, 0, -1, 2, 0, 1 ], [ -2, 1, -1, 2, 0, 1 ], [ -1, 0, -1, 2, -1, 1 ], [ 0, 0, -1, 2, 0, 0 ] ], 0 ], - [ [ [ -2, 0, -1, 2, 0, 1 ], [ -2, 0, -1, 2, 0, 2 ], [ -1, 0, -1, 2, -1, 1 ], [ 0, 0, -1, 2, 0, 0 ] ], 0 ], - [ [ [ -2, 0, -1, 2, 0, 1 ], [ -2, 0, -1, 2, 0, 2 ], [ -1, 0, -1, 2, -1, 1 ], [ 0, 0, -1, 1, 0, 1 ] ], 4.5 ] - ], - [ - [ [ [ -2, 0, -1, 2, 0, 1 ], [ -2, 0, -1, 3, 0, 1 ], [ -1, 0, -1, 2, -1, 1 ], [ 0, 0, -1, 1, 0, 1 ] ], 0 ], - [ [ [ -2, 0, -1, 2, 0, 1 ], [ -2, 0, -1, 3, 0, 1 ], [ -1, 0, -1, 2, -1, 1 ], [ -2, 0, 0, 2, 0, 1 ] ], 0 ], - [ [ [ -2, 0, -1, 2, 0, 1 ], [ -2, 0, -1, 3, 0, 1 ], [ -2, 1, -1, 2, 0, 1 ], [ -2, 0, 0, 2, 0, 1 ] ], 3.875 ], - [ [ [ -2, 0, -1, 2, 0, 1 ], [ -2, 0, -1, 3, 0, 1 ], [ -2, 1, -1, 2, 0, 1 ], [ "Rest" ] ], 0 ], - [ [ [ -2, 0, -1, 2, 0, 1 ], [ -2, 0, -1, 3, 0, 1 ], [ "Rest" ], [ "Rest" ] ], 0 ], - [ [ [ -2, 0, -1, 2, 0, 1 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 0 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 8.5 ] - ] - ] -], -"last_changes": -[ - [ [ -2, 0, -1, 2, 0, 1 ], [ -2, 0, -1, 2, 0, 2 ], [ -1, 0, -1, 2, -1, 1 ], [ 0, 0, -1, 2, 0, 0 ] ], - [ [ -2, 0, -1, 2, 0, 1 ], [ -2, 0, -1, 2, 0, 2 ], [ -1, 0, -1, 2, -1, 1 ], [ 0, 0, -1, 1, 0, 1 ] ], - [ [ -2, 0, -1, 2, 0, 1 ], [ -2, 0, -1, 3, 0, 1 ], [ -1, 0, -1, 2, -1, 1 ], [ 0, 0, -1, 1, 0, 1 ] ], - [ [ -2, 0, -1, 2, 0, 1 ], [ -2, 0, -1, 3, 0, 1 ], [ -1, 0, -1, 2, -1, 1 ], [ -2, 0, 0, 2, 0, 1 ] ], - [ [ -2, 0, -1, 2, 0, 1 ], [ -2, 0, -1, 3, 0, 1 ], [ -2, 1, -1, 2, 0, 1 ], [ -2, 0, 0, 2, 0, 1 ] ] -], -"cur_uid": "7fe1da13", -"ref_uid": "nil", -"order_seed": 962045, -"dur_seed": 299387, -"motifs_seed": 678579, -"entrances_probs_vals": [ 1, 0, 0, 3.8461538461538, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 1, 0, 0, 3.8461538461538, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 1, 0, 0, 3.8461538461538, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -1315.1702786378, 338.08049535604 ], [ -200.61919504644, 1452.6315789474 ], [ -386, 1675.5417956656 ], [ -219, 1694.1176470588 ] ], -"step_probs_vals": [ 0, 1200, 0, 0, 0.063786008230453, 0.92613636363636, 0.12757201646091, 0, 0.54732510288066, 0, 0.71604938271605, 0, 1, 0 ], -"passages_weights": [ 0.7, 0.29, 0.66, 0.74, 0.68 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 0 ], [ 3, 2, 1 ], [ ] ], - [ [ 0 ], [ 2, 1, 3 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ], - [ [ 1 ], [ 3, 0, 2 ], [ ] ], - [ [ 1 ], [ 3, 0, 2 ], [ ] ], - [ [ 1 ], [ 3, 2, 1 ], [ ] ], - [ [ 1 ], [ 3, 0, 2 ], [ ] ], - [ [ 0 ], [ 3, 2, 1 ], [ ] ], - [ [ 0 ], [ 3, 2, 1 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ], - [ [ 0 ], [ 1, 3, 2 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ], - [ [ 0 ], [ 1, 2, 3 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ], - [ [ 0 ], [ 3, 1, 2 ], [ ] ], - [ [ 0 ], [ 2, 1, 3 ], [ ] ], - [ [ 0 ], [ 1, 2, 3 ], [ ] ], - [ [ 0 ], [ 3, 1, 2 ], [ ] ], - [ [ 0 ], [ 3, 1, 2 ], [ ] ], - [ [ 0 ], [ 3, 2, 1 ], [ ] ], - [ [ 0 ], [ 1, 3, 2 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ], - [ [ 0 ], [ 2, 1, 3 ], [ ] ], - [ [ 0 ], [ 1, 3, 2 ], [ ] ] -], -"sus_weights": [ 1, 0, 0 ], -"order_size": [ 8, 10 ], -"passages_size": [ 0, 10 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_2/tmp/tmp_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_2/tmp/tmp_mus_model.json deleted file mode 100644 index d270a25..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_2/tmp/tmp_mus_model.json +++ /dev/null @@ -1,71 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ -2, 3, -2, -1, 1, 0 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 1 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ "Rest" ], [ "Rest" ], [ -2, 4, -2, -1, 1, 0 ] ], 0 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ "Rest" ], [ -1, 3, -2, -1, 2, 0 ], [ -2, 4, -2, -1, 1, 0 ] ], 0 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -1, -1, 1, 0 ], [ -1, 3, -2, -1, 2, 0 ], [ -2, 4, -2, -1, 1, 0 ] ], 7 ] - ], - [ - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -1, -1, 1, 0 ], [ -1, 3, -1, -1, 1, 0 ], [ -2, 4, -2, -1, 1, 0 ] ], 0 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 1, -1 ], [ -1, 3, -1, -1, 1, 0 ], [ -2, 4, -2, -1, 1, 0 ] ], 0 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 1, -1 ], [ -1, 3, -1, -1, 1, 0 ], [ -1, 3, -2, -1, 0, 0 ] ], 5.5 ] - ], - [ - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 1, -1 ], [ 0, 2, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 0, 0 ] ], 0 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 1, -1 ], [ 0, 2, -2, -1, 1, 0 ], [ -1, 2, -2, -1, 1, 0 ] ], 0 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -1, 3, -3, -1, 1, 0 ], [ 0, 2, -2, -1, 1, 0 ], [ -1, 2, -2, -1, 1, 0 ] ], 4 ] - ], - [ - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -1, 3, -3, -1, 1, 0 ], [ 0, 3, -2, -2, 1, 0 ], [ -1, 2, -2, -1, 1, 0 ] ], 0 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -1, 3, -3, -1, 1, 0 ], [ 0, 3, -2, -2, 1, 0 ], [ -2, 3, -1, -1, 1, 0 ] ], 0 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -2, -1, 1, 1 ], [ 0, 3, -2, -2, 1, 0 ], [ -2, 3, -1, -1, 1, 0 ] ], 5.625 ] - ], - [ - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -2, -1, 1, 1 ], [ -1, 3, -2, -1, 1, 0 ], [ -2, 3, -1, -1, 1, 0 ] ], 0 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -2, -1, 1, 1 ], [ -1, 3, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 1, -1 ] ], 0 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -2, 0, 1, 0 ], [ -1, 3, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 1, -1 ] ], 6.5 ], - [ [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -2, 0, 1, 0 ], [ "Rest" ], [ -1, 3, -2, -1, 1, -1 ] ], 0 ], - [ [ [ "Rest" ], [ -2, 3, -2, 0, 1, 0 ], [ "Rest" ], [ -1, 3, -2, -1, 1, -1 ] ], 0 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ -1, 3, -2, -1, 1, -1 ] ], 0 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 6.375 ] - ] - ] -], -"last_changes": -[ - [ [ -2, 3, -2, -1, 1, 0 ], [ -1, 3, -3, -1, 1, 0 ], [ 0, 3, -2, -2, 1, 0 ], [ -2, 3, -1, -1, 1, 0 ] ], - [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -2, -1, 1, 1 ], [ 0, 3, -2, -2, 1, 0 ], [ -2, 3, -1, -1, 1, 0 ] ], - [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -2, -1, 1, 1 ], [ -1, 3, -2, -1, 1, 0 ], [ -2, 3, -1, -1, 1, 0 ] ], - [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -2, -1, 1, 1 ], [ -1, 3, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 1, -1 ] ], - [ [ -2, 3, -2, -1, 1, 0 ], [ -2, 3, -2, 0, 1, 0 ], [ -1, 3, -2, -1, 1, 0 ], [ -1, 3, -2, -1, 1, -1 ] ] -], -"cur_uid": "tmp", -"ref_uid": 62300302, -"order_seed": 209649, -"dur_seed": 306774, -"motifs_seed": 821280, -"entrances_probs_vals": [ 1, 0, 2.9365079365079, 0.47, 2.8021978021978, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 1, 0, 2.7380952380952, 3.68, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 1, 0, 2.7380952380952, 3.68, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -1315.1702786378, 338.08049535604 ], [ -200.61919504644, 1452.6315789474 ], [ -386, 1675.5417956656 ], [ -219, 1694.1176470588 ] ], -"step_probs_vals": [ -1200, 1200, 0, 0, 0.35390946502058, 0, 0.5, 0.5, 0.62139917695473, 0, 1, 0 ], -"passages_weights": [ 0.7, 0.29, 0.66, 0.74, 0.68 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 0 ], [ 3, 2, 1 ], [ ] ], - [ [ 0 ], [ 2, 1, 3 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ] -], -"sus_weights": [ 1, 0, 0 ], -"order_size": [ 8.0714285714286, 10.091836734694 ], -"passages_size": [ 0, 10 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3.json b/resources/resources_bak_2024_01_03/string_quartet_3.json deleted file mode 100644 index f4e9aa1..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3.json +++ /dev/null @@ -1,21 +0,0 @@ -{ -"ledger": -[ - "5201b8af", - "781442dc", - "6f0f638f", - "577cf188", - "7c2de94c", - "5488f7e9", - "5ec14635", - "726a40c7", - "55f9b81e", - "45fa07e8", - "6a9928d6", - "55bd25a1", - "75316bf0", - "69c568c6", - "4ff624b0", - "7e230015" -] -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3.json_bak b/resources/resources_bak_2024_01_03/string_quartet_3.json_bak deleted file mode 100644 index 4417271..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3.json_bak +++ /dev/null @@ -1,20 +0,0 @@ -{ -"ledger": -[ - "5201b8af", - "781442dc", - "6f0f638f", - "577cf188", - "7c2de94c", - "5488f7e9", - "5ec14635", - "726a40c7", - "55f9b81e", - "45fa07e8", - "6a9928d6", - "55bd25a1", - "75316bf0", - "69c568c6", - "4ff624b0" -] -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3/45fa07e8/45fa07e8_code.scd b/resources/resources_bak_2024_01_03/string_quartet_3/45fa07e8/45fa07e8_code.scd deleted file mode 100644 index 92aa171..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3/45fa07e8/45fa07e8_code.scd +++ /dev/null @@ -1,966 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -/* -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance) -}; -*/ - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = true; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - if(pDistance < 0, {stepFunc.value(abs(pDistance))}, {0.001}); - //stepFunc.value(pDistance) -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - //tuples = dims.collect({[0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength.asInteger - minMotifLength.asInteger).rand + minMotifLength.asInteger).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - //noProgIns = (popSize - noSusIns).rand + 1; - noProgIns = (popSize - noSusIns); - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength.asInteger - minProgLength.asInteger).rand + minProgLength.asInteger).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - - - if(rangeScore.value(candidate, [0, 0, 0, 0, 0, 0], ranges[ins][1] - 500, ranges[ins][1], 0, true) == 1, { - isInRangeScore = 1 - rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0] + 500, ranges[ins][1] - 500, 0, true); - }, { - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - }); - - - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_3/45fa07e8/45fa07e8_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_3/45fa07e8/45fa07e8_mus_model.json deleted file mode 100644 index 10b6bb0..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3/45fa07e8/45fa07e8_mus_model.json +++ /dev/null @@ -1,443 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ 2, -5, 0, 3, -1, -1 ], [ "Rest" ], [ "Rest" ] ], 1.5 ], - [ [ [ "Rest" ], [ 2, -5, 0, 3, -1, -1 ], [ "Rest" ], [ 4, -5, -1, 2, -1, -1 ] ], 1.75 ], - [ [ [ 2, -5, -1, 3, -1, -1 ], [ 2, -5, 0, 3, -1, -1 ], [ "Rest" ], [ 4, -5, -1, 2, -1, -1 ] ], 1 ], - [ [ [ 2, -5, -1, 3, -1, -1 ], [ 2, -5, 0, 3, -1, -1 ], [ 4, -5, -1, 2, 0, -1 ], [ 4, -5, -1, 2, -1, -1 ] ], 1.375 ] - ], - [ - [ [ [ 2, -5, -1, 3, -1, -1 ], [ 4, -5, -1, 1, -1, -1 ], [ 4, -5, -1, 2, 0, -1 ], [ 4, -5, -1, 2, -1, -1 ] ], 0.875 ] - ], - [ - [ [ [ 2, -5, -1, 3, -1, -1 ], [ 4, -5, -1, 1, -1, -1 ], [ 4, -5, -1, 2, 0, -1 ], [ 3, -4, -1, 2, 0, -1 ] ], 1.625 ] - ], - [ - [ [ [ 2, -5, -1, 3, -1, -1 ], [ 3, -5, -1, 3, -1, -1 ], [ 4, -5, -1, 2, 0, -1 ], [ 3, -4, -1, 2, 0, -1 ] ], 0.75 ] - ], - [ - [ [ [ 2, -5, -1, 3, -1, -1 ], [ 4, -6, -1, 2, 0, -1 ], [ 4, -5, -1, 2, 0, -1 ], [ 3, -4, -1, 2, 0, -1 ] ], 1.75 ] - ], - [ - [ [ [ 3, -6, -1, 2, 0, -1 ], [ 4, -6, -1, 2, 0, -1 ], [ 4, -5, -1, 2, 0, -1 ], [ 3, -4, -1, 2, 0, -1 ] ], 1.375 ] - ], - [ - [ [ [ 3, -6, -1, 2, 0, -1 ], [ 4, -5, -1, 2, -1, -1 ], [ 4, -5, -1, 2, 0, -1 ], [ 3, -4, -1, 2, 0, -1 ] ], 1.125 ] - ], - [ - [ [ [ 3, -6, -1, 2, 0, -1 ], [ 4, -5, -1, 2, -1, -1 ], [ 3, -4, -1, 2, 1, -1 ], [ 3, -4, -1, 2, 0, -1 ] ], 1.625 ] - ], - [ - [ [ [ 3, -6, -1, 2, 0, -1 ], [ 4, -5, -1, 2, -1, -1 ], [ 3, -4, -1, 2, 1, -1 ], [ 2, -3, -1, 2, 1, -1 ] ], 1.125 ] - ], - [ - [ [ [ 3, -6, -1, 2, 0, -1 ], [ 4, -5, -1, 2, -1, -1 ], [ 3, -4, -1, 2, 1, -1 ], [ 3, -4, -2, 2, 1, -1 ] ], 1.5 ] - ], - [ - [ [ [ 3, -6, -1, 2, 0, -1 ], [ 4, -5, -1, 2, -1, -1 ], [ 4, -5, -2, 2, 1, -1 ], [ 3, -4, -2, 2, 1, -1 ] ], 1.375 ] - ], - [ - [ [ [ 3, -5, -2, 2, 0, -1 ], [ 4, -5, -1, 2, -1, -1 ], [ 4, -5, -2, 2, 1, -1 ], [ 3, -4, -2, 2, 1, -1 ] ], 1.5 ] - ], - [ - [ [ [ 3, -5, -2, 2, 0, -1 ], [ 4, -5, -2, 2, 0, -1 ], [ 4, -5, -2, 2, 1, -1 ], [ 3, -4, -2, 2, 1, -1 ] ], 1.625 ] - ], - [ - [ [ [ 3, -5, -2, 2, 0, -1 ], [ 4, -5, -2, 2, 0, -1 ], [ 4, -5, -2, 2, 1, -1 ], [ 5, -5, -2, 1, 0, -1 ] ], 1.25 ] - ], - [ - [ [ [ 3, -5, -2, 2, 0, -1 ], [ 4, -5, -3, 2, 1, -1 ], [ 4, -5, -2, 2, 1, -1 ], [ 5, -5, -2, 1, 0, -1 ] ], 1.75 ] - ], - [ - [ [ [ 3, -5, -2, 2, 0, -1 ], [ 4, -5, -3, 2, 1, -1 ], [ 4, -5, -2, 2, 1, -1 ], [ 3, -5, -2, 3, 1, -1 ] ], 0.875 ] - ], - [ - [ [ [ 3, -5, -2, 2, 0, -1 ], [ 5, -5, -2, 1, 0, -1 ], [ 4, -5, -2, 2, 1, -1 ], [ 3, -5, -2, 3, 1, -1 ] ], 0.625 ] - ], - [ - [ [ [ 3, -5, -2, 2, 0, -1 ], [ 5, -6, -2, 2, 0, -1 ], [ 4, -5, -2, 2, 1, -1 ], [ 3, -5, -2, 3, 1, -1 ] ], 0.75 ] - ], - [ - [ [ [ 3, -5, -2, 2, 0, -1 ], [ 5, -6, -2, 2, 0, -1 ], [ 4, -5, -2, 2, 1, -1 ], [ 5, -5, -2, 2, 0, -2 ] ], 1.125 ] - ], - [ - [ [ [ 3, -5, -2, 2, 0, -1 ], [ 6, -5, -2, 1, 0, -2 ], [ 4, -5, -2, 2, 1, -1 ], [ 5, -5, -2, 2, 0, -2 ] ], 1.5 ] - ], - [ - [ [ [ 4, -4, -2, 1, 0, -2 ], [ 6, -5, -2, 1, 0, -2 ], [ 4, -5, -2, 2, 1, -1 ], [ 5, -5, -2, 2, 0, -2 ] ], 1.375 ] - ], - [ - [ [ [ 4, -4, -2, 1, 0, -2 ], [ 6, -4, -2, 1, -1, -2 ], [ 4, -5, -2, 2, 1, -1 ], [ 5, -5, -2, 2, 0, -2 ] ], 1.625 ] - ], - [ - [ [ [ 4, -4, -2, 1, 0, -2 ], [ 6, -4, -2, 1, -1, -2 ], [ 6, -5, -2, 2, 0, -3 ], [ 5, -5, -2, 2, 0, -2 ] ], 1.375 ] - ], - [ - [ [ [ 5, -4, -2, 1, -2, -2 ], [ 6, -4, -2, 1, -1, -2 ], [ 6, -5, -2, 2, 0, -3 ], [ 5, -5, -2, 2, 0, -2 ] ], 0.75 ] - ], - [ - [ [ [ 5, -4, -2, 1, -2, -2 ], [ 6, -4, -2, 1, -1, -2 ], [ 5, -5, -1, 2, 0, -2 ], [ 5, -5, -2, 2, 0, -2 ] ], 1.375 ] - ], - [ - [ [ [ 5, -4, -2, 1, -2, -2 ], [ 6, -4, -2, 1, -1, -2 ], [ 5, -5, -2, 1, -1, -2 ], [ 5, -5, -2, 2, 0, -2 ] ], 1 ] - ], - [ - [ [ [ 5, -4, -2, 1, -2, -2 ], [ 6, -4, -2, 1, -1, -2 ], [ 4, -4, -2, 1, 0, -2 ], [ 5, -5, -2, 2, 0, -2 ] ], 1.625 ] - ], - [ - [ [ [ 5, -4, -2, 1, -2, -2 ], [ 6, -4, -2, 1, -1, -2 ], [ 4, -3, -2, 1, -1, -2 ], [ 5, -5, -2, 2, 0, -2 ] ], 1.625 ] - ], - [ - [ [ [ 5, -4, -2, 1, -2, -2 ], [ 5, -3, -2, 1, -2, -2 ], [ 4, -3, -2, 1, -1, -2 ], [ 5, -5, -2, 2, 0, -2 ] ], 1 ] - ], - [ - [ [ [ 4, -5, -2, 2, 0, -2 ], [ 5, -3, -2, 1, -2, -2 ], [ 4, -3, -2, 1, -1, -2 ], [ 5, -5, -2, 2, 0, -2 ] ], 1.125 ] - ], - [ - [ [ [ 4, -5, -2, 2, 0, -2 ], [ 5, -3, -2, 1, -2, -2 ], [ 5, -3, -2, 1, -3, -2 ], [ 5, -5, -2, 2, 0, -2 ] ], 0.75 ] - ], - [ - [ [ [ 4, -5, -2, 2, 0, -2 ], [ 5, -5, -2, 2, -1, -2 ], [ 5, -3, -2, 1, -3, -2 ], [ 5, -5, -2, 2, 0, -2 ] ], 1.5 ] - ], - [ - [ [ [ 4, -5, -2, 1, -1, -2 ], [ 5, -5, -2, 2, -1, -2 ], [ 5, -3, -2, 1, -3, -2 ], [ 5, -5, -2, 2, 0, -2 ] ], 0.875 ] - ], - [ - [ [ [ 4, -5, -2, 1, -1, -2 ], [ 4, -4, -2, 2, 0, -2 ], [ 5, -3, -2, 1, -3, -2 ], [ 5, -5, -2, 2, 0, -2 ] ], 1.75 ] - ], - [ - [ [ [ 4, -5, -2, 1, -1, -2 ], [ 4, -4, -2, 2, 0, -2 ], [ 5, -5, -2, 1, 0, -2 ], [ 5, -5, -2, 2, 0, -2 ] ], 0.875 ] - ], - [ - [ [ [ 4, -5, -2, 1, -1, -2 ], [ 4, -4, -2, 2, 0, -2 ], [ 5, -4, -2, 1, -1, -2 ], [ 5, -5, -2, 2, 0, -2 ] ], 0.875 ] - ], - [ - [ [ [ 4, -5, -2, 1, -1, -2 ], [ 4, -4, -2, 2, 0, -2 ], [ 4, -5, -1, 2, 0, -2 ], [ 5, -5, -2, 2, 0, -2 ] ], 1.5 ] - ], - [ - [ [ [ 4, -5, -2, 1, -1, -2 ], [ 4, -4, -2, 2, 0, -2 ], [ 5, -6, -2, 2, 0, -2 ], [ 5, -5, -2, 2, 0, -2 ] ], 0.875 ] - ], - [ - [ [ [ 4, -5, -2, 1, -1, -2 ], [ 4, -5, -2, 2, 0, -1 ], [ 5, -6, -2, 2, 0, -2 ], [ 5, -5, -2, 2, 0, -2 ] ], 1.625 ] - ], - [ - [ [ [ 4, -5, -2, 1, -1, -2 ], [ 4, -5, -2, 2, 0, -1 ], [ 5, -5, -2, 2, -1, -2 ], [ 5, -5, -2, 2, 0, -2 ] ], 1.125 ] - ], - [ - [ [ [ 4, -5, -2, 1, -1, -2 ], [ 4, -5, -2, 2, 0, -1 ], [ 5, -5, -2, 2, -1, -2 ], [ 5, -4, -2, 2, -1, -2 ] ], 1.5 ] - ], - [ - [ [ [ 4, -5, -2, 1, -1, -2 ], [ 5, -4, -3, 2, -1, -2 ], [ 5, -5, -2, 2, -1, -2 ], [ 5, -4, -2, 2, -1, -2 ] ], 0.875 ] - ], - [ - [ [ [ 4, -5, -2, 1, -1, -2 ], [ 5, -4, -3, 2, -1, -2 ], [ 5, -5, -2, 2, -1, -2 ], [ 6, -5, -3, 2, -1, -2 ] ], 1.5 ] - ], - [ - [ [ [ 4, -5, -2, 1, -1, -2 ], [ 5, -4, -3, 2, -1, -2 ], [ 6, -6, -3, 2, -1, -2 ], [ 6, -5, -3, 2, -1, -2 ] ], 1.25 ] - ], - [ - [ [ [ 4, -5, -2, 1, -1, -2 ], [ 5, -4, -3, 2, -1, -2 ], [ 6, -5, -2, 1, -1, -2 ], [ 6, -5, -3, 2, -1, -2 ] ], 1.5 ] - ], - [ - [ [ [ 4, -5, -2, 1, -1, -2 ], [ 7, -5, -2, 0, -1, -2 ], [ 6, -5, -2, 1, -1, -2 ], [ 6, -5, -3, 2, -1, -2 ] ], 0.75 ] - ], - [ - [ [ [ 4, -5, -2, 1, -1, -2 ], [ 7, -5, -2, 0, -1, -2 ], [ 6, -5, -2, 1, -1, -2 ], [ 6, -4, -2, 1, -1, -2 ] ], 0.75 ] - ], - [ - [ [ [ 5, -5, -2, 0, -1, -2 ], [ 7, -5, -2, 0, -1, -2 ], [ 6, -5, -2, 1, -1, -2 ], [ 6, -4, -2, 1, -1, -2 ] ], 1.125 ] - ], - [ - [ [ [ 5, -5, -2, 1, -1, -3 ], [ 7, -5, -2, 0, -1, -2 ], [ 6, -5, -2, 1, -1, -2 ], [ 6, -4, -2, 1, -1, -2 ] ], 1.625 ] - ], - [ - [ [ [ 5, -5, -2, 1, -1, -3 ], [ 6, -4, -3, 1, -1, -2 ], [ 6, -5, -2, 1, -1, -2 ], [ 6, -4, -2, 1, -1, -2 ] ], 1.75 ] - ], - [ - [ [ [ 5, -5, -2, 1, -1, -3 ], [ 6, -4, -3, 1, -1, -2 ], [ 5, -3, -2, 1, -1, -2 ], [ 6, -4, -2, 1, -1, -2 ] ], 0.875 ] - ], - [ - [ [ [ 4, -4, -2, 1, -1, -2 ], [ 6, -4, -3, 1, -1, -2 ], [ 5, -3, -2, 1, -1, -2 ], [ 6, -4, -2, 1, -1, -2 ] ], 1.25 ] - ], - [ - [ [ [ 4, -4, -2, 1, -1, -2 ], [ 6, -4, -3, 1, -1, -2 ], [ 5, -4, -2, 1, -1, -2 ], [ 6, -4, -2, 1, -1, -2 ] ], 1.625 ] - ], - [ - [ [ [ 4, -4, -2, 1, -1, -2 ], [ 5, -4, -2, 2, -1, -2 ], [ 5, -4, -2, 1, -1, -2 ], [ 6, -4, -2, 1, -1, -2 ] ], 1.875 ] - ], - [ - [ [ [ 4, -4, -2, 1, -1, -2 ], [ 3, -3, -2, 1, -1, -2 ], [ 5, -4, -2, 1, -1, -2 ], [ 6, -4, -2, 1, -1, -2 ] ], 1.625 ] - ], - [ - [ [ [ 4, -4, -2, 1, -1, -2 ], [ 4, -4, -3, 1, -1, -2 ], [ 5, -4, -2, 1, -1, -2 ], [ 6, -4, -2, 1, -1, -2 ] ], 1.5 ] - ], - [ - [ [ [ 4, -4, -2, 1, -1, -2 ], [ 4, -4, -3, 1, -1, -2 ], [ 5, -4, -2, 1, -1, -2 ], [ 5, -4, -3, 1, -1, -2 ] ], 0.625 ] - ], - [ - [ [ [ 4, -4, -2, 1, -1, -2 ], [ 3, -4, -2, 2, -1, -2 ], [ 5, -4, -2, 1, -1, -2 ], [ 5, -4, -3, 1, -1, -2 ] ], 1.625 ] - ], - [ - [ [ [ 4, -4, -2, 1, -1, -2 ], [ 5, -4, -3, 0, -1, -2 ], [ 5, -4, -2, 1, -1, -2 ], [ 5, -4, -3, 1, -1, -2 ] ], 1.625 ] - ], - [ - [ [ [ 5, -4, -3, 1, -2, -2 ], [ 5, -4, -3, 0, -1, -2 ], [ 5, -4, -2, 1, -1, -2 ], [ 5, -4, -3, 1, -1, -2 ] ], 0.875 ] - ], - [ - [ [ [ 5, -4, -3, 1, -2, -2 ], [ 5, -4, -3, 0, -1, -2 ], [ 6, -5, -3, 1, -1, -2 ], [ 5, -4, -3, 1, -1, -2 ] ], 1.125 ] - ], - [ - [ [ [ 4, -3, -3, 1, -1, -2 ], [ 5, -4, -3, 0, -1, -2 ], [ 6, -5, -3, 1, -1, -2 ], [ 5, -4, -3, 1, -1, -2 ] ], 1 ] - ], - [ - [ [ [ 4, -3, -3, 1, -1, -2 ], [ 5, -4, -3, 0, -1, -2 ], [ 6, -5, -3, 1, -1, -2 ], [ 6, -5, -4, 1, -1, -2 ] ], 1.5 ] - ], - [ - [ [ [ 5, -5, -2, 1, -1, -2 ], [ 5, -4, -3, 0, -1, -2 ], [ 6, -5, -3, 1, -1, -2 ], [ 6, -5, -4, 1, -1, -2 ] ], 1 ] - ], - [ - [ [ [ 5, -5, -2, 1, -1, -2 ], [ 5, -4, -3, 0, -1, -2 ], [ 6, -5, -3, 1, -1, -2 ], [ 5, -5, -3, 1, -1, -1 ] ], 1.25 ] - ], - [ - [ [ [ 5, -5, -2, 1, -1, -2 ], [ 5, -4, -3, 0, -1, -2 ], [ 5, -5, -2, 1, -1, -1 ], [ 5, -5, -3, 1, -1, -1 ] ], 1.375 ] - ], - [ - [ [ [ 5, -6, -2, 1, -1, -1 ], [ 5, -4, -3, 0, -1, -2 ], [ 5, -5, -2, 1, -1, -1 ], [ 5, -5, -3, 1, -1, -1 ] ], 1.375 ] - ], - [ - [ [ [ 5, -6, -2, 1, -1, -1 ], [ 5, -4, -3, 0, -1, -2 ], [ 5, -5, -2, 1, -1, -1 ], [ 4, -5, -2, 2, -1, -1 ] ], 1.5 ] - ], - [ - [ [ [ 5, -6, -2, 1, -1, -1 ], [ 5, -4, -3, 0, -1, -2 ], [ 5, -5, -2, 1, -1, -1 ], [ 6, -7, -2, 1, -1, -1 ] ], 1.375 ] - ], - [ - [ [ [ 5, -6, -2, 1, -1, -1 ], [ 5, -4, -3, 0, -1, -2 ], [ 5, -5, -2, 1, -1, -1 ], [ 6, -6, -2, 1, -2, -1 ] ], 1.625 ] - ], - [ - [ [ [ 5, -6, -2, 1, -1, -1 ], [ 5, -4, -3, 0, -1, -2 ], [ 6, -6, -3, 1, -1, -1 ], [ 6, -6, -2, 1, -2, -1 ] ], 1.125 ] - ], - [ - [ [ [ 5, -6, -2, 1, -1, -1 ], [ 5, -4, -3, 0, -1, -2 ], [ 5, -6, -2, 2, -1, -1 ], [ 6, -6, -2, 1, -2, -1 ] ], 1.125 ] - ], - [ - [ [ [ 5, -6, -2, 1, -1, -1 ], [ 5, -4, -3, 0, -1, -2 ], [ 5, -6, -2, 2, -1, -1 ], [ 6, -4, -2, 0, -1, -2 ] ], 0.625 ] - ], - [ - [ [ [ 5, -6, -2, 1, -1, -1 ], [ 5, -4, -3, 0, -1, -2 ], [ 7, -4, -2, -1, -1, -2 ], [ 6, -4, -2, 0, -1, -2 ] ], 1 ] - ], - [ - [ [ [ 5, -6, -2, 1, -1, -1 ], [ 5, -7, -2, 1, -1, -1 ], [ 7, -4, -2, -1, -1, -2 ], [ 6, -4, -2, 0, -1, -2 ] ], 1.5 ] - ], - [ - [ [ [ 5, -6, -2, 1, -1, -1 ], [ 4, -4, -2, 1, -1, -2 ], [ 7, -4, -2, -1, -1, -2 ], [ 6, -4, -2, 0, -1, -2 ] ], 1.25 ] - ], - [ - [ [ [ 5, -6, -2, 1, -1, -1 ], [ 4, -5, -2, 1, -1, -1 ], [ 7, -4, -2, -1, -1, -2 ], [ 6, -4, -2, 0, -1, -2 ] ], 1.625 ] - ], - [ - [ [ [ 5, -6, -2, 1, -1, -1 ], [ 4, -5, -2, 1, -1, -1 ], [ 7, -4, -2, -1, -1, -2 ], [ 5, -6, -2, 1, -1, 0 ] ], 1 ] - ], - [ - [ [ [ 5, -6, -2, 1, -1, -1 ], [ 4, -5, -2, 1, -1, -1 ], [ 6, -6, -2, 1, -1, -1 ], [ 5, -6, -2, 1, -1, 0 ] ], 1.625 ] - ], - [ - [ [ [ 5, -6, -2, 1, -1, -1 ], [ 4, -5, -2, 1, -1, -1 ], [ 5, -6, -1, 1, -1, 0 ], [ 5, -6, -2, 1, -1, 0 ] ], 1.25 ] - ], - [ - [ [ [ 5, -6, -2, 1, -1, -1 ], [ 4, -5, -2, 1, -1, -1 ], [ 5, -6, -1, 1, -1, 0 ], [ 5, -6, -2, 2, -1, -1 ] ], 1 ] - ], - [ - [ [ [ 5, -6, -2, 1, -1, -1 ], [ 4, -5, -2, 1, -1, -1 ], [ 5, -6, -1, 1, -1, 0 ], [ 5, -5, -1, 1, -1, -1 ] ], 1.625 ] - ], - [ - [ [ [ 5, -6, -2, 1, -1, -1 ], [ 4, -6, -1, 1, -1, -1 ], [ 5, -6, -1, 1, -1, 0 ], [ 5, -5, -1, 1, -1, -1 ] ], 1.25 ] - ], - [ - [ [ [ 5, -6, -2, 1, -1, -1 ], [ 5, -7, -2, 1, -1, -1 ], [ 5, -6, -1, 1, -1, 0 ], [ 5, -5, -1, 1, -1, -1 ] ], 0.875 ] - ], - [ - [ [ [ 5, -6, -2, 1, -1, -1 ], [ 5, -7, -2, 1, -1, -1 ], [ 6, -5, -1, 0, -1, -1 ], [ 5, -5, -1, 1, -1, -1 ] ], 1.25 ] - ], - [ - [ [ [ 5, -6, -2, 1, -1, -1 ], [ 5, -7, -2, 1, -1, -1 ], [ 6, -5, -1, 0, -1, -1 ], [ 6, -6, -2, 1, -1, -1 ] ], 0.75 ] - ], - [ - [ [ [ 5, -6, -2, 1, -1, -1 ], [ 5, -7, -2, 1, -1, -1 ], [ 7, -7, -2, 1, -1, -1 ], [ 6, -6, -2, 1, -1, -1 ] ], 1.125 ] - ], - [ - [ [ [ 5, -6, -2, 1, -1, -1 ], [ 5, -7, -2, 1, -1, -1 ], [ 4, -6, -2, 1, -1, -1 ], [ 6, -6, -2, 1, -1, -1 ] ], 1.625 ] - ], - [ - [ [ [ 5, -6, -2, 1, -1, -1 ], [ 5, -7, -2, 1, -1, -1 ], [ 4, -6, -2, 1, -1, -1 ], [ 7, -7, -3, 1, -1, -1 ] ], 1.125 ] - ], - [ - [ [ [ 5, -6, -2, 1, -1, -1 ], [ 5, -7, -2, 1, -1, -1 ], [ 4, -6, -2, 1, -1, -1 ], [ 6, -7, -2, 1, -1, 0 ] ], 1.375 ] - ], - [ - [ [ [ 5, -6, -2, 1, -1, -1 ], [ 5, -7, -2, 1, -1, -1 ], [ 4, -6, -2, 1, -1, -1 ], [ 6, -6, -1, 1, -1, -1 ] ], 1.75 ] - ], - [ - [ [ [ 4, -6, -1, 1, -1, 0 ], [ 5, -7, -2, 1, -1, -1 ], [ 4, -6, -2, 1, -1, -1 ], [ 6, -6, -1, 1, -1, -1 ] ], 1.125 ] - ], - [ - [ [ [ 4, -6, -1, 1, -1, 0 ], [ 5, -7, -2, 1, -1, -1 ], [ 4, -6, -2, 1, -1, -1 ], [ 7, -7, -2, 1, -1, -1 ] ], 1.25 ] - ], - [ - [ [ [ 4, -6, -1, 1, -1, 0 ], [ 5, -7, -2, 1, -1, -1 ], [ 4, -7, -2, 1, -1, 0 ], [ 7, -7, -2, 1, -1, -1 ] ], 0.75 ] - ], - [ - [ [ [ 4, -6, -1, 1, -1, 0 ], [ 5, -7, -2, 1, -1, -1 ], [ 4, -7, -2, 1, -1, 0 ], [ 6, -7, -1, 1, -1, 0 ] ], 1 ] - ], - [ - [ [ [ 4, -6, -1, 1, -1, 0 ], [ 5, -7, -2, 1, -1, -1 ], [ 4, -7, -2, 1, -1, 0 ], [ 5, -6, -1, 1, 0, 0 ] ], 1.125 ] - ], - [ - [ [ [ 4, -6, -1, 1, -1, 0 ], [ 4, -7, -1, 1, -1, 0 ], [ 4, -7, -2, 1, -1, 0 ], [ 5, -6, -1, 1, 0, 0 ] ], 0.625 ] - ], - [ - [ [ [ 4, -6, -1, 1, -1, 0 ], [ 4, -7, -1, 1, -1, 0 ], [ 3, -5, -1, 1, 0, 0 ], [ 5, -6, -1, 1, 0, 0 ] ], 1.25 ] - ], - [ - [ [ [ 4, -6, -1, 1, -1, 0 ], [ 4, -7, -1, 1, -1, 0 ], [ 3, -5, -1, 1, 0, 0 ], [ 5, -6, -2, 1, -1, 0 ] ], 1.25 ] - ], - [ - [ [ [ 4, -6, -1, 1, -1, 0 ], [ 4, -7, -1, 1, -1, 0 ], [ 3, -5, -1, 1, 0, 0 ], [ 6, -7, -1, 1, -1, -1 ] ], 1 ], - [ [ [ 4, -6, -1, 1, -1, 0 ], [ "Rest" ], [ 3, -5, -1, 1, 0, 0 ], [ 6, -7, -1, 1, -1, -1 ] ], 1.375 ], - [ [ [ 4, -6, -1, 1, -1, 0 ], [ "Rest" ], [ 3, -5, -1, 1, 0, 0 ], [ "Rest" ] ], 1.125 ], - [ [ [ "Rest" ], [ "Rest" ], [ 3, -5, -1, 1, 0, 0 ], [ "Rest" ] ], 1.5 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 6.375 ] - ] - ] -], -"last_changes": -[ - [ [ 4, -6, -1, 1, -1, 0 ], [ 5, -7, -2, 1, -1, -1 ], [ 4, -7, -2, 1, -1, 0 ], [ 5, -6, -1, 1, 0, 0 ] ], - [ [ 4, -6, -1, 1, -1, 0 ], [ 4, -7, -1, 1, -1, 0 ], [ 4, -7, -2, 1, -1, 0 ], [ 5, -6, -1, 1, 0, 0 ] ], - [ [ 4, -6, -1, 1, -1, 0 ], [ 4, -7, -1, 1, -1, 0 ], [ 3, -5, -1, 1, 0, 0 ], [ 5, -6, -1, 1, 0, 0 ] ], - [ [ 4, -6, -1, 1, -1, 0 ], [ 4, -7, -1, 1, -1, 0 ], [ 3, -5, -1, 1, 0, 0 ], [ 5, -6, -2, 1, -1, 0 ] ], - [ [ 4, -6, -1, 1, -1, 0 ], [ 4, -7, -1, 1, -1, 0 ], [ 3, -5, -1, 1, 0, 0 ], [ 6, -7, -1, 1, -1, -1 ] ] -], -"cur_uid": "45fa07e8", -"ref_uid": "55f9b81e", -"order_seed": 921383, -"dur_seed": 545846, -"motifs_seed": 212473, -"entrances_probs_vals": [ 0, 0, 0, 0.66, 1.8406593406593, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 0, 0, 0, 0.66, 1.8406593406593, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 0, 0, 0, 0.66, 1.8406593406593, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -2467, 2400 ], [ -1167, 2400 ], [ -702, 2400 ], [ -702, 2400 ] ], -"step_probs_vals": [ 0, 1200, 0, 0, 0.090534979423868, 0.92613636363636, 0.17489711934156, 0.079545454545455, 0.37037037037037, 0, 0.7201646090535, 0, 1, 0 ], -"passages_weights": [ 0.63, 0.62, 1, 0.41, 1 ], -"hd_exp": 6, -"hd_invert": 0, -"order": -[ - [ [ 1, 3, 0 ], [ 2 ], [ ] ], - [ [ 3, 0, 2 ], [ 1 ], [ ] ], - [ [ 0, 2, 1 ], [ 3 ], [ ] ], - [ [ 3, 0, 2 ], [ 1 ], [ ] ], - [ [ 0, 2, 3 ], [ 1 ], [ ] ], - [ [ 1, 3, 2 ], [ 0 ], [ ] ], - [ [ 0, 3, 2 ], [ 1 ], [ ] ], - [ [ 0, 3, 1 ], [ 2 ], [ ] ], - [ [ 0, 2, 1 ], [ 3 ], [ ] ], - [ [ 1, 2, 0 ], [ 3 ], [ ] ], - [ [ 1, 0, 3 ], [ 2 ], [ ] ], - [ [ 3, 1, 2 ], [ 0 ], [ ] ], - [ [ 3, 2, 0 ], [ 1 ], [ ] ], - [ [ 0, 1, 2 ], [ 3 ], [ ] ], - [ [ 3, 2, 0 ], [ 1 ], [ ] ], - [ [ 0, 1, 2 ], [ 3 ], [ ] ], - [ [ 3, 2, 0 ], [ 1 ], [ ] ], - [ [ 3, 0, 2 ], [ 1 ], [ ] ], - [ [ 2, 1, 0 ], [ 3 ], [ ] ], - [ [ 2, 0, 3 ], [ 1 ], [ ] ], - [ [ 2, 1, 3 ], [ 0 ], [ ] ], - [ [ 0, 3, 2 ], [ 1 ], [ ] ], - [ [ 3, 1, 0 ], [ 2 ], [ ] ], - [ [ 2, 3, 1 ], [ 0 ], [ ] ], - [ [ 1, 3, 0 ], [ 2 ], [ ] ], - [ [ 1, 3, 0 ], [ 2 ], [ ] ], - [ [ 1, 3, 0 ], [ 2 ], [ ] ], - [ [ 3, 1, 0 ], [ 2 ], [ ] ], - [ [ 0, 3, 2 ], [ 1 ], [ ] ], - [ [ 2, 3, 1 ], [ 0 ], [ ] ], - [ [ 1, 3, 0 ], [ 2 ], [ ] ], - [ [ 0, 2, 3 ], [ 1 ], [ ] ], - [ [ 1, 2, 3 ], [ 0 ], [ ] ], - [ [ 0, 3, 2 ], [ 1 ], [ ] ], - [ [ 3, 1, 0 ], [ 2 ], [ ] ], - [ [ 3, 0, 1 ], [ 2 ], [ ] ], - [ [ 0, 1, 3 ], [ 2 ], [ ] ], - [ [ 1, 3, 0 ], [ 2 ], [ ] ], - [ [ 3, 2, 0 ], [ 1 ], [ ] ], - [ [ 1, 0, 3 ], [ 2 ], [ ] ], - [ [ 0, 1, 2 ], [ 3 ], [ ] ], - [ [ 3, 0, 2 ], [ 1 ], [ ] ], - [ [ 1, 0, 2 ], [ 3 ], [ ] ], - [ [ 1, 3, 0 ], [ 2 ], [ ] ], - [ [ 0, 3, 1 ], [ 2 ], [ ] ], - [ [ 0, 3, 2 ], [ 1 ], [ ] ], - [ [ 1, 2, 0 ], [ 3 ], [ ] ], - [ [ 3, 1, 2 ], [ 0 ], [ ] ], - [ [ 3, 2, 1 ], [ 0 ], [ ] ], - [ [ 3, 2, 0 ], [ 1 ], [ ] ], - [ [ 0, 1, 3 ], [ 2 ], [ ] ], - [ [ 1, 3, 2 ], [ 0 ], [ ] ], - [ [ 3, 1, 0 ], [ 2 ], [ ] ], - [ [ 3, 0, 2 ], [ 1 ], [ ] ], - [ [ 3, 0, 2 ], [ 1 ], [ ] ], - [ [ 2, 3, 0 ], [ 1 ], [ ] ], - [ [ 2, 0, 1 ], [ 3 ], [ ] ], - [ [ 3, 2, 0 ], [ 1 ], [ ] ], - [ [ 2, 3, 0 ], [ 1 ], [ ] ], - [ [ 3, 2, 1 ], [ 0 ], [ ] ], - [ [ 1, 3, 0 ], [ 2 ], [ ] ], - [ [ 2, 3, 1 ], [ 0 ], [ ] ], - [ [ 1, 2, 0 ], [ 3 ], [ ] ], - [ [ 3, 1, 2 ], [ 0 ], [ ] ], - [ [ 1, 2, 0 ], [ 3 ], [ ] ], - [ [ 1, 3, 0 ], [ 2 ], [ ] ], - [ [ 3, 2, 1 ], [ 0 ], [ ] ], - [ [ 1, 0, 2 ], [ 3 ], [ ] ], - [ [ 2, 1, 0 ], [ 3 ], [ ] ], - [ [ 2, 0, 1 ], [ 3 ], [ ] ], - [ [ 3, 1, 0 ], [ 2 ], [ ] ], - [ [ 0, 1, 3 ], [ 2 ], [ ] ], - [ [ 2, 0, 1 ], [ 3 ], [ ] ], - [ [ 1, 0, 3 ], [ 2 ], [ ] ], - [ [ 2, 3, 0 ], [ 1 ], [ ] ], - [ [ 0, 2, 3 ], [ 1 ], [ ] ], - [ [ 3, 0, 2 ], [ 1 ], [ ] ], - [ [ 1, 0, 2 ], [ 3 ], [ ] ], - [ [ 3, 0, 1 ], [ 2 ], [ ] ], - [ [ 0, 1, 3 ], [ 2 ], [ ] ], - [ [ 2, 0, 1 ], [ 3 ], [ ] ], - [ [ 1, 0, 2 ], [ 3 ], [ ] ], - [ [ 0, 2, 3 ], [ 1 ], [ ] ], - [ [ 2, 3, 0 ], [ 1 ], [ ] ], - [ [ 3, 0, 1 ], [ 2 ], [ ] ], - [ [ 2, 1, 0 ], [ 3 ], [ ] ], - [ [ 1, 0, 3 ], [ 2 ], [ ] ], - [ [ 1, 3, 0 ], [ 2 ], [ ] ], - [ [ 1, 0, 2 ], [ 3 ], [ ] ], - [ [ 1, 0, 2 ], [ 3 ], [ ] ], - [ [ 1, 0, 2 ], [ 3 ], [ ] ], - [ [ 1, 3, 2 ], [ 0 ], [ ] ], - [ [ 1, 0, 2 ], [ 3 ], [ ] ], - [ [ 0, 1, 3 ], [ 2 ], [ ] ], - [ [ 2, 0, 1 ], [ 3 ], [ ] ], - [ [ 0, 2, 1 ], [ 3 ], [ ] ], - [ [ 3, 2, 0 ], [ 1 ], [ ] ], - [ [ 0, 3, 1 ], [ 2 ], [ ] ], - [ [ 1, 2, 0 ], [ 3 ], [ ] ], - [ [ 1, 0, 2 ], [ 3 ], [ ] ] -], -"sus_weights": [ 0, 0, 0.61 ], -"order_size": [ 100, 100 ], -"passages_size": [ 0, 0 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3/4ff624b0/4ff624b0_code.scd b/resources/resources_bak_2024_01_03/string_quartet_3/4ff624b0/4ff624b0_code.scd deleted file mode 100644 index 0d8c24b..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3/4ff624b0/4ff624b0_code.scd +++ /dev/null @@ -1,975 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array2) - hsArrayToCents.value(array1); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -/* -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance) -}; -*/ - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = true; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - //if(pDistance >= 0, {stepFunc.value(abs(pDistance))}, {0.01}); - stepFunc.value(pDistance) -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - //tuples = dims.collect({[0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum == 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength.asInteger - minMotifLength.asInteger).rand + minMotifLength.asInteger).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - //noProgIns = (popSize - noSusIns).rand + 1; - noProgIns = (popSize - noSusIns); - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength.asInteger - minProgLength.asInteger).rand + minProgLength.asInteger).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0.01); - - - - /* - if(rangeScore.value(candidate.collect({0}), voices[ins], ranges[ins][1] - 500, ranges[ins][1], 0, true) == 1, { - isInRangeScore = 1 - rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0] + 500, ranges[ins][1] - 500, 0, true); - isInRangeScore = isInRangeScore * rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true) - }, { - isInRangeScore = rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true); - }); - */ - - - isInRangeScore = rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true); - //old way - worked but actually by accident (I think) - //isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - - - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_3/4ff624b0/4ff624b0_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_3/4ff624b0/4ff624b0_mus_model.json deleted file mode 100644 index 0ef2a04..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3/4ff624b0/4ff624b0_mus_model.json +++ /dev/null @@ -1,552 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 1 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ] ], 1 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 1 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ -1, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ 1, 0, 0, 0, 0, 0 ], [ -1, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 1 ], - [ [ [ 1, 0, 0, 0, 0, 0 ], [ -1, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, -1, 0, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ 1, 0, 0, 0, 0, 0 ], [ 0, 0, 0, -1, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, -1, 0, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ 1, 0, 0, 0, 0, 0 ], [ 0, 0, 0, -1, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ -1, 1, 0, 0, 0, 0 ] ], 1 ], - [ [ [ 1, -1, 0, 0, 0, 0 ], [ 0, 0, 0, -1, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ -1, 1, 0, 0, 0, 0 ] ], 1 ], - [ [ [ 1, -1, 0, 0, 0, 0 ], [ 0, -1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ -1, 1, 0, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ 1, -1, 0, 0, 0, 0 ], [ 0, -1, 0, 0, 0, 0 ], [ -1, 2, 0, 0, 0, 0 ], [ -1, 1, 0, 0, 0, 0 ] ], 1 ], - [ [ [ 1, -1, 0, 0, 0, 0 ], [ -1, 0, 0, 0, 0, 0 ], [ -1, 2, 0, 0, 0, 0 ], [ -1, 1, 0, 0, 0, 0 ] ], 1 ], - [ [ [ 0, 1, 0, 0, 0, 0 ], [ -1, 0, 0, 0, 0, 0 ], [ -1, 2, 0, 0, 0, 0 ], [ -1, 1, 0, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ 1, 0, -1, 0, 0, 0 ], [ -1, 0, 0, 0, 0, 0 ], [ -1, 2, 0, 0, 0, 0 ], [ -1, 1, 0, 0, 0, 0 ] ], 1 ], - [ [ [ 1, 0, -1, 0, 0, 0 ], [ -1, 0, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ], [ -1, 1, 0, 0, 0, 0 ] ], 1 ], - [ [ [ 1, 0, -1, 0, 0, 0 ], [ -1, 0, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ], [ 0, 0, -1, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ 1, 0, -1, 0, 0, 0 ], [ -1, 0, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ], [ 0, 0, 1, 0, -1, 0 ] ], 1 ] - ], - [ - [ [ [ 1, 0, -1, 0, 0, 0 ], [ -1, 0, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 1 ], - [ [ [ 1, -1, 0, 0, 0, 0 ], [ -1, 0, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 1 ], - [ [ [ 1, -1, 0, 0, 0, 0 ], [ -1, 0, 0, 0, 0, 0 ], [ 0, -1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ 1, -1, 0, 0, 0, 0 ], [ -1, 0, 0, 0, 0, 0 ], [ 0, -1, 0, 0, 0, 0 ], [ 1, -1, -1, 0, 0, 0 ] ], 1 ], - [ [ [ 1, -1, 0, 0, 0, 0 ], [ -1, 0, 0, 0, 0, 0 ], [ -1, 1, 0, 0, 0, 0 ], [ 1, -1, -1, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ 0, 1, 0, 0, 0, 0 ], [ -1, 0, 0, 0, 0, 0 ], [ -1, 1, 0, 0, 0, 0 ], [ 1, -1, -1, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ 0, 1, 0, 0, 0, 0 ], [ -1, 0, 0, 0, 0, 0 ], [ -1, 1, 0, 0, 0, 0 ], [ -1, 2, 0, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ 0, 1, 0, 0, 0, 0 ], [ -2, 2, 0, 0, 0, 0 ], [ -1, 1, 0, 0, 0, 0 ], [ -1, 2, 0, 0, 0, 0 ] ], 1 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ -2, 2, 0, 0, 0, 0 ], [ -1, 1, 0, 0, 0, 0 ], [ -1, 2, 0, 0, 0, 0 ] ], 1 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ -2, 2, 0, 0, 0, 0 ], [ -1, 1, 0, 0, 0, 0 ], [ 0, 1, -1, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ -2, 2, 0, 0, 0, 0 ], [ -1, 1, 0, 0, 0, 0 ], [ -1, 1, 0, 1, 0, 0 ] ], 1 ], - [ [ [ -1, 2, 0, 0, 0, 0 ], [ -2, 2, 0, 0, 0, 0 ], [ -1, 1, 0, 0, 0, 0 ], [ -1, 1, 0, 1, 0, 0 ] ], 1 ], - [ [ [ -1, 2, 0, 0, 0, 0 ], [ -1, 1, -1, 0, 0, 0 ], [ -1, 1, 0, 0, 0, 0 ], [ -1, 1, 0, 1, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -1, 2, 0, 0, 0, 0 ], [ -1, 1, -1, 0, 0, 0 ], [ 0, 0, -1, 0, 0, 0 ], [ -1, 1, 0, 1, 0, 0 ] ], 1 ], - [ [ [ 0, 1, -1, 0, 0, 0 ], [ -1, 1, -1, 0, 0, 0 ], [ 0, 0, -1, 0, 0, 0 ], [ -1, 1, 0, 1, 0, 0 ] ], 1 ] - ], - [ - [ [ [ 0, 1, -1, 0, 0, 0 ], [ 0, 1, -1, -1, 0, 0 ], [ 0, 0, -1, 0, 0, 0 ], [ -1, 1, 0, 1, 0, 0 ] ], 1 ], - [ [ [ 0, 1, -1, 0, 0, 0 ], [ 0, 1, -1, -1, 0, 0 ], [ -1, 2, -1, 0, 0, 0 ], [ -1, 1, 0, 1, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -1, 3, -1, 0, 0, 0 ], [ 0, 1, -1, -1, 0, 0 ], [ -1, 2, -1, 0, 0, 0 ], [ -1, 1, 0, 1, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -1, 3, -1, 0, 0, 0 ], [ 0, 1, -1, -1, 0, 0 ], [ -1, 2, -1, 0, 0, 0 ], [ -2, 3, -1, 0, 0, 0 ] ], 1 ], - [ [ [ -1, 3, -1, 0, 0, 0 ], [ 0, 1, -1, -1, 0, 0 ], [ -1, 3, -1, 0, -1, 0 ], [ -2, 3, -1, 0, 0, 0 ] ], 1 ], - [ [ [ -1, 3, -1, 0, 0, 0 ], [ -1, 3, -1, -1, 0, 0 ], [ -1, 3, -1, 0, -1, 0 ], [ -2, 3, -1, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -1, 3, -1, 0, 0, 0 ], [ -1, 3, -1, -1, 0, 0 ], [ -1, 3, -1, 0, -1, 0 ], [ -2, 4, -1, 0, -1, 0 ] ], 1 ] - ], - [ - [ [ [ -1, 3, -1, 0, 0, 0 ], [ -1, 3, -1, -1, 0, 0 ], [ -1, 3, -1, 0, -1, 0 ], [ 0, 3, 0, -1, 0, 0 ] ], 1 ], - [ [ [ 0, 3, -1, -1, 0, 0 ], [ -1, 3, -1, -1, 0, 0 ], [ -1, 3, -1, 0, -1, 0 ], [ 0, 3, 0, -1, 0, 0 ] ], 1 ], - [ [ [ 0, 3, -1, -1, 0, 0 ], [ -1, 3, -1, -1, 0, 0 ], [ 0, 2, -1, -1, 0, 0 ], [ 0, 3, 0, -1, 0, 0 ] ], 1 ] - ], - [ - [ [ [ 0, 3, -1, -1, 0, 0 ], [ -1, 3, -1, -1, 0, 0 ], [ -1, 4, -1, -1, 0, 0 ], [ 0, 3, 0, -1, 0, 0 ] ], 1 ], - [ [ [ 0, 3, -1, -1, 0, 0 ], [ -1, 3, -1, -1, 0, 0 ], [ -1, 4, -1, -1, 0, 0 ], [ 0, 2, -1, -1, 0, 0 ] ], 1 ], - [ [ [ 0, 3, -1, -1, 0, 0 ], [ -1, 2, -1, -1, 0, 0 ], [ -1, 4, -1, -1, 0, 0 ], [ 0, 2, -1, -1, 0, 0 ] ], 1 ] - ], - [ - [ [ [ 0, 3, -1, -1, 0, 0 ], [ -2, 4, -1, -1, 0, 0 ], [ -1, 4, -1, -1, 0, 0 ], [ 0, 2, -1, -1, 0, 0 ] ], 1 ], - [ [ [ -2, 5, -1, -1, 0, 0 ], [ -2, 4, -1, -1, 0, 0 ], [ -1, 4, -1, -1, 0, 0 ], [ 0, 2, -1, -1, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 5, -1, -1, 0, 0 ], [ -2, 4, -1, -1, 0, 0 ], [ -1, 4, -1, -1, 0, 0 ], [ -1, 3, -1, -1, 0, 0 ] ], 1 ], - [ [ [ -2, 5, -1, -1, 0, 0 ], [ -3, 6, -1, -1, 0, 0 ], [ -1, 4, -1, -1, 0, 0 ], [ -1, 3, -1, -1, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 5, -1, -1, 0, 0 ], [ -3, 6, -1, -1, 0, 0 ], [ -1, 4, -1, -1, 0, 0 ], [ -3, 7, -1, -1, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 5, -1, -1, 0, 0 ], [ -3, 6, -1, -1, 0, 0 ], [ -2, 6, -1, -1, 0, 0 ], [ -3, 7, -1, -1, 0, 0 ] ], 1 ], - [ [ [ -2, 5, -1, -1, 0, 0 ], [ -4, 8, -1, -1, 0, 0 ], [ -2, 6, -1, -1, 0, 0 ], [ -3, 7, -1, -1, 0, 0 ] ], 1 ], - [ [ [ -3, 6, -1, -1, 0, 0 ], [ -4, 8, -1, -1, 0, 0 ], [ -2, 6, -1, -1, 0, 0 ], [ -3, 7, -1, -1, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -4, 7, -1, -1, 0, 0 ], [ -4, 8, -1, -1, 0, 0 ], [ -2, 6, -1, -1, 0, 0 ], [ -3, 7, -1, -1, 0, 0 ] ], 1 ], - [ [ [ -4, 7, -1, -1, 0, 0 ], [ -2, 7, -1, -1, 0, 0 ], [ -2, 6, -1, -1, 0, 0 ], [ -3, 7, -1, -1, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -4, 6, -1, -1, 0, 0 ], [ -2, 7, -1, -1, 0, 0 ], [ -2, 6, -1, -1, 0, 0 ], [ -3, 7, -1, -1, 0, 0 ] ], 1 ], - [ [ [ -4, 6, -1, -1, 0, 0 ], [ -2, 7, -1, -1, 0, 0 ], [ -3, 8, -1, -1, 0, 0 ], [ -3, 7, -1, -1, 0, 0 ] ], 1 ], - [ [ [ -4, 6, -1, -1, 0, 0 ], [ -2, 6, -1, -1, 0, 0 ], [ -3, 8, -1, -1, 0, 0 ], [ -3, 7, -1, -1, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -3, 6, -1, -1, 0, 0 ], [ -2, 6, -1, -1, 0, 0 ], [ -3, 8, -1, -1, 0, 0 ], [ -3, 7, -1, -1, 0, 0 ] ], 1 ], - [ [ [ -3, 6, -1, -1, 0, 0 ], [ -2, 6, -1, -1, 0, 0 ], [ -3, 7, -1, -1, 0, 1 ], [ -3, 7, -1, -1, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -3, 6, -1, -1, 0, 0 ], [ -2, 6, -1, -1, 0, 0 ], [ -3, 7, -1, -1, 0, 1 ], [ -3, 6, -1, -1, 0, 1 ] ], 1 ], - [ [ [ -3, 6, -1, -1, 0, 0 ], [ -4, 7, -1, 0, 0, 1 ], [ -3, 7, -1, -1, 0, 1 ], [ -3, 6, -1, -1, 0, 1 ] ], 1 ], - [ [ [ -5, 7, -1, 0, 0, 1 ], [ -4, 7, -1, 0, 0, 1 ], [ -3, 7, -1, -1, 0, 1 ], [ -3, 6, -1, -1, 0, 1 ] ], 1 ] - ], - [ - [ [ [ -4, 7, -1, -1, 0, 1 ], [ -4, 7, -1, 0, 0, 1 ], [ -3, 7, -1, -1, 0, 1 ], [ -3, 6, -1, -1, 0, 1 ] ], 1 ], - [ [ [ -4, 7, -1, -1, 0, 1 ], [ -4, 7, -1, 0, 0, 1 ], [ -4, 7, 0, 0, 0, 1 ], [ -3, 6, -1, -1, 0, 1 ] ], 1 ] - ], - [ - [ [ [ -4, 7, -1, -1, 0, 1 ], [ -4, 7, -1, 0, 0, 1 ], [ -3, 6, -1, 0, 0, 1 ], [ -3, 6, -1, -1, 0, 1 ] ], 1 ], - [ [ [ -4, 7, -1, -1, 0, 1 ], [ -3, 7, -1, -1, 0, 1 ], [ -3, 6, -1, 0, 0, 1 ], [ -3, 6, -1, -1, 0, 1 ] ], 1 ] - ], - [ - [ [ [ -3, 5, -1, -1, 0, 1 ], [ -3, 7, -1, -1, 0, 1 ], [ -3, 6, -1, 0, 0, 1 ], [ -3, 6, -1, -1, 0, 1 ] ], 1 ] - ], - [ - [ [ [ -3, 5, -1, -1, 0, 1 ], [ -3, 7, -1, -1, 0, 1 ], [ -3, 6, -1, 0, 0, 1 ], [ -3, 5, -1, 0, 0, 1 ] ], 1 ], - [ [ [ -3, 5, -1, -1, 0, 1 ], [ -2, 5, -1, -1, 0, 1 ], [ -3, 6, -1, 0, 0, 1 ], [ -3, 5, -1, 0, 0, 1 ] ], 1 ], - [ [ [ -3, 5, -1, -1, 0, 1 ], [ -2, 5, -1, -1, 0, 1 ], [ -2, 5, 0, -1, 0, 1 ], [ -3, 5, -1, 0, 0, 1 ] ], 1 ] - ], - [ - [ [ [ -3, 5, -1, -1, 0, 1 ], [ -1, 5, -1, -2, 0, 1 ], [ -2, 5, 0, -1, 0, 1 ], [ -3, 5, -1, 0, 0, 1 ] ], 1 ], - [ [ [ -3, 5, -1, -1, 0, 1 ], [ -1, 5, -1, -2, 0, 1 ], [ -1, 4, -1, -1, 0, 1 ], [ -3, 5, -1, 0, 0, 1 ] ], 1 ], - [ [ [ -3, 5, -1, -1, 0, 1 ], [ -1, 5, -1, -2, 0, 1 ], [ -1, 4, -1, -1, 0, 1 ], [ -2, 5, -1, -1, 0, 1 ] ], 1 ] - ], - [ - [ [ [ -2, 5, -1, -2, 0, 1 ], [ -1, 5, -1, -2, 0, 1 ], [ -1, 4, -1, -1, 0, 1 ], [ -2, 5, -1, -1, 0, 1 ] ], 1 ], - [ [ [ -2, 5, -1, -2, 0, 1 ], [ -1, 5, -1, -2, 0, 1 ], [ -1, 4, -1, -2, 0, 1 ], [ -2, 5, -1, -1, 0, 1 ] ], 1 ] - ], - [ - [ [ [ -2, 5, -1, -2, 0, 1 ], [ -1, 5, -1, -2, 0, 1 ], [ -2, 6, -1, -2, 0, 1 ], [ -2, 5, -1, -1, 0, 1 ] ], 1 ] - ], - [ - [ [ [ -2, 5, -1, -2, 0, 1 ], [ -1, 5, -1, -2, 0, 1 ], [ -1, 5, -2, -2, 0, 1 ], [ -2, 5, -1, -1, 0, 1 ] ], 1 ], - [ [ [ -2, 4, -1, -2, 0, 1 ], [ -1, 5, -1, -2, 0, 1 ], [ -1, 5, -2, -2, 0, 1 ], [ -2, 5, -1, -1, 0, 1 ] ], 1 ], - [ [ [ -2, 4, -1, -2, 0, 1 ], [ -1, 5, -1, -2, 0, 1 ], [ -1, 5, -2, -2, 0, 1 ], [ -1, 4, -1, -2, 0, 1 ] ], 1 ] - ], - [ - [ [ [ -3, 6, -1, -2, 0, 1 ], [ -1, 5, -1, -2, 0, 1 ], [ -1, 5, -2, -2, 0, 1 ], [ -1, 4, -1, -2, 0, 1 ] ], 1 ] - ], - [ - [ [ [ -3, 6, -1, -2, 0, 1 ], [ -1, 5, -1, -2, 0, 1 ], [ -1, 5, -2, -2, 0, 1 ], [ -2, 6, -1, -2, 0, 1 ] ], 1 ], - [ [ [ -3, 6, -1, -2, 0, 1 ], [ -1, 5, -1, -2, 0, 1 ], [ -2, 5, -1, -2, 0, 1 ], [ -2, 6, -1, -2, 0, 1 ] ], 1 ] - ], - [ - [ [ [ -3, 6, -1, -2, 0, 1 ], [ -1, 5, -1, -2, 0, 1 ], [ -2, 5, -1, -2, 0, 1 ], [ -1, 5, -2, -2, 0, 1 ] ], 1 ], - [ [ [ -3, 6, -1, -2, 0, 1 ], [ -1, 5, -1, -2, 0, 1 ], [ -1, 5, -1, -3, 0, 1 ], [ -1, 5, -2, -2, 0, 1 ] ], 1 ], - [ [ [ -2, 5, -2, -2, 0, 1 ], [ -1, 5, -1, -2, 0, 1 ], [ -1, 5, -1, -3, 0, 1 ], [ -1, 5, -2, -2, 0, 1 ] ], 1 ] - ], - [ - [ [ [ -2, 5, -2, -3, 0, 1 ], [ -1, 5, -1, -2, 0, 1 ], [ -1, 5, -1, -3, 0, 1 ], [ -1, 5, -2, -2, 0, 1 ] ], 1 ], - [ [ [ -2, 5, -2, -3, 0, 1 ], [ 0, 5, -1, -3, 0, 1 ], [ -1, 5, -1, -3, 0, 1 ], [ -1, 5, -2, -2, 0, 1 ] ], 1 ], - [ [ [ -2, 5, -2, -3, 0, 1 ], [ 0, 5, -1, -3, 0, 1 ], [ -1, 5, -1, -3, 0, 1 ], [ -1, 6, -1, -3, 0, 1 ] ], 1 ] - ], - [ - [ [ [ -2, 5, -2, -3, 0, 1 ], [ 0, 5, -1, -3, 0, 1 ], [ -1, 5, -1, -3, 0, 1 ], [ -1, 5, -2, -3, 0, 1 ] ], 1 ], - [ [ [ -2, 5, -2, -3, 0, 1 ], [ 1, 4, -2, -3, 0, 1 ], [ -1, 5, -1, -3, 0, 1 ], [ -1, 5, -2, -3, 0, 1 ] ], 1 ], - [ [ [ -2, 5, -2, -3, 0, 1 ], [ 1, 4, -2, -3, 0, 1 ], [ 0, 4, -2, -3, 0, 1 ], [ -1, 5, -2, -3, 0, 1 ] ], 1 ] - ], - [ - [ [ [ -2, 5, -2, -3, 0, 1 ], [ 0, 5, -2, -3, 0, 1 ], [ 0, 4, -2, -3, 0, 1 ], [ -1, 5, -2, -3, 0, 1 ] ], 1 ] - ], - [ - [ [ [ -2, 5, -2, -3, 0, 1 ], [ 1, 5, -2, -4, 0, 1 ], [ 0, 4, -2, -3, 0, 1 ], [ -1, 5, -2, -3, 0, 1 ] ], 1 ], - [ [ [ -1, 5, -2, -4, 0, 1 ], [ 1, 5, -2, -4, 0, 1 ], [ 0, 4, -2, -3, 0, 1 ], [ -1, 5, -2, -3, 0, 1 ] ], 1 ] - ], - [ - [ [ [ -1, 5, -2, -4, 0, 1 ], [ 1, 5, -2, -4, 0, 1 ], [ 0, 4, -2, -3, 0, 1 ], [ 0, 5, -2, -4, 0, 1 ] ], 1 ], - [ [ [ -1, 5, -2, -4, 0, 1 ], [ 0, 6, -2, -4, 0, 1 ], [ 0, 4, -2, -3, 0, 1 ], [ 0, 5, -2, -4, 0, 1 ] ], 1 ], - [ [ [ -1, 5, -2, -4, 0, 1 ], [ 0, 6, -2, -4, 0, 1 ], [ 0, 5, -1, -4, 0, 1 ], [ 0, 5, -2, -4, 0, 1 ] ], 1 ] - ], - [ - [ [ [ -2, 5, -1, -4, 0, 1 ], [ 0, 6, -2, -4, 0, 1 ], [ 0, 5, -1, -4, 0, 1 ], [ 0, 5, -2, -4, 0, 1 ] ], 1 ], - [ [ [ -2, 5, -1, -4, 0, 1 ], [ 0, 5, -1, -4, 1, 1 ], [ 0, 5, -1, -4, 0, 1 ], [ 0, 5, -2, -4, 0, 1 ] ], 1 ], - [ [ [ -2, 5, -1, -4, 0, 1 ], [ 0, 5, -1, -4, 1, 1 ], [ 0, 5, -1, -4, 0, 1 ], [ -1, 5, -1, -4, 1, 1 ] ], 1 ] - ], - [ - [ [ [ -2, 5, -1, -4, 0, 1 ], [ -1, 6, -1, -4, 0, 1 ], [ 0, 5, -1, -4, 0, 1 ], [ -1, 5, -1, -4, 1, 1 ] ], 1 ], - [ [ [ -1, 5, -1, -5, 0, 1 ], [ -1, 6, -1, -4, 0, 1 ], [ 0, 5, -1, -4, 0, 1 ], [ -1, 5, -1, -4, 1, 1 ] ], 1 ] - ], - [ - [ [ [ -1, 5, -1, -5, 0, 1 ], [ -1, 6, -1, -4, 0, 1 ], [ 0, 5, -1, -4, 0, 1 ], [ 1, 4, -1, -5, 0, 1 ] ], 1 ], - [ [ [ -1, 5, -1, -5, 0, 1 ], [ 0, 6, -1, -5, 0, 1 ], [ 0, 5, -1, -4, 0, 1 ], [ 1, 4, -1, -5, 0, 1 ] ], 1 ], - [ [ [ -1, 5, -1, -5, 0, 1 ], [ 0, 6, -1, -5, 0, 1 ], [ 1, 5, -1, -5, 0, 1 ], [ 1, 4, -1, -5, 0, 1 ] ], 1 ] - ], - [ - [ [ [ -1, 5, -1, -5, 0, 1 ], [ 0, 5, -1, -5, 0, 1 ], [ 1, 5, -1, -5, 0, 1 ], [ 1, 4, -1, -5, 0, 1 ] ], 1 ], - [ [ [ 0, 4, -1, -5, 0, 1 ], [ 0, 5, -1, -5, 0, 1 ], [ 1, 5, -1, -5, 0, 1 ], [ 1, 4, -1, -5, 0, 1 ] ], 1 ], - [ [ [ 0, 4, -1, -5, 0, 1 ], [ 0, 5, -1, -5, 0, 1 ], [ 2, 4, -1, -5, 0, 1 ], [ 1, 4, -1, -5, 0, 1 ] ], 1 ] - ], - [ - [ [ [ 0, 4, -1, -5, 0, 1 ], [ 0, 5, -1, -5, 0, 1 ], [ 2, 4, -1, -5, 0, 1 ], [ 0, 6, -1, -5, 0, 1 ] ], 1 ], - [ [ [ 0, 4, -1, -5, 0, 1 ], [ 0, 5, -1, -5, 0, 1 ], [ 1, 6, -1, -5, 0, 1 ], [ 0, 6, -1, -5, 0, 1 ] ], 1 ] - ], - [ - [ [ [ 0, 4, -1, -5, 0, 1 ], [ 0, 5, -1, -5, 0, 1 ], [ 1, 6, -1, -5, 0, 1 ], [ 2, 4, -1, -5, 0, 0 ] ], 1 ], - [ [ [ 0, 4, -1, -5, 0, 1 ], [ 1, 4, -2, -5, 0, 1 ], [ 1, 6, -1, -5, 0, 1 ], [ 2, 4, -1, -5, 0, 0 ] ], 1 ] - ], - [ - [ [ [ 0, 4, -1, -5, 0, 1 ], [ 1, 4, -2, -5, 0, 1 ], [ 1, 6, -1, -5, 0, 1 ], [ 1, 6, -1, -5, 0, 0 ] ], 1 ] - ], - [ - [ [ [ 0, 4, -1, -5, 0, 1 ], [ 1, 5, -1, -5, 0, 0 ], [ 1, 6, -1, -5, 0, 1 ], [ 1, 6, -1, -5, 0, 0 ] ], 1 ] - ], - [ - [ [ [ 0, 4, -1, -5, 0, 1 ], [ 1, 4, -1, -5, 0, 1 ], [ 1, 6, -1, -5, 0, 1 ], [ 1, 6, -1, -5, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -1, 5, -1, -5, 0, 1 ], [ 1, 4, -1, -5, 0, 1 ], [ 1, 6, -1, -5, 0, 1 ], [ 1, 6, -1, -5, 0, 0 ] ], 1 ], - [ [ [ -1, 5, -1, -5, 0, 1 ], [ 1, 4, -1, -5, 0, 1 ], [ 3, 4, -1, -5, 0, 0 ], [ 1, 6, -1, -5, 0, 0 ] ], 1 ], - [ [ [ -1, 5, -1, -5, 0, 1 ], [ 1, 4, -1, -5, 0, 1 ], [ 3, 4, -1, -5, 0, 0 ], [ 1, 5, -1, -5, 0, 1 ] ], 1 ] - ], - [ - [ [ [ -1, 5, -1, -5, 0, 1 ], [ 1, 5, -1, -5, -1, 1 ], [ 3, 4, -1, -5, 0, 0 ], [ 1, 5, -1, -5, 0, 1 ] ], 1 ], - [ [ [ 0, 4, -1, -5, 1, 0 ], [ 1, 5, -1, -5, -1, 1 ], [ 3, 4, -1, -5, 0, 0 ], [ 1, 5, -1, -5, 0, 1 ] ], 1 ] - ], - [ - [ [ [ 0, 4, -1, -5, 1, 0 ], [ 1, 5, -1, -5, -1, 1 ], [ 2, 4, -1, -5, -1, 1 ], [ 1, 5, -1, -5, 0, 1 ] ], 1 ], - [ [ [ 0, 4, -1, -5, 1, 0 ], [ 1, 5, -1, -5, -1, 1 ], [ 2, 4, -1, -5, -1, 1 ], [ 0, 5, -1, -4, -1, 1 ] ], 1 ], - [ [ [ -1, 5, -1, -4, -1, 1 ], [ 1, 5, -1, -5, -1, 1 ], [ 2, 4, -1, -5, -1, 1 ], [ 0, 5, -1, -4, -1, 1 ] ], 1 ] - ], - [ - [ [ [ -1, 5, -1, -4, -1, 1 ], [ 1, 5, -1, -5, -1, 1 ], [ 2, 4, -1, -5, -1, 1 ], [ -1, 5, -1, -3, -1, 1 ] ], 1 ], - [ [ [ -1, 5, -1, -4, -1, 1 ], [ 1, 5, -1, -5, -1, 1 ], [ 0, 5, -1, -3, -1, 1 ], [ -1, 5, -1, -3, -1, 1 ] ], 1 ] - ], - [ - [ [ [ -1, 5, -1, -4, -1, 1 ], [ 1, 5, -1, -5, -1, 1 ], [ 1, 5, -1, -4, -1, 1 ], [ -1, 5, -1, -3, -1, 1 ] ], 1 ], - [ [ [ -1, 5, -1, -4, -1, 1 ], [ 1, 5, -1, -5, -1, 1 ], [ 1, 5, -1, -4, -1, 1 ], [ 0, 5, -1, -4, -1, 1 ] ], 1 ] - ], - [ - [ [ [ -1, 5, -1, -4, -1, 1 ], [ 1, 5, -1, -5, -1, 1 ], [ 2, 5, -1, -5, -1, 1 ], [ 0, 5, -1, -4, -1, 1 ] ], 1 ] - ], - [ - [ [ [ -1, 5, -1, -4, -1, 1 ], [ 1, 5, -1, -5, -1, 1 ], [ 2, 5, -1, -5, -1, 1 ], [ 1, 6, -1, -5, -1, 1 ] ], 1 ], - [ [ [ 0, 5, -1, -5, -1, 1 ], [ 1, 5, -1, -5, -1, 1 ], [ 2, 5, -1, -5, -1, 1 ], [ 1, 6, -1, -5, -1, 1 ] ], 1 ], - [ [ [ 0, 5, -1, -5, -1, 1 ], [ 1, 5, -1, -5, -1, 1 ], [ 2, 5, -1, -5, -2, 1 ], [ 1, 6, -1, -5, -1, 1 ] ], 1 ] - ], - [ - [ [ [ 0, 5, -1, -5, -1, 1 ], [ 1, 6, -1, -5, -2, 1 ], [ 2, 5, -1, -5, -2, 1 ], [ 1, 6, -1, -5, -1, 1 ] ], 1 ] - ], - [ - [ [ [ 0, 6, -1, -5, -2, 1 ], [ 1, 6, -1, -5, -2, 1 ], [ 2, 5, -1, -5, -2, 1 ], [ 1, 6, -1, -5, -1, 1 ] ], 1 ] - ], - [ - [ [ [ 0, 6, -1, -5, -2, 1 ], [ 0, 6, -1, -5, -1, 1 ], [ 2, 5, -1, -5, -2, 1 ], [ 1, 6, -1, -5, -1, 1 ] ], 1 ], - [ [ [ 0, 6, -2, -5, -1, 1 ], [ 0, 6, -1, -5, -1, 1 ], [ 2, 5, -1, -5, -2, 1 ], [ 1, 6, -1, -5, -1, 1 ] ], 1 ], - [ [ [ 0, 6, -2, -5, -1, 1 ], [ 0, 6, -1, -5, -1, 1 ], [ 1, 6, -2, -5, -1, 1 ], [ 1, 6, -1, -5, -1, 1 ] ], 1 ] - ], - [ - [ [ [ 0, 6, -2, -5, -1, 1 ], [ 0, 6, -1, -5, -1, 1 ], [ 1, 6, -2, -5, -1, 1 ], [ 2, 5, -2, -5, -1, 1 ] ], 1 ], - [ [ [ -1, 7, -2, -5, -1, 1 ], [ 0, 6, -1, -5, -1, 1 ], [ 1, 6, -2, -5, -1, 1 ], [ 2, 5, -2, -5, -1, 1 ] ], 1 ] - ], - [ - [ [ [ -1, 7, -2, -5, -1, 1 ], [ 0, 6, -1, -5, -1, 1 ], [ 1, 6, -2, -5, -1, 1 ], [ 0, 7, -2, -5, -1, 1 ] ], 1 ], - [ [ [ -1, 7, -2, -5, -1, 1 ], [ 0, 6, -1, -5, -1, 1 ], [ 1, 5, -1, -5, -1, 1 ], [ 0, 7, -2, -5, -1, 1 ] ], 1 ] - ], - [ - [ [ [ -1, 7, -2, -5, -1, 1 ], [ -1, 8, -2, -5, -1, 1 ], [ 1, 5, -1, -5, -1, 1 ], [ 0, 7, -2, -5, -1, 1 ] ], 1 ], - [ [ [ -1, 7, -2, -5, -1, 1 ], [ -1, 8, -2, -5, -1, 1 ], [ 0, 8, -2, -5, -1, 1 ], [ 0, 7, -2, -5, -1, 1 ] ], 1 ] - ], - [ - [ [ [ -2, 8, -2, -5, -1, 1 ], [ -1, 8, -2, -5, -1, 1 ], [ 0, 8, -2, -5, -1, 1 ], [ 0, 7, -2, -5, -1, 1 ] ], 1 ], - [ [ [ -2, 8, -2, -5, -1, 1 ], [ 0, 8, -2, -6, -1, 1 ], [ 0, 8, -2, -5, -1, 1 ], [ 0, 7, -2, -5, -1, 1 ] ], 1 ], - [ [ [ -2, 8, -2, -5, -1, 1 ], [ 0, 8, -2, -6, -1, 1 ], [ 0, 8, -2, -5, -1, 1 ], [ -1, 9, -2, -5, -1, 1 ] ], 1 ] - ], - [ - [ [ [ -1, 8, -2, -6, -1, 1 ], [ 0, 8, -2, -6, -1, 1 ], [ 0, 8, -2, -5, -1, 1 ], [ -1, 9, -2, -5, -1, 1 ] ], 1 ], - [ [ [ -1, 8, -2, -6, -1, 1 ], [ 0, 8, -2, -6, -1, 1 ], [ 0, 8, -2, -5, -1, 1 ], [ 0, 8, -3, -5, -1, 1 ] ], 1 ] - ], - [ - [ [ [ -1, 8, -2, -6, -1, 1 ], [ 0, 8, -2, -6, -1, 1 ], [ 1, 8, -2, -6, -1, 1 ], [ 0, 8, -3, -5, -1, 1 ] ], 1 ] - ], - [ - [ [ [ -1, 8, -2, -6, -1, 1 ], [ 0, 8, -2, -6, -1, 1 ], [ 0, 9, -3, -5, -1, 1 ], [ 0, 8, -3, -5, -1, 1 ] ], 1 ], - [ [ [ -2, 8, -3, -5, -1, 2 ], [ 0, 8, -2, -6, -1, 1 ], [ 0, 9, -3, -5, -1, 1 ], [ 0, 8, -3, -5, -1, 1 ] ], 1 ], - [ [ [ -2, 8, -3, -5, -1, 2 ], [ -1, 8, -3, -5, -1, 2 ], [ 0, 9, -3, -5, -1, 1 ], [ 0, 8, -3, -5, -1, 1 ] ], 1 ] - ], - [ - [ [ [ -2, 8, -3, -5, -1, 2 ], [ -1, 8, -3, -5, -1, 2 ], [ 0, 8, -3, -5, -1, 2 ], [ 0, 8, -3, -5, -1, 1 ] ], 1 ], - [ [ [ -2, 8, -3, -5, -1, 2 ], [ -1, 8, -3, -5, -1, 2 ], [ 0, 8, -3, -5, -1, 2 ], [ 0, 7, -3, -5, -1, 2 ] ], 1 ] - ], - [ - [ [ [ -2, 8, -3, -5, -1, 2 ], [ -1, 8, -3, -5, -1, 2 ], [ 1, 8, -3, -6, -1, 2 ], [ 0, 7, -3, -5, -1, 2 ] ], 1 ], - [ [ [ -1, 8, -3, -6, -1, 2 ], [ -1, 8, -3, -5, -1, 2 ], [ 1, 8, -3, -6, -1, 2 ], [ 0, 7, -3, -5, -1, 2 ] ], 1 ] - ], - [ - [ [ [ -1, 7, -3, -6, -1, 2 ], [ -1, 8, -3, -5, -1, 2 ], [ 1, 8, -3, -6, -1, 2 ], [ 0, 7, -3, -5, -1, 2 ] ], 1 ], - [ [ [ -1, 7, -3, -6, -1, 2 ], [ -1, 8, -3, -5, -1, 2 ], [ -1, 8, -2, -5, -1, 2 ], [ 0, 7, -3, -5, -1, 2 ] ], 1 ] - ], - [ - [ [ [ -1, 7, -3, -6, -1, 2 ], [ -2, 8, -2, -4, -1, 2 ], [ -1, 8, -2, -5, -1, 2 ], [ 0, 7, -3, -5, -1, 2 ] ], 1 ], - [ [ [ -2, 7, -2, -5, -1, 2 ], [ -2, 8, -2, -4, -1, 2 ], [ -1, 8, -2, -5, -1, 2 ], [ 0, 7, -3, -5, -1, 2 ] ], 1 ] - ], - [ - [ [ [ -2, 7, -2, -5, -1, 2 ], [ -2, 8, -1, -5, -1, 2 ], [ -1, 8, -2, -5, -1, 2 ], [ 0, 7, -3, -5, -1, 2 ] ], 1 ] - ], - [ - [ [ [ -2, 7, -2, -5, -1, 2 ], [ -1, 7, -2, -5, -1, 2 ], [ -1, 8, -2, -5, -1, 2 ], [ 0, 7, -3, -5, -1, 2 ] ], 1 ], - [ [ [ -3, 9, -2, -5, -1, 2 ], [ -1, 7, -2, -5, -1, 2 ], [ -1, 8, -2, -5, -1, 2 ], [ 0, 7, -3, -5, -1, 2 ] ], 1 ] - ], - [ - [ [ [ -3, 9, -2, -5, -1, 2 ], [ 0, 6, -3, -5, -1, 2 ], [ -1, 8, -2, -5, -1, 2 ], [ 0, 7, -3, -5, -1, 2 ] ], 1 ], - [ [ [ -3, 9, -2, -5, -1, 2 ], [ 0, 6, -3, -5, -1, 2 ], [ -1, 8, -3, -5, -1, 2 ], [ 0, 7, -3, -5, -1, 2 ] ], 1 ], - [ [ [ -2, 8, -3, -5, -1, 2 ], [ 0, 6, -3, -5, -1, 2 ], [ -1, 8, -3, -5, -1, 2 ], [ 0, 7, -3, -5, -1, 2 ] ], 1 ] - ], - [ - [ [ [ -2, 7, -3, -5, -1, 2 ], [ 0, 6, -3, -5, -1, 2 ], [ -1, 8, -3, -5, -1, 2 ], [ 0, 7, -3, -5, -1, 2 ] ], 1 ], - [ [ [ -2, 7, -3, -5, -1, 2 ], [ 0, 6, -3, -5, -1, 2 ], [ 0, 7, -4, -5, -1, 2 ], [ 0, 7, -3, -5, -1, 2 ] ], 1 ] - ], - [ - [ [ [ -1, 7, -3, -6, -1, 2 ], [ 0, 6, -3, -5, -1, 2 ], [ 0, 7, -4, -5, -1, 2 ], [ 0, 7, -3, -5, -1, 2 ] ], 1 ], - [ [ [ -1, 7, -3, -6, -1, 2 ], [ -1, 8, -3, -5, -1, 2 ], [ 0, 7, -4, -5, -1, 2 ], [ 0, 7, -3, -5, -1, 2 ] ], 1 ], - [ [ [ -1, 7, -3, -6, -1, 2 ], [ -1, 8, -3, -5, -1, 2 ], [ -1, 7, -3, -4, -1, 2 ], [ 0, 7, -3, -5, -1, 2 ] ], 1 ] - ], - [ - [ [ [ -1, 7, -3, -6, -1, 2 ], [ -1, 8, -3, -5, -1, 2 ], [ -1, 7, -3, -4, -1, 2 ], [ -1, 7, -2, -4, -1, 2 ] ], 1 ], - [ [ [ -1, 7, -3, -6, -1, 2 ], [ -1, 6, -3, -4, -1, 2 ], [ -1, 7, -3, -4, -1, 2 ], [ -1, 7, -2, -4, -1, 2 ] ], 1 ], - [ [ [ -2, 6, -3, -4, -1, 2 ], [ -1, 6, -3, -4, -1, 2 ], [ -1, 7, -3, -4, -1, 2 ], [ -1, 7, -2, -4, -1, 2 ] ], 1 ] - ], - [ - [ [ [ -2, 6, -3, -4, -1, 2 ], [ -1, 6, -3, -4, -1, 2 ], [ 0, 6, -4, -4, -1, 2 ], [ -1, 7, -2, -4, -1, 2 ] ], 1 ], - [ [ [ -1, 6, -3, -5, -1, 2 ], [ -1, 6, -3, -4, -1, 2 ], [ 0, 6, -4, -4, -1, 2 ], [ -1, 7, -2, -4, -1, 2 ] ], 1 ] - ], - [ - [ [ [ -1, 6, -3, -5, -1, 2 ], [ -1, 6, -3, -4, -1, 2 ], [ -1, 6, -3, -3, -1, 2 ], [ -1, 7, -2, -4, -1, 2 ] ], 1 ], - [ [ [ -1, 5, -3, -4, -1, 2 ], [ -1, 6, -3, -4, -1, 2 ], [ -1, 6, -3, -3, -1, 2 ], [ -1, 7, -2, -4, -1, 2 ] ], 1 ], - [ [ [ -1, 5, -3, -4, -1, 2 ], [ -1, 6, -3, -4, -1, 2 ], [ -1, 6, -3, -3, -1, 2 ], [ 0, 6, -3, -4, -1, 2 ] ], 1 ] - ], - [ - [ [ [ -1, 5, -3, -4, -1, 2 ], [ 0, 5, -4, -4, -1, 2 ], [ -1, 6, -3, -3, -1, 2 ], [ 0, 6, -3, -4, -1, 2 ] ], 1 ] - ], - [ - [ [ [ -1, 5, -3, -4, -1, 2 ], [ 0, 5, -4, -4, -1, 2 ], [ 0, 5, -3, -4, -1, 2 ], [ 0, 6, -3, -4, -1, 2 ] ], 1 ], - [ [ [ -1, 5, -3, -4, -1, 2 ], [ 0, 5, -4, -4, -1, 2 ], [ 0, 5, -3, -4, -1, 2 ], [ 1, 5, -4, -4, -1, 2 ] ], 1 ], - [ [ [ -1, 5, -3, -4, -1, 2 ], [ -1, 5, -3, -3, -1, 2 ], [ 0, 5, -3, -4, -1, 2 ], [ 1, 5, -4, -4, -1, 2 ] ], 1 ] - ], - [ - [ [ [ -1, 5, -3, -4, -1, 2 ], [ 1, 5, -3, -4, -1, 2 ], [ 0, 5, -3, -4, -1, 2 ], [ 1, 5, -4, -4, -1, 2 ] ], 1 ], - [ [ [ -1, 5, -3, -4, -1, 2 ], [ 1, 5, -3, -4, -1, 2 ], [ 0, 5, -3, -4, -1, 2 ], [ 0, 5, -2, -4, -1, 2 ] ], 1 ], - [ [ [ -1, 5, -3, -4, -1, 2 ], [ 1, 5, -3, -4, -1, 2 ], [ 1, 5, -3, -5, -1, 2 ], [ 0, 5, -2, -4, -1, 2 ] ], 1 ] - ], - [ - [ [ [ -1, 5, -3, -4, -1, 2 ], [ 1, 5, -3, -4, -1, 2 ], [ 1, 4, -3, -4, -1, 2 ], [ 0, 5, -2, -4, -1, 2 ] ], 1 ], - [ [ [ -1, 5, -3, -4, -1, 2 ], [ 1, 5, -3, -4, -1, 2 ], [ 1, 4, -3, -4, -1, 2 ], [ 0, 5, -3, -4, -1, 2 ] ], 1 ], - [ [ [ -1, 5, -3, -4, -1, 2 ], [ 0, 6, -3, -4, -1, 2 ], [ 1, 4, -3, -4, -1, 2 ], [ 0, 5, -3, -4, -1, 2 ] ], 1 ] - ], - [ - [ [ [ 0, 4, -4, -4, -1, 2 ], [ 0, 6, -3, -4, -1, 2 ], [ 1, 4, -3, -4, -1, 2 ], [ 0, 5, -3, -4, -1, 2 ] ], 1 ], - [ [ [ 0, 4, -4, -4, -1, 2 ], [ 1, 4, -4, -4, -1, 2 ], [ 1, 4, -3, -4, -1, 2 ], [ 0, 5, -3, -4, -1, 2 ] ], 1 ], - [ [ [ 0, 4, -4, -4, -1, 2 ], [ 1, 4, -4, -4, -1, 2 ], [ 1, 4, -3, -4, -1, 2 ], [ 2, 4, -4, -4, -1, 2 ] ], 1 ] - ], - [ - [ [ [ 0, 3, -3, -4, -1, 2 ], [ 1, 4, -4, -4, -1, 2 ], [ 1, 4, -3, -4, -1, 2 ], [ 2, 4, -4, -4, -1, 2 ] ], 1 ] - ], - [ - [ [ [ 0, 3, -4, -4, -1, 2 ], [ 1, 4, -4, -4, -1, 2 ], [ 1, 4, -3, -4, -1, 2 ], [ 2, 4, -4, -4, -1, 2 ] ], 1 ] - ], - [ - [ [ [ 0, 4, -3, -5, -1, 2 ], [ 1, 4, -4, -4, -1, 2 ], [ 1, 4, -3, -4, -1, 2 ], [ 2, 4, -4, -4, -1, 2 ] ], 1 ] - ], - [ - [ [ [ 0, 4, -3, -5, -1, 2 ], [ 1, 4, -4, -4, -1, 2 ], [ 1, 4, -3, -4, -1, 2 ], [ 1, 4, -3, -3, -1, 2 ] ], 1 ], - [ [ [ -1, 4, -2, -4, -1, 2 ], [ 1, 4, -4, -4, -1, 2 ], [ 1, 4, -3, -4, -1, 2 ], [ 1, 4, -3, -3, -1, 2 ] ], 1 ] - ], - [ - [ [ [ -1, 4, -2, -4, -1, 2 ], [ 1, 4, -4, -4, -1, 2 ], [ 1, 4, -3, -4, -1, 2 ], [ 1, 5, -2, -4, -1, 2 ] ], 1 ] - ], - [ - [ [ [ -1, 4, -2, -4, -1, 2 ], [ 1, 4, -4, -4, -1, 2 ], [ 1, 4, -3, -4, -1, 2 ], [ 1, 4, -2, -4, -1, 2 ] ], 1 ], - [ [ [ -1, 4, -2, -4, -1, 2 ], [ 1, 4, -4, -4, -1, 2 ], [ 2, 3, -4, -4, -1, 2 ], [ 1, 4, -2, -4, -1, 2 ] ], 1 ] - ], - [ - [ [ [ -1, 4, -2, -4, -1, 2 ], [ 1, 4, -4, -4, -1, 2 ], [ 2, 3, -4, -4, -1, 2 ], [ 1, 3, -2, -4, -1, 2 ] ], 1 ] - ], - [ - [ [ [ -1, 4, -2, -4, -1, 2 ], [ 1, 4, -4, -4, -1, 2 ], [ 2, 3, -4, -4, -1, 2 ], [ 1, 4, -2, -5, -1, 2 ] ], 1 ], - [ [ [ -1, 4, -2, -4, -1, 2 ], [ 0, 4, -2, -4, 0, 2 ], [ 2, 3, -4, -4, -1, 2 ], [ 1, 4, -2, -5, -1, 2 ] ], 1 ], - [ [ [ -1, 4, -2, -4, -1, 2 ], [ 0, 4, -2, -4, 0, 2 ], [ 0, 5, -2, -4, -1, 2 ], [ 1, 4, -2, -5, -1, 2 ] ], 1 ] - ], - [ - [ [ [ -1, 4, -2, -4, -1, 2 ], [ 0, 4, -2, -4, 0, 2 ], [ 1, 4, -2, -4, 0, 1 ], [ 1, 4, -2, -5, -1, 2 ] ], 1 ], - [ [ [ -1, 4, -2, -4, -1, 2 ], [ 0, 4, -2, -4, 0, 2 ], [ 1, 4, -2, -4, 0, 1 ], [ 1, 4, -2, -4, -1, 1 ] ], 1 ] - ], - [ - [ [ [ 0, 3, -2, -4, 0, 1 ], [ 0, 4, -2, -4, 0, 2 ], [ 1, 4, -2, -4, 0, 1 ], [ 1, 4, -2, -4, -1, 1 ] ], 1 ] - ], - [ - [ [ [ -1, 4, -2, -4, 0, 1 ], [ 0, 4, -2, -4, 0, 2 ], [ 1, 4, -2, -4, 0, 1 ], [ 1, 4, -2, -4, -1, 1 ] ], 1 ], - [ [ [ -1, 4, -2, -4, 0, 1 ], [ 0, 4, -2, -4, 0, 2 ], [ 1, 4, -2, -4, 0, 1 ], [ 0, 4, -3, -4, 0, 2 ] ], 1 ], - [ [ [ -1, 4, -2, -4, 0, 1 ], [ 0, 4, -2, -4, 0, 2 ], [ 1, 3, -2, -4, 0, 2 ], [ 0, 4, -3, -4, 0, 2 ] ], 1 ] - ], - [ - [ [ [ -1, 4, -2, -4, 0, 1 ], [ 0, 4, -2, -4, 0, 2 ], [ 0, 5, -2, -4, 0, 2 ], [ 0, 4, -3, -4, 0, 2 ] ], 1 ] - ], - [ - [ [ [ -1, 3, -2, -4, 0, 2 ], [ 0, 4, -2, -4, 0, 2 ], [ 0, 5, -2, -4, 0, 2 ], [ 0, 4, -3, -4, 0, 2 ] ], 1 ], - [ [ [ -1, 3, -2, -4, 0, 2 ], [ "Rest" ], [ 0, 5, -2, -4, 0, 2 ], [ 0, 4, -3, -4, 0, 2 ] ], 1 ], - [ [ [ "Rest" ], [ "Rest" ], [ 0, 5, -2, -4, 0, 2 ], [ 0, 4, -3, -4, 0, 2 ] ], 1 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ 0, 4, -3, -4, 0, 2 ] ], 1 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 1 ] - ] - ] -], -"last_changes": -[ - [ [ -1, 4, -2, -4, 0, 1 ], [ 0, 4, -2, -4, 0, 2 ], [ 1, 4, -2, -4, 0, 1 ], [ 1, 4, -2, -4, -1, 1 ] ], - [ [ -1, 4, -2, -4, 0, 1 ], [ 0, 4, -2, -4, 0, 2 ], [ 1, 4, -2, -4, 0, 1 ], [ 0, 4, -3, -4, 0, 2 ] ], - [ [ -1, 4, -2, -4, 0, 1 ], [ 0, 4, -2, -4, 0, 2 ], [ 1, 3, -2, -4, 0, 2 ], [ 0, 4, -3, -4, 0, 2 ] ], - [ [ -1, 4, -2, -4, 0, 1 ], [ 0, 4, -2, -4, 0, 2 ], [ 0, 5, -2, -4, 0, 2 ], [ 0, 4, -3, -4, 0, 2 ] ], - [ [ -1, 3, -2, -4, 0, 2 ], [ 0, 4, -2, -4, 0, 2 ], [ 0, 5, -2, -4, 0, 2 ], [ 0, 4, -3, -4, 0, 2 ] ] -], -"cur_uid": "4ff624b0", -"ref_uid": "nil", -"order_seed": 492048, -"dur_seed": 518010, -"motifs_seed": 626337, -"entrances_probs_vals": [ 0, 0, 0, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 0, 0, 0, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 0, 0, 0, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -2400, 1200 ], [ -1200, 1200 ], [ -702, 1200 ], [ -702, 1200 ] ], -"step_probs_vals": [ -1200, 1200, 0.0020576131687243, 0.068181818181818, 0.074074074074074, 0.0625, 0.20576131687243, 0.0625, 0.45679012345679, 0.011363636363636, 0.53086419753086, 0, 0.54320987654321, 0.92045454545455, 0.58641975308642, 0.92613636363636, 0.61316872427983, 0, 0.98971193415638, 0 ], -"passages_weights": [ 0.48, 0.46, 0.48, 1, 1 ], -"hd_exp": 9, -"hd_invert": 0, -"order": -[ - [ [ 0, 3, 2 ], [ 1 ], [ ] ], - [ [ 1, 2 ], [ 0, 3 ], [ ] ], - [ [ 0, 3, 2 ], [ 1 ], [ ] ], - [ [ 2 ], [ 3, 0, 1 ], [ ] ], - [ [ 3 ], [ 2, 1, 0 ], [ ] ], - [ [ 1 ], [ 0, 2, 3 ], [ ] ], - [ [ 1, 2, 0 ], [ 3 ], [ ] ], - [ [ 1 ], [ 3, 0, 2 ], [ ] ], - [ [ 0, 1 ], [ 3, 2 ], [ ] ], - [ [ 3, 2, 1 ], [ 0 ], [ ] ], - [ [ 0, 1, 2 ], [ 3 ], [ ] ], - [ [ 2 ], [ 1, 0, 3 ], [ ] ], - [ [ 2 ], [ 3, 0, 1 ], [ ] ], - [ [ 3, 1 ], [ 2, 0 ], [ ] ], - [ [ 3, 0 ], [ 1, 2 ], [ ] ], - [ [ 2, 1, 3 ], [ 0 ], [ ] ], - [ [ 0 ], [ 3, 2, 1 ], [ ] ], - [ [ 0, 2, 1 ], [ 3 ], [ ] ], - [ [ 1 ], [ 3, 0, 2 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ], - [ [ 2, 3 ], [ 1, 0 ], [ ] ], - [ [ 2, 0 ], [ 3, 1 ], [ ] ], - [ [ 0, 1, 2 ], [ 3 ], [ ] ], - [ [ 3 ], [ 2, 1, 0 ], [ ] ], - [ [ 2, 3 ], [ 0, 1 ], [ ] ], - [ [ 3 ], [ 0, 2, 1 ], [ ] ], - [ [ 1, 3 ], [ 0, 2 ], [ ] ], - [ [ 2 ], [ 3, 1, 0 ], [ ] ], - [ [ 3, 1 ], [ 0, 2 ], [ ] ], - [ [ 3, 0 ], [ 2, 1 ], [ ] ], - [ [ 2, 1, 3 ], [ 0 ], [ ] ], - [ [ 0 ], [ 3, 1, 2 ], [ ] ], - [ [ 0 ], [ 1, 2, 3 ], [ ] ], - [ [ 1, 3 ], [ 0, 2 ], [ ] ], - [ [ 1, 3, 0 ], [ 2 ], [ ] ], - [ [ 1 ], [ 2, 0, 3 ], [ ] ], - [ [ 1, 3, 2 ], [ 0 ], [ ] ], - [ [ 1, 0 ], [ 3, 2 ], [ ] ], - [ [ 1 ], [ 3, 2, 0 ], [ ] ], - [ [ 2 ], [ 0, 1, 3 ], [ ] ], - [ [ 0 ], [ 3, 1, 2 ], [ ] ], - [ [ 2, 3, 0 ], [ 1 ], [ ] ], - [ [ 3, 2 ], [ 1, 0 ], [ ] ], - [ [ 0 ], [ 3, 1, 2 ], [ ] ], - [ [ 2 ], [ 0, 1, 3 ], [ ] ], - [ [ 3, 2 ], [ 1, 0 ], [ ] ], - [ [ 0 ], [ 3, 1, 2 ], [ ] ], - [ [ 3 ], [ 1, 0, 2 ], [ ] ], - [ [ 1, 0 ], [ 3, 2 ], [ ] ], - [ [ 0, 2 ], [ 3, 1 ], [ ] ], - [ [ 2, 1, 0 ], [ 3 ], [ ] ], - [ [ 3, 2, 0 ], [ 1 ], [ ] ], - [ [ 3, 2, 0 ], [ 1 ], [ ] ], - [ [ 1 ], [ 0, 2, 3 ], [ ] ], - [ [ 3, 2 ], [ 1, 0 ], [ ] ], - [ [ 1 ], [ 2, 3, 0 ], [ ] ], - [ [ 1, 0 ], [ 3, 2 ], [ ] ], - [ [ 1, 0 ], [ 2, 3 ], [ ] ], - [ [ 0, 3, 1 ], [ 2 ], [ ] ], - [ [ 1 ], [ 3, 0, 2 ], [ ] ], - [ [ 0, 3, 2 ], [ 1 ], [ ] ], - [ [ 1, 2, 3 ], [ 0 ], [ ] ], - [ [ 3 ], [ 1, 0, 2 ], [ ] ], - [ [ 2, 1 ], [ 3, 0 ], [ ] ], - [ [ 1, 0 ], [ 3, 2 ], [ ] ], - [ [ 0, 3 ], [ 1, 2 ], [ ] ], - [ [ 2 ], [ 0, 1, 3 ], [ ] ], - [ [ 1, 2 ], [ 0, 3 ], [ ] ], - [ [ 3, 0, 1 ], [ 2 ], [ ] ], - [ [ 3 ], [ 2, 0, 1 ], [ ] ], - [ [ 1, 0 ], [ 2, 3 ], [ ] ], - [ [ 1, 3 ], [ 2, 0 ], [ ] ], - [ [ 1, 3 ], [ 0, 2 ], [ ] ], - [ [ 3, 2 ], [ 1, 0 ], [ ] ], - [ [ 2, 0, 3 ], [ 1 ], [ ] ], - [ [ 3, 2 ], [ 1, 0 ], [ ] ], - [ [ 3 ], [ 1, 2, 0 ], [ ] ], - [ [ 3, 1 ], [ 0, 2 ], [ ] ], - [ [ 3 ], [ 0, 1, 2 ], [ ] ], - [ [ 2 ], [ 3, 1, 0 ], [ ] ], - [ [ 1, 3 ], [ 2, 0 ], [ ] ], - [ [ 1 ], [ 2, 0, 3 ], [ ] ], - [ [ 2, 0, 3 ], [ 1 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ], - [ [ 0 ], [ 1, 3, 2 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ], - [ [ 2 ], [ 0, 1, 3 ], [ ] ], - [ [ 2, 3, 1 ], [ 0 ], [ ] ], - [ [ 1, 2, 3 ], [ 0 ], [ ] ], - [ [ 2, 1, 3 ], [ 0 ], [ ] ], - [ [ 1, 2 ], [ 3, 0 ], [ ] ], - [ [ 2, 1, 0 ], [ 3 ], [ ] ], - [ [ 1, 0 ], [ 3, 2 ], [ ] ], - [ [ 1, 2, 0 ], [ 3 ], [ ] ], - [ [ 0 ], [ 3, 1, 2 ], [ ] ], - [ [ 1, 0 ], [ 2, 3 ], [ ] ], - [ [ 3, 2, 1 ], [ 0 ], [ ] ], - [ [ 1 ], [ 0, 3, 2 ], [ ] ], - [ [ 1, 3, 0 ], [ 2 ], [ ] ], - [ [ 1, 2, 3 ], [ 0 ], [ ] ] -], -"sus_weights": [ 0.35, 0.37, 0.38 ], -"order_size": [ 100, 100 ], -"passages_size": [ 0, 0 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3/5201b8af/5201b8af_code.scd b/resources/resources_bak_2024_01_03/string_quartet_3/5201b8af/5201b8af_code.scd deleted file mode 100644 index c194eef..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3/5201b8af/5201b8af_code.scd +++ /dev/null @@ -1,945 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance); -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_3/5201b8af/5201b8af_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_3/5201b8af/5201b8af_mus_model.json deleted file mode 100644 index aa90760..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3/5201b8af/5201b8af_mus_model.json +++ /dev/null @@ -1,58 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 1 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ], [ 1, 0, 0, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 1, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, 0, -1, 0 ], [ 0, 0, 1, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ] ], 4.875 ] - ], - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, 0, -1, 0 ], [ 1, 0, 0, 0, 0, -1 ], [ 1, 0, 0, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ], [ 1, 0, 0, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ], [ 0, 0, 1, 0, 0, 0 ] ], 4.75 ] - ], - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, -1, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], 4.125 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, -1, 0, 0, 0 ], [ "Rest" ], [ 1, 0, 0, 0, 0, -1 ] ], 0 ], - [ [ [ "Rest" ], [ 1, 0, -1, 0, 0, 0 ], [ "Rest" ], [ 1, 0, 0, 0, 0, -1 ] ], 0 ], - [ [ [ "Rest" ], [ 1, 0, -1, 0, 0, 0 ], [ "Rest" ], [ "Rest" ] ], 0 ] - ] - ] -], -"last_changes": -[ - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 1, 0, 0 ], [ 0, 0, 0, 0, 1, 0 ], [ 1, 0, 0, -1, 0, 0 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 1, 0, 0 ], [ 0, 0, 0, 0, 1, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 1, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, -1 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 1, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ] ], - [ [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ] ] -], -"cur_uid": "5201b8af", -"ref_uid": "77b0d2dc", -"order_seed": 921767, -"dur_seed": 954688, -"motifs_seed": 995213, -"entrances_probs_vals": [ 1, 0, 0, 3.68, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 1, 0, 0, 3.68, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 1, 0, 0, 3.68, 5, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -1315.1702786378, 338.08049535604 ], [ -200.61919504644, 1452.6315789474 ], [ -386, 1675.5417956656 ], [ -219, 1694.1176470588 ] ], -"step_probs_vals": [ 0, 1200, 0, 0, 0.063786008230453, 0.92613636363636, 0.12757201646091, 0, 0.54732510288066, 0, 0.71604938271605, 0, 1, 0 ], -"passages_weights": [ 0.7, 0.29, 0.66, 0.74, 0.68 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 0 ], [ 3, 2, 1 ], [ ] ], - [ [ 0 ], [ 2, 1, 3 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ] -], -"sus_weights": [ 1, 0, 0 ], -"order_size": [ 8, 10 ], -"passages_size": [ 0, 10 ], -"motif_edited": "true", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3/5201b8af/lilypond/part_I.ly b/resources/resources_bak_2024_01_03/string_quartet_3/5201b8af/lilypond/part_I.ly deleted file mode 100644 index 01ab702..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3/5201b8af/lilypond/part_I.ly +++ /dev/null @@ -1,16 +0,0 @@ -{ - { r2 c''2^\markup { \pad-markup #0.2 "+0"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }} ~ } - \bar "|" - { c''1 ~ } - \bar "|" - { c''2. ~ c''8.[ e'16^\markup { \pad-markup #0.2 "-14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }}] ~ } - \bar "|" - { e'1 ~ } - \bar "|" - { e'1 ~ } - \bar "|" - { e'4 ~ e'16[ e'8.^\markup { \pad-markup #0.2 "-41"}] ~ e'2 ~ } - \bar "|" - { e'1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3/5201b8af/lilypond/part_II.ly b/resources/resources_bak_2024_01_03/string_quartet_3/5201b8af/lilypond/part_II.ly deleted file mode 100644 index f176e75..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3/5201b8af/lilypond/part_II.ly +++ /dev/null @@ -1,16 +0,0 @@ -{ - { r2 e'2^\markup { \pad-markup #0.2 "-14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }} ~ } - \bar "|" - { e'1 ~ } - \bar "|" - { e'2. ~ e'8.[ e'16^\markup { \pad-markup #0.2 "-41"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↓" }}] ~ } - \bar "|" - { e'1 ~ } - \bar "|" - { e'1 ~ } - \bar "|" - { e'4 ~ e'16[ f'8.^\markup { \pad-markup #0.2 "-2"}] ~ f'2 ~ } - \bar "|" - { f'1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3/5201b8af/lilypond/part_III.ly b/resources/resources_bak_2024_01_03/string_quartet_3/5201b8af/lilypond/part_III.ly deleted file mode 100644 index 5f83063..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3/5201b8af/lilypond/part_III.ly +++ /dev/null @@ -1,16 +0,0 @@ -{ - { r2 fis'2^\markup { \pad-markup #0.2 "+49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 11↓" }} ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'2. ~ fis'8.[ g'16^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }}] ~ } - \bar "|" - { g'1 ~ } - \bar "|" - { g'1 ~ } - \bar "|" - { g'4 ~ g'16[ gis'8.^\markup { \pad-markup #0.2 "+14"}] ~ gis'2 ~ } - \bar "|" - { gis'1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3/5201b8af/lilypond/part_IV.ly b/resources/resources_bak_2024_01_03/string_quartet_3/5201b8af/lilypond/part_IV.ly deleted file mode 100644 index 67fc5d0..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3/5201b8af/lilypond/part_IV.ly +++ /dev/null @@ -1,16 +0,0 @@ -{ - { c'1^\markup { \pad-markup #0.2 "+0"} ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3/5488f7e9/5488f7e9_code.scd b/resources/resources_bak_2024_01_03/string_quartet_3/5488f7e9/5488f7e9_code.scd deleted file mode 100644 index e5197a1..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3/5488f7e9/5488f7e9_code.scd +++ /dev/null @@ -1,945 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = true; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - if(pDistance < 0, {stepFunc.value(pDistance)}, {0.001}); -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_3/5488f7e9/5488f7e9_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_3/5488f7e9/5488f7e9_mus_model.json deleted file mode 100644 index cf2a424..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3/5488f7e9/5488f7e9_mus_model.json +++ /dev/null @@ -1,163 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ -3, -2, 0, 1, 0, -2 ], [ "Rest" ], [ "Rest" ] ], 0.75 ], - [ [ [ "Rest" ], [ -3, -2, 0, 1, 0, -2 ], [ -3, -1, 0, 0, 0, -1 ], [ "Rest" ] ], 0.75 ], - [ [ [ -3, -1, 0, 1, 0, -2 ], [ -3, -2, 0, 1, 0, -2 ], [ -3, -1, 0, 0, 0, -1 ], [ "Rest" ] ], 0.5 ], - [ [ [ -3, -1, 0, 1, 0, -2 ], [ -3, -2, 0, 1, 0, -2 ], [ -3, -1, 0, 0, 0, -1 ], [ 0, -1, 0, 2, 0, -2 ] ], 0.5 ] - ], - [ - [ [ [ -3, -1, 0, 1, 0, -2 ], [ 0, -1, 0, 1, 0, -1 ], [ -3, -1, 0, 0, 0, -1 ], [ 0, -1, 0, 2, 0, -2 ] ], 0.75 ] - ], - [ - [ [ [ -3, -1, 0, 1, 0, -2 ], [ 2, -1, 0, 2, -1, -2 ], [ -3, -1, 0, 0, 0, -1 ], [ 0, -1, 0, 2, 0, -2 ] ], 0.5 ] - ], - [ - [ [ [ -3, -1, 0, 1, 0, -2 ], [ 2, -1, 0, 2, -1, -2 ], [ 2, -1, 0, 1, 0, -2 ], [ 0, -1, 0, 2, 0, -2 ] ], 0.875 ] - ], - [ - [ [ [ 0, 0, 0, 1, 0, -2 ], [ 2, -1, 0, 2, -1, -2 ], [ 2, -1, 0, 1, 0, -2 ], [ 0, -1, 0, 2, 0, -2 ] ], 0.5 ] - ], - [ - [ [ [ 0, 0, 0, 1, 0, -2 ], [ 2, -1, 0, 2, -1, -2 ], [ 2, -1, 0, 1, 0, -2 ], [ 1, 0, 0, 1, 0, -2 ] ], 0.5 ] - ], - [ - [ [ [ 0, 0, 0, 1, 0, -2 ], [ 2, -1, 0, 2, -1, -2 ], [ 2, -1, 0, 1, 0, -2 ], [ 0, 0, 0, 2, 0, -2 ] ], 1.25 ] - ], - [ - [ [ [ 0, 0, 0, 1, 0, -2 ], [ 2, -1, 0, 2, -1, -2 ], [ 2, -1, 0, 1, 0, -2 ], [ 1, 1, 0, 1, 0, -2 ] ], 0.875 ] - ], - [ - [ [ [ 0, 0, 0, 1, 0, -2 ], [ 2, 0, 0, 1, -1, -2 ], [ 2, -1, 0, 1, 0, -2 ], [ 1, 1, 0, 1, 0, -2 ] ], 1.125 ] - ], - [ - [ [ [ 0, 0, 0, 1, 0, -2 ], [ 2, 0, 0, 1, -1, -2 ], [ 1, 1, 0, 1, 1, -2 ], [ 1, 1, 0, 1, 0, -2 ] ], 0.125 ] - ], - [ - [ [ [ 0, 0, 0, 1, 0, -2 ], [ 0, 1, 0, 1, -1, -2 ], [ 1, 1, 0, 1, 1, -2 ], [ 1, 1, 0, 1, 0, -2 ] ], 0.625 ] - ], - [ - [ [ [ 0, 0, 0, 1, 0, -2 ], [ 0, 1, 0, 1, -1, -2 ], [ 0, 1, -1, 1, 0, -2 ], [ 1, 1, 0, 1, 0, -2 ] ], 1.125 ] - ], - [ - [ [ [ 0, 0, 0, 1, 0, -2 ], [ 0, 1, 0, 1, -1, -2 ], [ 1, 0, 0, 0, 0, -2 ], [ 1, 1, 0, 1, 0, -2 ] ], 0.875 ] - ], - [ - [ [ [ 0, 0, 0, 1, 0, -2 ], [ 0, 1, 0, 1, 0, -3 ], [ 1, 0, 0, 0, 0, -2 ], [ 1, 1, 0, 1, 0, -2 ] ], 0.25 ] - ], - [ - [ [ [ 0, 0, 0, 1, 0, -2 ], [ 2, -1, 0, 1, 0, -2 ], [ 1, 0, 0, 0, 0, -2 ], [ 1, 1, 0, 1, 0, -2 ] ], 1.125 ] - ], - [ - [ [ [ 0, 0, 0, 1, 0, -2 ], [ 2, -1, 0, 1, 0, -2 ], [ 1, -1, 0, 1, -1, -2 ], [ 1, 1, 0, 1, 0, -2 ] ], 0.25 ] - ], - [ - [ [ [ 0, 0, 0, 1, 0, -2 ], [ 1, -1, 0, 2, -1, -2 ], [ 1, -1, 0, 1, -1, -2 ], [ 1, 1, 0, 1, 0, -2 ] ], 0.875 ] - ], - [ - [ [ [ 0, 1, 0, 1, 0, -1 ], [ 1, -1, 0, 2, -1, -2 ], [ 1, -1, 0, 1, -1, -2 ], [ 1, 1, 0, 1, 0, -2 ] ], 0.75 ] - ], - [ - [ [ [ 0, 1, 0, 1, 0, -1 ], [ 1, -1, 0, 2, -1, -2 ], [ -1, 1, 1, 1, 0, -2 ], [ 1, 1, 0, 1, 0, -2 ] ], 0.75 ] - ], - [ - [ [ [ 0, 1, 1, 1, 0, -3 ], [ 1, -1, 0, 2, -1, -2 ], [ -1, 1, 1, 1, 0, -2 ], [ 1, 1, 0, 1, 0, -2 ] ], 1 ] - ], - [ - [ [ [ 0, 1, 1, 1, 0, -3 ], [ 1, -1, 0, 2, -1, -2 ], [ 1, 1, 1, 1, -1, -3 ], [ 1, 1, 0, 1, 0, -2 ] ], 1.125 ] - ], - [ - [ [ [ 0, 1, 1, 1, 0, -3 ], [ 1, -1, 0, 2, -1, -2 ], [ 2, -1, 0, 2, -1, -3 ], [ 1, 1, 0, 1, 0, -2 ] ], 0.375 ] - ], - [ - [ [ [ 2, -1, 0, 3, -1, -3 ], [ 1, -1, 0, 2, -1, -2 ], [ 2, -1, 0, 2, -1, -3 ], [ 1, 1, 0, 1, 0, -2 ] ], 0.75 ] - ], - [ - [ [ [ 2, -1, 0, 3, -1, -3 ], [ 1, -1, 0, 2, -1, -2 ], [ 2, -1, 0, 2, -1, -3 ], [ 3, -1, 0, 1, -1, -2 ] ], 1.125 ] - ], - [ - [ [ [ 2, -1, 0, 3, -1, -3 ], [ 2, -2, 0, 3, -1, -3 ], [ 2, -1, 0, 2, -1, -3 ], [ 3, -1, 0, 1, -1, -2 ] ], 0.375 ] - ], - [ - [ [ [ 2, -1, 0, 3, -1, -3 ], [ 2, -2, 0, 3, -1, -3 ], [ 2, -1, 0, 2, -1, -3 ], [ 2, -2, 1, 3, -1, -3 ] ], 0.625 ] - ], - [ - [ [ [ 2, -1, 0, 3, -1, -3 ], [ 2, -2, 0, 3, -1, -3 ], [ 2, -1, 0, 2, -1, -3 ], [ 2, -2, 0, 2, -1, -3 ] ], 0.25 ] - ], - [ - [ [ [ 1, -1, -1, 2, -1, -3 ], [ 2, -2, 0, 3, -1, -3 ], [ 2, -1, 0, 2, -1, -3 ], [ 2, -2, 0, 2, -1, -3 ] ], 1.125 ] - ], - [ - [ [ [ 1, -1, -1, 2, -1, -3 ], [ 2, -2, 0, 3, -1, -3 ], [ 2, -1, 0, 2, -1, -3 ], [ 2, -1, -1, 2, -1, -2 ] ], 0.25 ] - ], - [ - [ [ [ 1, -1, -1, 2, -1, -3 ], [ 2, -1, -1, 3, -1, -3 ], [ 2, -1, 0, 2, -1, -3 ], [ 2, -1, -1, 2, -1, -2 ] ], 0.875 ], - [ [ [ "Rest" ], [ 2, -1, -1, 3, -1, -3 ], [ 2, -1, 0, 2, -1, -3 ], [ 2, -1, -1, 2, -1, -2 ] ], 0 ], - [ [ [ "Rest" ], [ 2, -1, -1, 3, -1, -3 ], [ 2, -1, 0, 2, -1, -3 ], [ "Rest" ] ], 0.5 ], - [ [ [ "Rest" ], [ "Rest" ], [ 2, -1, 0, 2, -1, -3 ], [ "Rest" ] ], 0.375 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 6.625 ] - ] - ] -], -"last_changes": -[ - [ [ 2, -1, 0, 3, -1, -3 ], [ 2, -2, 0, 3, -1, -3 ], [ 2, -1, 0, 2, -1, -3 ], [ 2, -2, 1, 3, -1, -3 ] ], - [ [ 2, -1, 0, 3, -1, -3 ], [ 2, -2, 0, 3, -1, -3 ], [ 2, -1, 0, 2, -1, -3 ], [ 2, -2, 0, 2, -1, -3 ] ], - [ [ 1, -1, -1, 2, -1, -3 ], [ 2, -2, 0, 3, -1, -3 ], [ 2, -1, 0, 2, -1, -3 ], [ 2, -2, 0, 2, -1, -3 ] ], - [ [ 1, -1, -1, 2, -1, -3 ], [ 2, -2, 0, 3, -1, -3 ], [ 2, -1, 0, 2, -1, -3 ], [ 2, -1, -1, 2, -1, -2 ] ], - [ [ 1, -1, -1, 2, -1, -3 ], [ 2, -1, -1, 3, -1, -3 ], [ 2, -1, 0, 2, -1, -3 ], [ 2, -1, -1, 2, -1, -2 ] ] -], -"cur_uid": "5488f7e9", -"ref_uid": "7c2de94c", -"order_seed": 199804, -"dur_seed": 927098, -"motifs_seed": 741655, -"entrances_probs_vals": [ 0, 0, 0, 0, 1.2087912087912, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 0, 0, 0, 0, 1.2087912087912, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 0, 0, 0, 0, 1.2087912087912, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -1147.9876160991, 1638 ], [ -1240.866873065, 1453 ], [ -980.80495356037, 1768 ], [ -850.77399380805, 1843 ] ], -"step_probs_vals": [ 0, 1200, 0, 0, 0.063786008230453, 0.92613636363636, 0.12757201646091, 0, 0.54732510288066, 0, 0.71604938271605, 0, 1, 0 ], -"passages_weights": [ 1, 0.34, 0.98, 0.74, 0.68 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 1, 2, 0 ], [ 3 ], [ ] ], - [ [ 2, 0, 3 ], [ 1 ], [ ] ], - [ [ 0, 2, 3 ], [ 1 ], [ ] ], - [ [ 3, 1, 0 ], [ 2 ], [ ] ], - [ [ 1, 3, 2 ], [ 0 ], [ ] ], - [ [ 1, 2, 0 ], [ 3 ], [ ] ], - [ [ 1, 2, 0 ], [ 3 ], [ ] ], - [ [ 2, 0, 1 ], [ 3 ], [ ] ], - [ [ 2, 3, 0 ], [ 1 ], [ ] ], - [ [ 1, 0, 3 ], [ 2 ], [ ] ], - [ [ 3, 0, 2 ], [ 1 ], [ ] ], - [ [ 1, 3, 0 ], [ 2 ], [ ] ], - [ [ 3, 0, 1 ], [ 2 ], [ ] ], - [ [ 2, 3, 0 ], [ 1 ], [ ] ], - [ [ 2, 0, 3 ], [ 1 ], [ ] ], - [ [ 1, 0, 3 ], [ 2 ], [ ] ], - [ [ 3, 2, 0 ], [ 1 ], [ ] ], - [ [ 2, 1, 3 ], [ 0 ], [ ] ], - [ [ 1, 0, 3 ], [ 2 ], [ ] ], - [ [ 2, 3, 1 ], [ 0 ], [ ] ], - [ [ 3, 0, 1 ], [ 2 ], [ ] ], - [ [ 0, 3, 1 ], [ 2 ], [ ] ], - [ [ 2, 1, 3 ], [ 0 ], [ ] ], - [ [ 1, 2, 0 ], [ 3 ], [ ] ], - [ [ 3, 0, 2 ], [ 1 ], [ ] ], - [ [ 2, 1, 0 ], [ 3 ], [ ] ], - [ [ 2, 1, 0 ], [ 3 ], [ ] ], - [ [ 1, 2, 3 ], [ 0 ], [ ] ], - [ [ 2, 0, 1 ], [ 3 ], [ ] ], - [ [ 3, 0, 2 ], [ 1 ], [ ] ] -], -"sus_weights": [ 0, 0, 0.61 ], -"order_size": [ 30, 30 ], -"passages_size": [ 0, 0 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3/55bd25a1/55bd25a1_code.scd b/resources/resources_bak_2024_01_03/string_quartet_3/55bd25a1/55bd25a1_code.scd deleted file mode 100644 index 49436ca..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3/55bd25a1/55bd25a1_code.scd +++ /dev/null @@ -1,973 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array2) - hsArrayToCents.value(array1); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -/* -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance) -}; -*/ - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = true; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - //if(pDistance >= 0, {stepFunc.value(abs(pDistance))}, {0.01}); - stepFunc.value(pDistance) -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - //tuples = dims.collect({[0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength.asInteger - minMotifLength.asInteger).rand + minMotifLength.asInteger).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - //noProgIns = (popSize - noSusIns).rand + 1; - noProgIns = (popSize - noSusIns); - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength.asInteger - minProgLength.asInteger).rand + minProgLength.asInteger).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0.01); - - - - if(rangeScore.value(candidate.collect({0}), voices[ins], ranges[ins][1] - 500, ranges[ins][1], 0, true) == 1, { - isInRangeScore = 1 - rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0] + 500, ranges[ins][1] - 500, 0, true); - isInRangeScore = isInRangeScore * rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true) - }, { - isInRangeScore = rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true); - }); - - - //isInRangeScore = rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true); - //old way - worked but actually by accident (I think) - //isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - - - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_3/55bd25a1/55bd25a1_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_3/55bd25a1/55bd25a1_mus_model.json deleted file mode 100644 index b0cec78..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3/55bd25a1/55bd25a1_mus_model.json +++ /dev/null @@ -1,548 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ 7, -5, -2, -1, -3, -2 ], [ "Rest" ], [ "Rest" ] ], 1.125 ], - [ [ [ "Rest" ], [ 7, -5, -2, -1, -3, -2 ], [ "Rest" ], [ 6, -6, -2, 0, -1, -2 ] ], 1.25 ], - [ [ [ 5, -5, -2, 0, -2, -2 ], [ 7, -5, -2, -1, -3, -2 ], [ "Rest" ], [ 6, -6, -2, 0, -1, -2 ] ], 1.25 ], - [ [ [ 5, -5, -2, 0, -2, -2 ], [ 7, -5, -2, -1, -3, -2 ], [ 6, -5, -2, 0, -1, -2 ], [ 6, -6, -2, 0, -1, -2 ] ], 1.5 ] - ], - [ - [ [ [ 5, -5, -2, 0, -2, -2 ], [ 6, -6, -2, 0, -2, -2 ], [ 6, -5, -2, 0, -1, -2 ], [ 6, -6, -2, 0, -1, -2 ] ], 0.625 ], - [ [ [ 5, -5, -2, 0, -2, -2 ], [ 6, -6, -2, 0, -2, -2 ], [ 6, -4, -2, 0, -2, -2 ], [ 6, -6, -2, 0, -1, -2 ] ], 0.5 ] - ], - [ - [ [ [ 4, -3, -2, 0, -2, -2 ], [ 6, -6, -2, 0, -2, -2 ], [ 6, -4, -2, 0, -2, -2 ], [ 6, -6, -2, 0, -1, -2 ] ], 0.625 ], - [ [ [ 4, -3, -2, 0, -2, -2 ], [ 5, -4, -2, 0, -2, -2 ], [ 6, -4, -2, 0, -2, -2 ], [ 6, -6, -2, 0, -1, -2 ] ], 1 ] - ], - [ - [ [ [ 4, -3, -2, 0, -2, -2 ], [ 5, -4, -2, 0, -2, -2 ], [ 7, -4, -2, -1, -2, -2 ], [ 6, -6, -2, 0, -1, -2 ] ], 1 ], - [ [ [ 5, -4, -3, 0, -2, -2 ], [ 5, -4, -2, 0, -2, -2 ], [ 7, -4, -2, -1, -2, -2 ], [ 6, -6, -2, 0, -1, -2 ] ], 0.75 ], - [ [ [ 5, -4, -3, 0, -2, -2 ], [ 5, -4, -2, 0, -2, -2 ], [ 7, -4, -2, -1, -2, -2 ], [ 6, -5, -2, 0, -2, -2 ] ], 0.5 ] - ], - [ - [ [ [ 6, -6, -2, 0, -2, -2 ], [ 5, -4, -2, 0, -2, -2 ], [ 7, -4, -2, -1, -2, -2 ], [ 6, -5, -2, 0, -2, -2 ] ], 0.625 ], - [ [ [ 6, -6, -2, 0, -2, -2 ], [ 6, -5, -3, 0, -2, -2 ], [ 7, -4, -2, -1, -2, -2 ], [ 6, -5, -2, 0, -2, -2 ] ], 1.25 ], - [ [ [ 6, -6, -2, 0, -2, -2 ], [ 6, -5, -3, 0, -2, -2 ], [ 7, -5, -3, 0, -2, -2 ], [ 6, -5, -2, 0, -2, -2 ] ], 1.5 ] - ], - [ - [ [ [ 6, -6, -2, 0, -2, -2 ], [ 6, -5, -3, 0, -2, -2 ], [ 6, -5, -2, 1, -2, -2 ], [ 6, -5, -2, 0, -2, -2 ] ], 0.625 ] - ], - [ - [ [ [ 6, -5, -2, 0, -3, -2 ], [ 6, -5, -3, 0, -2, -2 ], [ 6, -5, -2, 1, -2, -2 ], [ 6, -5, -2, 0, -2, -2 ] ], 0.5 ], - [ [ [ 6, -5, -2, 0, -3, -2 ], [ 5, -5, -2, 1, -2, -2 ], [ 6, -5, -2, 1, -2, -2 ], [ 6, -5, -2, 0, -2, -2 ] ], 0.75 ], - [ [ [ 6, -5, -2, 0, -3, -2 ], [ 5, -5, -2, 1, -2, -2 ], [ 6, -4, -2, 0, -2, -2 ], [ 6, -5, -2, 0, -2, -2 ] ], 0.75 ] - ], - [ - [ [ [ 5, -5, -1, 0, -2, -2 ], [ 5, -5, -2, 1, -2, -2 ], [ 6, -4, -2, 0, -2, -2 ], [ 6, -5, -2, 0, -2, -2 ] ], 0.875 ], - [ [ [ 5, -5, -1, 0, -2, -2 ], [ 5, -4, -2, 0, -2, -2 ], [ 6, -4, -2, 0, -2, -2 ], [ 6, -5, -2, 0, -2, -2 ] ], 0.875 ], - [ [ [ 5, -5, -1, 0, -2, -2 ], [ 5, -4, -2, 0, -2, -2 ], [ 6, -5, -2, 0, -2, -1 ], [ 6, -5, -2, 0, -2, -2 ] ], 0.875 ] - ], - [ - [ [ [ 5, -5, -1, 0, -2, -2 ], [ 5, -4, -2, 0, -2, -2 ], [ 6, -5, -2, 0, -2, -1 ], [ 5, -5, -1, 1, -2, -2 ] ], 1.625 ], - [ [ [ 5, -5, -1, 0, -2, -2 ], [ 6, -6, -1, 0, -2, -2 ], [ 6, -5, -2, 0, -2, -1 ], [ 5, -5, -1, 1, -2, -2 ] ], 0.75 ] - ], - [ - [ [ [ 5, -5, -1, 0, -2, -2 ], [ 6, -6, -1, 0, -2, -2 ], [ 6, -5, -2, 0, -2, -1 ], [ 6, -5, -1, 0, -2, -2 ] ], 1.75 ] - ], - [ - [ [ [ 5, -5, -1, 0, -2, -2 ], [ 5, -4, -1, 0, -2, -2 ], [ 6, -5, -2, 0, -2, -1 ], [ 6, -5, -1, 0, -2, -2 ] ], 1.75 ], - [ [ [ 6, -5, -1, -1, -2, -2 ], [ 5, -4, -1, 0, -2, -2 ], [ 6, -5, -2, 0, -2, -1 ], [ 6, -5, -1, 0, -2, -2 ] ], 1.125 ], - [ [ [ 6, -5, -1, -1, -2, -2 ], [ 5, -4, -1, 0, -2, -2 ], [ 6, -4, -1, 0, -2, -2 ], [ 6, -5, -1, 0, -2, -2 ] ], 1.75 ] - ], - [ - [ [ [ 5, -4, -2, 0, -2, -2 ], [ 5, -4, -1, 0, -2, -2 ], [ 6, -4, -1, 0, -2, -2 ], [ 6, -5, -1, 0, -2, -2 ] ], 0.875 ], - [ [ [ 5, -4, -2, 0, -2, -2 ], [ 5, -4, -1, 0, -2, -2 ], [ 6, -4, -1, 0, -2, -2 ], [ 5, -3, -1, 0, -2, -2 ] ], 1.25 ], - [ [ [ 5, -4, -2, 0, -2, -2 ], [ 6, -4, -1, -1, -2, -2 ], [ 6, -4, -1, 0, -2, -2 ], [ 5, -3, -1, 0, -2, -2 ] ], 1 ] - ], - [ - [ [ [ 5, -5, -1, 0, -2, -2 ], [ 6, -4, -1, -1, -2, -2 ], [ 6, -4, -1, 0, -2, -2 ], [ 5, -3, -1, 0, -2, -2 ] ], 1.25 ] - ], - [ - [ [ [ 4, -3, -1, 0, -2, -2 ], [ 6, -4, -1, -1, -2, -2 ], [ 6, -4, -1, 0, -2, -2 ], [ 5, -3, -1, 0, -2, -2 ] ], 1.5 ], - [ [ [ 4, -3, -1, 0, -2, -2 ], [ 6, -4, -1, -1, -2, -2 ], [ 6, -4, -1, 0, -2, -2 ], [ 6, -4, -2, 0, -2, -2 ] ], 0.75 ] - ], - [ - [ [ [ 4, -3, -1, 0, -2, -2 ], [ 6, -4, -1, 0, -2, -3 ], [ 6, -4, -1, 0, -2, -2 ], [ 6, -4, -2, 0, -2, -2 ] ], 1.375 ] - ], - [ - [ [ [ 4, -3, -1, 0, -2, -2 ], [ 6, -4, -1, 0, -2, -3 ], [ 6, -4, -1, 0, -2, -2 ], [ 4, -4, -1, 1, -2, -2 ] ], 0.75 ], - [ [ [ 5, -4, -2, 0, -2, -2 ], [ 6, -4, -1, 0, -2, -3 ], [ 6, -4, -1, 0, -2, -2 ], [ 4, -4, -1, 1, -2, -2 ] ], 1.375 ], - [ [ [ 5, -4, -2, 0, -2, -2 ], [ 6, -5, -1, 0, -2, -2 ], [ 6, -4, -1, 0, -2, -2 ], [ 4, -4, -1, 1, -2, -2 ] ], 0.375 ] - ], - [ - [ [ [ 4, -4, -1, 1, -3, -2 ], [ 6, -5, -1, 0, -2, -2 ], [ 6, -4, -1, 0, -2, -2 ], [ 4, -4, -1, 1, -2, -2 ] ], 0.5 ], - [ [ [ 4, -4, -1, 1, -3, -2 ], [ 4, -4, -1, 1, -2, -1 ], [ 6, -4, -1, 0, -2, -2 ], [ 4, -4, -1, 1, -2, -2 ] ], 1.625 ], - [ [ [ 4, -4, -1, 1, -3, -2 ], [ 4, -4, -1, 1, -2, -1 ], [ 5, -4, -1, 1, -2, -2 ], [ 4, -4, -1, 1, -2, -2 ] ], 1.5 ] - ], - [ - [ [ [ 4, -4, -1, 1, -3, -2 ], [ 4, -4, -1, 1, -2, -1 ], [ 5, -4, -1, 1, -2, -2 ], [ 5, -4, -1, 0, -2, -2 ] ], 1.25 ], - [ [ [ 4, -4, -1, 1, -3, -2 ], [ 4, -4, -1, 1, -2, -2 ], [ 5, -4, -1, 1, -2, -2 ], [ 5, -4, -1, 0, -2, -2 ] ], 1.625 ], - [ [ [ 4, -4, -2, 1, -2, -2 ], [ 4, -4, -1, 1, -2, -2 ], [ 5, -4, -1, 1, -2, -2 ], [ 5, -4, -1, 0, -2, -2 ] ], 0.5 ] - ], - [ - [ [ [ 4, -4, -2, 1, -2, -2 ], [ 4, -4, -1, 1, -2, -2 ], [ 6, -4, -2, 0, -2, -2 ], [ 5, -4, -1, 0, -2, -2 ] ], 0.875 ], - [ [ [ 4, -4, -2, 1, -2, -2 ], [ 4, -4, -1, 1, -2, -2 ], [ 6, -4, -2, 0, -2, -2 ], [ 4, -4, 0, 1, -2, -2 ] ], 0.875 ] - ], - [ - [ [ [ 4, -4, -2, 1, -2, -2 ], [ 4, -4, -1, 1, -2, -2 ], [ 4, -4, 0, 1, -2, -1 ], [ 4, -4, 0, 1, -2, -2 ] ], 1.75 ], - [ [ [ 3, -4, -1, 2, -2, -2 ], [ 4, -4, -1, 1, -2, -2 ], [ 4, -4, 0, 1, -2, -1 ], [ 4, -4, 0, 1, -2, -2 ] ], 1.625 ] - ], - [ - [ [ [ 3, -4, -1, 2, -2, -2 ], [ 4, -4, -1, 1, -2, -2 ], [ 4, -4, 0, 1, -2, -1 ], [ 3, -4, -1, 2, -2, -1 ] ], 1.375 ], - [ [ [ 3, -4, -1, 2, -2, -2 ], [ 3, -4, 0, 2, -2, -2 ], [ 4, -4, 0, 1, -2, -1 ], [ 3, -4, -1, 2, -2, -1 ] ], 1.625 ], - [ [ [ 3, -4, -1, 2, -2, -2 ], [ 3, -4, 0, 2, -2, -2 ], [ 4, -4, 0, 2, -2, -2 ], [ 3, -4, -1, 2, -2, -1 ] ], 1.5 ] - ], - [ - [ [ [ 3, -5, -1, 2, -2, -1 ], [ 3, -4, 0, 2, -2, -2 ], [ 4, -4, 0, 2, -2, -2 ], [ 3, -4, -1, 2, -2, -1 ] ], 1 ], - [ [ [ 3, -5, -1, 2, -2, -1 ], [ 2, -4, -1, 2, -2, 0 ], [ 4, -4, 0, 2, -2, -2 ], [ 3, -4, -1, 2, -2, -1 ] ], 1.25 ] - ], - [ - [ [ [ 2, -4, 0, 2, -1, -2 ], [ 2, -4, -1, 2, -2, 0 ], [ 4, -4, 0, 2, -2, -2 ], [ 3, -4, -1, 2, -2, -1 ] ], 1.25 ], - [ [ [ 2, -4, 0, 2, -1, -2 ], [ 2, -4, 0, 2, -2, -1 ], [ 4, -4, 0, 2, -2, -2 ], [ 3, -4, -1, 2, -2, -1 ] ], 0.875 ] - ], - [ - [ [ [ 2, -4, 0, 2, -1, -2 ], [ 2, -4, 0, 2, -2, -1 ], [ 4, -5, 0, 2, -2, -1 ], [ 3, -4, -1, 2, -2, -1 ] ], 1.75 ], - [ [ [ 2, -4, 0, 2, -1, -2 ], [ 2, -4, 0, 2, -2, -1 ], [ 4, -5, 0, 2, -2, -1 ], [ 2, -4, 0, 3, -2, -1 ] ], 1.5 ] - ], - [ - [ [ [ 2, -4, 0, 2, -1, -2 ], [ 2, -5, 0, 2, -2, 0 ], [ 4, -5, 0, 2, -2, -1 ], [ 2, -4, 0, 3, -2, -1 ] ], 0.625 ], - [ [ [ 2, -4, 0, 2, -1, -2 ], [ 2, -5, 0, 2, -2, 0 ], [ 4, -5, 0, 2, -2, -1 ], [ 3, -4, 0, 2, -2, -1 ] ], 1.25 ] - ], - [ - [ [ [ 2, -4, 0, 2, -1, -2 ], [ 3, -4, 0, 2, -2, -2 ], [ 4, -5, 0, 2, -2, -1 ], [ 3, -4, 0, 2, -2, -1 ] ], 0.625 ], - [ [ [ 2, -4, 0, 2, -1, -2 ], [ 3, -4, 0, 2, -2, -2 ], [ 4, -5, 0, 2, -2, -1 ], [ 4, -5, 0, 2, -1, -2 ] ], 1.625 ] - ], - [ - [ [ [ 2, -4, 0, 2, -1, -2 ], [ 3, -4, 0, 2, -2, -2 ], [ 4, -5, 0, 2, -2, -1 ], [ 4, -4, 0, 2, -2, -2 ] ], 1.5 ], - [ [ [ 2, -4, 0, 2, -1, -2 ], [ 3, -4, 0, 2, -2, -2 ], [ 3, -4, 0, 2, -2, -1 ], [ 4, -4, 0, 2, -2, -2 ] ], 1.5 ] - ], - [ - [ [ [ 2, -4, 0, 2, -1, -2 ], [ 3, -4, -1, 2, -1, -2 ], [ 3, -4, 0, 2, -2, -1 ], [ 4, -4, 0, 2, -2, -2 ] ], 1.625 ], - [ [ [ 2, -4, 0, 2, -1, -2 ], [ 3, -4, -1, 2, -1, -2 ], [ 4, -5, 0, 2, -1, -2 ], [ 4, -4, 0, 2, -2, -2 ] ], 1.25 ], - [ [ [ 2, -4, 0, 2, -1, -2 ], [ 3, -4, -1, 2, -1, -2 ], [ 4, -5, 0, 2, -1, -2 ], [ 4, -4, 0, 1, -1, -2 ] ], 1.75 ] - ], - [ - [ [ [ 2, -4, 0, 2, -1, -2 ], [ 3, -4, -1, 2, -1, -2 ], [ 3, -3, 0, 2, -1, -2 ], [ 4, -4, 0, 1, -1, -2 ] ], 0.75 ], - [ [ [ 2, -4, 0, 2, -1, -2 ], [ 3, -4, -1, 2, -1, -2 ], [ 3, -3, 0, 2, -1, -2 ], [ 3, -4, 1, 2, -1, -2 ] ], 1.5 ], - [ [ [ 2, -4, 0, 2, -1, -2 ], [ 2, -4, 0, 3, -1, -2 ], [ 3, -3, 0, 2, -1, -2 ], [ 3, -4, 1, 2, -1, -2 ] ], 1 ] - ], - [ - [ [ [ 2, -4, 0, 2, -1, -2 ], [ 2, -4, 0, 3, -1, -2 ], [ 2, -3, 0, 3, -1, -2 ], [ 3, -4, 1, 2, -1, -2 ] ], 1.625 ] - ], - [ - [ [ [ 1, -4, 1, 3, -1, -2 ], [ 2, -4, 0, 3, -1, -2 ], [ 2, -3, 0, 3, -1, -2 ], [ 3, -4, 1, 2, -1, -2 ] ], 1.25 ], - [ [ [ 1, -4, 1, 3, -1, -2 ], [ 2, -4, 0, 3, -1, -2 ], [ 4, -4, 1, 1, -1, -2 ], [ 3, -4, 1, 2, -1, -2 ] ], 0.5 ], - [ [ [ 1, -4, 1, 3, -1, -2 ], [ 2, -3, 1, 2, -1, -2 ], [ 4, -4, 1, 1, -1, -2 ], [ 3, -4, 1, 2, -1, -2 ] ], 1 ] - ], - [ - [ [ [ 1, -4, 1, 3, -1, -2 ], [ 2, -3, 1, 2, -1, -2 ], [ 4, -4, 1, 1, -1, -2 ], [ 2, -2, 1, 2, -1, -2 ] ], 1.5 ], - [ [ [ 1, -4, 1, 3, -1, -2 ], [ 2, -3, 1, 2, -1, -2 ], [ 3, -4, 1, 2, -1, -2 ], [ 2, -2, 1, 2, -1, -2 ] ], 1.125 ] - ], - [ - [ [ [ 1, -4, 1, 3, -1, -2 ], [ 2, -3, 1, 2, -1, -2 ], [ 3, -5, 1, 3, -1, -2 ], [ 2, -2, 1, 2, -1, -2 ] ], 1.125 ] - ], - [ - [ [ [ 1, -4, 1, 3, -1, -2 ], [ 2, -3, 1, 2, -1, -2 ], [ 1, -2, 1, 3, -1, -2 ], [ 2, -2, 1, 2, -1, -2 ] ], 1 ] - ], - [ - [ [ [ 1, -4, 1, 3, -1, -2 ], [ 2, -3, 1, 2, -1, -2 ], [ 2, -4, 2, 3, -1, -2 ], [ 2, -2, 1, 2, -1, -2 ] ], 1.25 ], - [ [ [ 1, -4, 1, 3, -1, -2 ], [ 2, -3, 1, 2, -1, -2 ], [ 2, -4, 2, 3, -1, -2 ], [ 3, -3, 0, 2, -1, -2 ] ], 0.875 ] - ], - [ - [ [ [ 1, -4, 1, 3, -1, -2 ], [ 2, -4, 1, 2, -1, -2 ], [ 2, -4, 2, 3, -1, -2 ], [ 3, -3, 0, 2, -1, -2 ] ], 0.875 ], - [ [ [ 1, -4, 1, 3, -1, -2 ], [ 2, -4, 1, 2, -1, -2 ], [ 3, -4, 1, 2, -1, -2 ], [ 3, -3, 0, 2, -1, -2 ] ], 0.5 ], - [ [ [ 1, -4, 1, 3, -1, -2 ], [ 2, -4, 1, 2, -1, -2 ], [ 3, -4, 1, 2, -1, -2 ], [ 2, -4, 2, 3, -1, -2 ] ], 1.25 ] - ], - [ - [ [ [ 1, -4, 1, 3, -1, -2 ], [ 2, -4, 1, 2, -1, -2 ], [ 3, -4, 1, 2, -1, -2 ], [ 4, -4, 1, 1, -1, -2 ] ], 0.5 ] - ], - [ - [ [ [ 1, -4, 1, 3, -1, -2 ], [ 3, -4, 1, 1, -1, -2 ], [ 3, -4, 1, 2, -1, -2 ], [ 4, -4, 1, 1, -1, -2 ] ], 1.625 ], - [ [ [ 2, -4, 1, 2, -1, -2 ], [ 3, -4, 1, 1, -1, -2 ], [ 3, -4, 1, 2, -1, -2 ], [ 4, -4, 1, 1, -1, -2 ] ], 1.25 ], - [ [ [ 2, -4, 1, 2, -1, -2 ], [ 3, -4, 1, 1, -1, -2 ], [ 3, -4, 1, 2, -1, -2 ], [ 1, -4, 1, 2, -1, -1 ] ], 0.625 ] - ], - [ - [ [ [ 2, -4, 1, 2, -1, -2 ], [ 3, -4, 1, 1, -1, -2 ], [ 3, -4, 1, 2, -1, -2 ], [ 3, -4, 0, 1, -1, -2 ] ], 1 ] - ], - [ - [ [ [ 2, -4, 0, 2, -1, -2 ], [ 3, -4, 1, 1, -1, -2 ], [ 3, -4, 1, 2, -1, -2 ], [ 3, -4, 0, 1, -1, -2 ] ], 1.125 ] - ], - [ - [ [ [ 2, -4, 0, 2, -1, -2 ], [ 3, -4, 1, 1, -1, -2 ], [ 4, -4, 1, 1, -1, -2 ], [ 3, -4, 0, 1, -1, -2 ] ], 1 ] - ], - [ - [ [ [ 2, -4, 0, 2, -1, -2 ], [ 3, -4, 1, 1, -1, -2 ], [ 4, -4, 1, 1, -1, -2 ], [ 2, -4, 1, 2, -1, -2 ] ], 1.625 ], - [ [ [ 2, -4, 0, 2, -1, -2 ], [ 2, -3, 0, 2, -1, -2 ], [ 4, -4, 1, 1, -1, -2 ], [ 2, -4, 1, 2, -1, -2 ] ], 1.625 ], - [ [ [ 2, -4, 0, 2, -1, -2 ], [ 2, -3, 0, 2, -1, -2 ], [ 3, -3, 0, 2, -1, -2 ], [ 2, -4, 1, 2, -1, -2 ] ], 1.375 ] - ], - [ - [ [ [ 1, -2, 0, 2, -1, -2 ], [ 2, -3, 0, 2, -1, -2 ], [ 3, -3, 0, 2, -1, -2 ], [ 2, -4, 1, 2, -1, -2 ] ], 0.625 ], - [ [ [ 1, -2, 0, 2, -1, -2 ], [ 2, -3, 0, 2, -1, -2 ], [ 2, -3, 0, 2, -1, -1 ], [ 2, -4, 1, 2, -1, -2 ] ], 1.375 ] - ], - [ - [ [ [ 1, -2, 0, 2, -1, -2 ], [ 2, -3, 0, 2, -1, -2 ], [ 2, -3, 0, 2, -1, -1 ], [ 2, -2, 0, 2, -1, -3 ] ], 1.375 ], - [ [ [ 1, -2, 0, 2, -1, -2 ], [ 1, -1, 0, 2, -1, -2 ], [ 2, -3, 0, 2, -1, -1 ], [ 2, -2, 0, 2, -1, -3 ] ], 1.375 ] - ], - [ - [ [ [ 0, 0, 0, 2, -1, -2 ], [ 1, -1, 0, 2, -1, -2 ], [ 2, -3, 0, 2, -1, -1 ], [ 2, -2, 0, 2, -1, -3 ] ], 1.25 ], - [ [ [ 0, 0, 0, 2, -1, -2 ], [ 1, -1, 0, 2, -1, -2 ], [ 2, -1, -1, 2, -1, -2 ], [ 2, -2, 0, 2, -1, -3 ] ], 1 ] - ], - [ - [ [ [ 2, -2, -1, 2, -1, -3 ], [ 1, -1, 0, 2, -1, -2 ], [ 2, -1, -1, 2, -1, -2 ], [ 2, -2, 0, 2, -1, -3 ] ], 1.75 ], - [ [ [ 2, -2, -1, 2, -1, -3 ], [ 2, -2, -1, 2, -1, -2 ], [ 2, -1, -1, 2, -1, -2 ], [ 2, -2, 0, 2, -1, -3 ] ], 0.625 ] - ], - [ - [ [ [ 2, -2, -1, 2, -1, -3 ], [ 2, -2, -1, 2, -1, -2 ], [ 2, -1, -1, 2, -1, -2 ], [ 1, -1, -2, 2, -1, -2 ] ], 0.5 ], - [ [ [ 2, -3, -1, 2, -1, -2 ], [ 2, -2, -1, 2, -1, -2 ], [ 2, -1, -1, 2, -1, -2 ], [ 1, -1, -2, 2, -1, -2 ] ], 0.875 ] - ], - [ - [ [ [ 2, -3, -1, 2, -1, -2 ], [ 2, -2, -1, 2, -1, -2 ], [ 3, -2, -2, 2, -1, -2 ], [ 1, -1, -2, 2, -1, -2 ] ], 0.875 ] - ], - [ - [ [ [ 2, -3, -1, 2, -1, -2 ], [ 2, -2, -1, 2, -1, -2 ], [ 3, -2, -2, 2, -1, -2 ], [ 2, -2, -3, 2, -1, -2 ] ], 1.125 ], - [ [ [ 2, -3, -2, 2, -1, -2 ], [ 2, -2, -1, 2, -1, -2 ], [ 3, -2, -2, 2, -1, -2 ], [ 2, -2, -3, 2, -1, -2 ] ], 0.5 ] - ], - [ - [ [ [ 2, -3, -2, 2, -1, -2 ], [ 2, -2, -1, 2, -1, -2 ], [ 2, -2, -1, 3, -1, -2 ], [ 2, -2, -3, 2, -1, -2 ] ], 0.875 ], - [ [ [ 2, -3, -2, 2, -1, -2 ], [ 2, -2, -1, 2, -1, -2 ], [ 2, -2, -1, 3, -1, -2 ], [ 2, -2, -1, 2, -2, -2 ] ], 0.875 ], - [ [ [ 2, -2, -1, 1, -1, -2 ], [ 2, -2, -1, 2, -1, -2 ], [ 2, -2, -1, 3, -1, -2 ], [ 2, -2, -1, 2, -2, -2 ] ], 1.375 ] - ], - [ - [ [ [ 2, -2, -1, 2, -1, -3 ], [ 2, -2, -1, 2, -1, -2 ], [ 2, -2, -1, 3, -1, -2 ], [ 2, -2, -1, 2, -2, -2 ] ], 0.875 ] - ], - [ - [ [ [ 2, -2, -1, 2, -1, -3 ], [ 2, -1, -1, 2, -2, -2 ], [ 2, -2, -1, 3, -1, -2 ], [ 2, -2, -1, 2, -2, -2 ] ], 0.875 ] - ], - [ - [ [ [ 2, -2, -1, 2, -1, -3 ], [ 2, -1, -1, 2, -2, -2 ], [ 3, -2, -1, 2, -2, -2 ], [ 2, -2, -1, 2, -2, -2 ] ], 1.75 ] - ], - [ - [ [ [ 2, -2, -1, 2, -1, -3 ], [ 2, -1, -1, 2, -2, -2 ], [ 4, -2, -1, 1, -2, -2 ], [ 2, -2, -1, 2, -2, -2 ] ], 0.875 ], - [ [ [ 2, -2, -1, 2, -1, -3 ], [ 1, -2, -1, 2, -2, -1 ], [ 4, -2, -1, 1, -2, -2 ], [ 2, -2, -1, 2, -2, -2 ] ], 1.5 ] - ], - [ - [ [ [ 2, -2, -1, 2, -1, -3 ], [ 1, -2, -1, 2, -2, -1 ], [ 4, -2, -1, 1, -2, -2 ], [ 1, -2, -1, 2, -1, -1 ] ], 1.625 ], - [ [ [ 2, -2, -1, 1, -2, -1 ], [ 1, -2, -1, 2, -2, -1 ], [ 4, -2, -1, 1, -2, -2 ], [ 1, -2, -1, 2, -1, -1 ] ], 0.625 ], - [ [ [ 2, -2, -1, 1, -2, -1 ], [ 1, -2, -1, 2, -2, -1 ], [ 3, -2, -1, 1, -2, -1 ], [ 1, -2, -1, 2, -1, -1 ] ], 0.875 ] - ], - [ - [ [ [ 2, -2, -1, 1, -2, -1 ], [ 1, -2, -1, 2, -2, -1 ], [ 4, -2, -1, 0, -2, -1 ], [ 1, -2, -1, 2, -1, -1 ] ], 0.625 ], - [ [ [ 2, -2, -1, 1, -2, -1 ], [ 1, -2, -1, 2, -2, -1 ], [ 4, -2, -1, 0, -2, -1 ], [ 3, -3, -1, 1, -2, -1 ] ], 1.75 ], - [ [ [ 2, -2, -1, 1, -2, -1 ], [ 1, -2, -1, 1, -2, 0 ], [ 4, -2, -1, 0, -2, -1 ], [ 3, -3, -1, 1, -2, -1 ] ], 1.25 ] - ], - [ - [ [ [ 2, -2, -1, 1, -2, -1 ], [ 1, -2, -1, 1, -2, 0 ], [ 4, -2, -1, 0, -2, -1 ], [ 3, -2, 0, 0, -2, -1 ] ], 1.375 ] - ], - [ - [ [ [ 2, -2, -1, 0, -2, 0 ], [ 1, -2, -1, 1, -2, 0 ], [ 4, -2, -1, 0, -2, -1 ], [ 3, -2, 0, 0, -2, -1 ] ], 1.875 ], - [ [ [ 2, -2, -1, 0, -2, 0 ], [ 1, -2, -1, 1, -2, 0 ], [ 4, -2, -1, 0, -2, -1 ], [ 2, -2, -1, 1, -2, 0 ] ], 0.5 ], - [ [ [ 2, -2, -1, 0, -2, 0 ], [ 1, -2, -1, 1, -2, 0 ], [ 2, -1, -1, 1, -2, 0 ], [ 2, -2, -1, 1, -2, 0 ] ], 0.875 ] - ], - [ - [ [ [ 2, -2, -1, 0, -2, 0 ], [ 0, 0, -1, 1, -2, 0 ], [ 2, -1, -1, 1, -2, 0 ], [ 2, -2, -1, 1, -2, 0 ] ], 1.625 ], - [ [ [ 1, -1, -2, 1, -2, 0 ], [ 0, 0, -1, 1, -2, 0 ], [ 2, -1, -1, 1, -2, 0 ], [ 2, -2, -1, 1, -2, 0 ] ], 1.625 ] - ], - [ - [ [ [ 1, -1, -2, 1, -2, 0 ], [ 1, -2, 0, 1, -2, 0 ], [ 2, -1, -1, 1, -2, 0 ], [ 2, -2, -1, 1, -2, 0 ] ], 1.5 ] - ], - [ - [ [ [ 1, -1, -2, 1, -2, 0 ], [ 0, -1, -1, 2, -2, 0 ], [ 2, -1, -1, 1, -2, 0 ], [ 2, -2, -1, 1, -2, 0 ] ], 0.375 ], - [ [ [ 1, -1, -2, 1, -2, 0 ], [ 0, -1, -1, 2, -2, 0 ], [ 2, -1, -1, 1, -2, 0 ], [ 1, 0, -1, 1, -2, 0 ] ], 1.375 ], - [ [ [ 1, -2, -1, 1, -2, 0 ], [ 0, -1, -1, 2, -2, 0 ], [ 2, -1, -1, 1, -2, 0 ], [ 1, 0, -1, 1, -2, 0 ] ], 1 ] - ], - [ - [ [ [ 0, 0, -1, 1, -2, 0 ], [ 0, -1, -1, 2, -2, 0 ], [ 2, -1, -1, 1, -2, 0 ], [ 1, 0, -1, 1, -2, 0 ] ], 0.5 ] - ], - [ - [ [ [ 0, 0, -1, 1, -2, 0 ], [ 0, -1, -1, 2, -2, 0 ], [ 1, -1, -1, 2, -2, 0 ], [ 1, 0, -1, 1, -2, 0 ] ], 1.125 ] - ], - [ - [ [ [ 0, 0, -1, 1, -2, 0 ], [ 0, -1, -1, 2, -2, 0 ], [ 2, -1, -1, 1, -2, 0 ], [ 1, 0, -1, 1, -2, 0 ] ], 0.875 ], - [ [ [ -1, 0, -1, 2, -2, 0 ], [ 0, -1, -1, 2, -2, 0 ], [ 2, -1, -1, 1, -2, 0 ], [ 1, 0, -1, 1, -2, 0 ] ], 1 ], - [ [ [ -1, 0, -1, 2, -2, 0 ], [ 0, -1, -1, 2, -2, 0 ], [ 2, -1, -1, 1, -2, 0 ], [ 1, -1, -1, 2, -2, 0 ] ], 1.125 ] - ], - [ - [ [ [ -1, 0, -1, 2, -2, 0 ], [ 0, -1, -1, 2, -2, 0 ], [ 2, -1, -1, 1, -2, 0 ], [ 0, -1, -1, 3, -2, 0 ] ], 0.875 ], - [ [ [ 0, -1, -2, 2, -2, 0 ], [ 0, -1, -1, 2, -2, 0 ], [ 2, -1, -1, 1, -2, 0 ], [ 0, -1, -1, 3, -2, 0 ] ], 1.625 ] - ], - [ - [ [ [ 1, -1, -2, 1, -2, 0 ], [ 0, -1, -1, 2, -2, 0 ], [ 2, -1, -1, 1, -2, 0 ], [ 0, -1, -1, 3, -2, 0 ] ], 0.5 ] - ], - [ - [ [ [ 1, -1, -2, 1, -2, 0 ], [ 0, -1, -1, 2, -2, 0 ], [ 1, -1, -1, 2, -2, 0 ], [ 0, -1, -1, 3, -2, 0 ] ], 0.5 ], - [ [ [ 1, -1, -2, 1, -2, 0 ], [ 0, -1, -1, 2, -2, 0 ], [ 1, -1, -1, 2, -2, 0 ], [ 2, -1, -1, 1, -2, 0 ] ], 0.75 ], - [ [ [ -1, -1, -1, 2, -2, 1 ], [ 0, -1, -1, 2, -2, 0 ], [ 1, -1, -1, 2, -2, 0 ], [ 2, -1, -1, 1, -2, 0 ] ], 0.5 ] - ], - [ - [ [ [ -1, -1, -1, 2, -2, 1 ], [ 0, -1, -1, 2, -2, 0 ], [ 1, -1, -1, 1, -2, 1 ], [ 2, -1, -1, 1, -2, 0 ] ], 1.75 ], - [ [ [ -1, -1, -1, 2, -2, 1 ], [ 1, -1, -1, 1, -2, 0 ], [ 1, -1, -1, 1, -2, 1 ], [ 2, -1, -1, 1, -2, 0 ] ], 0.875 ], - [ [ [ 0, 0, -1, 1, -2, 0 ], [ 1, -1, -1, 1, -2, 0 ], [ 1, -1, -1, 1, -2, 1 ], [ 2, -1, -1, 1, -2, 0 ] ], 0.5 ] - ], - [ - [ [ [ 0, 0, -1, 1, -2, 0 ], [ 1, -1, -1, 1, -2, 0 ], [ 1, -1, -1, 1, -2, 1 ], [ 0, -1, -1, 2, -2, 0 ] ], 1.375 ], - [ [ [ 0, -1, -1, 1, -2, 1 ], [ 1, -1, -1, 1, -2, 0 ], [ 1, -1, -1, 1, -2, 1 ], [ 0, -1, -1, 2, -2, 0 ] ], 1.25 ] - ], - [ - [ [ [ 1, -2, -1, 1, -2, 0 ], [ 1, -1, -1, 1, -2, 0 ], [ 1, -1, -1, 1, -2, 1 ], [ 0, -1, -1, 2, -2, 0 ] ], 1.625 ] - ], - [ - [ [ [ 1, -2, -1, 1, -2, 0 ], [ 1, -1, -1, 1, -2, 0 ], [ 1, -1, -1, 2, -2, 0 ], [ 0, -1, -1, 2, -2, 0 ] ], 0.75 ] - ], - [ - [ [ [ 1, -2, -1, 1, -2, 0 ], [ 1, -1, -1, 1, -2, 0 ], [ 2, -1, -1, 1, -2, 0 ], [ 0, -1, -1, 2, -2, 0 ] ], 1.5 ], - [ [ [ 1, -1, -1, 1, -3, 0 ], [ 1, -1, -1, 1, -2, 0 ], [ 2, -1, -1, 1, -2, 0 ], [ 0, -1, -1, 2, -2, 0 ] ], 0.5 ] - ], - [ - [ [ [ 1, -1, -1, 1, -3, 0 ], [ 1, -1, -1, 1, -2, 0 ], [ 2, -1, -2, 1, -2, 0 ], [ 0, -1, -1, 2, -2, 0 ] ], 1.625 ], - [ [ [ 1, -1, -2, 1, -2, 0 ], [ 1, -1, -1, 1, -2, 0 ], [ 2, -1, -2, 1, -2, 0 ], [ 0, -1, -1, 2, -2, 0 ] ], 1.625 ] - ], - [ - [ [ [ 1, -1, -2, 1, -2, 0 ], [ 1, -1, -1, 1, -2, 0 ], [ 1, -1, -1, 2, -2, 0 ], [ 0, -1, -1, 2, -2, 0 ] ], 1.375 ], - [ [ [ -1, -1, -1, 3, -2, 0 ], [ 1, -1, -1, 1, -2, 0 ], [ 1, -1, -1, 2, -2, 0 ], [ 0, -1, -1, 2, -2, 0 ] ], 1.375 ] - ], - [ - [ [ [ -1, -1, -1, 3, -2, 0 ], [ 1, -2, -1, 2, -2, 0 ], [ 1, -1, -1, 2, -2, 0 ], [ 0, -1, -1, 2, -2, 0 ] ], 1.625 ], - [ [ [ -1, -1, -1, 3, -2, 0 ], [ 1, -2, -1, 2, -2, 0 ], [ 2, -1, -1, 1, -2, 0 ], [ 0, -1, -1, 2, -2, 0 ] ], 1.25 ], - [ [ [ -1, -2, -1, 2, -2, 0 ], [ 1, -2, -1, 2, -2, 0 ], [ 2, -1, -1, 1, -2, 0 ], [ 0, -1, -1, 2, -2, 0 ] ], 1.75 ] - ], - [ - [ [ [ 0, -2, -1, 1, -2, 0 ], [ 1, -2, -1, 2, -2, 0 ], [ 2, -1, -1, 1, -2, 0 ], [ 0, -1, -1, 2, -2, 0 ] ], 1.5 ], - [ [ [ 0, -2, -1, 1, -2, 0 ], [ 1, -2, -1, 2, -2, 0 ], [ 2, -1, -1, 1, -2, 0 ], [ 1, -1, -1, 1, -2, 0 ] ], 0.5 ], - [ [ [ 0, -2, -1, 1, -2, 0 ], [ 2, -2, -1, 1, -2, 0 ], [ 2, -1, -1, 1, -2, 0 ], [ 1, -1, -1, 1, -2, 0 ] ], 0.5 ] - ], - [ - [ [ [ 0, -2, -1, 1, -2, 0 ], [ 2, -2, -1, 1, -2, 0 ], [ 1, -2, -1, 1, -2, 0 ], [ 1, -1, -1, 1, -2, 0 ] ], 0.875 ], - [ [ [ 1, -2, -1, 0, -2, 0 ], [ 2, -2, -1, 1, -2, 0 ], [ 1, -2, -1, 1, -2, 0 ], [ 1, -1, -1, 1, -2, 0 ] ], 1.625 ] - ], - [ - [ [ [ 0, -2, -2, 1, -2, 0 ], [ 2, -2, -1, 1, -2, 0 ], [ 1, -2, -1, 1, -2, 0 ], [ 1, -1, -1, 1, -2, 0 ] ], 1.375 ], - [ [ [ 0, -2, -2, 1, -2, 0 ], [ 2, -2, -1, 1, -2, 0 ], [ 2, -2, -1, 0, -2, 0 ], [ 1, -1, -1, 1, -2, 0 ] ], 1.75 ], - [ [ [ 0, -2, -2, 1, -2, 0 ], [ 2, -2, -1, 1, -2, 0 ], [ 2, -2, -1, 0, -2, 0 ], [ 2, -2, -2, 1, -2, 0 ] ], 1.5 ] - ], - [ - [ [ [ 0, -2, -2, 1, -2, 0 ], [ 2, -2, -1, 1, -2, 0 ], [ 1, -1, -2, 1, -2, 0 ], [ 2, -2, -2, 1, -2, 0 ] ], 1.5 ], - [ [ [ 0, -2, -2, 1, -2, 0 ], [ 2, -2, -1, 1, -2, 0 ], [ 1, -1, -2, 1, -2, 0 ], [ 3, -2, -2, 0, -2, 0 ] ], 0.5 ] - ], - [ - [ [ [ 0, -2, -2, 1, -2, 0 ], [ 2, -2, -1, 1, -2, 0 ], [ 1, -1, -2, 1, -2, 0 ], [ 1, -1, -2, 2, -2, 0 ] ], 1.625 ] - ], - [ - [ [ [ -1, 0, -2, 1, -2, 0 ], [ 2, -2, -1, 1, -2, 0 ], [ 1, -1, -2, 1, -2, 0 ], [ 1, -1, -2, 2, -2, 0 ] ], 1 ], - [ [ [ -1, 0, -2, 1, -2, 0 ], [ 2, -2, -1, 1, -2, 0 ], [ 1, -1, -2, 1, -2, 0 ], [ 2, -1, -2, 1, -2, 0 ] ], 1.75 ], - [ [ [ -1, 0, -2, 1, -2, 0 ], [ 1, 0, -2, 1, -2, 0 ], [ 1, -1, -2, 1, -2, 0 ], [ 2, -1, -2, 1, -2, 0 ] ], 1.75 ] - ], - [ - [ [ [ -1, 0, -2, 1, -2, 0 ], [ 1, 0, -2, 1, -2, 0 ], [ 0, 1, -2, 1, -2, 0 ], [ 2, -1, -2, 1, -2, 0 ] ], 0.875 ] - ], - [ - [ [ [ -1, 0, -2, 1, -2, 0 ], [ 0, 2, -2, 1, -2, 0 ], [ 0, 1, -2, 1, -2, 0 ], [ 2, -1, -2, 1, -2, 0 ] ], 0.75 ], - [ [ [ -2, 2, -2, 1, -2, 0 ], [ 0, 2, -2, 1, -2, 0 ], [ 0, 1, -2, 1, -2, 0 ], [ 2, -1, -2, 1, -2, 0 ] ], 0.5 ], - [ [ [ -2, 2, -2, 1, -2, 0 ], [ 0, 2, -2, 1, -2, 0 ], [ 0, 1, -2, 1, -2, 0 ], [ 1, 1, -2, 1, -2, 0 ] ], 0.875 ] - ], - [ - [ [ [ -2, 2, -2, 1, -2, 0 ], [ 0, 2, -2, 1, -2, 0 ], [ -1, 3, -2, 1, -2, 0 ], [ 1, 1, -2, 1, -2, 0 ] ], 1.375 ], - [ [ [ -1, 1, -3, 1, -2, 0 ], [ 0, 2, -2, 1, -2, 0 ], [ -1, 3, -2, 1, -2, 0 ], [ 1, 1, -2, 1, -2, 0 ] ], 1.375 ] - ], - [ - [ [ [ -1, 1, -3, 1, -2, 0 ], [ 0, 2, -2, 1, -2, 0 ], [ -1, 3, -2, 1, -2, 0 ], [ 0, 3, -2, 1, -2, 0 ] ], 1.875 ], - [ [ [ -1, 1, -3, 1, -2, 0 ], [ 0, 2, -2, 1, -2, 0 ], [ 0, 2, -3, 1, -2, 0 ], [ 0, 3, -2, 1, -2, 0 ] ], 1.5 ] - ], - [ - [ [ [ -1, 1, -3, 1, -2, 0 ], [ 1, 1, -3, 1, -2, 0 ], [ 0, 2, -3, 1, -2, 0 ], [ 0, 3, -2, 1, -2, 0 ] ], 0.875 ] - ], - [ - [ [ [ -2, 3, -3, 1, -2, 0 ], [ 1, 1, -3, 1, -2, 0 ], [ 0, 2, -3, 1, -2, 0 ], [ 0, 3, -2, 1, -2, 0 ] ], 1.25 ], - [ [ [ -2, 3, -3, 1, -2, 0 ], [ 1, 1, -3, 1, -2, 0 ], [ 0, 2, -3, 1, -2, 0 ], [ 0, 3, -3, 1, -2, 0 ] ], 1.625 ] - ], - [ - [ [ [ -1, 2, -4, 1, -2, 0 ], [ 1, 1, -3, 1, -2, 0 ], [ 0, 2, -3, 1, -2, 0 ], [ 0, 3, -3, 1, -2, 0 ] ], 0.5 ] - ], - [ - [ [ [ -1, 2, -4, 1, -2, 0 ], [ 1, 1, -3, 1, -2, 0 ], [ 0, 2, -3, 1, -2, 0 ], [ 1, 2, -4, 1, -2, 0 ] ], 1.25 ], - [ [ [ 0, 0, -3, 1, -2, 0 ], [ 1, 1, -3, 1, -2, 0 ], [ 0, 2, -3, 1, -2, 0 ], [ 1, 2, -4, 1, -2, 0 ] ], 1.25 ] - ], - [ - [ [ [ -1, 2, -3, 1, -2, 0 ], [ 1, 1, -3, 1, -2, 0 ], [ 0, 2, -3, 1, -2, 0 ], [ 1, 2, -4, 1, -2, 0 ] ], 0.75 ], - [ [ [ -1, 2, -3, 1, -2, 0 ], [ 1, 1, -3, 1, -2, 0 ], [ 0, 2, -3, 1, -2, 0 ], [ 2, 0, -3, 1, -2, 0 ] ], 1 ] - ], - [ - [ [ [ -1, 2, -3, 1, -2, 0 ], [ 1, 0, -3, 1, -2, 0 ], [ 0, 2, -3, 1, -2, 0 ], [ 2, 0, -3, 1, -2, 0 ] ], 0.75 ], - [ [ [ -1, 2, -3, 1, -2, 0 ], [ 1, 0, -3, 1, -2, 0 ], [ 1, 0, -2, 1, -2, 0 ], [ 2, 0, -3, 1, -2, 0 ] ], 1 ], - [ [ [ 0, 0, -2, 1, -2, 0 ], [ 1, 0, -3, 1, -2, 0 ], [ 1, 0, -2, 1, -2, 0 ], [ 2, 0, -3, 1, -2, 0 ] ], 1 ] - ], - [ - [ [ [ 0, 0, -2, 1, -2, 0 ], [ 1, 0, -3, 1, -2, 0 ], [ 1, 0, -2, 1, -2, 0 ], [ 1, -1, -2, 1, -2, 0 ] ], 0.5 ], - [ [ [ 0, 0, -2, 1, -2, 0 ], [ 0, 0, -2, 2, -2, 0 ], [ 1, 0, -2, 1, -2, 0 ], [ 1, -1, -2, 1, -2, 0 ] ], 0.75 ], - [ [ [ 0, 0, -2, 1, -2, 0 ], [ 0, 0, -2, 2, -2, 0 ], [ 0, 1, -2, 1, -2, 0 ], [ 1, -1, -2, 1, -2, 0 ] ], 0.625 ] - ], - [ - [ [ [ 0, 0, -2, 1, -2, 0 ], [ 0, 0, -2, 2, -2, 0 ], [ 1, 0, -3, 1, -2, 0 ], [ 1, -1, -2, 1, -2, 0 ] ], 0.75 ] - ], - [ - [ [ [ 0, -1, -2, 2, -2, 0 ], [ 0, 0, -2, 2, -2, 0 ], [ 1, 0, -3, 1, -2, 0 ], [ 1, -1, -2, 1, -2, 0 ] ], 0.625 ], - [ [ [ 0, -1, -2, 2, -2, 0 ], [ 1, 0, -2, 1, -2, 0 ], [ 1, 0, -3, 1, -2, 0 ], [ 1, -1, -2, 1, -2, 0 ] ], 0.875 ] - ], - [ - [ [ [ 0, -1, -2, 2, -2, 0 ], [ 1, 0, -2, 1, -2, 0 ], [ 1, 0, -3, 1, -2, 0 ], [ 0, -1, -1, 2, -2, 0 ] ], 1.625 ], - [ [ [ 0, -1, -2, 2, -2, 0 ], [ 1, -1, -2, 2, -2, 0 ], [ 1, 0, -3, 1, -2, 0 ], [ 0, -1, -1, 2, -2, 0 ] ], 0.75 ], - [ [ [ 0, -1, -2, 2, -2, 0 ], [ 1, -1, -2, 2, -2, 0 ], [ 0, 0, -2, 2, -2, 0 ], [ 0, -1, -1, 2, -2, 0 ] ], 1.375 ] - ], - [ - [ [ [ 0, -1, -2, 2, -2, 0 ], [ 1, 0, -2, 2, -3, 0 ], [ 0, 0, -2, 2, -2, 0 ], [ 0, -1, -1, 2, -2, 0 ] ], 1.25 ] - ], - [ - [ [ [ 0, -1, -2, 2, -2, 0 ], [ 1, -1, -1, 2, -2, 0 ], [ 0, 0, -2, 2, -2, 0 ], [ 0, -1, -1, 2, -2, 0 ] ], 1.25 ], - [ [ [ 0, -1, -2, 2, -2, 0 ], [ 1, -1, -1, 2, -2, 0 ], [ 0, 0, -2, 2, -2, 0 ], [ 1, -2, -2, 2, -2, 0 ] ], 0.875 ] - ], - [ - [ [ [ 0, -1, -2, 2, -2, 0 ], [ 1, -1, -1, 2, -2, 0 ], [ 0, 0, -2, 2, -2, 0 ], [ 1, -1, -2, 2, -2, 0 ] ], 1.375 ], - [ [ [ 0, -1, -2, 2, -2, 0 ], [ 1, -1, -1, 2, -2, 0 ], [ 1, -1, -3, 2, -2, 0 ], [ 1, -1, -2, 2, -2, 0 ] ], 0.625 ], - [ [ [ 0, -1, -2, 2, -2, 0 ], [ 2, -2, -2, 2, -2, 0 ], [ 1, -1, -3, 2, -2, 0 ], [ 1, -1, -2, 2, -2, 0 ] ], 1 ] - ], - [ - [ [ [ 1, -2, -3, 2, -2, 0 ], [ 2, -2, -2, 2, -2, 0 ], [ 1, -1, -3, 2, -2, 0 ], [ 1, -1, -2, 2, -2, 0 ] ], 0.875 ], - [ [ [ 1, -2, -3, 2, -2, 0 ], [ 2, -2, -2, 2, -2, 0 ], [ 1, -2, -2, 2, -2, 0 ], [ 1, -1, -2, 2, -2, 0 ] ], 0.75 ] - ], - [ - [ [ [ 1, -2, -3, 2, -2, 0 ], [ 2, -1, -2, 2, -3, 0 ], [ 1, -2, -2, 2, -2, 0 ], [ 1, -1, -2, 2, -2, 0 ] ], 1.125 ], - [ [ [ 1, -2, -3, 2, -2, 0 ], [ 2, -1, -2, 2, -3, 0 ], [ 0, 0, -2, 2, -2, 0 ], [ 1, -1, -2, 2, -2, 0 ] ], 1.5 ], - [ [ [ 1, -1, -2, 1, -2, 0 ], [ 2, -1, -2, 2, -3, 0 ], [ 0, 0, -2, 2, -2, 0 ], [ 1, -1, -2, 2, -2, 0 ] ], 1.625 ], - [ [ [ 1, -1, -2, 1, -2, 0 ], [ "Rest" ], [ 0, 0, -2, 2, -2, 0 ], [ 1, -1, -2, 2, -2, 0 ] ], 1.625 ], - [ [ [ "Rest" ], [ "Rest" ], [ 0, 0, -2, 2, -2, 0 ], [ 1, -1, -2, 2, -2, 0 ] ], 1.25 ], - [ [ [ "Rest" ], [ "Rest" ], [ 0, 0, -2, 2, -2, 0 ], [ "Rest" ] ], 1.25 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 7.25 ] - ] - ] -], -"last_changes": -[ - [ [ 1, -2, -3, 2, -2, 0 ], [ 2, -2, -2, 2, -2, 0 ], [ 1, -1, -3, 2, -2, 0 ], [ 1, -1, -2, 2, -2, 0 ] ], - [ [ 1, -2, -3, 2, -2, 0 ], [ 2, -2, -2, 2, -2, 0 ], [ 1, -2, -2, 2, -2, 0 ], [ 1, -1, -2, 2, -2, 0 ] ], - [ [ 1, -2, -3, 2, -2, 0 ], [ 2, -1, -2, 2, -3, 0 ], [ 1, -2, -2, 2, -2, 0 ], [ 1, -1, -2, 2, -2, 0 ] ], - [ [ 1, -2, -3, 2, -2, 0 ], [ 2, -1, -2, 2, -3, 0 ], [ 0, 0, -2, 2, -2, 0 ], [ 1, -1, -2, 2, -2, 0 ] ], - [ [ 1, -1, -2, 1, -2, 0 ], [ 2, -1, -2, 2, -3, 0 ], [ 0, 0, -2, 2, -2, 0 ], [ 1, -1, -2, 2, -2, 0 ] ] -], -"cur_uid": "55bd25a1", -"ref_uid": "6a9928d6", -"order_seed": 807265, -"dur_seed": 754968, -"motifs_seed": 848720, -"entrances_probs_vals": [ 0, 0, 0, 0.41, 1.84, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 0, 0, 0, 0.41, 1.84, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 0, 0, 0, 0.41, 1.84, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -2430, -293 ], [ -869, 1211 ], [ -832, 1285 ], [ -702, 1211 ] ], -"step_probs_vals": [ -1200, 1200, 0.0020576131687243, 0.068181818181818, 0.074074074074074, 0.0625, 0.20576131687243, 0.0625, 0.45679012345679, 0.011363636363636, 0.53086419753086, 0, 0.54320987654321, 0.92045454545455, 0.58641975308642, 0.92613636363636, 0.61316872427983, 0, 0.98971193415638, 0 ], -"passages_weights": [ 0.48, 0.46, 0.48, 1, 1 ], -"hd_exp": 9, -"hd_invert": 0, -"order": -[ - [ [ 1, 3, 0 ], [ 2 ], [ ] ], - [ [ 3, 0 ], [ 1, 2 ], [ ] ], - [ [ 3, 2 ], [ 0, 1 ], [ ] ], - [ [ 1 ], [ 2, 0, 3 ], [ ] ], - [ [ 3 ], [ 0, 1, 2 ], [ ] ], - [ [ 0, 1, 3 ], [ 2 ], [ ] ], - [ [ 3 ], [ 0, 1, 2 ], [ ] ], - [ [ 3 ], [ 0, 1, 2 ], [ ] ], - [ [ 2, 0 ], [ 3, 1 ], [ ] ], - [ [ 0, 1, 2 ], [ 3 ], [ ] ], - [ [ 3 ], [ 1, 0, 2 ], [ ] ], - [ [ 2 ], [ 0, 3, 1 ], [ ] ], - [ [ 2, 3, 1 ], [ 0 ], [ ] ], - [ [ 2, 1 ], [ 0, 3 ], [ ] ], - [ [ 3, 2, 0 ], [ 1 ], [ ] ], - [ [ 2 ], [ 3, 0, 1 ], [ ] ], - [ [ 3 ], [ 0, 1, 2 ], [ ] ], - [ [ 2 ], [ 3, 1, 0 ], [ ] ], - [ [ 0, 1 ], [ 2, 3 ], [ ] ], - [ [ 3, 1 ], [ 2, 0 ], [ ] ], - [ [ 0 ], [ 3, 1, 2 ], [ ] ], - [ [ 3, 2 ], [ 0, 1 ], [ ] ], - [ [ 2, 3 ], [ 0, 1 ], [ ] ], - [ [ 1, 0 ], [ 2, 3 ], [ ] ], - [ [ 2, 0 ], [ 1, 3 ], [ ] ], - [ [ 0, 2 ], [ 1, 3 ], [ ] ], - [ [ 0, 1 ], [ 3, 2 ], [ ] ], - [ [ 0 ], [ 1, 2, 3 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ], - [ [ 3, 0, 1 ], [ 2 ], [ ] ], - [ [ 3 ], [ 0, 2, 1 ], [ ] ], - [ [ 1, 0 ], [ 3, 2 ], [ ] ], - [ [ 0, 3, 1 ], [ 2 ], [ ] ], - [ [ 3, 1, 0 ], [ 2 ], [ ] ], - [ [ 0, 1 ], [ 2, 3 ], [ ] ], - [ [ 0 ], [ 1, 2, 3 ], [ ] ], - [ [ 0, 2, 1 ], [ 3 ], [ ] ], - [ [ 2 ], [ 1, 0, 3 ], [ ] ], - [ [ 0, 1, 2 ], [ 3 ], [ ] ], - [ [ 2, 3, 1 ], [ 0 ], [ ] ], - [ [ 1, 0, 3 ], [ 2 ], [ ] ], - [ [ 0 ], [ 3, 1, 2 ], [ ] ], - [ [ 3, 1 ], [ 0, 2 ], [ ] ], - [ [ 0, 2 ], [ 3, 1 ], [ ] ], - [ [ 1, 3 ], [ 0, 2 ], [ ] ], - [ [ 2, 3 ], [ 0, 1 ], [ ] ], - [ [ 1, 2 ], [ 3, 0 ], [ ] ], - [ [ 3, 1, 0 ], [ 2 ], [ ] ], - [ [ 2, 1 ], [ 3, 0 ], [ ] ], - [ [ 1 ], [ 2, 3, 0 ], [ ] ], - [ [ 1, 3, 2 ], [ 0 ], [ ] ], - [ [ 3, 2, 0 ], [ 1 ], [ ] ], - [ [ 0, 1, 3 ], [ 2 ], [ ] ], - [ [ 3, 0 ], [ 2, 1 ], [ ] ], - [ [ 1 ], [ 3, 0, 2 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ], - [ [ 1, 2, 0 ], [ 3 ], [ ] ], - [ [ 1 ], [ 0, 3, 2 ], [ ] ], - [ [ 2, 3 ], [ 1, 0 ], [ ] ], - [ [ 0, 3, 2 ], [ 1 ], [ ] ], - [ [ 2 ], [ 1, 3, 0 ], [ ] ], - [ [ 2, 3, 1 ], [ 0 ], [ ] ], - [ [ 1, 0, 3 ], [ 2 ], [ ] ], - [ [ 1 ], [ 2, 0, 3 ], [ ] ], - [ [ 1, 2 ], [ 3, 0 ], [ ] ], - [ [ 2, 1, 3 ], [ 0 ], [ ] ], - [ [ 1 ], [ 2, 3, 0 ], [ ] ], - [ [ 3 ], [ 2, 1, 0 ], [ ] ], - [ [ 1, 2 ], [ 3, 0 ], [ ] ], - [ [ 2, 1, 3 ], [ 0 ], [ ] ], - [ [ 0, 1, 3 ], [ 2 ], [ ] ], - [ [ 1, 3 ], [ 2, 0 ], [ ] ], - [ [ 3, 1 ], [ 2, 0 ], [ ] ], - [ [ 1, 3 ], [ 2, 0 ], [ ] ], - [ [ 3 ], [ 1, 2, 0 ], [ ] ], - [ [ 2 ], [ 0, 3, 1 ], [ ] ], - [ [ 1, 3 ], [ 2, 0 ], [ ] ], - [ [ 1 ], [ 0, 2, 3 ], [ ] ], - [ [ 1, 0 ], [ 2, 3 ], [ ] ], - [ [ 1, 2, 0 ], [ 3 ], [ ] ], - [ [ 2 ], [ 0, 3, 1 ], [ ] ], - [ [ 1, 0, 3 ], [ 2 ], [ ] ], - [ [ 2 ], [ 1, 0, 3 ], [ ] ], - [ [ 1, 3 ], [ 2, 0 ], [ ] ], - [ [ 1, 0 ], [ 3, 2 ], [ ] ], - [ [ 3, 0, 2 ], [ 1 ], [ ] ], - [ [ 1, 2 ], [ 0, 3 ], [ ] ], - [ [ 3, 2, 1 ], [ 0 ], [ ] ], - [ [ 2, 1 ], [ 3, 0 ], [ ] ], - [ [ 2, 1 ], [ 0, 3 ], [ ] ], - [ [ 3 ], [ 1, 2, 0 ], [ ] ], - [ [ 0 ], [ 3, 1, 2 ], [ ] ], - [ [ 1, 3, 0 ], [ 2 ], [ ] ], - [ [ 3, 2 ], [ 0, 1 ], [ ] ], - [ [ 0 ], [ 3, 1, 2 ], [ ] ], - [ [ 2, 3, 0 ], [ 1 ], [ ] ], - [ [ 2, 0 ], [ 1, 3 ], [ ] ], - [ [ 0 ], [ 3, 2, 1 ], [ ] ], - [ [ 3, 1 ], [ 0, 2 ], [ ] ], - [ [ 3 ], [ 1, 2, 0 ], [ ] ] -], -"sus_weights": [ 0.35, 0.37, 0.38 ], -"order_size": [ 100, 100 ], -"passages_size": [ 0, 0 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3/55f9b81e/55f9b81e_code.scd b/resources/resources_bak_2024_01_03/string_quartet_3/55f9b81e/55f9b81e_code.scd deleted file mode 100644 index 2dad11e..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3/55f9b81e/55f9b81e_code.scd +++ /dev/null @@ -1,958 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -/* -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance) -}; -*/ - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = true; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - if(pDistance < 0, {stepFunc.value(abs(pDistance))}, {0.001}); - //stepFunc.value(pDistance) -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - //tuples = dims.collect({[0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength.asInteger - minMotifLength.asInteger).rand + minMotifLength.asInteger).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - //noProgIns = (popSize - noSusIns).rand + 1; - noProgIns = (popSize - noSusIns); - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength.asInteger - minProgLength.asInteger).rand + minProgLength.asInteger).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_3/55f9b81e/55f9b81e_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_3/55f9b81e/55f9b81e_mus_model.json deleted file mode 100644 index 52fe7d6..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3/55f9b81e/55f9b81e_mus_model.json +++ /dev/null @@ -1,443 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ "Rest" ], [ -3, 1, 1, 4, 1, -2 ], [ "Rest" ] ], 1.125 ], - [ [ [ -2, 0, 0, 3, 1, -2 ], [ "Rest" ], [ -3, 1, 1, 4, 1, -2 ], [ "Rest" ] ], 1.75 ], - [ [ [ -2, 0, 0, 3, 1, -2 ], [ -2, 1, 1, 3, 1, -2 ], [ -3, 1, 1, 4, 1, -2 ], [ "Rest" ] ], 1.375 ], - [ [ [ -2, 0, 0, 3, 1, -2 ], [ -2, 1, 1, 3, 1, -2 ], [ -3, 1, 1, 4, 1, -2 ], [ -2, 1, 1, 4, 1, -2 ] ], 1 ] - ], - [ - [ [ [ -2, 0, 0, 3, 1, -2 ], [ -2, 1, 1, 3, 1, -2 ], [ -2, 0, 0, 4, 1, -2 ], [ -2, 1, 1, 4, 1, -2 ] ], 1.5 ] - ], - [ - [ [ [ -2, 0, 0, 3, 1, -2 ], [ -2, 1, 1, 3, 1, -2 ], [ -1, 0, 0, 3, 1, -2 ], [ -2, 1, 1, 4, 1, -2 ] ], 0.875 ] - ], - [ - [ [ [ -2, 0, 0, 3, 1, -2 ], [ -3, 1, 2, 4, 1, -2 ], [ -1, 0, 0, 3, 1, -2 ], [ -2, 1, 1, 4, 1, -2 ] ], 1.125 ] - ], - [ - [ [ [ -4, 1, 2, 4, 1, -2 ], [ -3, 1, 2, 4, 1, -2 ], [ -1, 0, 0, 3, 1, -2 ], [ -2, 1, 1, 4, 1, -2 ] ], 0.75 ] - ], - [ - [ [ [ -4, 1, 1, 4, 2, -2 ], [ -3, 1, 2, 4, 1, -2 ], [ -1, 0, 0, 3, 1, -2 ], [ -2, 1, 1, 4, 1, -2 ] ], 1.25 ] - ], - [ - [ [ [ -4, 1, 1, 4, 2, -2 ], [ -2, 0, 1, 4, 1, -2 ], [ -1, 0, 0, 3, 1, -2 ], [ -2, 1, 1, 4, 1, -2 ] ], 1.125 ] - ], - [ - [ [ [ -4, 1, 1, 4, 2, -2 ], [ -2, 0, 1, 4, 1, -2 ], [ -3, 1, 2, 4, 1, -2 ], [ -2, 1, 1, 4, 1, -2 ] ], 1 ] - ], - [ - [ [ [ -4, 2, 1, 4, 1, -2 ], [ -2, 0, 1, 4, 1, -2 ], [ -3, 1, 2, 4, 1, -2 ], [ -2, 1, 1, 4, 1, -2 ] ], 1.75 ] - ], - [ - [ [ [ -4, 2, 1, 4, 1, -2 ], [ -2, 1, 2, 3, 1, -2 ], [ -3, 1, 2, 4, 1, -2 ], [ -2, 1, 1, 4, 1, -2 ] ], 1.75 ] - ], - [ - [ [ [ -4, 2, 1, 4, 1, -2 ], [ -2, 1, 2, 3, 1, -2 ], [ -2, 0, 1, 4, 1, -2 ], [ -2, 1, 1, 4, 1, -2 ] ], 1.25 ] - ], - [ - [ [ [ -4, 2, 1, 4, 1, -2 ], [ -2, 1, 2, 3, 1, -2 ], [ -2, 1, 1, 4, 0, -2 ], [ -2, 1, 1, 4, 1, -2 ] ], 0.875 ] - ], - [ - [ [ [ -2, 1, 1, 3, 0, -2 ], [ -2, 1, 2, 3, 1, -2 ], [ -2, 1, 1, 4, 0, -2 ], [ -2, 1, 1, 4, 1, -2 ] ], 1 ] - ], - [ - [ [ [ -2, 1, 1, 3, 0, -2 ], [ -2, 1, 2, 3, 1, -2 ], [ -3, 2, 2, 3, 1, -2 ], [ -2, 1, 1, 4, 1, -2 ] ], 1.625 ] - ], - [ - [ [ [ -2, 1, 1, 3, 0, -2 ], [ -2, 2, 2, 3, 0, -2 ], [ -3, 2, 2, 3, 1, -2 ], [ -2, 1, 1, 4, 1, -2 ] ], 1 ] - ], - [ - [ [ [ -2, 1, 1, 3, 0, -2 ], [ -2, 2, 2, 3, 0, -2 ], [ -3, 3, 2, 3, 0, -2 ], [ -2, 1, 1, 4, 1, -2 ] ], 1.75 ] - ], - [ - [ [ [ -2, 1, 1, 3, 0, -2 ], [ -2, 2, 2, 3, 0, -2 ], [ -3, 3, 2, 3, 0, -2 ], [ -2, 2, 2, 3, 1, -2 ] ], 1.25 ] - ], - [ - [ [ [ -2, 1, 1, 3, 0, -2 ], [ -2, 2, 2, 3, 0, -2 ], [ -2, 1, 1, 3, 0, -1 ], [ -2, 2, 2, 3, 1, -2 ] ], 1.625 ] - ], - [ - [ [ [ -2, 0, 1, 3, 0, -1 ], [ -2, 2, 2, 3, 0, -2 ], [ -2, 1, 1, 3, 0, -1 ], [ -2, 2, 2, 3, 1, -2 ] ], 1.375 ] - ], - [ - [ [ [ -2, 0, 1, 3, 0, -1 ], [ -2, 2, 2, 3, 0, -2 ], [ -1, 0, 0, 3, 0, -1 ], [ -2, 2, 2, 3, 1, -2 ] ], 1.75 ] - ], - [ - [ [ [ -2, 0, 1, 3, 0, -1 ], [ -2, 2, 2, 3, 0, -2 ], [ -2, 0, 1, 3, 0, 0 ], [ -2, 2, 2, 3, 1, -2 ] ], 1 ] - ], - [ - [ [ [ -2, 0, 1, 3, 0, -1 ], [ -2, 2, 2, 3, 0, -2 ], [ -2, 0, 1, 3, 0, 0 ], [ -1, 2, 2, 3, -1, -2 ] ], 1.375 ] - ], - [ - [ [ [ -2, -1, 1, 3, 0, 0 ], [ -2, 2, 2, 3, 0, -2 ], [ -2, 0, 1, 3, 0, 0 ], [ -1, 2, 2, 3, -1, -2 ] ], 1.375 ] - ], - [ - [ [ [ -2, -1, 1, 3, 0, 0 ], [ -1, 0, 1, 2, 0, 0 ], [ -2, 0, 1, 3, 0, 0 ], [ -1, 2, 2, 3, -1, -2 ] ], 1.625 ] - ], - [ - [ [ [ -2, -1, 1, 3, 0, 0 ], [ -1, 0, 1, 2, 0, 0 ], [ -2, 0, 1, 3, 0, 0 ], [ -2, 0, 1, 3, 0, 1 ] ], 1.25 ] - ], - [ - [ [ [ -2, -1, 1, 3, 0, 0 ], [ -1, 0, 1, 2, 0, 0 ], [ -2, 0, 1, 3, 0, 0 ], [ -2, 0, 1, 4, 0, 0 ] ], 1.625 ] - ], - [ - [ [ [ -2, -1, 1, 3, 0, 0 ], [ -1, 0, 1, 2, 0, 0 ], [ -2, 0, 1, 3, 0, 0 ], [ -1, -1, 1, 3, 1, 0 ] ], 1.25 ] - ], - [ - [ [ [ -2, -1, 1, 3, 0, 0 ], [ -1, 0, 1, 2, 0, 0 ], [ -1, -1, 0, 3, 0, 0 ], [ -1, -1, 1, 3, 1, 0 ] ], 0.75 ] - ], - [ - [ [ [ -2, -1, 1, 3, 0, 0 ], [ -1, 0, 1, 2, 0, 0 ], [ -1, -1, 0, 3, 0, 0 ], [ -1, -1, 0, 4, 0, 0 ] ], 1.125 ] - ], - [ - [ [ [ -1, 0, 1, 2, 0, -1 ], [ -1, 0, 1, 2, 0, 0 ], [ -1, -1, 0, 3, 0, 0 ], [ -1, -1, 0, 4, 0, 0 ] ], 0.875 ] - ], - [ - [ [ [ -1, -1, 1, 2, 0, 0 ], [ -1, 0, 1, 2, 0, 0 ], [ -1, -1, 0, 3, 0, 0 ], [ -1, -1, 0, 4, 0, 0 ] ], 1.625 ] - ], - [ - [ [ [ -2, 0, 0, 3, 0, 0 ], [ -1, 0, 1, 2, 0, 0 ], [ -1, -1, 0, 3, 0, 0 ], [ -1, -1, 0, 4, 0, 0 ] ], 1.5 ] - ], - [ - [ [ [ -2, -1, 0, 4, 0, 0 ], [ -1, 0, 1, 2, 0, 0 ], [ -1, -1, 0, 3, 0, 0 ], [ -1, -1, 0, 4, 0, 0 ] ], 1.625 ] - ], - [ - [ [ [ -2, -1, 0, 4, 0, 0 ], [ -1, -1, 1, 3, 0, 0 ], [ -1, -1, 0, 3, 0, 0 ], [ -1, -1, 0, 4, 0, 0 ] ], 1.75 ] - ], - [ - [ [ [ -2, -1, 0, 4, 0, 0 ], [ -1, -1, 1, 3, 0, 0 ], [ -1, -1, 0, 3, 0, 0 ], [ -1, -1, 1, 4, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -2, -1, 0, 4, 0, 0 ], [ -1, -1, 1, 3, 0, 0 ], [ -1, -1, 0, 3, 0, 0 ], [ -1, 0, 0, 3, 0, 0 ] ], 1.25 ] - ], - [ - [ [ [ -1, -1, 1, 3, -1, 0 ], [ -1, -1, 1, 3, 0, 0 ], [ -1, -1, 0, 3, 0, 0 ], [ -1, 0, 0, 3, 0, 0 ] ], 0.75 ] - ], - [ - [ [ [ -1, -1, 1, 3, -1, 0 ], [ -1, -1, 1, 3, 0, 0 ], [ -2, -1, 1, 3, 0, 1 ], [ -1, 0, 0, 3, 0, 0 ] ], 1.5 ] - ], - [ - [ [ [ -1, -1, 1, 3, -1, 0 ], [ -1, -1, 1, 3, 0, 0 ], [ -1, 0, 0, 3, -1, 0 ], [ -1, 0, 0, 3, 0, 0 ] ], 1.75 ] - ], - [ - [ [ [ -1, -1, 1, 3, -1, 0 ], [ 0, -1, 1, 3, -2, 0 ], [ -1, 0, 0, 3, -1, 0 ], [ -1, 0, 0, 3, 0, 0 ] ], 1.25 ] - ], - [ - [ [ [ -1, -1, 1, 3, -1, 0 ], [ -1, 0, 1, 3, -1, 0 ], [ -1, 0, 0, 3, -1, 0 ], [ -1, 0, 0, 3, 0, 0 ] ], 1.5 ] - ], - [ - [ [ [ -1, -1, 1, 3, -1, 0 ], [ 0, -1, 0, 3, -1, 0 ], [ -1, 0, 0, 3, -1, 0 ], [ -1, 0, 0, 3, 0, 0 ] ], 1.75 ] - ], - [ - [ [ [ -1, -1, 0, 3, 0, 0 ], [ 0, -1, 0, 3, -1, 0 ], [ -1, 0, 0, 3, -1, 0 ], [ -1, 0, 0, 3, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 0, 0, 3, 1, 0 ], [ 0, -1, 0, 3, -1, 0 ], [ -1, 0, 0, 3, -1, 0 ], [ -1, 0, 0, 3, 0, 0 ] ], 1.375 ] - ], - [ - [ [ [ -2, 0, 0, 3, 1, 0 ], [ 0, -1, 0, 3, -1, 0 ], [ -1, 0, 0, 3, -1, 0 ], [ -1, 1, 0, 3, -1, 0 ] ], 1.875 ] - ], - [ - [ [ [ -2, 1, 0, 3, 0, 0 ], [ 0, -1, 0, 3, -1, 0 ], [ -1, 0, 0, 3, -1, 0 ], [ -1, 1, 0, 3, -1, 0 ] ], 1.375 ] - ], - [ - [ [ [ -2, 1, 0, 3, 0, 0 ], [ 0, -1, 0, 3, -1, 0 ], [ -1, 0, 0, 3, -1, 0 ], [ -1, 0, 0, 3, -1, 1 ] ], 1.75 ] - ], - [ - [ [ [ -2, 1, 0, 3, 0, 0 ], [ 0, -1, 0, 3, -1, 0 ], [ -1, -1, 0, 4, -1, 0 ], [ -1, 0, 0, 3, -1, 1 ] ], 1.625 ] - ], - [ - [ [ [ 0, -1, -1, 3, -1, 0 ], [ 0, -1, 0, 3, -1, 0 ], [ -1, -1, 0, 4, -1, 0 ], [ -1, 0, 0, 3, -1, 1 ] ], 0.625 ] - ], - [ - [ [ [ 0, -1, -1, 3, -1, 0 ], [ 0, -1, 0, 3, -1, 0 ], [ -1, -1, 0, 4, -1, 0 ], [ 1, -2, 0, 3, -1, 0 ] ], 1.125 ] - ], - [ - [ [ [ 0, -1, -1, 3, -1, 0 ], [ 0, -1, 0, 3, -1, 0 ], [ 1, -2, 0, 3, -2, 0 ], [ 1, -2, 0, 3, -1, 0 ] ], 0.75 ] - ], - [ - [ [ [ 1, -3, 0, 3, -1, 0 ], [ 0, -1, 0, 3, -1, 0 ], [ 1, -2, 0, 3, -2, 0 ], [ 1, -2, 0, 3, -1, 0 ] ], 0.875 ] - ], - [ - [ [ [ 1, -3, 0, 3, -1, 0 ], [ 0, -1, 0, 3, -1, 0 ], [ 0, -2, 0, 3, -1, 1 ], [ 1, -2, 0, 3, -1, 0 ] ], 0.875 ] - ], - [ - [ [ [ 1, -3, 0, 3, -1, 0 ], [ 0, -1, 0, 3, -1, 0 ], [ 2, -3, 0, 3, -1, -1 ], [ 1, -2, 0, 3, -1, 0 ] ], 1.375 ] - ], - [ - [ [ [ 1, -2, 0, 3, -2, 0 ], [ 0, -1, 0, 3, -1, 0 ], [ 2, -3, 0, 3, -1, -1 ], [ 1, -2, 0, 3, -1, 0 ] ], 1.125 ] - ], - [ - [ [ [ 1, -2, 0, 3, -2, 0 ], [ 1, -2, -1, 3, -1, 0 ], [ 2, -3, 0, 3, -1, -1 ], [ 1, -2, 0, 3, -1, 0 ] ], 1 ] - ], - [ - [ [ [ 1, -2, 0, 3, -2, 0 ], [ 2, -2, 0, 2, -2, 0 ], [ 2, -3, 0, 3, -1, -1 ], [ 1, -2, 0, 3, -1, 0 ] ], 0.75 ] - ], - [ - [ [ [ 1, -2, 0, 3, -2, 0 ], [ 2, -2, 0, 2, -2, 0 ], [ 0, -2, 0, 4, -1, 0 ], [ 1, -2, 0, 3, -1, 0 ] ], 1.75 ] - ], - [ - [ [ [ 1, -2, 0, 3, -2, 0 ], [ 2, -2, 0, 2, -2, 0 ], [ 0, -2, 0, 4, -1, 0 ], [ 2, -2, 0, 3, -3, 0 ] ], 1.5 ] - ], - [ - [ [ [ 1, -2, 0, 3, -2, 0 ], [ 1, -2, 1, 3, -2, 0 ], [ 0, -2, 0, 4, -1, 0 ], [ 2, -2, 0, 3, -3, 0 ] ], 1.625 ] - ], - [ - [ [ [ 1, -2, 0, 3, -2, 0 ], [ 1, -2, 0, 3, -1, 0 ], [ 0, -2, 0, 4, -1, 0 ], [ 2, -2, 0, 3, -3, 0 ] ], 1 ] - ], - [ - [ [ [ 1, -1, 0, 3, -3, 0 ], [ 1, -2, 0, 3, -1, 0 ], [ 0, -2, 0, 4, -1, 0 ], [ 2, -2, 0, 3, -3, 0 ] ], 1.625 ] - ], - [ - [ [ [ 2, -2, -1, 3, -3, 0 ], [ 1, -2, 0, 3, -1, 0 ], [ 0, -2, 0, 4, -1, 0 ], [ 2, -2, 0, 3, -3, 0 ] ], 0.75 ] - ], - [ - [ [ [ -1, -3, 0, 3, -1, 0 ], [ 1, -2, 0, 3, -1, 0 ], [ 0, -2, 0, 4, -1, 0 ], [ 2, -2, 0, 3, -3, 0 ] ], 1.125 ] - ], - [ - [ [ [ -1, -3, 0, 3, -1, 0 ], [ 1, -2, 0, 3, -1, 0 ], [ 2, -4, 0, 3, -1, 0 ], [ 2, -2, 0, 3, -3, 0 ] ], 0.875 ] - ], - [ - [ [ [ -1, -3, 0, 3, -1, 0 ], [ 1, -3, 0, 3, -1, 1 ], [ 2, -4, 0, 3, -1, 0 ], [ 2, -2, 0, 3, -3, 0 ] ], 1.25 ] - ], - [ - [ [ [ -1, -3, 0, 3, -1, 0 ], [ 1, -3, 0, 3, -1, 1 ], [ 2, -4, 0, 3, -1, 0 ], [ 2, -4, 1, 3, -1, 0 ] ], 0.875 ] - ], - [ - [ [ [ -1, -3, 0, 3, -1, 0 ], [ 1, -3, 0, 3, -1, 1 ], [ 2, -4, 0, 3, -1, 0 ], [ 1, -4, 0, 3, -1, 0 ] ], 1.875 ] - ], - [ - [ [ [ -1, -3, 0, 3, -1, 0 ], [ 2, -4, 1, 3, -1, 0 ], [ 2, -4, 0, 3, -1, 0 ], [ 1, -4, 0, 3, -1, 0 ] ], 1.625 ] - ], - [ - [ [ [ -1, -3, 0, 3, -1, 0 ], [ 0, -4, 0, 3, -1, 0 ], [ 2, -4, 0, 3, -1, 0 ], [ 1, -4, 0, 3, -1, 0 ] ], 0.875 ] - ], - [ - [ [ [ -1, -3, 0, 3, -1, 0 ], [ -1, -2, 0, 3, -1, 0 ], [ 2, -4, 0, 3, -1, 0 ], [ 1, -4, 0, 3, -1, 0 ] ], 1.625 ] - ], - [ - [ [ [ -1, -3, 0, 3, -1, 0 ], [ -1, -2, 0, 3, -1, 0 ], [ 2, -4, 0, 3, -1, 0 ], [ 0, -2, 0, 3, -1, 0 ] ], 1.75 ] - ], - [ - [ [ [ -1, -3, 0, 3, -1, 0 ], [ 0, -3, -1, 3, -1, 0 ], [ 2, -4, 0, 3, -1, 0 ], [ 0, -2, 0, 3, -1, 0 ] ], 0.875 ] - ], - [ - [ [ [ -2, -2, 0, 3, 0, 0 ], [ 0, -3, -1, 3, -1, 0 ], [ 2, -4, 0, 3, -1, 0 ], [ 0, -2, 0, 3, -1, 0 ] ], 0.625 ] - ], - [ - [ [ [ -1, -4, 0, 3, -1, 1 ], [ 0, -3, -1, 3, -1, 0 ], [ 2, -4, 0, 3, -1, 0 ], [ 0, -2, 0, 3, -1, 0 ] ], 0.875 ] - ], - [ - [ [ [ -1, -4, 0, 3, -1, 1 ], [ 1, -5, 0, 3, -1, 0 ], [ 2, -4, 0, 3, -1, 0 ], [ 0, -2, 0, 3, -1, 0 ] ], 1.375 ] - ], - [ - [ [ [ -1, -4, 0, 3, -1, 1 ], [ 1, -5, 0, 3, -1, 0 ], [ 2, -4, 0, 3, -1, 0 ], [ 1, -5, 0, 4, -1, 0 ] ], 1.625 ] - ], - [ - [ [ [ -1, -4, 0, 3, -1, 1 ], [ 1, -5, 0, 3, -1, 0 ], [ 2, -4, 0, 3, -1, 0 ], [ 2, -4, 0, 3, -1, -1 ] ], 1 ] - ], - [ - [ [ [ 1, -6, 0, 3, -1, 0 ], [ 1, -5, 0, 3, -1, 0 ], [ 2, -4, 0, 3, -1, 0 ], [ 2, -4, 0, 3, -1, -1 ] ], 0.625 ] - ], - [ - [ [ [ 1, -6, 0, 3, -1, 0 ], [ 1, -5, 0, 3, -1, 0 ], [ 3, -5, -1, 3, -1, 0 ], [ 2, -4, 0, 3, -1, -1 ] ], 0.625 ] - ], - [ - [ [ [ 1, -6, 0, 3, -1, 0 ], [ 1, -5, 0, 3, -1, 0 ], [ 3, -6, 1, 3, -1, 0 ], [ 2, -4, 0, 3, -1, -1 ] ], 1.625 ] - ], - [ - [ [ [ 0, -6, 1, 3, -1, 1 ], [ 1, -5, 0, 3, -1, 0 ], [ 3, -6, 1, 3, -1, 0 ], [ 2, -4, 0, 3, -1, -1 ] ], 1.25 ] - ], - [ - [ [ [ 0, -6, 1, 3, -1, 1 ], [ 0, -5, 1, 3, -1, 1 ], [ 3, -6, 1, 3, -1, 0 ], [ 2, -4, 0, 3, -1, -1 ] ], 0.75 ] - ], - [ - [ [ [ 0, -6, 1, 4, -1, 0 ], [ 0, -5, 1, 3, -1, 1 ], [ 3, -6, 1, 3, -1, 0 ], [ 2, -4, 0, 3, -1, -1 ] ], 0.75 ] - ], - [ - [ [ [ 0, -6, 1, 4, -1, 0 ], [ 0, -5, 1, 4, -1, 0 ], [ 3, -6, 1, 3, -1, 0 ], [ 2, -4, 0, 3, -1, -1 ] ], 0.875 ] - ], - [ - [ [ [ 0, -6, 1, 4, -1, 0 ], [ 0, -5, 1, 4, -1, 0 ], [ 2, -6, 2, 4, -1, 0 ], [ 2, -4, 0, 3, -1, -1 ] ], 1 ] - ], - [ - [ [ [ 0, -6, 1, 4, -1, 0 ], [ 0, -5, 1, 4, -1, 0 ], [ 3, -7, 1, 4, -1, 0 ], [ 2, -4, 0, 3, -1, -1 ] ], 1 ] - ], - [ - [ [ [ 0, -6, 1, 4, -1, 0 ], [ 2, -7, 1, 3, -1, 0 ], [ 3, -7, 1, 4, -1, 0 ], [ 2, -4, 0, 3, -1, -1 ] ], 1.25 ] - ], - [ - [ [ [ 1, -7, 0, 4, -1, 0 ], [ 2, -7, 1, 3, -1, 0 ], [ 3, -7, 1, 4, -1, 0 ], [ 2, -4, 0, 3, -1, -1 ] ], 0.625 ] - ], - [ - [ [ [ 0, -7, 1, 5, -1, 0 ], [ 2, -7, 1, 3, -1, 0 ], [ 3, -7, 1, 4, -1, 0 ], [ 2, -4, 0, 3, -1, -1 ] ], 0.75 ] - ], - [ - [ [ [ 0, -7, 1, 5, -1, 0 ], [ 2, -7, 1, 3, -1, 0 ], [ 4, -7, 1, 2, -1, 0 ], [ 2, -4, 0, 3, -1, -1 ] ], 1 ] - ], - [ - [ [ [ 0, -7, 1, 5, -1, 0 ], [ 2, -5, 0, 3, -1, -1 ], [ 4, -7, 1, 2, -1, 0 ], [ 2, -4, 0, 3, -1, -1 ] ], 1.625 ] - ], - [ - [ [ [ 3, -7, 1, 2, -2, 0 ], [ 2, -5, 0, 3, -1, -1 ], [ 4, -7, 1, 2, -1, 0 ], [ 2, -4, 0, 3, -1, -1 ] ], 1.75 ] - ], - [ - [ [ [ 3, -7, 1, 2, -2, 0 ], [ 2, -5, 0, 3, -1, -1 ], [ 5, -7, 1, 2, -3, 0 ], [ 2, -4, 0, 3, -1, -1 ] ], 0.875 ] - ], - [ - [ [ [ 3, -7, 1, 2, -2, 0 ], [ 2, -5, 0, 3, -1, -1 ], [ 2, -3, 0, 3, -1, -1 ], [ 2, -4, 0, 3, -1, -1 ] ], 1.25 ] - ], - [ - [ [ [ 3, -7, 1, 2, -2, 0 ], [ 2, -5, 0, 3, -1, -1 ], [ 2, -4, 0, 3, -1, 0 ], [ 2, -4, 0, 3, -1, -1 ] ], 1.75 ] - ], - [ - [ [ [ 2, -5, -1, 3, -1, -1 ], [ 2, -5, 0, 3, -1, -1 ], [ 2, -4, 0, 3, -1, 0 ], [ 2, -4, 0, 3, -1, -1 ] ], 1.625 ] - ], - [ - [ [ [ 2, -5, -1, 3, -1, -1 ], [ 2, -5, 0, 3, -1, -1 ], [ 2, -4, 0, 3, -1, 0 ], [ 3, -5, -1, 3, -1, -1 ] ], 1.25 ] - ], - [ - [ [ [ 2, -5, -1, 3, -1, -1 ], [ 2, -5, 0, 3, -1, -1 ], [ 2, -4, 0, 3, -1, 0 ], [ 2, -5, 0, 4, -1, -1 ] ], 1.375 ] - ], - [ - [ [ [ 2, -5, -1, 3, -1, -1 ], [ 2, -5, 0, 3, -1, -1 ], [ 2, -4, 0, 3, -1, 0 ], [ 4, -5, -1, 2, -1, -1 ] ], 1.625 ], - [ [ [ "Rest" ], [ 2, -5, 0, 3, -1, -1 ], [ 2, -4, 0, 3, -1, 0 ], [ 4, -5, -1, 2, -1, -1 ] ], 1.125 ], - [ [ [ "Rest" ], [ 2, -5, 0, 3, -1, -1 ], [ "Rest" ], [ 4, -5, -1, 2, -1, -1 ] ], 1.75 ], - [ [ [ "Rest" ], [ 2, -5, 0, 3, -1, -1 ], [ "Rest" ], [ "Rest" ] ], 1.5 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 3.0 ] - ] - ] -], -"last_changes": -[ - [ [ 3, -7, 1, 2, -2, 0 ], [ 2, -5, 0, 3, -1, -1 ], [ 2, -4, 0, 3, -1, 0 ], [ 2, -4, 0, 3, -1, -1 ] ], - [ [ 2, -5, -1, 3, -1, -1 ], [ 2, -5, 0, 3, -1, -1 ], [ 2, -4, 0, 3, -1, 0 ], [ 2, -4, 0, 3, -1, -1 ] ], - [ [ 2, -5, -1, 3, -1, -1 ], [ 2, -5, 0, 3, -1, -1 ], [ 2, -4, 0, 3, -1, 0 ], [ 3, -5, -1, 3, -1, -1 ] ], - [ [ 2, -5, -1, 3, -1, -1 ], [ 2, -5, 0, 3, -1, -1 ], [ 2, -4, 0, 3, -1, 0 ], [ 2, -5, 0, 4, -1, -1 ] ], - [ [ 2, -5, -1, 3, -1, -1 ], [ 2, -5, 0, 3, -1, -1 ], [ 2, -4, 0, 3, -1, 0 ], [ 4, -5, -1, 2, -1, -1 ] ] -], -"cur_uid": "55f9b81e", -"ref_uid": "726a40c7", -"order_seed": 540514, -"dur_seed": 331257, -"motifs_seed": 728928, -"entrances_probs_vals": [ 0, 0, 0, 0.66, 1.8406593406593, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 0, 0, 0, 0.66, 1.8406593406593, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 0, 0, 0, 0.66, 1.8406593406593, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -2467, 2400 ], [ -1167, 2400 ], [ -702, 2400 ], [ -702, 2400 ] ], -"step_probs_vals": [ 0, 1200, 0, 0, 0.090534979423868, 0.92613636363636, 0.17489711934156, 0.079545454545455, 0.37037037037037, 0, 0.7201646090535, 0, 1, 0 ], -"passages_weights": [ 0.63, 0.62, 1, 0.41, 1 ], -"hd_exp": 3.09, -"hd_invert": 0, -"order": -[ - [ [ 2, 0, 1 ], [ 3 ], [ ] ], - [ [ 0, 1, 3 ], [ 2 ], [ ] ], - [ [ 0, 1, 3 ], [ 2 ], [ ] ], - [ [ 3, 0, 2 ], [ 1 ], [ ] ], - [ [ 1, 2, 3 ], [ 0 ], [ ] ], - [ [ 2, 1, 3 ], [ 0 ], [ ] ], - [ [ 0, 3, 2 ], [ 1 ], [ ] ], - [ [ 3, 1, 0 ], [ 2 ], [ ] ], - [ [ 2, 1, 3 ], [ 0 ], [ ] ], - [ [ 0, 2, 3 ], [ 1 ], [ ] ], - [ [ 0, 1, 3 ], [ 2 ], [ ] ], - [ [ 0, 3, 1 ], [ 2 ], [ ] ], - [ [ 3, 2, 1 ], [ 0 ], [ ] ], - [ [ 3, 0, 1 ], [ 2 ], [ ] ], - [ [ 0, 3, 2 ], [ 1 ], [ ] ], - [ [ 0, 1, 3 ], [ 2 ], [ ] ], - [ [ 1, 0, 2 ], [ 3 ], [ ] ], - [ [ 0, 1, 3 ], [ 2 ], [ ] ], - [ [ 1, 2, 3 ], [ 0 ], [ ] ], - [ [ 1, 0, 3 ], [ 2 ], [ ] ], - [ [ 0, 3, 1 ], [ 2 ], [ ] ], - [ [ 0, 1, 2 ], [ 3 ], [ ] ], - [ [ 1, 3, 2 ], [ 0 ], [ ] ], - [ [ 0, 2, 3 ], [ 1 ], [ ] ], - [ [ 1, 0, 2 ], [ 3 ], [ ] ], - [ [ 1, 2, 0 ], [ 3 ], [ ] ], - [ [ 0, 1, 2 ], [ 3 ], [ ] ], - [ [ 1, 0, 3 ], [ 2 ], [ ] ], - [ [ 1, 2, 0 ], [ 3 ], [ ] ], - [ [ 2, 3, 1 ], [ 0 ], [ ] ], - [ [ 3, 1, 2 ], [ 0 ], [ ] ], - [ [ 1, 3, 2 ], [ 0 ], [ ] ], - [ [ 3, 2, 1 ], [ 0 ], [ ] ], - [ [ 2, 3, 0 ], [ 1 ], [ ] ], - [ [ 1, 0, 2 ], [ 3 ], [ ] ], - [ [ 2, 1, 0 ], [ 3 ], [ ] ], - [ [ 2, 3, 1 ], [ 0 ], [ ] ], - [ [ 3, 1, 0 ], [ 2 ], [ ] ], - [ [ 3, 1, 0 ], [ 2 ], [ ] ], - [ [ 0, 2, 3 ], [ 1 ], [ ] ], - [ [ 2, 3, 0 ], [ 1 ], [ ] ], - [ [ 3, 2, 0 ], [ 1 ], [ ] ], - [ [ 1, 2, 3 ], [ 0 ], [ ] ], - [ [ 1, 2, 3 ], [ 0 ], [ ] ], - [ [ 1, 2, 0 ], [ 3 ], [ ] ], - [ [ 3, 1, 2 ], [ 0 ], [ ] ], - [ [ 1, 2, 0 ], [ 3 ], [ ] ], - [ [ 0, 3, 1 ], [ 2 ], [ ] ], - [ [ 2, 3, 1 ], [ 0 ], [ ] ], - [ [ 1, 0, 2 ], [ 3 ], [ ] ], - [ [ 0, 3, 1 ], [ 2 ], [ ] ], - [ [ 2, 1, 3 ], [ 0 ], [ ] ], - [ [ 1, 0, 3 ], [ 2 ], [ ] ], - [ [ 3, 0, 1 ], [ 2 ], [ ] ], - [ [ 2, 1, 3 ], [ 0 ], [ ] ], - [ [ 0, 3, 2 ], [ 1 ], [ ] ], - [ [ 0, 3, 2 ], [ 1 ], [ ] ], - [ [ 3, 0, 1 ], [ 2 ], [ ] ], - [ [ 2, 1, 0 ], [ 3 ], [ ] ], - [ [ 0, 3, 2 ], [ 1 ], [ ] ], - [ [ 2, 0, 3 ], [ 1 ], [ ] ], - [ [ 2, 1, 3 ], [ 0 ], [ ] ], - [ [ 3, 1, 2 ], [ 0 ], [ ] ], - [ [ 3, 1, 2 ], [ 0 ], [ ] ], - [ [ 0, 3, 1 ], [ 2 ], [ ] ], - [ [ 2, 3, 0 ], [ 1 ], [ ] ], - [ [ 1, 2, 0 ], [ 3 ], [ ] ], - [ [ 2, 0, 1 ], [ 3 ], [ ] ], - [ [ 0, 3, 2 ], [ 1 ], [ ] ], - [ [ 3, 0, 2 ], [ 1 ], [ ] ], - [ [ 3, 2, 0 ], [ 1 ], [ ] ], - [ [ 2, 0, 1 ], [ 3 ], [ ] ], - [ [ 0, 3, 2 ], [ 1 ], [ ] ], - [ [ 1, 3, 2 ], [ 0 ], [ ] ], - [ [ 2, 3, 1 ], [ 0 ], [ ] ], - [ [ 2, 3, 0 ], [ 1 ], [ ] ], - [ [ 0, 2, 1 ], [ 3 ], [ ] ], - [ [ 1, 2, 0 ], [ 3 ], [ ] ], - [ [ 2, 3, 1 ], [ 0 ], [ ] ], - [ [ 0, 3, 1 ], [ 2 ], [ ] ], - [ [ 3, 1, 0 ], [ 2 ], [ ] ], - [ [ 1, 2, 3 ], [ 0 ], [ ] ], - [ [ 3, 2, 0 ], [ 1 ], [ ] ], - [ [ 2, 1, 3 ], [ 0 ], [ ] ], - [ [ 0, 3, 2 ], [ 1 ], [ ] ], - [ [ 1, 3, 0 ], [ 2 ], [ ] ], - [ [ 3, 0, 1 ], [ 2 ], [ ] ], - [ [ 2, 3, 0 ], [ 1 ], [ ] ], - [ [ 2, 1, 3 ], [ 0 ], [ ] ], - [ [ 1, 2, 3 ], [ 0 ], [ ] ], - [ [ 0, 1, 3 ], [ 2 ], [ ] ], - [ [ 0, 3, 2 ], [ 1 ], [ ] ], - [ [ 3, 1, 2 ], [ 0 ], [ ] ], - [ [ 3, 0, 1 ], [ 2 ], [ ] ], - [ [ 3, 0, 1 ], [ 2 ], [ ] ], - [ [ 0, 1, 3 ], [ 2 ], [ ] ], - [ [ 1, 3, 2 ], [ 0 ], [ ] ], - [ [ 1, 2, 0 ], [ 3 ], [ ] ], - [ [ 0, 2, 1 ], [ 3 ], [ ] ], - [ [ 0, 2, 1 ], [ 3 ], [ ] ] -], -"sus_weights": [ 0, 0, 0.61 ], -"order_size": [ 100, 100 ], -"passages_size": [ 0, 0 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3/577cf188/577cf188_code.scd b/resources/resources_bak_2024_01_03/string_quartet_3/577cf188/577cf188_code.scd deleted file mode 100644 index 5a3854b..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3/577cf188/577cf188_code.scd +++ /dev/null @@ -1,945 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = true; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance); -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_3/577cf188/577cf188_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_3/577cf188/577cf188_mus_model.json deleted file mode 100644 index b37c8be..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3/577cf188/577cf188_mus_model.json +++ /dev/null @@ -1,198 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ] ], 0 ], - [ [ [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ] ], 0 ], - [ [ [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 2.375 ], - [ [ [ -1, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 1.875 ] - ], - [ - [ [ [ 0, -1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 1.5 ] - ], - [ - [ [ [ 0, -1, 0, 0, 0, 0 ], [ 1, -1, 0, 0, -1, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 1.125 ] - ], - [ - [ [ [ 1, -2, 0, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 1.625 ] - ], - [ - [ [ [ 0, -1, 1, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 2.5 ] - ], - [ - [ [ [ 0, -1, 1, 0, -1, 0 ], [ 0, 0, 1, 0, -1, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 2 ] - ], - [ - [ [ [ 0, -1, 1, 0, -1, 0 ], [ 0, -1, 1, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 2.625 ] - ], - [ - [ [ [ 0, -1, 1, 0, -1, 0 ], [ 0, -1, 1, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, -1, 0 ] ], 1.125 ] - ], - [ - [ [ [ 0, -1, 1, 0, -1, 0 ], [ 0, -1, 1, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 1, 0, -1, 0 ] ], 1.875 ] - ], - [ - [ [ [ -1, 0, 2, 0, -1, 0 ], [ 0, -1, 1, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 1, 0, -1, 0 ] ], 1.125 ] - ], - [ - [ [ [ 0, -2, 1, 0, 0, 0 ], [ 0, -1, 1, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 1, 0, -1, 0 ] ], 1.625 ] - ], - [ - [ [ [ 0, -2, 1, 0, 0, 0 ], [ 0, -1, 1, 0, 0, 0 ], [ 0, -2, 1, 1, 0, 0 ], [ 0, 0, 1, 0, -1, 0 ] ], 1.375 ] - ], - [ - [ [ [ 0, -2, 1, 0, 0, 0 ], [ 0, -1, 1, 0, 0, 0 ], [ 1, -1, 1, -1, 0, 0 ], [ 0, 0, 1, 0, -1, 0 ] ], 1.875 ] - ], - [ - [ [ [ 0, 0, 1, -1, -1, 0 ], [ 0, -1, 1, 0, 0, 0 ], [ 1, -1, 1, -1, 0, 0 ], [ 0, 0, 1, 0, -1, 0 ] ], 2.5 ] - ], - [ - [ [ [ 0, 0, 1, -1, -1, 0 ], [ -1, 0, 1, 1, -1, 0 ], [ 1, -1, 1, -1, 0, 0 ], [ 0, 0, 1, 0, -1, 0 ] ], 2 ] - ], - [ - [ [ [ 0, 0, 1, -1, -1, 0 ], [ 1, -1, 0, -1, 0, 0 ], [ 1, -1, 1, -1, 0, 0 ], [ 0, 0, 1, 0, -1, 0 ] ], 1.25 ] - ], - [ - [ [ [ 0, 0, 1, -1, -1, 0 ], [ 1, -1, 0, -1, 0, 0 ], [ 1, -1, 1, -1, 0, 0 ], [ 1, 0, 1, -1, 0, 0 ] ], 2 ] - ], - [ - [ [ [ 0, 0, 1, -1, -1, 0 ], [ 1, 0, 2, -1, 0, 0 ], [ 1, -1, 1, -1, 0, 0 ], [ 1, 0, 1, -1, 0, 0 ] ], 2.5 ] - ], - [ - [ [ [ 0, 0, 1, -1, -1, 0 ], [ 1, 0, 2, -1, 0, 0 ], [ 0, 0, 2, -1, 0, 0 ], [ 1, 0, 1, -1, 0, 0 ] ], 2.375 ] - ], - [ - [ [ [ 0, 0, 1, -1, -1, 0 ], [ 1, 0, 2, -1, 0, 0 ], [ 0, 0, 2, -1, 0, 0 ], [ 0, 1, 2, -1, 0, 0 ] ], 2.125 ] - ], - [ - [ [ [ 0, 0, 1, -1, -1, 0 ], [ 1, 0, 2, -1, 0, 0 ], [ 0, 0, 1, -1, -1, 1 ], [ 0, 1, 2, -1, 0, 0 ] ], 1.375 ] - ], - [ - [ [ [ 0, 0, 1, -1, -1, 0 ], [ 1, 0, 2, -1, 0, 0 ], [ 0, 1, 2, -1, 0, -1 ], [ 0, 1, 2, -1, 0, 0 ] ], 1.25 ] - ], - [ - [ [ [ 0, 1, 2, -1, 0, -2 ], [ 1, 0, 2, -1, 0, 0 ], [ 0, 1, 2, -1, 0, -1 ], [ 0, 1, 2, -1, 0, 0 ] ], 2.875 ] - ], - [ - [ [ [ 0, 1, 2, -1, 0, -2 ], [ 1, 1, 2, -1, 0, -1 ], [ 0, 1, 2, -1, 0, -1 ], [ 0, 1, 2, -1, 0, 0 ] ], 2.5 ] - ], - [ - [ [ [ 0, 1, 2, -1, 0, -2 ], [ 1, 1, 2, -1, 0, -1 ], [ 0, 1, 2, -1, 0, -1 ], [ 2, 1, 2, -1, 0, -3 ] ], 1.875 ] - ], - [ - [ [ [ 0, 1, 2, -1, 0, -2 ], [ 3, 1, 2, -1, 0, -4 ], [ 0, 1, 2, -1, 0, -1 ], [ 2, 1, 2, -1, 0, -3 ] ], 1.375 ] - ], - [ - [ [ [ 0, 1, 2, -2, 0, -1 ], [ 3, 1, 2, -1, 0, -4 ], [ 0, 1, 2, -1, 0, -1 ], [ 2, 1, 2, -1, 0, -3 ] ], 2.25 ] - ], - [ - [ [ [ 0, 1, 2, -2, 0, -1 ], [ 3, 1, 2, -1, 0, -4 ], [ 0, 1, 2, -1, 0, -1 ], [ 2, 2, 2, -1, 0, -4 ] ], 2 ] - ], - [ - [ [ [ 0, 1, 2, -2, 0, -1 ], [ 3, 1, 2, -1, 0, -4 ], [ 0, 1, 2, -1, 0, -1 ], [ 2, 1, 2, -3, 0, -1 ] ], 2 ] - ], - [ - [ [ [ 0, 1, 2, -2, 0, -1 ], [ 3, 1, 2, -1, 0, -4 ], [ 0, 1, 2, -1, 0, -1 ], [ 0, 1, 3, -1, 0, -1 ] ], 2 ] - ], - [ - [ [ [ 0, 1, 2, -2, 0, -1 ], [ 1, 2, 2, -2, 0, -1 ], [ 0, 1, 2, -1, 0, -1 ], [ 0, 1, 3, -1, 0, -1 ] ], 0 ], - [ [ [ 0, 1, 2, -2, 0, -1 ], [ 1, 2, 2, -2, 0, -1 ], [ 2, 1, 2, -3, 0, -1 ], [ 0, 1, 3, -1, 0, -1 ] ], 0 ], - [ [ [ 0, 1, 2, -2, 0, -1 ], [ 1, 2, 2, -2, 0, -1 ], [ 2, 1, 2, -3, 0, -1 ], [ 2, 1, 1, -2, 0, -1 ] ], 2.625 ], - [ [ [ 0, 1, 2, -2, 0, -1 ], [ 2, 1, 2, -2, -1, -1 ], [ 2, 1, 2, -3, 0, -1 ], [ 2, 1, 1, -2, 0, -1 ] ], 0 ], - [ [ [ 0, 1, 2, -2, 0, -1 ], [ 2, 1, 2, -2, -1, -1 ], [ 1, 1, 2, -1, 0, -1 ], [ 2, 1, 1, -2, 0, -1 ] ], 0 ], - [ [ [ 0, 1, 2, -2, 0, -1 ], [ 2, 1, 2, -2, -1, -1 ], [ 1, 1, 2, -1, 0, -1 ], [ 3, 1, 2, -3, 0, -1 ] ], 1.625 ], - [ [ [ 0, 1, 2, -2, 0, -1 ], [ 1, 1, 2, -2, 1, -1 ], [ 1, 1, 2, -1, 0, -1 ], [ 3, 1, 2, -3, 0, -1 ] ], 0 ], - [ [ [ 0, 1, 2, -2, 0, -1 ], [ 1, 1, 2, -2, 1, -1 ], [ 1, 1, 2, -2, 0, 0 ], [ 3, 1, 2, -3, 0, -1 ] ], 0 ], - [ [ [ 0, 1, 2, -2, 0, -1 ], [ 1, 1, 2, -2, 1, -1 ], [ 1, 1, 2, -2, 0, 0 ], [ 1, 1, 3, -2, 0, -1 ] ], 1.75 ], - [ [ [ 0, 1, 2, -2, 0, -1 ], [ 2, 0, 2, -2, 0, -1 ], [ 1, 1, 2, -2, 0, 0 ], [ 1, 1, 3, -2, 0, -1 ] ], 0 ], - [ [ [ 0, 1, 2, -2, 0, -1 ], [ 2, 0, 2, -2, 0, -1 ], [ 1, 2, 2, -2, 0, -1 ], [ 1, 1, 3, -2, 0, -1 ] ], 0 ], - [ [ [ 0, 1, 2, -2, 0, -1 ], [ 2, 0, 2, -2, 0, -1 ], [ 1, 2, 2, -2, 0, -1 ], [ 2, 1, 2, -2, 0, -2 ] ], 1.375 ] - ], - [ - [ [ [ 0, 1, 2, -2, 0, -1 ], [ 0, 2, 2, -1, 0, -1 ], [ 1, 2, 2, -2, 0, -1 ], [ 2, 1, 2, -2, 0, -2 ] ], 1.625 ], - [ [ [ 0, 1, 2, -2, 0, -1 ], [ 0, 2, 2, -2, 0, 0 ], [ 1, 2, 2, -2, 0, -1 ], [ 2, 1, 2, -2, 0, -2 ] ], 1.625 ] - ], - [ - [ [ [ 0, 1, 2, -2, 0, -1 ], [ 2, 1, 2, -3, 0, -1 ], [ 1, 2, 2, -2, 0, -1 ], [ 2, 1, 2, -2, 0, -2 ] ], 0 ], - [ [ [ 0, 1, 2, -2, 0, -1 ], [ 2, 1, 2, -3, 0, -1 ], [ 2, 1, 2, -2, -1, -1 ], [ 2, 1, 2, -2, 0, -2 ] ], 0 ], - [ [ [ 0, 1, 2, -2, 0, -1 ], [ 2, 1, 2, -3, 0, -1 ], [ 2, 1, 2, -2, -1, -1 ], [ 3, 1, 2, -2, 0, -2 ] ], 2.625 ], - [ [ [ 0, 1, 2, -2, 0, -1 ], [ 0, 2, 2, -2, 0, -1 ], [ 2, 1, 2, -2, -1, -1 ], [ 3, 1, 2, -2, 0, -2 ] ], 0 ], - [ [ [ 0, 1, 2, -2, 0, -1 ], [ 0, 2, 2, -2, 0, -1 ], [ 1, 1, 2, -2, 1, -1 ], [ 3, 1, 2, -2, 0, -2 ] ], 0 ], - [ [ [ 0, 1, 2, -2, 0, -1 ], [ 0, 2, 2, -2, 0, -1 ], [ 1, 1, 2, -2, 1, -1 ], [ 3, 1, 2, -3, 0, -1 ] ], 2.125 ], - [ [ [ 0, 1, 2, -2, 0, -1 ], [ 1, 1, 2, -2, -1, -1 ], [ 1, 1, 2, -2, 1, -1 ], [ 3, 1, 2, -3, 0, -1 ] ], 0 ], - [ [ [ 0, 1, 2, -2, 0, -1 ], [ 1, 1, 2, -2, -1, -1 ], [ 2, 0, 2, -2, 0, -1 ], [ 3, 1, 2, -3, 0, -1 ] ], 0 ], - [ [ [ 0, 1, 2, -2, 0, -1 ], [ 1, 1, 2, -2, -1, -1 ], [ 2, 0, 2, -2, 0, -1 ], [ 2, 1, 2, -2, 0, -1 ] ], 1.5 ], - [ [ [ 0, 1, 2, -2, 0, -1 ], [ 1, 1, 2, -2, 0, -1 ], [ 2, 0, 2, -2, 0, -1 ], [ 2, 1, 2, -2, 0, -1 ] ], 0 ], - [ [ [ 0, 1, 2, -2, 0, -1 ], [ 1, 1, 2, -2, 0, -1 ], [ 1, 1, 3, -2, 0, -1 ], [ 2, 1, 2, -2, 0, -1 ] ], 0 ], - [ [ [ 0, 1, 2, -2, 0, -1 ], [ 1, 1, 2, -2, 0, -1 ], [ 1, 1, 3, -2, 0, -1 ], [ 2, 1, 3, -2, 0, -1 ] ], 2.25 ], - [ [ [ 0, 1, 2, -2, 0, -1 ], [ 1, 1, 2, -2, 0, -1 ], [ "Rest" ], [ 2, 1, 3, -2, 0, -1 ] ], 0 ], - [ [ [ 0, 1, 2, -2, 0, -1 ], [ 1, 1, 2, -2, 0, -1 ], [ "Rest" ], [ "Rest" ] ], 0 ], - [ [ [ 0, 1, 2, -2, 0, -1 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 0 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 7.0 ] - ] - ] -], -"last_changes": -[ - [ [ 0, 1, 2, -2, 0, -1 ], [ 1, 1, 2, -2, -1, -1 ], [ 2, 0, 2, -2, 0, -1 ], [ 3, 1, 2, -3, 0, -1 ] ], - [ [ 0, 1, 2, -2, 0, -1 ], [ 1, 1, 2, -2, -1, -1 ], [ 2, 0, 2, -2, 0, -1 ], [ 2, 1, 2, -2, 0, -1 ] ], - [ [ 0, 1, 2, -2, 0, -1 ], [ 1, 1, 2, -2, 0, -1 ], [ 2, 0, 2, -2, 0, -1 ], [ 2, 1, 2, -2, 0, -1 ] ], - [ [ 0, 1, 2, -2, 0, -1 ], [ 1, 1, 2, -2, 0, -1 ], [ 1, 1, 3, -2, 0, -1 ], [ 2, 1, 2, -2, 0, -1 ] ], - [ [ 0, 1, 2, -2, 0, -1 ], [ 1, 1, 2, -2, 0, -1 ], [ 1, 1, 3, -2, 0, -1 ], [ 2, 1, 3, -2, 0, -1 ] ] -], -"cur_uid": "577cf188", -"ref_uid": "nil", -"order_seed": 755225, -"dur_seed": 543380, -"motifs_seed": 119394, -"entrances_probs_vals": [ 1, 0, 0, 1.1263736263736, 2.83, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 1, 0, 0, 1.1263736263736, 2.83, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 1, 0, 0, 1.1263736263736, 2.83, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -1315, 1582.6625386997 ], [ -702.16718266254, 1453 ], [ -386, 1676 ], [ -219, 1694 ] ], -"step_probs_vals": [ 0, 1200, 0, 0, 0.063786008230453, 0.92613636363636, 0.12757201646091, 0, 0.54732510288066, 0, 0.71604938271605, 0, 1, 0 ], -"passages_weights": [ 1, 1, 0.66, 0.74, 1 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 3, 1, 2 ], [ 0 ], [ ] ], - [ [ 3, 1, 2 ], [ 0 ], [ ] ], - [ [ 0, 2, 3 ], [ 1 ], [ ] ], - [ [ 2, 3, 1 ], [ 0 ], [ ] ], - [ [ 1, 2, 3 ], [ 0 ], [ ] ], - [ [ 3, 2, 0 ], [ 1 ], [ ] ], - [ [ 2, 3, 0 ], [ 1 ], [ ] ], - [ [ 1, 2, 0 ], [ 3 ], [ ] ], - [ [ 1, 0, 2 ], [ 3 ], [ ] ], - [ [ 2, 1, 3 ], [ 0 ], [ ] ], - [ [ 2, 1, 3 ], [ 0 ], [ ] ], - [ [ 3, 1, 0 ], [ 2 ], [ ] ], - [ [ 1, 3, 0 ], [ 2 ], [ ] ], - [ [ 3, 2, 1 ], [ 0 ], [ ] ], - [ [ 2, 0, 3 ], [ 1 ], [ ] ], - [ [ 0, 2, 3 ], [ 1 ], [ ] ], - [ [ 1, 0, 2 ], [ 3 ], [ ] ], - [ [ 3, 2, 0 ], [ 1 ], [ ] ], - [ [ 3, 1, 0 ], [ 2 ], [ ] ], - [ [ 1, 0, 2 ], [ 3 ], [ ] ], - [ [ 0, 1, 3 ], [ 2 ], [ ] ], - [ [ 1, 0, 3 ], [ 2 ], [ ] ], - [ [ 3, 1, 2 ], [ 0 ], [ ] ], - [ [ 0, 2, 3 ], [ 1 ], [ ] ], - [ [ 1, 0, 2 ], [ 3 ], [ ] ], - [ [ 2, 3, 0 ], [ 1 ], [ ] ], - [ [ 2, 1, 3 ], [ 0 ], [ ] ], - [ [ 1, 0, 2 ], [ 3 ], [ ] ], - [ [ 1, 0, 2 ], [ 3 ], [ ] ], - [ [ 0, 2, 1 ], [ 3 ], [ ] ], - [ [ 0 ], [ 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3 ], [ ] ], - [ [ 3, 2, 1 ], [ 1 ], [ ] ], - [ [ 0 ], [ 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3 ], [ ] ] -], -"sus_weights": [ 0, 0, 0.51 ], -"order_size": [ 30, 30 ], -"passages_size": [ 0, 0 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3/5ec14635/5ec14635_code.scd b/resources/resources_bak_2024_01_03/string_quartet_3/5ec14635/5ec14635_code.scd deleted file mode 100644 index f822edb..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3/5ec14635/5ec14635_code.scd +++ /dev/null @@ -1,946 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = true; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - if(pDistance < 0, {stepFunc.value(abs(pDistance))}, {0.001}); - //stepFunc.value(pDistance) -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_3/5ec14635/5ec14635_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_3/5ec14635/5ec14635_mus_model.json deleted file mode 100644 index c4309f6..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3/5ec14635/5ec14635_mus_model.json +++ /dev/null @@ -1,163 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ "Rest" ], [ -2, -1, 0, 0, 0, -1 ], [ "Rest" ] ], 0.375 ], - [ [ [ "Rest" ], [ -2, -2, 0, 1, 0, -2 ], [ -2, -1, 0, 0, 0, -1 ], [ "Rest" ] ], 0 ], - [ [ [ -2, -1, 0, 1, 0, -2 ], [ -2, -2, 0, 1, 0, -2 ], [ -2, -1, 0, 0, 0, -1 ], [ "Rest" ] ], 0.5 ], - [ [ [ -2, -1, 0, 1, 0, -2 ], [ -2, -2, 0, 1, 0, -2 ], [ -2, -1, 0, 0, 0, -1 ], [ 1, -2, 0, 2, 0, -2 ] ], 0.125 ] - ], - [ - [ [ [ -2, -1, 0, 1, 0, -2 ], [ -2, -2, 0, 1, 0, -2 ], [ 0, 0, 0, 1, 0, -2 ], [ 1, -2, 0, 2, 0, -2 ] ], 1 ] - ], - [ - [ [ [ -2, -1, 0, 1, 0, -2 ], [ -2, -2, 0, 1, 0, -2 ], [ 0, 0, 0, 1, 0, -2 ], [ 0, 0, 0, 1, 0, -1 ] ], 1.125 ] - ], - [ - [ [ [ -2, -1, 0, 1, 0, -2 ], [ -1, 1, 0, 1, 0, -1 ], [ 0, 0, 0, 1, 0, -2 ], [ 0, 0, 0, 1, 0, -1 ] ], 1.125 ] - ], - [ - [ [ [ -2, -1, 0, 1, 0, -2 ], [ 0, 0, 1, 1, 0, -2 ], [ 0, 0, 0, 1, 0, -2 ], [ 0, 0, 0, 1, 0, -1 ] ], 0.125 ] - ], - [ - [ [ [ -2, -1, 0, 1, 0, -2 ], [ 0, 0, 1, 1, 0, -2 ], [ -1, 0, 1, 1, 0, -1 ], [ 0, 0, 0, 1, 0, -1 ] ], 0.75 ] - ], - [ - [ [ [ -2, -1, 0, 1, 0, -2 ], [ 0, 0, 1, 1, 0, -2 ], [ -1, 0, 1, 2, 0, -2 ], [ 0, 0, 0, 1, 0, -1 ] ], 0.75 ] - ], - [ - [ [ [ -2, -1, 0, 1, 0, -2 ], [ 0, 0, 1, 1, 0, -2 ], [ 0, -1, 0, 2, 0, -2 ], [ 0, 0, 0, 1, 0, -1 ] ], 0 ] - ], - [ - [ [ [ -2, -1, 0, 1, 0, -2 ], [ 0, 0, 1, 1, 0, -2 ], [ -1, 1, 0, 1, 0, -1 ], [ 0, 0, 0, 1, 0, -1 ] ], 0.625 ] - ], - [ - [ [ [ -2, -1, 0, 1, 0, -2 ], [ 0, 0, 1, 1, 0, -2 ], [ -1, 1, 0, 1, 0, -1 ], [ 0, 0, 1, 1, 1, -2 ] ], 1.125 ] - ], - [ - [ [ [ -2, -1, 0, 1, 0, -2 ], [ 0, 0, 1, 1, 0, -2 ], [ -1, 1, 1, 1, 1, -2 ], [ 0, 0, 1, 1, 1, -2 ] ], 1 ] - ], - [ - [ [ [ -2, -1, 0, 1, 0, -2 ], [ 0, 0, 1, 1, 0, -2 ], [ -1, 1, 1, 1, 1, -2 ], [ 1, -1, 0, 1, 1, -2 ] ], 0.625 ] - ], - [ - [ [ [ -2, -1, 0, 1, 0, -2 ], [ 1, -1, 0, 1, 0, -2 ], [ -1, 1, 1, 1, 1, -2 ], [ 1, -1, 0, 1, 1, -2 ] ], 0.75 ] - ], - [ - [ [ [ -1, -1, 0, 2, 1, -2 ], [ 1, -1, 0, 1, 0, -2 ], [ -1, 1, 1, 1, 1, -2 ], [ 1, -1, 0, 1, 1, -2 ] ], 1.125 ] - ], - [ - [ [ [ -1, 0, 1, 1, 1, -2 ], [ 1, -1, 0, 1, 0, -2 ], [ -1, 1, 1, 1, 1, -2 ], [ 1, -1, 0, 1, 1, -2 ] ], 0.25 ] - ], - [ - [ [ [ -1, 0, 1, 1, 1, -2 ], [ -1, 0, 1, 1, 1, -1 ], [ -1, 1, 1, 1, 1, -2 ], [ 1, -1, 0, 1, 1, -2 ] ], 0.25 ] - ], - [ - [ [ [ -1, 0, 1, 1, 1, -2 ], [ -1, 0, 1, 2, 1, -2 ], [ -1, 1, 1, 1, 1, -2 ], [ 1, -1, 0, 1, 1, -2 ] ], 1.125 ] - ], - [ - [ [ [ -1, 0, 1, 1, 1, -2 ], [ -1, 0, 1, 2, 1, -2 ], [ -2, 0, 1, 3, 1, -2 ], [ 1, -1, 0, 1, 1, -2 ] ], 1.125 ] - ], - [ - [ [ [ -1, 0, 1, 1, 1, -2 ], [ -1, 0, 1, 2, 1, -2 ], [ -2, 0, 1, 3, 1, -2 ], [ -1, 0, 1, 3, 0, -2 ] ], 1 ] - ], - [ - [ [ [ -1, 0, 1, 1, 1, -2 ], [ -1, 0, 1, 2, 1, -2 ], [ -2, 0, 1, 3, 1, -2 ], [ 0, -1, 1, 2, 1, -2 ] ], 0.25 ] - ], - [ - [ [ [ -1, 0, 1, 2, 1, -3 ], [ -1, 0, 1, 2, 1, -2 ], [ -2, 0, 1, 3, 1, -2 ], [ 0, -1, 1, 2, 1, -2 ] ], 0.25 ] - ], - [ - [ [ [ -3, 1, 1, 3, 1, -2 ], [ -1, 0, 1, 2, 1, -2 ], [ -2, 0, 1, 3, 1, -2 ], [ 0, -1, 1, 2, 1, -2 ] ], 0 ] - ], - [ - [ [ [ -2, 0, 1, 2, 2, -2 ], [ -1, 0, 1, 2, 1, -2 ], [ -2, 0, 1, 3, 1, -2 ], [ 0, -1, 1, 2, 1, -2 ] ], 1 ] - ], - [ - [ [ [ -2, 0, 1, 2, 2, -2 ], [ -1, 0, 1, 2, 1, -2 ], [ -2, 0, 1, 3, 1, -2 ], [ -1, 0, 0, 3, 1, -2 ] ], 0.75 ] - ], - [ - [ [ [ -2, 0, 1, 2, 2, -2 ], [ -1, 0, 1, 2, 1, -2 ], [ -1, -1, 1, 2, 2, -2 ], [ -1, 0, 0, 3, 1, -2 ] ], 0.625 ] - ], - [ - [ [ [ -1, 0, 1, 2, 0, -2 ], [ -1, 0, 1, 2, 1, -2 ], [ -1, -1, 1, 2, 2, -2 ], [ -1, 0, 0, 3, 1, -2 ] ], 0.125 ] - ], - [ - [ [ [ -1, 0, 1, 2, 0, -2 ], [ -1, 0, 1, 2, 1, -2 ], [ -1, -1, 0, 3, 1, -2 ], [ -1, 0, 0, 3, 1, -2 ] ], 0.75 ] - ], - [ - [ [ [ -1, 0, 1, 2, 0, -2 ], [ 0, 0, 1, 2, -1, -2 ], [ -1, -1, 0, 3, 1, -2 ], [ -1, 0, 0, 3, 1, -2 ] ], 0.25 ] - ], - [ - [ [ [ -1, 0, 1, 2, 0, -2 ], [ 0, -1, 0, 2, 1, -2 ], [ -1, -1, 0, 3, 1, -2 ], [ -1, 0, 0, 3, 1, -2 ] ], 1.25 ] - ], - [ - [ [ [ -1, 0, 1, 2, 0, -2 ], [ 0, -1, 0, 2, 1, -2 ], [ -1, -1, 0, 3, 1, -2 ], [ 0, -1, 0, 2, 2, -2 ] ], 0.625 ], - [ [ [ "Rest" ], [ 0, -1, 0, 2, 1, -2 ], [ -1, -1, 0, 3, 1, -2 ], [ 0, -1, 0, 2, 2, -2 ] ], 0.625 ], - [ [ [ "Rest" ], [ 0, -1, 0, 2, 1, -2 ], [ -1, -1, 0, 3, 1, -2 ], [ "Rest" ] ], 0.375 ], - [ [ [ "Rest" ], [ "Rest" ], [ -1, -1, 0, 3, 1, -2 ], [ "Rest" ] ], 0.875 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 1.375 ] - ] - ] -], -"last_changes": -[ - [ [ -1, 0, 1, 2, 0, -2 ], [ -1, 0, 1, 2, 1, -2 ], [ -1, -1, 1, 2, 2, -2 ], [ -1, 0, 0, 3, 1, -2 ] ], - [ [ -1, 0, 1, 2, 0, -2 ], [ -1, 0, 1, 2, 1, -2 ], [ -1, -1, 0, 3, 1, -2 ], [ -1, 0, 0, 3, 1, -2 ] ], - [ [ -1, 0, 1, 2, 0, -2 ], [ 0, 0, 1, 2, -1, -2 ], [ -1, -1, 0, 3, 1, -2 ], [ -1, 0, 0, 3, 1, -2 ] ], - [ [ -1, 0, 1, 2, 0, -2 ], [ 0, -1, 0, 2, 1, -2 ], [ -1, -1, 0, 3, 1, -2 ], [ -1, 0, 0, 3, 1, -2 ] ], - [ [ -1, 0, 1, 2, 0, -2 ], [ 0, -1, 0, 2, 1, -2 ], [ -1, -1, 0, 3, 1, -2 ], [ 0, -1, 0, 2, 2, -2 ] ] -], -"cur_uid": "5ec14635", -"ref_uid": "7c2de94c", -"order_seed": 733231, -"dur_seed": 711733, -"motifs_seed": 934821, -"entrances_probs_vals": [ 0, 0, 0, 0, 1.2087912087912, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 0, 0, 0, 0, 1.2087912087912, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 0, 0, 0, 0, 1.2087912087912, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -2170, 338 ], [ -2373.9938080495, 1453 ], [ -1650, 1676 ], [ -1370.8978328173, 1694 ] ], -"step_probs_vals": [ 0, 1200, 0, 0, 0.063786008230453, 0.92613636363636, 0.12757201646091, 0, 0.54732510288066, 0, 0.71604938271605, 0, 1, 0 ], -"passages_weights": [ 1, 0, 0.2, 0.74, 0.68 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 2, 1, 0 ], [ 3 ], [ ] ], - [ [ 1, 3, 0 ], [ 2 ], [ ] ], - [ [ 2, 1, 0 ], [ 3 ], [ ] ], - [ [ 0, 2, 3 ], [ 1 ], [ ] ], - [ [ 2, 3, 0 ], [ 1 ], [ ] ], - [ [ 3, 0, 1 ], [ 2 ], [ ] ], - [ [ 3, 0, 1 ], [ 2 ], [ ] ], - [ [ 3, 1, 0 ], [ 2 ], [ ] ], - [ [ 1, 0, 3 ], [ 2 ], [ ] ], - [ [ 0, 1, 2 ], [ 3 ], [ ] ], - [ [ 1, 0, 3 ], [ 2 ], [ ] ], - [ [ 0, 2, 1 ], [ 3 ], [ ] ], - [ [ 0, 2, 3 ], [ 1 ], [ ] ], - [ [ 3, 1, 2 ], [ 0 ], [ ] ], - [ [ 2, 3, 1 ], [ 0 ], [ ] ], - [ [ 0, 3, 2 ], [ 1 ], [ ] ], - [ [ 3, 2, 0 ], [ 1 ], [ ] ], - [ [ 0, 1, 3 ], [ 2 ], [ ] ], - [ [ 1, 0, 2 ], [ 3 ], [ ] ], - [ [ 2, 1, 0 ], [ 3 ], [ ] ], - [ [ 3, 1, 2 ], [ 0 ], [ ] ], - [ [ 2, 3, 1 ], [ 0 ], [ ] ], - [ [ 3, 1, 2 ], [ 0 ], [ ] ], - [ [ 2, 1, 0 ], [ 3 ], [ ] ], - [ [ 0, 1, 3 ], [ 2 ], [ ] ], - [ [ 1, 3, 2 ], [ 0 ], [ ] ], - [ [ 1, 3, 0 ], [ 2 ], [ ] ], - [ [ 2, 0, 3 ], [ 1 ], [ ] ], - [ [ 3, 0, 2 ], [ 1 ], [ ] ], - [ [ 0, 1, 2 ], [ 3 ], [ ] ] -], -"sus_weights": [ 0, 0, 0.61 ], -"order_size": [ 30, 30 ], -"passages_size": [ 0, 0 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3/69c568c6/69c568c6_code.scd b/resources/resources_bak_2024_01_03/string_quartet_3/69c568c6/69c568c6_code.scd deleted file mode 100644 index a40da01..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3/69c568c6/69c568c6_code.scd +++ /dev/null @@ -1,973 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array2) - hsArrayToCents.value(array1); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -/* -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance) -}; -*/ - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = true; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - //if(pDistance >= 0, {stepFunc.value(abs(pDistance))}, {0.01}); - stepFunc.value(pDistance) -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - //tuples = dims.collect({[0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum == 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength.asInteger - minMotifLength.asInteger).rand + minMotifLength.asInteger).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - //noProgIns = (popSize - noSusIns).rand + 1; - noProgIns = (popSize - noSusIns); - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength.asInteger - minProgLength.asInteger).rand + minProgLength.asInteger).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0.01); - - - - if(rangeScore.value(candidate.collect({0}), voices[ins], ranges[ins][1] - 500, ranges[ins][1], 0, true) == 1, { - isInRangeScore = 1 - rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0] + 500, ranges[ins][1] - 500, 0, true); - isInRangeScore = isInRangeScore * rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true) - }, { - isInRangeScore = rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true); - }); - - - //isInRangeScore = rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true); - //old way - worked but actually by accident (I think) - //isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - - - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_3/69c568c6/69c568c6_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_3/69c568c6/69c568c6_mus_model.json deleted file mode 100644 index a490727..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3/69c568c6/69c568c6_mus_model.json +++ /dev/null @@ -1,535 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ] ], 1.625 ], - [ [ [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ] ], 1 ], - [ [ [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 1.125 ], - [ [ [ 1, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ 1, 0, 0, 0, 0, 0 ], [ -1, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 0.625 ], - [ [ [ 1, 0, 0, 0, 0, 0 ], [ -1, 0, 0, 0, 0, 0 ], [ -1, 1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 0.75 ] - ], - [ - [ [ [ 1, 0, 0, 0, 0, 0 ], [ -1, 0, 0, 0, 0, 0 ], [ -1, 1, 0, 0, 0, 0 ], [ -1, 2, 0, 0, 0, 0 ] ], 1.25 ] - ], - [ - [ [ [ 1, 0, 0, 0, 0, 0 ], [ -2, 2, 0, 0, 0, 0 ], [ -1, 1, 0, 0, 0, 0 ], [ -1, 2, 0, 0, 0, 0 ] ], 1.625 ] - ], - [ - [ [ [ 0, 1, 0, 0, 0, 0 ], [ -2, 2, 0, 0, 0, 0 ], [ -1, 1, 0, 0, 0, 0 ], [ -1, 2, 0, 0, 0, 0 ] ], 0.75 ] - ], - [ - [ [ [ 0, 1, 0, 0, 0, 0 ], [ -1, 1, -1, 0, 0, 0 ], [ -1, 1, 0, 0, 0, 0 ], [ -1, 2, 0, 0, 0, 0 ] ], 1.125 ], - [ [ [ 0, 1, 0, 0, 0, 0 ], [ -1, 1, -1, 0, 0, 0 ], [ -1, 1, 0, 0, 0, 0 ], [ 0, 1, -1, 0, 0, 0 ] ], 1.125 ] - ], - [ - [ [ [ 1, 0, -1, 0, 0, 0 ], [ -1, 1, -1, 0, 0, 0 ], [ -1, 1, 0, 0, 0, 0 ], [ 0, 1, -1, 0, 0, 0 ] ], 0.5 ], - [ [ [ 1, 0, -1, 0, 0, 0 ], [ -1, 1, -1, 0, 0, 0 ], [ 0, 0, -1, 0, 0, 0 ], [ 0, 1, -1, 0, 0, 0 ] ], 0.875 ], - [ [ [ 1, 0, -1, 0, 0, 0 ], [ -1, 1, -1, 0, 0, 0 ], [ 0, 0, -1, 0, 0, 0 ], [ 1, 1, -1, -1, 0, 0 ] ], 1.5 ] - ], - [ - [ [ [ 1, 0, -1, 0, 0, 0 ], [ -1, 1, -1, 0, 0, 0 ], [ -1, 2, -1, 0, 0, 0 ], [ 1, 1, -1, -1, 0, 0 ] ], 1 ], - [ [ [ 0, 2, -1, 0, 0, 0 ], [ -1, 1, -1, 0, 0, 0 ], [ -1, 2, -1, 0, 0, 0 ], [ 1, 1, -1, -1, 0, 0 ] ], 0.875 ] - ], - [ - [ [ [ 0, 2, -1, 0, 0, 0 ], [ 0, 1, -1, -1, 0, 0 ], [ -1, 2, -1, 0, 0, 0 ], [ 1, 1, -1, -1, 0, 0 ] ], 1.375 ], - [ [ [ -2, 2, -1, -1, 0, 0 ], [ 0, 1, -1, -1, 0, 0 ], [ -1, 2, -1, 0, 0, 0 ], [ 1, 1, -1, -1, 0, 0 ] ], 0.875 ], - [ [ [ -2, 2, -1, -1, 0, 0 ], [ 0, 1, -1, -1, 0, 0 ], [ 0, 2, -1, -1, 0, 0 ], [ 1, 1, -1, -1, 0, 0 ] ], 0.5 ] - ], - [ - [ [ [ -2, 2, -1, -1, 0, 0 ], [ 0, 1, -1, -1, 0, 0 ], [ 0, 1, 0, -1, 0, 0 ], [ 1, 1, -1, -1, 0, 0 ] ], 1.75 ], - [ [ [ -2, 1, -1, -1, 0, 1 ], [ 0, 1, -1, -1, 0, 0 ], [ 0, 1, 0, -1, 0, 0 ], [ 1, 1, -1, -1, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 1, -1, -1, 0, 1 ], [ 1, 1, -1, -2, 0, 0 ], [ 0, 1, 0, -1, 0, 0 ], [ 1, 1, -1, -1, 0, 0 ] ], 1.25 ] - ], - [ - [ [ [ -2, 1, -1, -1, 0, 1 ], [ 1, 1, -1, -2, 0, 0 ], [ 1, 0, -1, -1, 0, 0 ], [ 1, 1, -1, -1, 0, 0 ] ], 0.625 ], - [ [ [ -2, 1, -1, -1, 0, 1 ], [ -1, 2, -1, -1, 0, 1 ], [ 1, 0, -1, -1, 0, 0 ], [ 1, 1, -1, -1, 0, 0 ] ], 0.875 ] - ], - [ - [ [ [ -2, 1, -1, -1, 0, 1 ], [ 0, 1, -2, -1, 0, 1 ], [ 1, 0, -1, -1, 0, 0 ], [ 1, 1, -1, -1, 0, 0 ] ], 1.25 ] - ], - [ - [ [ [ -2, 1, -1, -1, 0, 1 ], [ 1, 1, -1, -1, -1, 0 ], [ 1, 0, -1, -1, 0, 0 ], [ 1, 1, -1, -1, 0, 0 ] ], 0.75 ], - [ [ [ -2, 1, -1, -1, 0, 1 ], [ 1, 1, -1, -1, -1, 0 ], [ 0, 2, -1, -1, 0, 0 ], [ 1, 1, -1, -1, 0, 0 ] ], 0.875 ] - ], - [ - [ [ [ -1, 2, -1, -2, 0, 0 ], [ 1, 1, -1, -1, -1, 0 ], [ 0, 2, -1, -1, 0, 0 ], [ 1, 1, -1, -1, 0, 0 ] ], 1.625 ] - ], - [ - [ [ [ -1, 2, -1, -2, 0, 0 ], [ -1, 2, -1, -1, 0, 0 ], [ 0, 2, -1, -1, 0, 0 ], [ 1, 1, -1, -1, 0, 0 ] ], 1.375 ] - ], - [ - [ [ [ -1, 2, -1, -2, 0, 0 ], [ -1, 2, -1, -1, 0, 0 ], [ 1, 2, -1, -2, 0, 0 ], [ 1, 1, -1, -1, 0, 0 ] ], 1.125 ], - [ [ [ -1, 2, -1, -2, 0, 0 ], [ -1, 2, -1, -1, 0, 0 ], [ 1, 2, -1, -2, 0, 0 ], [ 0, 2, -1, -1, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -1, 2, -1, -2, 0, 0 ], [ 0, 2, -1, -2, 0, 0 ], [ 1, 2, -1, -2, 0, 0 ], [ 0, 2, -1, -1, 0, 0 ] ], 1.625 ], - [ [ [ -1, 2, -1, -2, 0, 0 ], [ 0, 2, -1, -2, 0, 0 ], [ 0, 2, 0, -1, 0, 0 ], [ 0, 2, -1, -1, 0, 0 ] ], 0.75 ] - ], - [ - [ [ [ -1, 2, -1, -2, 0, 0 ], [ -1, 2, 0, -1, 0, 0 ], [ 0, 2, 0, -1, 0, 0 ], [ 0, 2, -1, -1, 0, 0 ] ], 1.375 ], - [ [ [ -1, 2, -1, -2, 0, 0 ], [ -1, 2, 0, -1, 0, 0 ], [ 1, 2, 0, -2, 0, 0 ], [ 0, 2, -1, -1, 0, 0 ] ], 1.75 ] - ], - [ - [ [ [ -1, 2, -1, -2, 0, 0 ], [ -1, 2, 0, -1, 0, 0 ], [ 0, 2, -1, -2, 1, 0 ], [ 0, 2, -1, -1, 0, 0 ] ], 1 ], - [ [ [ -1, 2, -1, -2, 0, 0 ], [ 1, 2, -1, -2, 0, -1 ], [ 0, 2, -1, -2, 1, 0 ], [ 0, 2, -1, -1, 0, 0 ] ], 1.125 ], - [ [ [ -1, 2, -1, -2, 0, 0 ], [ 1, 2, -1, -2, 0, -1 ], [ 0, 2, -1, -2, 1, 0 ], [ 1, 2, -1, -2, 0, 0 ] ], 1.125 ] - ], - [ - [ [ [ -1, 2, -1, -2, 0, 0 ], [ 1, 2, -1, -2, 0, -1 ], [ 0, 3, -1, -2, 0, 0 ], [ 1, 2, -1, -2, 0, 0 ] ], 1.375 ], - [ [ [ -1, 2, -1, -2, 0, 0 ], [ 1, 2, -1, -2, 0, -1 ], [ 0, 3, -1, -2, 0, 0 ], [ 1, 2, -1, -1, 0, -1 ] ], 1.125 ] - ], - [ - [ [ [ -1, 2, -1, -2, 0, 0 ], [ 1, 2, -1, -2, 0, -1 ], [ 0, 3, -1, -2, 0, 0 ], [ 1, 3, -2, -2, 0, 0 ] ], 0.75 ], - [ [ [ -1, 2, -1, -2, 0, 0 ], [ -1, 3, -1, -1, 0, 0 ], [ 0, 3, -1, -2, 0, 0 ], [ 1, 3, -2, -2, 0, 0 ] ], 1.5 ], - [ [ [ -1, 3, -1, -2, 0, 0 ], [ -1, 3, -1, -1, 0, 0 ], [ 0, 3, -1, -2, 0, 0 ], [ 1, 3, -2, -2, 0, 0 ] ], 1 ] - ], - [ - [ [ [ 0, 2, -2, -2, 0, 0 ], [ -1, 3, -1, -1, 0, 0 ], [ 0, 3, -1, -2, 0, 0 ], [ 1, 3, -2, -2, 0, 0 ] ], 1.75 ] - ], - [ - [ [ [ 0, 2, -2, -2, 0, 0 ], [ -1, 3, -1, -1, 0, 0 ], [ 1, 2, -2, -2, 0, 0 ], [ 1, 3, -2, -2, 0, 0 ] ], 1.375 ] - ], - [ - [ [ [ 0, 2, -2, -2, 0, 0 ], [ -1, 3, -1, -1, 0, 0 ], [ 0, 3, -2, -2, 0, 0 ], [ 1, 3, -2, -2, 0, 0 ] ], 1.625 ], - [ [ [ 0, 2, -2, -2, 0, 0 ], [ 0, 2, -2, -1, 0, 0 ], [ 0, 3, -2, -2, 0, 0 ], [ 1, 3, -2, -2, 0, 0 ] ], 1.75 ], - [ [ [ 0, 2, -2, -2, 0, 0 ], [ 0, 2, -2, -1, 0, 0 ], [ 0, 3, -2, -2, 0, 0 ], [ 1, 2, -2, -2, 0, 1 ] ], 1 ] - ], - [ - [ [ [ 0, 1, -2, -2, 0, 1 ], [ 0, 2, -2, -1, 0, 0 ], [ 0, 3, -2, -2, 0, 0 ], [ 1, 2, -2, -2, 0, 1 ] ], 1.875 ], - [ [ [ 0, 1, -2, -2, 0, 1 ], [ 0, 2, -1, -2, 0, 1 ], [ 0, 3, -2, -2, 0, 0 ], [ 1, 2, -2, -2, 0, 1 ] ], 0.5 ], - [ [ [ 0, 1, -2, -2, 0, 1 ], [ 0, 2, -1, -2, 0, 1 ], [ 0, 2, -2, -2, 0, 1 ], [ 1, 2, -2, -2, 0, 1 ] ], 0.875 ] - ], - [ - [ [ [ 0, 1, -2, -2, 0, 1 ], [ 0, 2, -1, -2, 0, 1 ], [ 0, 1, -2, -2, 0, 2 ], [ 1, 2, -2, -2, 0, 1 ] ], 1.375 ], - [ [ [ 0, 1, -2, -2, 0, 1 ], [ 0, 2, -1, -2, 0, 1 ], [ 0, 1, -2, -2, 0, 2 ], [ 1, 1, -2, -2, 0, 2 ] ], 0.625 ] - ], - [ - [ [ [ 0, 1, -2, -2, 0, 1 ], [ 0, 2, -1, -2, 0, 1 ], [ 0, 1, -2, -2, 0, 2 ], [ 1, 2, -1, -2, 0, 1 ] ], 0.625 ], - [ [ [ -1, 1, -1, -2, 0, 1 ], [ 0, 2, -1, -2, 0, 1 ], [ 0, 1, -2, -2, 0, 2 ], [ 1, 2, -1, -2, 0, 1 ] ], 0.5 ] - ], - [ - [ [ [ -1, 1, -1, -2, 0, 1 ], [ 1, 1, -2, -2, 0, 1 ], [ 0, 1, -2, -2, 0, 2 ], [ 1, 2, -1, -2, 0, 1 ] ], 0.75 ] - ], - [ - [ [ [ -1, 1, -1, -2, 0, 1 ], [ 1, 1, -2, -2, 0, 1 ], [ 0, 1, -1, -2, 1, 1 ], [ 1, 2, -1, -2, 0, 1 ] ], 0.875 ] - ], - [ - [ [ [ -1, 1, -1, -2, 0, 1 ], [ 1, 1, -2, -2, 0, 1 ], [ 0, 2, -1, -2, 0, 1 ], [ 1, 2, -1, -2, 0, 1 ] ], 1.5 ], - [ [ [ -2, 3, -1, -2, 0, 1 ], [ 1, 1, -2, -2, 0, 1 ], [ 0, 2, -1, -2, 0, 1 ], [ 1, 2, -1, -2, 0, 1 ] ], 1.125 ] - ], - [ - [ [ [ -1, 2, -2, -2, 0, 1 ], [ 1, 1, -2, -2, 0, 1 ], [ 0, 2, -1, -2, 0, 1 ], [ 1, 2, -1, -2, 0, 1 ] ], 0.625 ], - [ [ [ -1, 2, -2, -2, 0, 1 ], [ 1, 1, -2, -2, 0, 1 ], [ 0, 2, -1, -2, 0, 1 ], [ 1, 2, -2, -2, 0, 1 ] ], 1.75 ], - [ [ [ -1, 2, -2, -2, 0, 1 ], [ 1, 1, -2, -2, 0, 1 ], [ 0, 2, -2, -2, 0, 1 ], [ 1, 2, -2, -2, 0, 1 ] ], 0.625 ] - ], - [ - [ [ [ -1, 2, -2, -2, 0, 1 ], [ 1, 1, -2, -2, 0, 1 ], [ 1, 1, -3, -2, 0, 1 ], [ 1, 2, -2, -2, 0, 1 ] ], 0.625 ], - [ [ [ 0, 1, -3, -2, 0, 1 ], [ 1, 1, -2, -2, 0, 1 ], [ 1, 1, -3, -2, 0, 1 ], [ 1, 2, -2, -2, 0, 1 ] ], 1.25 ] - ], - [ - [ [ [ 0, 1, -3, -2, 0, 1 ], [ 1, 0, -3, -2, 0, 1 ], [ 1, 1, -3, -2, 0, 1 ], [ 1, 2, -2, -2, 0, 1 ] ], 1.375 ], - [ [ [ -1, 2, -3, -2, 0, 1 ], [ 1, 0, -3, -2, 0, 1 ], [ 1, 1, -3, -2, 0, 1 ], [ 1, 2, -2, -2, 0, 1 ] ], 0.5 ] - ], - [ - [ [ [ -1, 2, -3, -2, 0, 1 ], [ 0, 2, -3, -2, 0, 1 ], [ 1, 1, -3, -2, 0, 1 ], [ 1, 2, -2, -2, 0, 1 ] ], 1 ], - [ [ [ 0, 1, -4, -2, 0, 1 ], [ 0, 2, -3, -2, 0, 1 ], [ 1, 1, -3, -2, 0, 1 ], [ 1, 2, -2, -2, 0, 1 ] ], 1.5 ] - ], - [ - [ [ [ 0, 1, -4, -2, 0, 1 ], [ 1, 1, -4, -2, 0, 1 ], [ 1, 1, -3, -2, 0, 1 ], [ 1, 2, -2, -2, 0, 1 ] ], 1.75 ], - [ [ [ -2, 3, -2, -2, 0, 1 ], [ 1, 1, -4, -2, 0, 1 ], [ 1, 1, -3, -2, 0, 1 ], [ 1, 2, -2, -2, 0, 1 ] ], 1.625 ] - ], - [ - [ [ [ -2, 2, -2, -2, 0, 2 ], [ 1, 1, -4, -2, 0, 1 ], [ 1, 1, -3, -2, 0, 1 ], [ 1, 2, -2, -2, 0, 1 ] ], 1.25 ], - [ [ [ -2, 2, -2, -2, 0, 2 ], [ 1, 1, -4, -2, 0, 1 ], [ 1, 2, -2, -3, 0, 1 ], [ 1, 2, -2, -2, 0, 1 ] ], 1.25 ], - [ [ [ -2, 2, -2, -2, 0, 2 ], [ -1, 2, -2, -2, 0, 2 ], [ 1, 2, -2, -3, 0, 1 ], [ 1, 2, -2, -2, 0, 1 ] ], 0.5 ] - ], - [ - [ [ [ -2, 2, -2, -2, 0, 2 ], [ 0, 3, -2, -3, 0, 1 ], [ 1, 2, -2, -3, 0, 1 ], [ 1, 2, -2, -2, 0, 1 ] ], 0.625 ], - [ [ [ -1, 3, -2, -3, 0, 1 ], [ 0, 3, -2, -3, 0, 1 ], [ 1, 2, -2, -3, 0, 1 ], [ 1, 2, -2, -2, 0, 1 ] ], 0.625 ] - ], - [ - [ [ [ -1, 3, -2, -3, 0, 1 ], [ 0, 3, -2, -3, 0, 1 ], [ 1, 2, -2, -3, 0, 1 ], [ 2, 2, -2, -3, 0, 1 ] ], 0.75 ] - ], - [ - [ [ [ -1, 3, -2, -3, 0, 1 ], [ 0, 3, -2, -3, 0, 1 ], [ 0, 4, -2, -3, 0, 1 ], [ 2, 2, -2, -3, 0, 1 ] ], 0.75 ], - [ [ [ 0, 3, -2, -4, 0, 1 ], [ 0, 3, -2, -3, 0, 1 ], [ 0, 4, -2, -3, 0, 1 ], [ 2, 2, -2, -3, 0, 1 ] ], 0.875 ] - ], - [ - [ [ [ 0, 3, -2, -4, 0, 1 ], [ 0, 3, -2, -3, 0, 1 ], [ 0, 4, -2, -3, 0, 1 ], [ 1, 4, -2, -3, 0, 1 ] ], 0.875 ] - ], - [ - [ [ [ -1, 3, -1, -3, 0, 1 ], [ 0, 3, -2, -3, 0, 1 ], [ 0, 4, -2, -3, 0, 1 ], [ 1, 4, -2, -3, 0, 1 ] ], 1.25 ] - ], - [ - [ [ [ 0, 2, -2, -3, 0, 1 ], [ 0, 3, -2, -3, 0, 1 ], [ 0, 4, -2, -3, 0, 1 ], [ 1, 4, -2, -3, 0, 1 ] ], 1.25 ] - ], - [ - [ [ [ 0, 2, -2, -3, 0, 1 ], [ 0, 3, -2, -3, 0, 1 ], [ 0, 4, -2, -3, 0, 1 ], [ 1, 3, -1, -3, 0, 1 ] ], 1.125 ], - [ [ [ 0, 3, -2, -3, -1, 1 ], [ 0, 3, -2, -3, 0, 1 ], [ 0, 4, -2, -3, 0, 1 ], [ 1, 3, -1, -3, 0, 1 ] ], 1.25 ] - ], - [ - [ [ [ 0, 3, -2, -3, -1, 1 ], [ 0, 4, -2, -3, -1, 1 ], [ 0, 4, -2, -3, 0, 1 ], [ 1, 3, -1, -3, 0, 1 ] ], 0.875 ], - [ [ [ -1, 3, -2, -3, 0, 1 ], [ 0, 4, -2, -3, -1, 1 ], [ 0, 4, -2, -3, 0, 1 ], [ 1, 3, -1, -3, 0, 1 ] ], 1.625 ], - [ [ [ -1, 3, -2, -3, 0, 1 ], [ 0, 4, -2, -3, -1, 1 ], [ 0, 4, -2, -3, 0, 1 ], [ 0, 4, -2, -2, 0, 1 ] ], 0.375 ] - ], - [ - [ [ [ -1, 3, -2, -3, 0, 1 ], [ 0, 3, -1, -3, 0, 1 ], [ 0, 4, -2, -3, 0, 1 ], [ 0, 4, -2, -2, 0, 1 ] ], 0.5 ], - [ [ [ -1, 3, -2, -3, 0, 1 ], [ 0, 3, -1, -3, 0, 1 ], [ 0, 4, -2, -3, 0, 1 ], [ 1, 4, -2, -3, 0, 1 ] ], 0.5 ] - ], - [ - [ [ [ -1, 4, -2, -3, 0, 0 ], [ 0, 3, -1, -3, 0, 1 ], [ 0, 4, -2, -3, 0, 1 ], [ 1, 4, -2, -3, 0, 1 ] ], 0.75 ], - [ [ [ -1, 4, -2, -3, 0, 0 ], [ -1, 4, -2, -2, 0, 1 ], [ 0, 4, -2, -3, 0, 1 ], [ 1, 4, -2, -3, 0, 1 ] ], 1.5 ] - ], - [ - [ [ [ -1, 4, -2, -3, 0, 0 ], [ -1, 4, -2, -2, 0, 1 ], [ 0, 4, -2, -2, 0, 0 ], [ 1, 4, -2, -3, 0, 1 ] ], 1.125 ], - [ [ [ -1, 4, -2, -3, 0, 0 ], [ -1, 4, -2, -2, 0, 1 ], [ 0, 4, -2, -2, 0, 0 ], [ 2, 3, -2, -3, 0, 0 ] ], 1.5 ] - ], - [ - [ [ [ -1, 3, -2, -2, 0, 0 ], [ -1, 4, -2, -2, 0, 1 ], [ 0, 4, -2, -2, 0, 0 ], [ 2, 3, -2, -3, 0, 0 ] ], 0.625 ], - [ [ [ -1, 3, -2, -2, 0, 0 ], [ 1, 3, -2, -3, 0, 0 ], [ 0, 4, -2, -2, 0, 0 ], [ 2, 3, -2, -3, 0, 0 ] ], 1.125 ], - [ [ [ -1, 3, -2, -2, 0, 0 ], [ 1, 3, -2, -3, 0, 0 ], [ 1, 4, -2, -3, 0, 0 ], [ 2, 3, -2, -3, 0, 0 ] ], 1.625 ] - ], - [ - [ [ [ -1, 3, -2, -2, 0, 0 ], [ 1, 3, -2, -3, 0, 0 ], [ 1, 4, -2, -3, 0, 0 ], [ 1, 5, -2, -3, 0, 0 ] ], 1.125 ] - ], - [ - [ [ [ -1, 3, -2, -2, 0, 0 ], [ 1, 3, -2, -3, 0, 0 ], [ 1, 4, -2, -3, 0, 0 ], [ 3, 3, -2, -3, 0, -1 ] ], 0.75 ], - [ [ [ -1, 3, -2, -2, 0, 0 ], [ 1, 3, -2, -3, 0, 0 ], [ 2, 3, -3, -3, 0, 0 ], [ 3, 3, -2, -3, 0, -1 ] ], 0.5 ], - [ [ [ 0, 3, -2, -3, 0, 0 ], [ 1, 3, -2, -3, 0, 0 ], [ 2, 3, -3, -3, 0, 0 ], [ 3, 3, -2, -3, 0, -1 ] ], 1.25 ] - ], - [ - [ [ [ 0, 3, -2, -3, 0, 0 ], [ 1, 3, -2, -3, 0, 0 ], [ 2, 2, -2, -3, 0, 0 ], [ 3, 3, -2, -3, 0, -1 ] ], 1.5 ] - ], - [ - [ [ [ 0, 3, -2, -3, 0, 0 ], [ 1, 3, -2, -3, 0, 0 ], [ 1, 4, -2, -3, 0, -1 ], [ 3, 3, -2, -3, 0, -1 ] ], 1 ], - [ [ [ 0, 3, -2, -2, 0, -1 ], [ 1, 3, -2, -3, 0, 0 ], [ 1, 4, -2, -3, 0, -1 ], [ 3, 3, -2, -3, 0, -1 ] ], 1.375 ], - [ [ [ 0, 3, -2, -2, 0, -1 ], [ 1, 3, -2, -2, 0, -1 ], [ 1, 4, -2, -3, 0, -1 ], [ 3, 3, -2, -3, 0, -1 ] ], 0.875 ] - ], - [ - [ [ [ 0, 3, -2, -2, 0, -1 ], [ 2, 3, -2, -3, 0, -1 ], [ 1, 4, -2, -3, 0, -1 ], [ 3, 3, -2, -3, 0, -1 ] ], 0.75 ], - [ [ [ 1, 3, -2, -3, 0, -1 ], [ 2, 3, -2, -3, 0, -1 ], [ 1, 4, -2, -3, 0, -1 ], [ 3, 3, -2, -3, 0, -1 ] ], 0.375 ] - ], - [ - [ [ [ 1, 3, -2, -3, 0, -1 ], [ 2, 3, -2, -3, 0, -1 ], [ 2, 3, -3, -3, 0, -1 ], [ 3, 3, -2, -3, 0, -1 ] ], 1.75 ], - [ [ [ 1, 3, -2, -3, 0, -1 ], [ 2, 3, -2, -3, 0, -1 ], [ 2, 3, -3, -3, 0, -1 ], [ 3, 3, -3, -3, 0, -1 ] ], 1.25 ] - ], - [ - [ [ [ 1, 3, -2, -3, 0, -1 ], [ 2, 3, -2, -3, 0, -1 ], [ 3, 3, -3, -4, 0, -1 ], [ 3, 3, -3, -3, 0, -1 ] ], 1.75 ], - [ [ [ 1, 3, -2, -3, 0, -1 ], [ 1, 3, -3, -3, 0, 0 ], [ 3, 3, -3, -4, 0, -1 ], [ 3, 3, -3, -3, 0, -1 ] ], 0.5 ], - [ [ [ 2, 2, -3, -3, 0, -1 ], [ 1, 3, -3, -3, 0, 0 ], [ 3, 3, -3, -4, 0, -1 ], [ 3, 3, -3, -3, 0, -1 ] ], 1.625 ] - ], - [ - [ [ [ 2, 2, -3, -3, 0, -1 ], [ 3, 1, -3, -3, 0, -1 ], [ 3, 3, -3, -4, 0, -1 ], [ 3, 3, -3, -3, 0, -1 ] ], 0.875 ] - ], - [ - [ [ [ 2, 2, -3, -3, 0, -1 ], [ 3, 1, -3, -3, 0, -1 ], [ 3, 3, -3, -4, 0, -1 ], [ 4, 2, -4, -3, 0, -1 ] ], 1.125 ] - ], - [ - [ [ [ 2, 2, -3, -3, 0, -1 ], [ 3, 1, -3, -3, 0, -1 ], [ 3, 3, -3, -4, 0, -1 ], [ 4, 3, -3, -4, 0, -1 ] ], 1.625 ], - [ [ [ 3, 2, -3, -4, 0, -1 ], [ 3, 1, -3, -3, 0, -1 ], [ 3, 3, -3, -4, 0, -1 ], [ 4, 3, -3, -4, 0, -1 ] ], 1.375 ] - ], - [ - [ [ [ 2, 4, -3, -4, 0, -1 ], [ 3, 1, -3, -3, 0, -1 ], [ 3, 3, -3, -4, 0, -1 ], [ 4, 3, -3, -4, 0, -1 ] ], 0.75 ] - ], - [ - [ [ [ 2, 4, -3, -4, 0, -1 ], [ 1, 5, -3, -4, 0, -1 ], [ 3, 3, -3, -4, 0, -1 ], [ 4, 3, -3, -4, 0, -1 ] ], 1.5 ], - [ [ [ 2, 4, -3, -4, 0, -1 ], [ 1, 5, -3, -4, 0, -1 ], [ 3, 3, -3, -4, 0, -1 ], [ 4, 4, -3, -4, -1, -1 ] ], 0.875 ], - [ [ [ 2, 4, -3, -4, 0, -1 ], [ 1, 5, -3, -4, 0, -1 ], [ 3, 4, -3, -4, -1, -1 ], [ 4, 4, -3, -4, -1, -1 ] ], 1.625 ] - ], - [ - [ [ [ 2, 4, -3, -4, 0, -1 ], [ 1, 5, -3, -4, 0, -1 ], [ 3, 4, -4, -4, 0, -1 ], [ 4, 4, -3, -4, -1, -1 ] ], 0.5 ], - [ [ [ 2, 4, -3, -4, 0, -1 ], [ 2, 4, -4, -4, 0, -1 ], [ 3, 4, -4, -4, 0, -1 ], [ 4, 4, -3, -4, -1, -1 ] ], 1.375 ] - ], - [ - [ [ [ 2, 4, -3, -4, 0, -1 ], [ 2, 4, -4, -4, 0, -1 ], [ 3, 4, -4, -4, 0, -1 ], [ 3, 4, -2, -4, 0, -1 ] ], 1.75 ], - [ [ [ 2, 4, -3, -4, 0, -1 ], [ 1, 4, -3, -3, 0, -1 ], [ 3, 4, -4, -4, 0, -1 ], [ 3, 4, -2, -4, 0, -1 ] ], 0.625 ], - [ [ [ 2, 4, -3, -4, 0, -1 ], [ 1, 4, -3, -3, 0, -1 ], [ 2, 4, -3, -3, 0, -1 ], [ 3, 4, -2, -4, 0, -1 ] ], 1.75 ] - ], - [ - [ [ [ 2, 4, -3, -4, 0, -1 ], [ 1, 4, -3, -3, 0, -1 ], [ 2, 4, -3, -3, 0, -1 ], [ 2, 5, -3, -3, 0, -1 ] ], 0.75 ], - [ [ [ 2, 4, -3, -4, 0, -1 ], [ 1, 4, -3, -3, 0, -1 ], [ 3, 4, -3, -4, 0, -1 ], [ 2, 5, -3, -3, 0, -1 ] ], 0.5 ] - ], - [ - [ [ [ 2, 3, -3, -3, 0, -1 ], [ 1, 4, -3, -3, 0, -1 ], [ 3, 4, -3, -4, 0, -1 ], [ 2, 5, -3, -3, 0, -1 ] ], 0.75 ], - [ [ [ 2, 3, -3, -3, 0, -1 ], [ 1, 4, -3, -3, 0, -1 ], [ 2, 4, -2, -3, 0, -1 ], [ 2, 5, -3, -3, 0, -1 ] ], 1.75 ] - ], - [ - [ [ [ 2, 3, -3, -3, 0, -1 ], [ 1, 4, -3, -3, 0, -1 ], [ 3, 3, -3, -3, 0, -1 ], [ 2, 5, -3, -3, 0, -1 ] ], 1 ], - [ [ [ 2, 3, -3, -3, 0, -1 ], [ 2, 3, -4, -3, 0, -1 ], [ 3, 3, -3, -3, 0, -1 ], [ 2, 5, -3, -3, 0, -1 ] ], 1.125 ] - ], - [ - [ [ [ 2, 3, -3, -3, 0, -1 ], [ 2, 3, -4, -3, 0, -1 ], [ 3, 3, -3, -3, 0, -1 ], [ 3, 3, -2, -3, 0, -1 ] ], 1.5 ], - [ [ [ 2, 3, -3, -3, 0, -1 ], [ 2, 2, -3, -3, 0, -1 ], [ 3, 3, -3, -3, 0, -1 ], [ 3, 3, -2, -3, 0, -1 ] ], 1.625 ], - [ [ [ 3, 3, -3, -4, 0, -1 ], [ 2, 2, -3, -3, 0, -1 ], [ 3, 3, -3, -3, 0, -1 ], [ 3, 3, -2, -3, 0, -1 ] ], 0.5 ] - ], - [ - [ [ [ 3, 3, -3, -4, 0, -1 ], [ 3, 2, -3, -4, 0, -1 ], [ 3, 3, -3, -3, 0, -1 ], [ 3, 3, -2, -3, 0, -1 ] ], 0.75 ] - ], - [ - [ [ [ 2, 3, -2, -3, 0, -1 ], [ 3, 2, -3, -4, 0, -1 ], [ 3, 3, -3, -3, 0, -1 ], [ 3, 3, -2, -3, 0, -1 ] ], 0.875 ], - [ [ [ 2, 3, -2, -3, 0, -1 ], [ 3, 2, -3, -4, 0, -1 ], [ 3, 3, -3, -3, 0, -1 ], [ 2, 3, -3, -3, 0, -1 ] ], 1.125 ] - ], - [ - [ [ [ 2, 3, -2, -3, 0, -1 ], [ 2, 3, -4, -3, 0, -1 ], [ 3, 3, -3, -3, 0, -1 ], [ 2, 3, -3, -3, 0, -1 ] ], 0.875 ], - [ [ [ 3, 2, -3, -3, 0, -1 ], [ 2, 3, -4, -3, 0, -1 ], [ 3, 3, -3, -3, 0, -1 ], [ 2, 3, -3, -3, 0, -1 ] ], 0.875 ] - ], - [ - [ [ [ 3, 2, -3, -3, 0, -1 ], [ 2, 3, -4, -3, 0, -1 ], [ 3, 3, -3, -3, 0, -1 ], [ 3, 3, -3, -4, 0, -1 ] ], 1.25 ], - [ [ [ 3, 2, -3, -3, 0, -1 ], [ 1, 3, -3, -2, 0, -1 ], [ 3, 3, -3, -3, 0, -1 ], [ 3, 3, -3, -4, 0, -1 ] ], 1.25 ], - [ [ [ 2, 4, -3, -3, 0, -1 ], [ 1, 3, -3, -2, 0, -1 ], [ 3, 3, -3, -3, 0, -1 ], [ 3, 3, -3, -4, 0, -1 ] ], 1.125 ] - ], - [ - [ [ [ 2, 4, -3, -3, 0, -1 ], [ 1, 3, -3, -2, 0, -1 ], [ 3, 3, -3, -3, 0, -1 ], [ 1, 4, -3, -2, 0, -1 ] ], 0.625 ] - ], - [ - [ [ [ 2, 3, -3, -2, 0, -1 ], [ 1, 3, -3, -2, 0, -1 ], [ 3, 3, -3, -3, 0, -1 ], [ 1, 4, -3, -2, 0, -1 ] ], 1.25 ], - [ [ [ 2, 3, -3, -2, 0, -1 ], [ 1, 3, -3, -2, 0, -1 ], [ 2, 3, -2, -2, 0, -1 ], [ 1, 4, -3, -2, 0, -1 ] ], 1.375 ] - ], - [ - [ [ [ 1, 3, -2, -2, 0, -1 ], [ 1, 3, -3, -2, 0, -1 ], [ 2, 3, -2, -2, 0, -1 ], [ 1, 4, -3, -2, 0, -1 ] ], 0.875 ] - ], - [ - [ [ [ 1, 3, -2, -2, 0, -1 ], [ 1, 3, -3, -2, 0, -1 ], [ 2, 3, -2, -2, 0, -1 ], [ 2, 2, -2, -2, 0, -1 ] ], 1.5 ] - ], - [ - [ [ [ 1, 3, -2, -2, 0, -1 ], [ 2, 1, -2, -2, 0, -1 ], [ 2, 3, -2, -2, 0, -1 ], [ 2, 2, -2, -2, 0, -1 ] ], 0.5 ] - ], - [ - [ [ [ 1, 3, -2, -2, 0, -1 ], [ 2, 1, -2, -2, 0, -1 ], [ 3, 1, -2, -2, 0, -1 ], [ 2, 2, -2, -2, 0, -1 ] ], 1.625 ], - [ [ [ 2, 0, -2, -2, 0, -1 ], [ 2, 1, -2, -2, 0, -1 ], [ 3, 1, -2, -2, 0, -1 ], [ 2, 2, -2, -2, 0, -1 ] ], 1.5 ], - [ [ [ 2, 0, -2, -2, 0, -1 ], [ 2, 1, -2, -2, 0, -1 ], [ 3, 1, -2, -2, 0, -1 ], [ 3, 1, -3, -2, 0, -1 ] ], 0.75 ] - ], - [ - [ [ [ 2, 0, -2, -2, 0, -1 ], [ 3, 0, -3, -2, 0, -1 ], [ 3, 1, -2, -2, 0, -1 ], [ 3, 1, -3, -2, 0, -1 ] ], 1.5 ] - ], - [ - [ [ [ 2, 0, -2, -2, 0, -1 ], [ 3, 0, -3, -2, 0, -1 ], [ 4, 0, -3, -2, 0, -1 ], [ 3, 1, -3, -2, 0, -1 ] ], 1 ], - [ [ [ 2, 0, -3, -2, 0, -1 ], [ 3, 0, -3, -2, 0, -1 ], [ 4, 0, -3, -2, 0, -1 ], [ 3, 1, -3, -2, 0, -1 ] ], 1.25 ], - [ [ [ 2, 0, -3, -2, 0, -1 ], [ 3, 0, -3, -2, 0, -1 ], [ 4, 0, -3, -2, 0, -1 ], [ 4, 0, -4, -2, 0, -1 ] ], 1.25 ] - ], - [ - [ [ [ 2, 0, -3, -2, 0, -1 ], [ 2, 0, -4, -2, 0, 0 ], [ 4, 0, -3, -2, 0, -1 ], [ 4, 0, -4, -2, 0, -1 ] ], 0.5 ], - [ [ [ 3, -1, -4, -2, 0, -1 ], [ 2, 0, -4, -2, 0, 0 ], [ 4, 0, -3, -2, 0, -1 ], [ 4, 0, -4, -2, 0, -1 ] ], 1.125 ], - [ [ [ 3, -1, -4, -2, 0, -1 ], [ 2, 0, -4, -2, 0, 0 ], [ 5, -1, -4, -2, 0, -1 ], [ 4, 0, -4, -2, 0, -1 ] ], 0.5 ] - ], - [ - [ [ [ 3, -1, -4, -2, 0, -1 ], [ 2, 0, -4, -2, 0, 0 ], [ 5, -1, -4, -2, 0, -1 ], [ 4, -1, -4, -2, 0, 0 ] ], 1.75 ] - ], - [ - [ [ [ 2, 0, -4, -2, 0, -1 ], [ 2, 0, -4, -2, 0, 0 ], [ 5, -1, -4, -2, 0, -1 ], [ 4, -1, -4, -2, 0, 0 ] ], 0.5 ], - [ [ [ 2, 0, -4, -2, 0, -1 ], [ 2, 0, -4, -2, 0, 0 ], [ 5, -1, -4, -2, 0, -1 ], [ 3, 1, -4, -2, 0, 0 ] ], 1.125 ], - [ [ [ 2, 0, -4, -2, 0, -1 ], [ 2, 0, -4, -2, 0, 0 ], [ 3, 0, -4, -1, 0, 0 ], [ 3, 1, -4, -2, 0, 0 ] ], 0.5 ] - ], - [ - [ [ [ 2, -1, -4, -2, 0, 0 ], [ 2, 0, -4, -2, 0, 0 ], [ 3, 0, -4, -1, 0, 0 ], [ 3, 1, -4, -2, 0, 0 ] ], 1.625 ], - [ [ [ 2, -1, -4, -2, 0, 0 ], [ 2, 0, -4, -2, 0, 0 ], [ 4, 1, -4, -2, 0, -1 ], [ 3, 1, -4, -2, 0, 0 ] ], 0.75 ] - ], - [ - [ [ [ 2, -1, -4, -2, 0, 0 ], [ 2, 0, -4, -2, 0, 0 ], [ 4, 0, -5, -2, 0, 0 ], [ 3, 1, -4, -2, 0, 0 ] ], 1.75 ], - [ [ [ 2, -1, -4, -2, 0, 0 ], [ 2, 0, -4, -2, 0, 0 ], [ 4, 0, -5, -2, 0, 0 ], [ 4, -1, -4, -2, 0, -1 ] ], 0.5 ] - ], - [ - [ [ [ 2, -1, -4, -2, 0, 0 ], [ 2, 0, -4, -2, 0, 0 ], [ 4, 0, -5, -2, 0, 0 ], [ 2, 0, -4, -1, 0, 0 ] ], 1.75 ] - ], - [ - [ [ [ 1, 1, -4, -2, 0, 0 ], [ 2, 0, -4, -2, 0, 0 ], [ 4, 0, -5, -2, 0, 0 ], [ 2, 0, -4, -1, 0, 0 ] ], 0.875 ], - [ [ [ 1, 1, -4, -2, 0, 0 ], [ 2, 0, -4, -2, 0, 0 ], [ 3, 0, -4, -1, 0, 0 ], [ 2, 0, -4, -1, 0, 0 ] ], 0.875 ] - ], - [ - [ [ [ 1, 1, -4, -2, 0, 0 ], [ 2, 0, -4, -2, 0, 0 ], [ 4, 1, -4, -2, 0, -1 ], [ 2, 0, -4, -1, 0, 0 ] ], 1.625 ] - ], - [ - [ [ [ 1, 1, -4, -2, 0, 0 ], [ 1, 2, -4, -2, 0, 0 ], [ 4, 1, -4, -2, 0, -1 ], [ 2, 0, -4, -1, 0, 0 ] ], 0.5 ], - [ [ [ 1, 1, -4, -2, 0, 0 ], [ 1, 2, -4, -2, 0, 0 ], [ 3, 1, -4, -2, 0, 0 ], [ 2, 0, -4, -1, 0, 0 ] ], 0.875 ], - [ [ [ 1, 1, -4, -2, 0, 0 ], [ 1, 2, -4, -2, 0, 0 ], [ 3, 1, -4, -2, 0, 0 ], [ 2, 1, -4, -2, 0, 0 ] ], 1.125 ] - ], - [ - [ [ [ 0, 2, -4, -2, 0, 0 ], [ 1, 2, -4, -2, 0, 0 ], [ 3, 1, -4, -2, 0, 0 ], [ 2, 1, -4, -2, 0, 0 ] ], 1.625 ] - ], - [ - [ [ [ 0, 2, -4, -2, 0, 0 ], [ 1, 2, -4, -2, 0, 0 ], [ 3, 1, -4, -2, 0, 0 ], [ 1, 3, -4, -2, 0, 0 ] ], 0.75 ] - ], - [ - [ [ [ 1, 2, -4, -3, 0, 0 ], [ 1, 2, -4, -2, 0, 0 ], [ 3, 1, -4, -2, 0, 0 ], [ 1, 3, -4, -2, 0, 0 ] ], 0.875 ] - ], - [ - [ [ [ 1, 2, -4, -3, 0, 0 ], [ 1, 2, -4, -2, 0, 0 ], [ 3, 1, -4, -2, 0, 0 ], [ 3, 1, -4, -2, 0, -1 ] ], 1.5 ], - [ [ [ 1, 2, -4, -3, 0, 0 ], [ 2, 2, -4, -3, 0, 0 ], [ 3, 1, -4, -2, 0, 0 ], [ 3, 1, -4, -2, 0, -1 ] ], 1.5 ] - ], - [ - [ [ [ 1, 2, -4, -3, 0, 0 ], [ 2, 2, -4, -3, 0, 0 ], [ 3, 1, -4, -2, 0, 0 ], [ 3, 0, -4, -2, 0, 0 ] ], 0.5 ], - [ [ [ 1, 1, -4, -2, 0, 0 ], [ 2, 2, -4, -3, 0, 0 ], [ 3, 1, -4, -2, 0, 0 ], [ 3, 0, -4, -2, 0, 0 ] ], 0.5 ], - [ [ [ 1, 1, -4, -2, 0, 0 ], [ 2, 1, -4, -2, 0, 0 ], [ 3, 1, -4, -2, 0, 0 ], [ 3, 0, -4, -2, 0, 0 ] ], 0.5 ] - ], - [ - [ [ [ 1, 1, -4, -2, 0, 0 ], [ 2, 1, -4, -2, 0, 0 ], [ 4, 0, -5, -2, 0, 0 ], [ 3, 0, -4, -2, 0, 0 ] ], 1.375 ], - [ [ [ 2, 0, -5, -2, 0, 0 ], [ 2, 1, -4, -2, 0, 0 ], [ 4, 0, -5, -2, 0, 0 ], [ 3, 0, -4, -2, 0, 0 ] ], 0.875 ], - [ [ [ 2, 0, -5, -2, 0, 0 ], [ 3, 0, -5, -2, 0, 0 ], [ 4, 0, -5, -2, 0, 0 ], [ 3, 0, -4, -2, 0, 0 ] ], 0.625 ] - ], - [ - [ [ [ 1, 0, -4, -2, 0, 0 ], [ 3, 0, -5, -2, 0, 0 ], [ 4, 0, -5, -2, 0, 0 ], [ 3, 0, -4, -2, 0, 0 ] ], 0.625 ], - [ [ [ 1, 0, -4, -2, 0, 0 ], [ 2, 0, -4, -2, 0, 0 ], [ 4, 0, -5, -2, 0, 0 ], [ 3, 0, -4, -2, 0, 0 ] ], 1.375 ], - [ [ [ 1, 0, -4, -2, 0, 0 ], [ 2, 0, -4, -2, 0, 0 ], [ 3, 1, -4, -2, 0, 0 ], [ 3, 0, -4, -2, 0, 0 ] ], 1.125 ] - ], - [ - [ [ [ 1, 0, -4, -2, 0, 0 ], [ 2, 0, -4, -2, 0, 0 ], [ 2, 1, -4, -2, 0, 0 ], [ 3, 0, -4, -2, 0, 0 ] ], 1.625 ], - [ [ [ 1, 0, -4, -2, 0, 0 ], [ 2, 0, -4, -2, 0, 0 ], [ 2, 1, -4, -2, 0, 0 ], [ 4, 0, -4, -3, 0, 0 ] ], 1.25 ] - ], - [ - [ [ [ 1, 0, -4, -2, 0, 0 ], [ 2, 0, -4, -2, 0, 0 ], [ 3, 0, -5, -2, 0, 0 ], [ 4, 0, -4, -3, 0, 0 ] ], 0.75 ], - [ [ [ 1, 0, -4, -2, 0, 0 ], [ 2, 0, -4, -2, 0, 0 ], [ 3, 0, -5, -2, 0, 0 ], [ 2, 1, -4, -2, 0, 0 ] ], 1.375 ] - ], - [ - [ [ [ 1, 0, -4, -2, 0, 0 ], [ 2, 0, -5, -2, 1, 0 ], [ 3, 0, -5, -2, 0, 0 ], [ 2, 1, -4, -2, 0, 0 ] ], 1.625 ], - [ [ [ 1, 0, -4, -2, 0, 0 ], [ 2, 0, -5, -2, 1, 0 ], [ 3, 0, -5, -2, 0, 0 ], [ 2, 0, -4, -1, 0, 0 ] ], 0.75 ] - ], - [ - [ [ [ 1, 0, -5, -2, 1, 0 ], [ 2, 0, -5, -2, 1, 0 ], [ 3, 0, -5, -2, 0, 0 ], [ 2, 0, -4, -1, 0, 0 ] ], 1.375 ], - [ [ [ 1, 0, -5, -2, 1, 0 ], [ 3, 0, -5, -2, -1, 0 ], [ 3, 0, -5, -2, 0, 0 ], [ 2, 0, -4, -1, 0, 0 ] ], 1.75 ], - [ [ [ 1, 0, -5, -2, 1, 0 ], [ 3, 0, -5, -2, -1, 0 ], [ 3, 0, -5, -2, 0, 0 ], [ 4, 0, -5, -2, 0, -1 ] ], 1.25 ] - ], - [ - [ [ [ 1, 0, -5, -2, 1, 0 ], [ 3, 0, -5, -2, -1, 0 ], [ 3, 0, -6, -2, 1, 0 ], [ 4, 0, -5, -2, 0, -1 ] ], 1.375 ], - [ [ [ 1, 0, -5, -2, 1, 0 ], [ 3, 0, -5, -2, -1, 0 ], [ 3, 0, -6, -2, 1, 0 ], [ "Rest" ] ], 0.625 ], - [ [ [ 1, 0, -5, -2, 1, 0 ], [ 3, 0, -5, -2, -1, 0 ], [ "Rest" ], [ "Rest" ] ], 0.875 ], - [ [ [ 1, 0, -5, -2, 1, 0 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 1.375 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 6.75 ] - ] - ] -], -"last_changes": -[ - [ [ 1, 0, -4, -2, 0, 0 ], [ 2, 0, -5, -2, 1, 0 ], [ 3, 0, -5, -2, 0, 0 ], [ 2, 0, -4, -1, 0, 0 ] ], - [ [ 1, 0, -5, -2, 1, 0 ], [ 2, 0, -5, -2, 1, 0 ], [ 3, 0, -5, -2, 0, 0 ], [ 2, 0, -4, -1, 0, 0 ] ], - [ [ 1, 0, -5, -2, 1, 0 ], [ 3, 0, -5, -2, -1, 0 ], [ 3, 0, -5, -2, 0, 0 ], [ 2, 0, -4, -1, 0, 0 ] ], - [ [ 1, 0, -5, -2, 1, 0 ], [ 3, 0, -5, -2, -1, 0 ], [ 3, 0, -5, -2, 0, 0 ], [ 4, 0, -5, -2, 0, -1 ] ], - [ [ 1, 0, -5, -2, 1, 0 ], [ 3, 0, -5, -2, -1, 0 ], [ 3, 0, -6, -2, 1, 0 ], [ 4, 0, -5, -2, 0, -1 ] ] -], -"cur_uid": "69c568c6", -"ref_uid": "nil", -"order_seed": 712406, -"dur_seed": 506999, -"motifs_seed": 551883, -"entrances_probs_vals": [ 0, 0, 0, 0.41, 1.84, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 0, 0, 0, 0.41, 1.84, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 0, 0, 3.2936507936508, 0.41, 1.84, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -2400, 1200 ], [ -1200, 1200 ], [ -702, 1200 ], [ -702, 1200 ] ], -"step_probs_vals": [ -1200, 1200, 0.0020576131687243, 0.068181818181818, 0.074074074074074, 0.0625, 0.20576131687243, 0.0625, 0.45679012345679, 0.011363636363636, 0.53086419753086, 0, 0.54320987654321, 0.92045454545455, 0.58641975308642, 0.92613636363636, 0.61316872427983, 0, 0.98971193415638, 0 ], -"passages_weights": [ 0.48, 0.46, 0.48, 1, 1 ], -"hd_exp": 9, -"hd_invert": 0, -"order": -[ - [ [ 1, 2, 3 ], [ 0 ], [ ] ], - [ [ 0, 3 ], [ 1, 2 ], [ ] ], - [ [ 0, 2, 1 ], [ 3 ], [ ] ], - [ [ 3, 2, 0 ], [ 1 ], [ ] ], - [ [ 3, 2, 1 ], [ 0 ], [ ] ], - [ [ 0, 2 ], [ 1, 3 ], [ ] ], - [ [ 1 ], [ 0, 2, 3 ], [ ] ], - [ [ 1, 3 ], [ 2, 0 ], [ ] ], - [ [ 3 ], [ 1, 0, 2 ], [ ] ], - [ [ 3, 1 ], [ 2, 0 ], [ ] ], - [ [ 3, 0, 2 ], [ 1 ], [ ] ], - [ [ 0, 3 ], [ 2, 1 ], [ ] ], - [ [ 3, 0, 2 ], [ 1 ], [ ] ], - [ [ 3, 0 ], [ 1, 2 ], [ ] ], - [ [ 3, 1, 2 ], [ 0 ], [ ] ], - [ [ 3, 2, 0 ], [ 1 ], [ ] ], - [ [ 0, 1 ], [ 2, 3 ], [ ] ], - [ [ 3, 0 ], [ 1, 2 ], [ ] ], - [ [ 0, 3 ], [ 1, 2 ], [ ] ], - [ [ 0 ], [ 2, 1, 3 ], [ ] ], - [ [ 0, 1 ], [ 2, 3 ], [ ] ], - [ [ 2 ], [ 3, 1, 0 ], [ ] ], - [ [ 3, 1, 2 ], [ 0 ], [ ] ], - [ [ 3, 1, 0 ], [ 2 ], [ ] ], - [ [ 0 ], [ 2, 1, 3 ], [ ] ], - [ [ 3 ], [ 0, 1, 2 ], [ ] ], - [ [ 0, 1 ], [ 2, 3 ], [ ] ], - [ [ 2, 1 ], [ 3, 0 ], [ ] ], - [ [ 3, 0, 2 ], [ 1 ], [ ] ], - [ [ 0, 1, 3 ], [ 2 ], [ ] ], - [ [ 1, 3 ], [ 2, 0 ], [ ] ], - [ [ 1 ], [ 0, 3, 2 ], [ ] ], - [ [ 3, 1 ], [ 2, 0 ], [ ] ], - [ [ 2, 3 ], [ 1, 0 ], [ ] ], - [ [ 3, 2 ], [ 1, 0 ], [ ] ], - [ [ 2, 3 ], [ 1, 0 ], [ ] ], - [ [ 3 ], [ 0, 2, 1 ], [ ] ], - [ [ 2, 3 ], [ 1, 0 ], [ ] ], - [ [ 1, 0, 2 ], [ 3 ], [ ] ], - [ [ 3, 1 ], [ 2, 0 ], [ ] ], - [ [ 2, 0, 1 ], [ 3 ], [ ] ], - [ [ 3, 1, 2 ], [ 0 ], [ ] ], - [ [ 2, 1, 3 ], [ 0 ], [ ] ], - [ [ 1, 2 ], [ 3, 0 ], [ ] ], - [ [ 2 ], [ 1, 0, 3 ], [ ] ], - [ [ 2, 0 ], [ 1, 3 ], [ ] ], - [ [ 2, 3 ], [ 0, 1 ], [ ] ], - [ [ 0, 1 ], [ 2, 3 ], [ ] ], - [ [ 3 ], [ 0, 1, 2 ], [ ] ], - [ [ 2, 0, 1 ], [ 3 ], [ ] ], - [ [ 1 ], [ 3, 2, 0 ], [ ] ], - [ [ 3, 0, 1 ], [ 2 ], [ ] ], - [ [ 3 ], [ 2, 0, 1 ], [ ] ], - [ [ 3, 2 ], [ 1, 0 ], [ ] ], - [ [ 0, 1 ], [ 2, 3 ], [ ] ], - [ [ 3 ], [ 2, 1, 0 ], [ ] ], - [ [ 0, 3, 2 ], [ 1 ], [ ] ], - [ [ 1, 2, 0 ], [ 3 ], [ ] ], - [ [ 1, 2 ], [ 3, 0 ], [ ] ], - [ [ 3, 2, 1 ], [ 0 ], [ ] ], - [ [ 0 ], [ 1, 3, 2 ], [ ] ], - [ [ 3, 0 ], [ 2, 1 ], [ ] ], - [ [ 0 ], [ 3, 1, 2 ], [ ] ], - [ [ 1, 0 ], [ 3, 2 ], [ ] ], - [ [ 1, 3 ], [ 0, 2 ], [ ] ], - [ [ 3, 0 ], [ 2, 1 ], [ ] ], - [ [ 2 ], [ 3, 1, 0 ], [ ] ], - [ [ 0, 3, 2 ], [ 1 ], [ ] ], - [ [ 1, 2 ], [ 0, 3 ], [ ] ], - [ [ 3, 2 ], [ 1, 0 ], [ ] ], - [ [ 2 ], [ 3, 1, 0 ], [ ] ], - [ [ 0, 2, 1 ], [ 3 ], [ ] ], - [ [ 3, 1 ], [ 0, 2 ], [ ] ], - [ [ 1, 2, 3 ], [ 0 ], [ ] ], - [ [ 2, 0, 1 ], [ 3 ], [ ] ], - [ [ 2, 0, 3 ], [ 1 ], [ ] ], - [ [ 1 ], [ 2, 0, 3 ], [ ] ], - [ [ 2, 3, 0 ], [ 1 ], [ ] ], - [ [ 1 ], [ 2, 0, 3 ], [ ] ], - [ [ 3 ], [ 1, 0, 2 ], [ ] ], - [ [ 0, 2, 1 ], [ 3 ], [ ] ], - [ [ 1 ], [ 0, 3, 2 ], [ ] ], - [ [ 3, 1 ], [ 0, 2 ], [ ] ], - [ [ 1, 0 ], [ 2, 3 ], [ ] ], - [ [ 0, 1, 2 ], [ 3 ], [ ] ], - [ [ 3, 1 ], [ 0, 2 ], [ ] ], - [ [ 3, 1, 0 ], [ 2 ], [ ] ], - [ [ 0 ], [ 1, 2, 3 ], [ ] ], - [ [ 1, 3, 2 ], [ 0 ], [ ] ], - [ [ 2, 1, 0 ], [ 3 ], [ ] ], - [ [ 3, 2, 1 ], [ 0 ], [ ] ], - [ [ 2, 0 ], [ 3, 1 ], [ ] ], - [ [ 2 ], [ 3, 0, 1 ], [ ] ], - [ [ 3 ], [ 2, 0, 1 ], [ ] ], - [ [ 3 ], [ 0, 1, 2 ], [ ] ], - [ [ 0, 1 ], [ 2, 3 ], [ ] ], - [ [ 1, 0 ], [ 2, 3 ], [ ] ], - [ [ 0, 2 ], [ 1, 3 ], [ ] ], - [ [ 2 ], [ 0, 1, 3 ], [ ] ], - [ [ 0, 3, 1 ], [ 2 ], [ ] ] -], -"sus_weights": [ 0.35, 0.37, 0.38 ], -"order_size": [ 100, 100 ], -"passages_size": [ 0, 0 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3/6a9928d6/6a9928d6_code.scd b/resources/resources_bak_2024_01_03/string_quartet_3/6a9928d6/6a9928d6_code.scd deleted file mode 100644 index 49436ca..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3/6a9928d6/6a9928d6_code.scd +++ /dev/null @@ -1,973 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array2) - hsArrayToCents.value(array1); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -/* -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance) -}; -*/ - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = true; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - //if(pDistance >= 0, {stepFunc.value(abs(pDistance))}, {0.01}); - stepFunc.value(pDistance) -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - //tuples = dims.collect({[0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength.asInteger - minMotifLength.asInteger).rand + minMotifLength.asInteger).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - //noProgIns = (popSize - noSusIns).rand + 1; - noProgIns = (popSize - noSusIns); - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength.asInteger - minProgLength.asInteger).rand + minProgLength.asInteger).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0.01); - - - - if(rangeScore.value(candidate.collect({0}), voices[ins], ranges[ins][1] - 500, ranges[ins][1], 0, true) == 1, { - isInRangeScore = 1 - rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0] + 500, ranges[ins][1] - 500, 0, true); - isInRangeScore = isInRangeScore * rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true) - }, { - isInRangeScore = rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true); - }); - - - //isInRangeScore = rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true); - //old way - worked but actually by accident (I think) - //isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - - - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_3/6a9928d6/6a9928d6_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_3/6a9928d6/6a9928d6_mus_model.json deleted file mode 100644 index 7ef872c..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3/6a9928d6/6a9928d6_mus_model.json +++ /dev/null @@ -1,554 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ "Rest" ], [ 2, -4, 0, 3, -1, 0 ], [ "Rest" ] ], 1.5 ], - [ [ [ "Rest" ], [ "Rest" ], [ 2, -4, 0, 3, -1, 0 ], [ 4, -5, -1, 2, -1, -1 ] ], 0.5 ], - [ [ [ "Rest" ], [ 2, -5, 0, 3, -1, -1 ], [ 2, -4, 0, 3, -1, 0 ], [ 4, -5, -1, 2, -1, -1 ] ], 1.75 ], - [ [ [ 1, -5, 0, 3, -1, -1 ], [ 2, -5, 0, 3, -1, -1 ], [ 2, -4, 0, 3, -1, 0 ], [ 4, -5, -1, 2, -1, -1 ] ], 0.875 ] - ], - [ - [ [ [ 1, -5, 0, 3, -1, -1 ], [ 4, -5, -1, 2, -1, -2 ], [ 2, -4, 0, 3, -1, 0 ], [ 4, -5, -1, 2, -1, -1 ] ], 1.125 ], - [ [ [ 1, -5, 0, 3, -1, -1 ], [ 4, -5, -1, 2, -1, -2 ], [ 4, -5, -2, 2, -1, -1 ], [ 4, -5, -1, 2, -1, -1 ] ], 1.625 ], - [ [ [ 2, -5, 0, 2, -1, -1 ], [ 4, -5, -1, 2, -1, -2 ], [ 4, -5, -2, 2, -1, -1 ], [ 4, -5, -1, 2, -1, -1 ] ], 1.875 ] - ], - [ - [ [ [ 2, -5, 0, 2, -1, -1 ], [ 4, -5, -1, 2, -1, -2 ], [ 3, -5, 0, 2, 0, -1 ], [ 4, -5, -1, 2, -1, -1 ] ], 1.125 ], - [ [ [ 2, -5, 0, 2, -1, -1 ], [ 4, -5, -1, 2, -1, -2 ], [ 3, -5, 0, 2, 0, -1 ], [ 4, -6, 0, 2, -1, -1 ] ], 0.5 ], - [ [ [ 2, -5, 0, 2, -1, -1 ], [ 3, -6, 0, 2, -1, -1 ], [ 3, -5, 0, 2, 0, -1 ], [ 4, -6, 0, 2, -1, -1 ] ], 1.875 ] - ], - [ - [ [ [ 2, -5, 0, 2, -1, -1 ], [ 2, -5, 0, 2, 0, -2 ], [ 3, -5, 0, 2, 0, -1 ], [ 4, -6, 0, 2, -1, -1 ] ], 0.75 ], - [ [ [ 1, -5, 0, 2, 0, 0 ], [ 2, -5, 0, 2, 0, -2 ], [ 3, -5, 0, 2, 0, -1 ], [ 4, -6, 0, 2, -1, -1 ] ], 0.5 ], - [ [ [ 1, -5, 0, 2, 0, 0 ], [ 2, -5, 0, 2, 0, -2 ], [ 3, -5, 0, 2, 0, -1 ], [ 3, -5, -1, 2, 0, -1 ] ], 0.75 ] - ], - [ - [ [ [ 1, -5, 0, 2, 0, 0 ], [ 2, -5, 0, 2, 0, -2 ], [ 3, -5, 0, 2, 1, -2 ], [ 3, -5, -1, 2, 0, -1 ] ], 1.625 ], - [ [ [ 3, -5, 0, 1, 0, -2 ], [ 2, -5, 0, 2, 0, -2 ], [ 3, -5, 0, 2, 1, -2 ], [ 3, -5, -1, 2, 0, -1 ] ], 1.625 ] - ], - [ - [ [ [ 3, -5, 0, 2, 0, -3 ], [ 2, -5, 0, 2, 0, -2 ], [ 3, -5, 0, 2, 1, -2 ], [ 3, -5, -1, 2, 0, -1 ] ], 1.875 ] - ], - [ - [ [ [ 3, -5, 0, 2, 0, -3 ], [ 2, -5, 0, 2, 0, -2 ], [ 4, -5, 1, 2, 0, -3 ], [ 3, -5, -1, 2, 0, -1 ] ], 0.625 ], - [ [ [ 3, -5, 0, 2, 0, -3 ], [ 2, -5, 0, 3, 0, -3 ], [ 4, -5, 1, 2, 0, -3 ], [ 3, -5, -1, 2, 0, -1 ] ], 1.125 ], - [ [ [ 3, -5, 0, 2, 0, -3 ], [ 2, -5, 0, 3, 0, -3 ], [ 4, -5, 1, 2, 0, -3 ], [ 5, -5, 0, 1, 0, -3 ] ], 1.625 ] - ], - [ - [ [ [ 3, -5, 0, 2, 0, -3 ], [ 4, -5, -1, 2, 0, -3 ], [ 4, -5, 1, 2, 0, -3 ], [ 5, -5, 0, 1, 0, -3 ] ], 1 ], - [ [ [ 3, -5, 0, 2, 0, -3 ], [ 4, -5, -1, 2, 0, -3 ], [ 4, -5, 1, 2, 0, -3 ], [ 5, -5, 0, 2, 0, -4 ] ], 0.5 ], - [ [ [ 3, -5, 0, 2, 0, -3 ], [ 4, -5, -1, 2, 0, -3 ], [ 4, -5, 0, 2, 1, -3 ], [ 5, -5, 0, 2, 0, -4 ] ], 1.5 ] - ], - [ - [ [ [ 3, -5, 0, 3, 0, -4 ], [ 4, -5, -1, 2, 0, -3 ], [ 4, -5, 0, 2, 1, -3 ], [ 5, -5, 0, 2, 0, -4 ] ], 0.5 ] - ], - [ - [ [ [ 3, -5, 0, 2, 1, -4 ], [ 4, -5, -1, 2, 0, -3 ], [ 4, -5, 0, 2, 1, -3 ], [ 5, -5, 0, 2, 0, -4 ] ], 1.875 ], - [ [ [ 3, -5, 0, 2, 1, -4 ], [ 4, -5, 0, 2, 1, -4 ], [ 4, -5, 0, 2, 1, -3 ], [ 5, -5, 0, 2, 0, -4 ] ], 1.75 ], - [ [ [ 3, -5, 0, 2, 1, -4 ], [ 4, -5, 0, 2, 1, -4 ], [ 4, -5, 0, 2, 1, -3 ], [ 3, -4, 0, 2, 1, -3 ] ], 0.5 ] - ], - [ - [ [ [ 3, -5, 0, 2, 1, -4 ], [ 4, -5, 0, 2, 1, -4 ], [ 4, -5, 0, 2, 1, -3 ], [ 3, -5, 0, 2, 1, -2 ] ], 1.5 ] - ], - [ - [ [ [ 3, -5, 0, 2, 1, -4 ], [ 4, -5, 0, 2, 1, -4 ], [ 4, -5, 0, 2, 2, -4 ], [ 3, -5, 0, 2, 1, -2 ] ], 1.25 ] - ], - [ - [ [ [ 2, -5, -1, 2, 1, -2 ], [ 4, -5, 0, 2, 1, -4 ], [ 4, -5, 0, 2, 2, -4 ], [ 3, -5, 0, 2, 1, -2 ] ], 1.375 ], - [ [ [ 2, -5, -1, 2, 1, -2 ], [ 4, -5, 0, 2, 1, -4 ], [ 4, -5, 0, 1, 1, -2 ], [ 3, -5, 0, 2, 1, -2 ] ], 0.875 ], - [ [ [ 2, -5, -1, 2, 1, -2 ], [ 2, -5, 0, 3, 1, -2 ], [ 4, -5, 0, 1, 1, -2 ], [ 3, -5, 0, 2, 1, -2 ] ], 1.875 ] - ], - [ - [ [ [ 2, -5, -1, 2, 1, -2 ], [ 4, -5, -1, 2, 1, -3 ], [ 4, -5, 0, 1, 1, -2 ], [ 3, -5, 0, 2, 1, -2 ] ], 0.875 ], - [ [ [ 2, -5, -1, 2, 1, -2 ], [ 4, -5, -1, 2, 1, -3 ], [ 4, -5, 0, 1, 1, -2 ], [ 4, -6, -1, 2, 1, -2 ] ], 1.75 ], - [ [ [ 2, -5, -1, 2, 1, -2 ], [ 4, -5, -1, 2, 1, -3 ], [ 3, -4, -1, 2, 1, -2 ], [ 4, -6, -1, 2, 1, -2 ] ], 0.875 ] - ], - [ - [ [ [ 2, -5, -1, 2, 1, -2 ], [ 4, -5, -1, 2, 1, -3 ], [ 3, -4, -1, 2, 1, -2 ], [ 5, -5, -1, 1, 1, -3 ] ], 1.125 ], - [ [ [ 2, -5, -1, 2, 1, -2 ], [ 4, -5, -1, 2, 1, -3 ], [ 4, -6, -1, 2, 1, -2 ], [ 5, -5, -1, 1, 1, -3 ] ], 1 ] - ], - [ - [ [ [ 2, -5, -1, 2, 1, -2 ], [ 4, -5, -1, 2, 1, -3 ], [ 4, -6, -1, 2, 1, -2 ], [ 3, -6, -1, 3, 1, -2 ] ], 0.625 ], - [ [ [ 3, -6, -2, 2, 1, -2 ], [ 4, -5, -1, 2, 1, -3 ], [ 4, -6, -1, 2, 1, -2 ], [ 3, -6, -1, 3, 1, -2 ] ], 0.75 ], - [ [ [ 3, -6, -2, 2, 1, -2 ], [ 2, -6, -1, 2, 1, -1 ], [ 4, -6, -1, 2, 1, -2 ], [ 3, -6, -1, 3, 1, -2 ] ], 0.5 ] - ], - [ - [ [ [ 3, -6, -2, 2, 1, -2 ], [ 4, -6, -2, 1, 1, -2 ], [ 4, -6, -1, 2, 1, -2 ], [ 3, -6, -1, 3, 1, -2 ] ], 1.5 ], - [ [ [ 3, -6, -2, 2, 1, -2 ], [ 4, -6, -2, 1, 1, -2 ], [ 4, -6, -1, 2, 1, -2 ], [ 5, -6, -2, 2, 1, -3 ] ], 0.75 ], - [ [ [ 3, -6, -2, 2, 1, -2 ], [ 4, -6, -2, 1, 1, -2 ], [ 5, -7, -2, 2, 1, -2 ], [ 5, -6, -2, 2, 1, -3 ] ], 0.875 ] - ], - [ - [ [ [ 3, -6, -2, 2, 1, -2 ], [ 4, -6, -2, 2, 1, -3 ], [ 5, -7, -2, 2, 1, -2 ], [ 5, -6, -2, 2, 1, -3 ] ], 1 ], - [ [ [ 3, -6, -2, 2, 1, -2 ], [ 4, -6, -2, 2, 1, -3 ], [ 5, -7, -2, 2, 1, -2 ], [ 4, -6, -2, 2, 2, -2 ] ], 0.5 ], - [ [ [ 3, -6, -2, 2, 1, -2 ], [ 4, -6, -2, 2, 1, -3 ], [ 5, -6, -2, 2, 0, -2 ], [ 4, -6, -2, 2, 2, -2 ] ], 1.125 ] - ], - [ - [ [ [ 3, -6, -2, 2, 1, -2 ], [ 3, -6, -2, 2, 2, -2 ], [ 5, -6, -2, 2, 0, -2 ], [ 4, -6, -2, 2, 2, -2 ] ], 1.75 ], - [ [ [ 3, -6, -2, 2, 1, -2 ], [ 3, -6, -2, 2, 2, -2 ], [ 5, -6, -2, 2, 0, -2 ], [ 5, -6, -2, 1, 1, -2 ] ], 0.5 ], - [ [ [ 3, -6, -2, 2, 1, -2 ], [ 3, -6, -2, 2, 2, -2 ], [ 4, -6, -2, 2, 2, -2 ], [ 5, -6, -2, 1, 1, -2 ] ], 1.75 ] - ], - [ - [ [ [ 3, -6, -2, 2, 1, -2 ], [ 5, -7, -2, 1, 1, -2 ], [ 4, -6, -2, 2, 2, -2 ], [ 5, -6, -2, 1, 1, -2 ] ], 0.875 ] - ], - [ - [ [ [ 3, -6, -2, 2, 1, -2 ], [ 5, -7, -2, 1, 1, -2 ], [ 6, -7, -2, 1, 0, -2 ], [ 5, -6, -2, 1, 1, -2 ] ], 1.25 ] - ], - [ - [ [ [ 3, -6, -2, 2, 1, -2 ], [ 5, -7, -2, 1, 1, -2 ], [ 6, -7, -3, 1, 1, -2 ], [ 5, -6, -2, 1, 1, -2 ] ], 1.625 ], - [ [ [ 3, -6, -2, 2, 1, -2 ], [ 5, -7, -2, 1, 1, -2 ], [ 6, -7, -3, 1, 1, -2 ], [ 5, -7, -2, 1, 1, -1 ] ], 1.375 ], - [ [ [ 5, -7, -2, 1, 0, -2 ], [ 5, -7, -2, 1, 1, -2 ], [ 6, -7, -3, 1, 1, -2 ], [ 5, -7, -2, 1, 1, -1 ] ], 1.375 ] - ], - [ - [ [ [ 5, -7, -2, 1, 0, -2 ], [ 5, -7, -2, 1, 1, -2 ], [ 7, -7, -2, 1, 0, -3 ], [ 5, -7, -2, 1, 1, -1 ] ], 1.5 ], - [ [ [ 5, -7, -2, 1, 0, -2 ], [ 5, -6, -2, 1, 0, -2 ], [ 7, -7, -2, 1, 0, -3 ], [ 5, -7, -2, 1, 1, -1 ] ], 0.875 ] - ], - [ - [ [ [ 5, -7, -2, 1, 0, -2 ], [ 5, -6, -2, 1, 0, -2 ], [ 7, -7, -2, 1, 0, -3 ], [ 5, -6, -2, 1, 0, -1 ] ], 0.75 ], - [ [ [ 6, -8, -2, 1, 0, -3 ], [ 5, -6, -2, 1, 0, -2 ], [ 7, -7, -2, 1, 0, -3 ], [ 5, -6, -2, 1, 0, -1 ] ], 1.75 ] - ], - [ - [ [ [ 6, -8, -2, 1, 0, -3 ], [ 5, -6, -2, 1, 0, -2 ], [ 5, -6, -2, 2, 0, -2 ], [ 5, -6, -2, 1, 0, -1 ] ], 0.5 ] - ], - [ - [ [ [ 6, -8, -2, 1, 0, -3 ], [ 5, -6, -2, 1, 0, -2 ], [ 5, -6, -2, 2, 0, -2 ], [ 6, -6, -2, 1, -1, -2 ] ], 1.375 ], - [ [ [ 6, -8, -2, 1, 0, -3 ], [ 5, -6, -2, 1, 0, -2 ], [ 6, -6, -3, 1, 0, -2 ], [ 6, -6, -2, 1, -1, -2 ] ], 1.25 ] - ], - [ - [ [ [ 5, -6, -3, 1, -1, -2 ], [ 5, -6, -2, 1, 0, -2 ], [ 6, -6, -3, 1, 0, -2 ], [ 6, -6, -2, 1, -1, -2 ] ], 1.75 ], - [ [ [ 5, -6, -3, 1, -1, -2 ], [ 5, -5, -2, 1, -1, -2 ], [ 6, -6, -3, 1, 0, -2 ], [ 6, -6, -2, 1, -1, -2 ] ], 1.375 ], - [ [ [ 5, -6, -3, 1, -1, -2 ], [ 5, -5, -2, 1, -1, -2 ], [ 4, -5, -2, 1, -1, -2 ], [ 6, -6, -2, 1, -1, -2 ] ], 1.25 ] - ], - [ - [ [ [ 5, -6, -3, 1, -1, -2 ], [ 6, -6, -3, 1, -1, -2 ], [ 4, -5, -2, 1, -1, -2 ], [ 6, -6, -2, 1, -1, -2 ] ], 1.375 ], - [ [ [ 4, -6, -2, 2, -1, -2 ], [ 6, -6, -3, 1, -1, -2 ], [ 4, -5, -2, 1, -1, -2 ], [ 6, -6, -2, 1, -1, -2 ] ], 1.125 ], - [ [ [ 4, -6, -2, 2, -1, -2 ], [ 6, -6, -3, 1, -1, -2 ], [ 4, -6, -2, 1, -1, -1 ], [ 6, -6, -2, 1, -1, -2 ] ], 1.75 ] - ], - [ - [ [ [ 4, -6, -2, 2, -1, -2 ], [ 5, -6, -2, 2, -1, -3 ], [ 4, -6, -2, 1, -1, -1 ], [ 6, -6, -2, 1, -1, -2 ] ], 1.625 ], - [ [ [ 4, -6, -2, 2, -1, -2 ], [ 5, -6, -2, 2, -1, -3 ], [ 4, -6, -2, 1, -1, -1 ], [ 5, -6, -1, 2, -1, -2 ] ], 0.875 ], - [ [ [ 4, -6, -2, 2, -1, -2 ], [ 5, -6, -2, 2, -1, -3 ], [ 3, -6, -2, 3, -1, -2 ], [ 5, -6, -1, 2, -1, -2 ] ], 1.625 ] - ], - [ - [ [ [ 4, -6, -2, 2, -1, -2 ], [ 5, -6, -2, 2, -1, -3 ], [ 3, -5, -1, 2, -1, -2 ], [ 5, -6, -1, 2, -1, -2 ] ], 0.875 ], - [ [ [ 3, -6, -1, 3, -1, -2 ], [ 5, -6, -2, 2, -1, -3 ], [ 3, -5, -1, 2, -1, -2 ], [ 5, -6, -1, 2, -1, -2 ] ], 1.375 ] - ], - [ - [ [ [ 3, -6, -1, 3, -1, -2 ], [ 4, -6, 0, 2, -1, -2 ], [ 3, -5, -1, 2, -1, -2 ], [ 5, -6, -1, 2, -1, -2 ] ], 1.25 ], - [ [ [ 3, -6, -1, 3, -1, -2 ], [ 4, -6, 0, 2, -1, -2 ], [ 4, -6, -2, 2, -1, -2 ], [ 5, -6, -1, 2, -1, -2 ] ], 1.25 ], - [ [ [ 3, -5, -1, 2, -1, -2 ], [ 4, -6, 0, 2, -1, -2 ], [ 4, -6, -2, 2, -1, -2 ], [ 5, -6, -1, 2, -1, -2 ] ], 1.25 ] - ], - [ - [ [ [ 3, -5, -1, 2, -1, -2 ], [ 4, -6, 0, 2, -1, -2 ], [ 4, -5, -1, 2, -1, -3 ], [ 5, -6, -1, 2, -1, -2 ] ], 1.5 ], - [ [ [ 3, -5, -1, 2, -1, -2 ], [ 5, -7, -1, 2, -1, -2 ], [ 4, -5, -1, 2, -1, -3 ], [ 5, -6, -1, 2, -1, -2 ] ], 1.125 ] - ], - [ - [ [ [ 3, -5, -1, 2, -1, -2 ], [ 5, -7, -1, 2, -1, -2 ], [ 4, -5, -1, 2, -1, -3 ], [ 5, -7, 0, 2, -1, -2 ] ], 0.75 ], - [ [ [ 3, -5, -1, 2, -1, -2 ], [ 5, -7, -1, 2, -1, -2 ], [ 4, -6, -1, 2, -1, -2 ], [ 5, -7, 0, 2, -1, -2 ] ], 1.5 ], - [ [ [ 5, -7, -1, 2, -1, -3 ], [ 5, -7, -1, 2, -1, -2 ], [ 4, -6, -1, 2, -1, -2 ], [ 5, -7, 0, 2, -1, -2 ] ], 1.625 ] - ], - [ - [ [ [ 5, -7, -1, 2, -1, -3 ], [ 4, -7, 0, 3, -1, -2 ], [ 4, -6, -1, 2, -1, -2 ], [ 5, -7, 0, 2, -1, -2 ] ], 1.375 ], - [ [ [ 5, -7, -1, 2, -1, -3 ], [ 4, -7, 0, 3, -1, -2 ], [ 6, -8, -1, 2, -1, -3 ], [ 5, -7, 0, 2, -1, -2 ] ], 0.375 ] - ], - [ - [ [ [ 5, -7, -1, 2, -1, -3 ], [ 4, -7, 0, 3, -1, -2 ], [ 3, -7, 0, 3, -1, -1 ], [ 5, -7, 0, 2, -1, -2 ] ], 1.125 ], - [ [ [ 4, -7, 0, 2, -1, -2 ], [ 4, -7, 0, 3, -1, -2 ], [ 3, -7, 0, 3, -1, -1 ], [ 5, -7, 0, 2, -1, -2 ] ], 0.875 ], - [ [ [ 4, -7, 0, 2, -1, -2 ], [ 4, -7, 0, 3, -1, -2 ], [ 3, -7, 0, 3, -1, -1 ], [ 5, -7, 0, 3, -1, -3 ] ], 1.125 ] - ], - [ - [ [ [ 3, -7, 0, 3, -1, -2 ], [ 4, -7, 0, 3, -1, -2 ], [ 3, -7, 0, 3, -1, -1 ], [ 5, -7, 0, 3, -1, -3 ] ], 0.75 ], - [ [ [ 3, -7, 0, 3, -1, -2 ], [ 4, -7, 0, 3, -1, -2 ], [ 3, -7, 0, 3, -1, -1 ], [ 5, -8, 0, 3, -1, -2 ] ], 0.625 ], - [ [ [ 3, -7, 0, 3, -1, -2 ], [ 4, -7, 0, 3, -1, -2 ], [ 3, -7, 0, 4, -1, -2 ], [ 5, -8, 0, 3, -1, -2 ] ], 1.125 ] - ], - [ - [ [ [ 3, -7, 0, 3, -1, -2 ], [ 4, -7, 0, 4, -1, -3 ], [ 3, -7, 0, 4, -1, -2 ], [ 5, -8, 0, 3, -1, -2 ] ], 0.5 ] - ], - [ - [ [ [ 3, -7, 0, 3, -1, -2 ], [ 4, -7, -1, 3, -1, -2 ], [ 3, -7, 0, 4, -1, -2 ], [ 5, -8, 0, 3, -1, -2 ] ], 0.625 ], - [ [ [ 3, -7, 0, 3, -1, -2 ], [ 4, -7, -1, 3, -1, -2 ], [ 4, -8, 0, 3, 0, -2 ], [ 5, -8, 0, 3, -1, -2 ] ], 1.625 ] - ], - [ - [ [ [ 3, -7, 0, 3, -1, -2 ], [ 4, -7, -1, 3, -1, -2 ], [ 4, -8, 0, 3, 0, -2 ], [ 5, -7, 0, 3, -2, -2 ] ], 1.125 ], - [ [ [ 3, -7, 0, 3, -1, -2 ], [ 4, -7, -1, 3, -1, -2 ], [ 4, -7, 0, 3, -1, -2 ], [ 5, -7, 0, 3, -2, -2 ] ], 1.625 ], - [ [ [ 3, -7, 0, 3, -1, -2 ], [ 3, -7, 0, 4, -1, -2 ], [ 4, -7, 0, 3, -1, -2 ], [ 5, -7, 0, 3, -2, -2 ] ], 1 ] - ], - [ - [ [ [ 3, -7, 0, 3, -1, -2 ], [ 3, -7, 0, 4, -1, -2 ], [ 4, -7, 0, 4, -1, -3 ], [ 5, -7, 0, 3, -2, -2 ] ], 0.875 ] - ], - [ - [ [ [ 4, -7, 0, 3, -3, -2 ], [ 3, -7, 0, 4, -1, -2 ], [ 4, -7, 0, 4, -1, -3 ], [ 5, -7, 0, 3, -2, -2 ] ], 1.625 ], - [ [ [ 4, -7, 0, 3, -3, -2 ], [ 3, -7, 0, 3, -1, -2 ], [ 4, -7, 0, 4, -1, -3 ], [ 5, -7, 0, 3, -2, -2 ] ], 1 ] - ], - [ - [ [ [ 4, -7, 0, 3, -3, -2 ], [ 3, -7, 0, 4, -1, -3 ], [ 4, -7, 0, 4, -1, -3 ], [ 5, -7, 0, 3, -2, -2 ] ], 0.75 ], - [ [ [ 4, -7, 0, 3, -3, -2 ], [ 3, -7, 0, 4, -1, -3 ], [ 4, -7, 0, 4, -1, -3 ], [ 5, -7, 0, 4, -1, -4 ] ], 1.5 ] - ], - [ - [ [ [ 4, -7, 0, 3, -3, -2 ], [ 3, -7, 0, 4, -1, -3 ], [ 3, -6, 0, 4, -1, -3 ], [ 5, -7, 0, 4, -1, -4 ] ], 1 ], - [ [ [ 3, -7, 0, 5, -1, -4 ], [ 3, -7, 0, 4, -1, -3 ], [ 3, -6, 0, 4, -1, -3 ], [ 5, -7, 0, 4, -1, -4 ] ], 0.625 ] - ], - [ - [ [ [ 3, -7, 0, 5, -1, -4 ], [ 3, -7, 0, 4, -1, -3 ], [ 5, -8, 0, 4, -1, -4 ], [ 5, -7, 0, 4, -1, -4 ] ], 1 ], - [ [ [ 3, -7, 0, 5, -1, -4 ], [ 3, -7, 0, 4, 0, -4 ], [ 5, -8, 0, 4, -1, -4 ], [ 5, -7, 0, 4, -1, -4 ] ], 0.5 ] - ], - [ - [ [ [ 3, -7, 0, 5, -1, -4 ], [ 3, -7, 0, 4, 0, -4 ], [ 5, -8, 0, 4, -1, -4 ], [ 4, -7, 1, 5, -1, -4 ] ], 1.25 ] - ], - [ - [ [ [ 4, -8, 0, 4, 0, -4 ], [ 3, -7, 0, 4, 0, -4 ], [ 5, -8, 0, 4, -1, -4 ], [ 4, -7, 1, 5, -1, -4 ] ], 1.75 ], - [ [ [ 4, -8, 0, 4, 0, -4 ], [ 3, -7, 0, 4, 0, -4 ], [ 3, -7, 0, 4, 0, -3 ], [ 4, -7, 1, 5, -1, -4 ] ], 1.75 ], - [ [ [ 4, -8, 0, 4, 0, -4 ], [ 3, -7, 0, 4, 0, -4 ], [ 3, -7, 0, 4, 0, -3 ], [ 4, -7, 0, 4, 1, -4 ] ], 1 ] - ], - [ - [ [ [ 4, -8, 0, 4, 0, -4 ], [ 3, -7, 0, 4, 0, -4 ], [ 3, -7, 0, 4, 2, -4 ], [ 4, -7, 0, 4, 1, -4 ] ], 1.25 ], - [ [ [ 4, -8, 0, 4, 0, -4 ], [ 3, -7, -1, 4, 1, -4 ], [ 3, -7, 0, 4, 2, -4 ], [ 4, -7, 0, 4, 1, -4 ] ], 0.625 ], - [ [ [ 2, -7, 0, 5, 1, -4 ], [ 3, -7, -1, 4, 1, -4 ], [ 3, -7, 0, 4, 2, -4 ], [ 4, -7, 0, 4, 1, -4 ] ], 0.875 ] - ], - [ - [ [ [ 2, -7, 0, 5, 1, -4 ], [ 3, -7, -1, 4, 1, -4 ], [ 3, -7, 0, 4, 2, -4 ], [ 3, -7, 0, 4, 2, -3 ] ], 0.875 ] - ], - [ - [ [ [ 2, -7, 0, 5, 1, -4 ], [ 3, -7, -1, 4, 1, -4 ], [ 3, -7, 0, 4, 2, -4 ], [ 4, -8, 0, 4, 2, -4 ] ], 0.5 ], - [ [ [ 2, -7, 0, 5, 1, -4 ], [ 3, -7, 0, 4, 2, -5 ], [ 3, -7, 0, 4, 2, -4 ], [ 4, -8, 0, 4, 2, -4 ] ], 1.375 ], - [ [ [ 2, -7, 0, 4, 3, -4 ], [ 3, -7, 0, 4, 2, -5 ], [ 3, -7, 0, 4, 2, -4 ], [ 4, -8, 0, 4, 2, -4 ] ], 0.5 ] - ], - [ - [ [ [ 2, -7, 0, 4, 3, -4 ], [ 3, -7, 0, 4, 2, -5 ], [ 3, -7, 0, 4, 2, -4 ], [ 3, -6, 0, 4, 2, -4 ] ], 1.375 ], - [ [ [ 2, -7, 0, 4, 3, -4 ], [ 3, -8, 0, 4, 2, -4 ], [ 3, -7, 0, 4, 2, -4 ], [ 3, -6, 0, 4, 2, -4 ] ], 0.375 ] - ], - [ - [ [ [ 1, -5, 0, 4, 2, -4 ], [ 3, -8, 0, 4, 2, -4 ], [ 3, -7, 0, 4, 2, -4 ], [ 3, -6, 0, 4, 2, -4 ] ], 1.375 ], - [ [ [ 1, -5, 0, 4, 2, -4 ], [ 2, -6, 0, 4, 2, -4 ], [ 3, -7, 0, 4, 2, -4 ], [ 3, -6, 0, 4, 2, -4 ] ], 1.125 ], - [ [ [ 1, -5, 0, 4, 2, -4 ], [ 2, -6, 0, 4, 2, -4 ], [ 2, -5, 0, 4, 2, -4 ], [ 3, -6, 0, 4, 2, -4 ] ], 1.5 ] - ], - [ - [ [ [ 2, -5, 0, 3, 2, -4 ], [ 2, -6, 0, 4, 2, -4 ], [ 2, -5, 0, 4, 2, -4 ], [ 3, -6, 0, 4, 2, -4 ] ], 1.5 ], - [ [ [ 2, -5, 0, 3, 2, -4 ], [ 1, -4, 0, 4, 2, -4 ], [ 2, -5, 0, 4, 2, -4 ], [ 3, -6, 0, 4, 2, -4 ] ], 1.125 ], - [ [ [ 2, -5, 0, 3, 2, -4 ], [ 1, -4, 0, 4, 2, -4 ], [ 2, -5, 0, 4, 2, -4 ], [ 3, -5, 0, 4, 1, -4 ] ], 0.625 ] - ], - [ - [ [ [ 2, -5, 0, 3, 2, -4 ], [ 1, -4, 0, 4, 2, -4 ], [ 2, -4, 0, 4, 1, -4 ], [ 3, -5, 0, 4, 1, -4 ] ], 1.25 ] - ], - [ - [ [ [ 2, -5, 0, 3, 2, -4 ], [ 3, -5, 0, 3, 1, -4 ], [ 2, -4, 0, 4, 1, -4 ], [ 3, -5, 0, 4, 1, -4 ] ], 1.75 ], - [ [ [ 2, -5, 0, 3, 2, -4 ], [ 3, -5, 0, 3, 1, -4 ], [ 3, -5, 0, 3, 2, -5 ], [ 3, -5, 0, 4, 1, -4 ] ], 1.625 ], - [ [ [ 2, -5, 0, 3, 2, -4 ], [ 3, -5, 0, 3, 1, -4 ], [ 3, -5, 0, 3, 2, -5 ], [ 3, -5, 0, 3, 2, -4 ] ], 0.625 ] - ], - [ - [ [ [ 3, -5, 0, 3, 0, -4 ], [ 3, -5, 0, 3, 1, -4 ], [ 3, -5, 0, 3, 2, -5 ], [ 3, -5, 0, 3, 2, -4 ] ], 1.625 ], - [ [ [ 3, -5, 0, 3, 0, -4 ], [ 3, -5, 0, 3, 1, -4 ], [ 3, -6, 0, 3, 2, -4 ], [ 3, -5, 0, 3, 2, -4 ] ], 1 ] - ], - [ - [ [ [ 3, -5, 0, 3, 0, -4 ], [ 3, -5, 0, 3, 1, -4 ], [ 3, -6, 0, 3, 2, -4 ], [ 3, -6, 0, 4, 2, -4 ] ], 1.375 ], - [ [ [ 2, -6, 1, 3, 2, -4 ], [ 3, -5, 0, 3, 1, -4 ], [ 3, -6, 0, 3, 2, -4 ], [ 3, -6, 0, 4, 2, -4 ] ], 1 ], - [ [ [ 2, -6, 1, 3, 2, -4 ], [ 3, -6, 1, 3, 2, -4 ], [ 3, -6, 0, 3, 2, -4 ], [ 3, -6, 0, 4, 2, -4 ] ], 0.75 ] - ], - [ - [ [ [ 2, -6, 1, 3, 2, -4 ], [ 3, -6, 0, 3, 3, -4 ], [ 3, -6, 0, 3, 2, -4 ], [ 3, -6, 0, 4, 2, -4 ] ], 0.875 ] - ], - [ - [ [ [ 2, -6, 0, 3, 3, -4 ], [ 3, -6, 0, 3, 3, -4 ], [ 3, -6, 0, 3, 2, -4 ], [ 3, -6, 0, 4, 2, -4 ] ], 1.5 ], - [ [ [ 2, -6, 0, 3, 3, -4 ], [ 3, -6, 0, 3, 3, -4 ], [ 3, -6, -1, 3, 3, -4 ], [ 3, -6, 0, 4, 2, -4 ] ], 0.5 ], - [ [ [ 2, -6, 0, 3, 3, -4 ], [ 3, -6, 0, 3, 3, -4 ], [ 3, -6, -1, 3, 3, -4 ], [ 3, -6, 0, 3, 4, -4 ] ], 1.5 ] - ], - [ - [ [ [ 2, -6, 0, 3, 3, -4 ], [ 3, -6, -1, 3, 4, -4 ], [ 3, -6, -1, 3, 3, -4 ], [ 3, -6, 0, 3, 4, -4 ] ], 1.125 ] - ], - [ - [ [ [ 2, -6, 0, 3, 3, -4 ], [ 4, -6, -2, 3, 3, -4 ], [ 3, -6, -1, 3, 3, -4 ], [ 3, -6, 0, 3, 4, -4 ] ], 1 ] - ], - [ - [ [ [ 2, -6, 0, 3, 3, -4 ], [ 4, -6, -2, 3, 3, -4 ], [ 3, -6, -1, 3, 3, -4 ], [ 3, -6, -2, 4, 3, -4 ] ], 1.625 ], - [ [ [ 2, -6, 0, 3, 3, -4 ], [ 4, -6, -2, 3, 3, -4 ], [ 3, -6, -2, 3, 4, -4 ], [ 3, -6, -2, 4, 3, -4 ] ], 0.625 ], - [ [ [ 2, -6, -2, 4, 3, -4 ], [ 4, -6, -2, 3, 3, -4 ], [ 3, -6, -2, 3, 4, -4 ], [ 3, -6, -2, 4, 3, -4 ] ], 1.625 ] - ], - [ - [ [ [ 2, -6, -2, 4, 3, -4 ], [ 3, -6, -1, 4, 3, -4 ], [ 3, -6, -2, 3, 4, -4 ], [ 3, -6, -2, 4, 3, -4 ] ], 1.375 ], - [ [ [ 2, -6, -2, 4, 3, -4 ], [ 3, -6, -1, 4, 3, -4 ], [ 2, -6, -2, 5, 3, -4 ], [ 3, -6, -2, 4, 3, -4 ] ], 0.5 ], - [ [ [ 1, -6, -2, 4, 3, -3 ], [ 3, -6, -1, 4, 3, -4 ], [ 2, -6, -2, 5, 3, -4 ], [ 3, -6, -2, 4, 3, -4 ] ], 1.625 ] - ], - [ - [ [ [ 1, -6, -2, 4, 3, -3 ], [ 2, -6, -2, 4, 3, -4 ], [ 2, -6, -2, 5, 3, -4 ], [ 3, -6, -2, 4, 3, -4 ] ], 1.125 ], - [ [ [ 1, -6, -2, 4, 3, -3 ], [ 2, -6, -2, 4, 3, -4 ], [ 3, -6, -2, 4, 3, -5 ], [ 3, -6, -2, 4, 3, -4 ] ], 1.125 ] - ], - [ - [ [ [ 1, -6, -2, 4, 3, -3 ], [ 2, -6, -2, 4, 3, -4 ], [ 3, -6, -2, 4, 3, -5 ], [ 3, -7, -2, 4, 3, -3 ] ], 1 ], - [ [ [ 1, -6, -2, 4, 3, -3 ], [ 2, -6, -2, 4, 3, -4 ], [ 1, -6, -2, 4, 3, -2 ], [ 3, -7, -2, 4, 3, -3 ] ], 0.875 ], - [ [ [ 1, -6, -2, 4, 3, -3 ], [ 2, -7, -2, 4, 3, -3 ], [ 1, -6, -2, 4, 3, -2 ], [ 3, -7, -2, 4, 3, -3 ] ], 1.125 ] - ], - [ - [ [ [ 1, -6, -2, 4, 3, -3 ], [ 3, -7, -2, 3, 3, -3 ], [ 1, -6, -2, 4, 3, -2 ], [ 3, -7, -2, 4, 3, -3 ] ], 1.75 ], - [ [ [ 1, -7, -2, 5, 3, -3 ], [ 3, -7, -2, 3, 3, -3 ], [ 1, -6, -2, 4, 3, -2 ], [ 3, -7, -2, 4, 3, -3 ] ], 1.5 ], - [ [ [ 1, -7, -2, 5, 3, -3 ], [ 3, -7, -2, 3, 3, -3 ], [ 2, -7, -2, 4, 4, -3 ], [ 3, -7, -2, 4, 3, -3 ] ], 0.75 ] - ], - [ - [ [ [ 1, -7, -2, 5, 3, -3 ], [ 3, -7, -2, 3, 3, -3 ], [ 2, -6, -2, 4, 3, -3 ], [ 3, -7, -2, 4, 3, -3 ] ], 0.625 ] - ], - [ - [ [ [ 1, -6, -1, 4, 3, -3 ], [ 3, -7, -2, 3, 3, -3 ], [ 2, -6, -2, 4, 3, -3 ], [ 3, -7, -2, 4, 3, -3 ] ], 1.375 ], - [ [ [ 1, -6, -1, 4, 3, -3 ], [ 3, -7, -2, 4, 3, -4 ], [ 2, -6, -2, 4, 3, -3 ], [ 3, -7, -2, 4, 3, -3 ] ], 1.625 ] - ], - [ - [ [ [ 1, -6, -1, 4, 3, -3 ], [ 3, -7, -2, 4, 3, -4 ], [ 2, -6, -1, 4, 3, -4 ], [ 3, -7, -2, 4, 3, -3 ] ], 0.875 ], - [ [ [ 1, -6, -1, 4, 3, -3 ], [ 3, -7, -2, 4, 3, -4 ], [ 2, -6, -1, 4, 3, -4 ], [ 3, -6, -1, 3, 3, -3 ] ], 1.625 ], - [ [ [ 1, -6, -1, 4, 3, -3 ], [ 2, -6, -1, 4, 2, -3 ], [ 2, -6, -1, 4, 3, -4 ], [ 3, -6, -1, 3, 3, -3 ] ], 1.375 ] - ], - [ - [ [ [ 1, -6, -1, 4, 3, -3 ], [ 0, -6, -1, 4, 3, -2 ], [ 2, -6, -1, 4, 3, -4 ], [ 3, -6, -1, 3, 3, -3 ] ], 1.5 ] - ], - [ - [ [ [ 1, -5, -1, 3, 3, -3 ], [ 0, -6, -1, 4, 3, -2 ], [ 2, -6, -1, 4, 3, -4 ], [ 3, -6, -1, 3, 3, -3 ] ], 1.625 ], - [ [ [ 1, -5, -1, 3, 3, -3 ], [ 0, -6, -1, 4, 3, -2 ], [ 3, -6, -1, 3, 3, -4 ], [ 3, -6, -1, 3, 3, -3 ] ], 1.625 ] - ], - [ - [ [ [ 1, -5, -1, 3, 3, -3 ], [ 1, -6, -1, 3, 3, -2 ], [ 3, -6, -1, 3, 3, -4 ], [ 3, -6, -1, 3, 3, -3 ] ], 1.875 ], - [ [ [ 1, -5, -1, 3, 3, -3 ], [ 1, -6, -1, 3, 3, -2 ], [ 1, -6, -1, 4, 3, -3 ], [ 3, -6, -1, 3, 3, -3 ] ], 1.5 ], - [ [ [ 2, -6, -2, 3, 3, -3 ], [ 1, -6, -1, 3, 3, -2 ], [ 1, -6, -1, 4, 3, -3 ], [ 3, -6, -1, 3, 3, -3 ] ], 0.625 ] - ], - [ - [ [ [ 2, -6, -1, 3, 2, -3 ], [ 1, -6, -1, 3, 3, -2 ], [ 1, -6, -1, 4, 3, -3 ], [ 3, -6, -1, 3, 3, -3 ] ], 1 ] - ], - [ - [ [ [ 0, -6, -1, 5, 3, -3 ], [ 1, -6, -1, 3, 3, -2 ], [ 1, -6, -1, 4, 3, -3 ], [ 3, -6, -1, 3, 3, -3 ] ], 1.75 ] - ], - [ - [ [ [ 0, -6, -1, 5, 3, -3 ], [ 1, -6, -1, 3, 3, -2 ], [ 2, -6, -1, 2, 3, -2 ], [ 3, -6, -1, 3, 3, -3 ] ], 0.625 ], - [ [ [ 1, -6, -1, 4, 3, -3 ], [ 1, -6, -1, 3, 3, -2 ], [ 2, -6, -1, 2, 3, -2 ], [ 3, -6, -1, 3, 3, -3 ] ], 0.875 ] - ], - [ - [ [ [ 1, -5, -1, 2, 3, -2 ], [ 1, -6, -1, 3, 3, -2 ], [ 2, -6, -1, 2, 3, -2 ], [ 3, -6, -1, 3, 3, -3 ] ], 0.875 ], - [ [ [ 1, -5, -1, 2, 3, -2 ], [ 1, -6, -1, 3, 3, -2 ], [ 2, -6, -1, 2, 3, -2 ], [ 4, -6, -1, 1, 3, -2 ] ], 1 ] - ], - [ - [ [ [ 3, -6, -1, 1, 2, -2 ], [ 1, -6, -1, 3, 3, -2 ], [ 2, -6, -1, 2, 3, -2 ], [ 4, -6, -1, 1, 3, -2 ] ], 1.375 ], - [ [ [ 3, -6, -1, 1, 2, -2 ], [ 2, -6, -1, 1, 3, -1 ], [ 2, -6, -1, 2, 3, -2 ], [ 4, -6, -1, 1, 3, -2 ] ], 0.5 ], - [ [ [ 3, -6, -1, 1, 2, -2 ], [ 2, -6, -1, 1, 3, -1 ], [ 3, -6, -1, 1, 3, -2 ], [ 4, -6, -1, 1, 3, -2 ] ], 1.5 ] - ], - [ - [ [ [ 3, -6, -1, 1, 2, -2 ], [ 2, -6, -1, 1, 3, -1 ], [ 3, -6, -1, 1, 3, -2 ], [ 3, -6, -1, 2, 3, -2 ] ], 0.625 ], - [ [ [ 3, -6, -2, 1, 3, -2 ], [ 2, -6, -1, 1, 3, -1 ], [ 3, -6, -1, 1, 3, -2 ], [ 3, -6, -1, 2, 3, -2 ] ], 1.75 ] - ], - [ - [ [ [ 3, -6, -2, 1, 3, -2 ], [ 2, -6, -1, 1, 3, -1 ], [ 3, -6, -2, 1, 4, -2 ], [ 3, -6, -1, 2, 3, -2 ] ], 1.25 ], - [ [ [ 3, -6, -2, 1, 3, -2 ], [ 4, -6, -2, 0, 3, -2 ], [ 3, -6, -2, 1, 4, -2 ], [ 3, -6, -1, 2, 3, -2 ] ], 1.625 ], - [ [ [ 3, -6, -2, 1, 3, -2 ], [ 4, -6, -2, 0, 3, -2 ], [ 3, -6, -2, 1, 4, -2 ], [ 5, -6, -2, 1, 3, -3 ] ], 0.875 ] - ], - [ - [ [ [ 3, -6, -2, 1, 3, -2 ], [ 4, -6, -2, 0, 3, -2 ], [ 3, -6, -2, 1, 4, -2 ], [ 4, -6, -2, 1, 3, -2 ] ], 1.125 ], - [ [ [ 3, -7, -2, 0, 3, -2 ], [ 4, -6, -2, 0, 3, -2 ], [ 3, -6, -2, 1, 4, -2 ], [ 4, -6, -2, 1, 3, -2 ] ], 0.375 ] - ], - [ - [ [ [ 3, -7, -2, 0, 3, -2 ], [ 2, -6, -2, 2, 3, -2 ], [ 3, -6, -2, 1, 4, -2 ], [ 4, -6, -2, 1, 3, -2 ] ], 1 ] - ], - [ - [ [ [ 1, -6, -2, 2, 3, -2 ], [ 2, -6, -2, 2, 3, -2 ], [ 3, -6, -2, 1, 4, -2 ], [ 4, -6, -2, 1, 3, -2 ] ], 0.5 ] - ], - [ - [ [ [ 2, -6, -2, 1, 2, -2 ], [ 2, -6, -2, 2, 3, -2 ], [ 3, -6, -2, 1, 4, -2 ], [ 4, -6, -2, 1, 3, -2 ] ], 0.875 ] - ], - [ - [ [ [ 2, -6, -2, 1, 2, -2 ], [ 2, -6, -2, 2, 3, -2 ], [ 3, -6, -2, 1, 4, -2 ], [ 4, -6, -2, 2, 3, -3 ] ], 1.125 ], - [ [ [ 2, -6, -2, 1, 2, -2 ], [ 2, -6, -2, 2, 3, -2 ], [ 3, -6, -2, 1, 3, -2 ], [ 4, -6, -2, 2, 3, -3 ] ], 0.5 ] - ], - [ - [ [ [ 2, -6, -2, 1, 2, -2 ], [ 2, -6, -2, 2, 3, -2 ], [ 4, -6, -2, 1, 1, -2 ], [ 4, -6, -2, 2, 3, -3 ] ], 1 ], - [ [ [ 2, -6, -2, 1, 2, -2 ], [ 3, -6, -2, 1, 3, -2 ], [ 4, -6, -2, 1, 1, -2 ], [ 4, -6, -2, 2, 3, -3 ] ], 1.625 ] - ], - [ - [ [ [ 2, -6, -2, 1, 2, -2 ], [ 3, -6, -2, 1, 3, -2 ], [ 4, -6, -2, 1, 1, -2 ], [ 6, -6, -2, 0, 1, -2 ] ], 1.375 ], - [ [ [ 3, -6, -2, 1, 0, -2 ], [ 3, -6, -2, 1, 3, -2 ], [ 4, -6, -2, 1, 1, -2 ], [ 6, -6, -2, 0, 1, -2 ] ], 1.5 ], - [ [ [ 3, -6, -2, 1, 0, -2 ], [ 3, -5, -2, 1, 1, -2 ], [ 4, -6, -2, 1, 1, -2 ], [ 6, -6, -2, 0, 1, -2 ] ], 0.5 ] - ], - [ - [ [ [ 3, -6, -2, 1, 0, -2 ], [ 5, -6, -2, 0, 0, -2 ], [ 4, -6, -2, 1, 1, -2 ], [ 6, -6, -2, 0, 1, -2 ] ], 1.25 ], - [ [ [ 4, -6, -2, 0, 0, -2 ], [ 5, -6, -2, 0, 0, -2 ], [ 4, -6, -2, 1, 1, -2 ], [ 6, -6, -2, 0, 1, -2 ] ], 0.5 ], - [ [ [ 4, -6, -2, 0, 0, -2 ], [ 5, -6, -2, 0, 0, -2 ], [ 5, -6, -2, 0, 1, -2 ], [ 6, -6, -2, 0, 1, -2 ] ], 0.625 ] - ], - [ - [ [ [ 5, -6, -2, -1, 0, -2 ], [ 5, -6, -2, 0, 0, -2 ], [ 5, -6, -2, 0, 1, -2 ], [ 6, -6, -2, 0, 1, -2 ] ], 1.625 ], - [ [ [ 5, -6, -2, -1, 0, -2 ], [ 5, -6, -2, 0, 0, -2 ], [ 5, -5, -2, 0, 0, -2 ], [ 6, -6, -2, 0, 1, -2 ] ], 1.625 ], - [ [ [ 5, -6, -2, -1, 0, -2 ], [ 5, -6, -2, 0, 0, -2 ], [ 5, -5, -2, 0, 0, -2 ], [ 7, -6, -2, 0, -1, -2 ] ], 1 ] - ], - [ - [ [ [ 5, -6, -2, -1, 0, -2 ], [ 4, -4, -2, 0, 0, -2 ], [ 5, -5, -2, 0, 0, -2 ], [ 7, -6, -2, 0, -1, -2 ] ], 1.625 ] - ], - [ - [ [ [ 5, -6, -2, -1, 0, -2 ], [ 4, -4, -2, 0, 0, -2 ], [ 7, -6, -2, -1, -1, -2 ], [ 7, -6, -2, 0, -1, -2 ] ], 1 ] - ], - [ - [ [ [ 6, -6, -2, -1, -2, -2 ], [ 4, -4, -2, 0, 0, -2 ], [ 7, -6, -2, -1, -1, -2 ], [ 7, -6, -2, 0, -1, -2 ] ], 0.5 ], - [ [ [ 6, -6, -2, -1, -2, -2 ], [ 7, -6, -2, -1, -2, -2 ], [ 7, -6, -2, -1, -1, -2 ], [ 7, -6, -2, 0, -1, -2 ] ], 1.375 ], - [ [ [ 6, -6, -2, -1, -2, -2 ], [ 7, -6, -2, -1, -2, -2 ], [ 7, -6, -2, -1, -1, -2 ], [ 7, -5, -2, -1, -1, -2 ] ], 1.125 ] - ], - [ - [ [ [ 6, -6, -2, -1, -2, -2 ], [ 7, -6, -3, -1, -1, -2 ], [ 7, -6, -2, -1, -1, -2 ], [ 7, -5, -2, -1, -1, -2 ] ], 0.625 ], - [ [ [ 6, -6, -3, -1, -1, -2 ], [ 7, -6, -3, -1, -1, -2 ], [ 7, -6, -2, -1, -1, -2 ], [ 7, -5, -2, -1, -1, -2 ] ], 0.875 ] - ], - [ - [ [ [ 6, -6, -3, -1, -1, -2 ], [ 7, -6, -3, -1, -1, -2 ], [ 7, -6, -2, -1, -1, -2 ], [ 8, -6, -3, -1, -1, -2 ] ], 0.625 ], - [ [ [ 6, -6, -3, -1, -1, -2 ], [ 8, -6, -3, -2, -1, -2 ], [ 7, -6, -2, -1, -1, -2 ], [ 8, -6, -3, -1, -1, -2 ] ], 1.5 ] - ], - [ - [ [ [ 6, -6, -3, -1, -1, -2 ], [ 8, -6, -3, -2, -1, -2 ], [ 7, -6, -2, -1, -1, -2 ], [ 7, -6, -2, 0, -1, -2 ] ], 1.125 ] - ], - [ - [ [ [ 6, -6, -3, -1, -1, -2 ], [ 8, -6, -3, -2, -1, -2 ], [ 7, -6, -2, -1, -1, -2 ], [ 7, -5, -3, -2, -1, -2 ] ], 0.375 ] - ], - [ - [ [ [ 6, -6, -3, -1, -1, -2 ], [ 8, -6, -3, -2, -1, -2 ], [ 7, -6, -2, -1, -1, -2 ], [ 7, -6, -2, -1, -2, -2 ] ], 1.5 ] - ], - [ - [ [ [ 6, -6, -3, -1, -1, -2 ], [ 8, -6, -3, -2, -1, -2 ], [ 7, -6, -2, -1, -1, -2 ], [ 6, -6, -2, -1, -1, -1 ] ], 1.25 ] - ], - [ - [ [ [ 6, -6, -3, -1, -1, -2 ], [ 8, -6, -3, -2, -1, -2 ], [ 7, -6, -2, -1, -1, -2 ], [ 6, -6, -2, 0, -1, -2 ] ], 1.625 ], - [ [ [ 6, -6, -3, -1, -1, -2 ], [ 7, -6, -2, -1, -2, -2 ], [ 7, -6, -2, -1, -1, -2 ], [ 6, -6, -2, 0, -1, -2 ] ], 1.75 ], - [ [ [ 5, -6, -2, 0, -1, -2 ], [ 7, -6, -2, -1, -2, -2 ], [ 7, -6, -2, -1, -1, -2 ], [ 6, -6, -2, 0, -1, -2 ] ], 0.5 ] - ], - [ - [ [ [ 5, -6, -2, 0, -1, -2 ], [ 7, -6, -2, -1, -2, -2 ], [ 7, -5, -2, -1, -2, -2 ], [ 6, -6, -2, 0, -1, -2 ] ], 1.5 ] - ], - [ - [ [ [ 5, -6, -2, 0, -1, -2 ], [ 7, -5, -2, -1, -3, -2 ], [ 7, -5, -2, -1, -2, -2 ], [ 6, -6, -2, 0, -1, -2 ] ], 1.375 ], - [ [ [ 5, -5, -2, 0, -2, -2 ], [ 7, -5, -2, -1, -3, -2 ], [ 7, -5, -2, -1, -2, -2 ], [ 6, -6, -2, 0, -1, -2 ] ], 1.25 ] - ], - [ - [ [ [ 5, -5, -2, 0, -2, -2 ], [ 7, -5, -2, -1, -3, -2 ], [ 8, -5, -2, -1, -4, -2 ], [ 6, -6, -2, 0, -1, -2 ] ], 0.75 ], - [ [ [ 5, -5, -2, 0, -2, -2 ], [ 7, -5, -2, -1, -3, -2 ], [ "Rest" ], [ 6, -6, -2, 0, -1, -2 ] ], 1.25 ], - [ [ [ "Rest" ], [ 7, -5, -2, -1, -3, -2 ], [ "Rest" ], [ 6, -6, -2, 0, -1, -2 ] ], 0.5 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ 6, -6, -2, 0, -1, -2 ] ], 1.25 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 6.625 ] - ] - ] -], -"last_changes": -[ - [ [ 5, -6, -2, 0, -1, -2 ], [ 7, -6, -2, -1, -2, -2 ], [ 7, -6, -2, -1, -1, -2 ], [ 6, -6, -2, 0, -1, -2 ] ], - [ [ 5, -6, -2, 0, -1, -2 ], [ 7, -6, -2, -1, -2, -2 ], [ 7, -5, -2, -1, -2, -2 ], [ 6, -6, -2, 0, -1, -2 ] ], - [ [ 5, -6, -2, 0, -1, -2 ], [ 7, -5, -2, -1, -3, -2 ], [ 7, -5, -2, -1, -2, -2 ], [ 6, -6, -2, 0, -1, -2 ] ], - [ [ 5, -5, -2, 0, -2, -2 ], [ 7, -5, -2, -1, -3, -2 ], [ 7, -5, -2, -1, -2, -2 ], [ 6, -6, -2, 0, -1, -2 ] ], - [ [ 5, -5, -2, 0, -2, -2 ], [ 7, -5, -2, -1, -3, -2 ], [ 8, -5, -2, -1, -4, -2 ], [ 6, -6, -2, 0, -1, -2 ] ] -], -"cur_uid": "6a9928d6", -"ref_uid": "55f9b81e", -"order_seed": 963124, -"dur_seed": 397683, -"motifs_seed": 845264, -"entrances_probs_vals": [ 0, 0, 0, 0.41, 1.8406593406593, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 0, 0, 0, 0.41, 1.8406593406593, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 0, 0, 0, 0.41, 1.8406593406593, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -2430, -293.49845201238 ], [ -869, 1211.1455108359 ], [ -832.19814241486, 1285 ], [ -702, 1211.1455108359 ] ], -"step_probs_vals": [ -1200, 1200, 0.0020576131687243, 0.068181818181818, 0.074074074074074, 0.0625, 0.20576131687243, 0.0625, 0.45679012345679, 0.011363636363636, 0.53086419753086, 0, 0.54320987654321, 0.92045454545455, 0.58641975308642, 0.92613636363636, 0.61316872427983, 0, 0.98971193415638, 0 ], -"passages_weights": [ 0.48, 0.46, 0.48, 1, 1 ], -"hd_exp": 1.52, -"hd_invert": 0, -"order": -[ - [ [ 2, 3, 1 ], [ 0 ], [ ] ], - [ [ 3 ], [ 1, 2, 0 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ], - [ [ 2 ], [ 1, 0, 3 ], [ ] ], - [ [ 3, 1 ], [ 2, 0 ], [ ] ], - [ [ 2, 3, 1 ], [ 0 ], [ ] ], - [ [ 0 ], [ 2, 1, 3 ], [ ] ], - [ [ 0 ], [ 1, 3, 2 ], [ ] ], - [ [ 3, 1, 2 ], [ 0 ], [ ] ], - [ [ 2 ], [ 0, 1, 3 ], [ ] ], - [ [ 0, 2, 1 ], [ 3 ], [ ] ], - [ [ 0, 3, 1 ], [ 2 ], [ ] ], - [ [ 3 ], [ 0, 2, 1 ], [ ] ], - [ [ 0 ], [ 1, 3, 2 ], [ ] ], - [ [ 0, 1 ], [ 3, 2 ], [ ] ], - [ [ 2 ], [ 3, 0, 1 ], [ ] ], - [ [ 0 ], [ 1, 3, 2 ], [ ] ], - [ [ 0 ], [ 1, 3, 2 ], [ ] ], - [ [ 0 ], [ 1, 3, 2 ], [ ] ], - [ [ 0, 3, 2 ], [ 1 ], [ ] ], - [ [ 0, 1, 3 ], [ 2 ], [ ] ], - [ [ 1 ], [ 2, 3, 0 ], [ ] ], - [ [ 3, 0 ], [ 2, 1 ], [ ] ], - [ [ 2, 1 ], [ 3, 0 ], [ ] ], - [ [ 1, 0, 3 ], [ 2 ], [ ] ], - [ [ 1, 0 ], [ 3, 2 ], [ ] ], - [ [ 3 ], [ 0, 1, 2 ], [ ] ], - [ [ 3 ], [ 1, 0, 2 ], [ ] ], - [ [ 0 ], [ 1, 3, 2 ], [ ] ], - [ [ 1, 3 ], [ 2, 0 ], [ ] ], - [ [ 3 ], [ 1, 2, 0 ], [ ] ], - [ [ 3, 0 ], [ 2, 1 ], [ ] ], - [ [ 1 ], [ 3, 2, 0 ], [ ] ], - [ [ 3, 0 ], [ 1, 2 ], [ ] ], - [ [ 1 ], [ 2, 0, 3 ], [ ] ], - [ [ 1 ], [ 0, 3, 2 ], [ ] ], - [ [ 0, 3, 2 ], [ 1 ], [ ] ], - [ [ 0, 3 ], [ 1, 2 ], [ ] ], - [ [ 0 ], [ 3, 2, 1 ], [ ] ], - [ [ 0, 3, 1 ], [ 2 ], [ ] ], - [ [ 2, 3 ], [ 0, 1 ], [ ] ], - [ [ 0, 2 ], [ 1, 3 ], [ ] ], - [ [ 3, 1 ], [ 2, 0 ], [ ] ], - [ [ 3, 0 ], [ 2, 1 ], [ ] ], - [ [ 0, 1, 2 ], [ 3 ], [ ] ], - [ [ 1 ], [ 0, 2, 3 ], [ ] ], - [ [ 3 ], [ 2, 1, 0 ], [ ] ], - [ [ 2, 0, 1 ], [ 3 ], [ ] ], - [ [ 2 ], [ 3, 1, 0 ], [ ] ], - [ [ 0, 2 ], [ 3, 1 ], [ ] ], - [ [ 3 ], [ 0, 1, 2 ], [ ] ], - [ [ 2 ], [ 0, 1, 3 ], [ ] ], - [ [ 1, 3, 0 ], [ 2 ], [ ] ], - [ [ 0 ], [ 1, 2, 3 ], [ ] ], - [ [ 3, 1 ], [ 0, 2 ], [ ] ], - [ [ 2 ], [ 3, 0, 1 ], [ ] ], - [ [ 2, 3, 0 ], [ 1 ], [ ] ], - [ [ 1 ], [ 0, 2, 3 ], [ ] ], - [ [ 3, 0, 2 ], [ 1 ], [ ] ], - [ [ 3, 2, 0 ], [ 1 ], [ ] ], - [ [ 1 ], [ 3, 2, 0 ], [ ] ], - [ [ 3 ], [ 1, 2, 0 ], [ ] ], - [ [ 3, 0 ], [ 1, 2 ], [ ] ], - [ [ 0 ], [ 3, 2, 1 ], [ ] ], - [ [ 3 ], [ 1, 0, 2 ], [ ] ], - [ [ 1, 0, 3 ], [ 2 ], [ ] ], - [ [ 3, 2 ], [ 0, 1 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ], - [ [ 3, 0, 2 ], [ 1 ], [ ] ], - [ [ 1, 3 ], [ 0, 2 ], [ ] ], - [ [ 3 ], [ 1, 2, 0 ], [ ] ], - [ [ 1, 2, 3 ], [ 0 ], [ ] ], - [ [ 3, 2, 1 ], [ 0 ], [ ] ], - [ [ 1, 3 ], [ 2, 0 ], [ ] ], - [ [ 2, 1 ], [ 0, 3 ], [ ] ], - [ [ 3 ], [ 0, 1, 2 ], [ ] ], - [ [ 1, 2 ], [ 3, 0 ], [ ] ], - [ [ 0 ], [ 2, 1, 3 ], [ ] ], - [ [ 1, 2 ], [ 3, 0 ], [ ] ], - [ [ 3, 0, 2 ], [ 1 ], [ ] ], - [ [ 1, 3, 2 ], [ 0 ], [ ] ], - [ [ 1, 3, 2 ], [ 0 ], [ ] ], - [ [ 1, 0 ], [ 3, 2 ], [ ] ], - [ [ 3, 0 ], [ 2, 1 ], [ ] ], - [ [ 2 ], [ 3, 0, 1 ], [ ] ], - [ [ 3 ], [ 1, 0, 2 ], [ ] ], - [ [ 1 ], [ 0, 2, 3 ], [ ] ], - [ [ 0, 2, 3 ], [ 1 ], [ ] ], - [ [ 0, 3, 1 ], [ 2 ], [ ] ], - [ [ 2 ], [ 0, 1, 3 ], [ ] ], - [ [ 3, 2 ], [ 1, 0 ], [ ] ], - [ [ 0, 2 ], [ 3, 1 ], [ ] ], - [ [ 1, 2, 0 ], [ 3 ], [ ] ], - [ [ 0, 2, 1 ], [ 3 ], [ ] ], - [ [ 1, 0, 2 ], [ 3 ], [ ] ], - [ [ 1, 2, 0 ], [ 3 ], [ ] ], - [ [ 2 ], [ 3, 1, 0 ], [ ] ], - [ [ 0, 3, 1 ], [ 2 ], [ ] ], - [ [ 3, 2 ], [ 1, 0 ], [ ] ], - [ [ 3, 0, 1 ], [ 2 ], [ ] ] -], -"sus_weights": [ 0.35, 0.37, 0.38 ], -"order_size": [ 100, 100 ], -"passages_size": [ 0, 0 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3/6f0f638f/6f0f638f_code.scd b/resources/resources_bak_2024_01_03/string_quartet_3/6f0f638f/6f0f638f_code.scd deleted file mode 100644 index c194eef..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3/6f0f638f/6f0f638f_code.scd +++ /dev/null @@ -1,945 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance); -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_3/6f0f638f/6f0f638f_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_3/6f0f638f/6f0f638f_mus_model.json deleted file mode 100644 index e65877d..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3/6f0f638f/6f0f638f_mus_model.json +++ /dev/null @@ -1,105 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ 0, 0, 0, -1, -1, 0 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 0 ], - [ [ [ 0, 0, 0, -1, -1, 0 ], [ "Rest" ], [ 1, 0, 0, -1, -1, 1 ], [ "Rest" ] ], 0 ], - [ [ [ 0, 0, 0, -1, -1, 0 ], [ "Rest" ], [ 1, 0, 0, -1, -1, 1 ], [ 1, 0, 0, -1, -1, 2 ] ], 1.25 ], - [ [ [ 0, 0, 0, -1, -1, 0 ], [ 0, 0, 0, -1, -2, 2 ], [ 1, 0, 0, -1, -1, 1 ], [ 1, 0, 0, -1, -1, 2 ] ], 1.5 ], - [ [ [ 0, 0, 0, -1, -1, 0 ], [ 0, -1, 0, -1, -1, 2 ], [ 1, 0, 0, -1, -1, 1 ], [ 1, 0, 0, -1, -1, 2 ] ], 2.625 ] - ], - [ - [ [ [ 0, 0, 0, -1, -1, 0 ], [ "Rest" ], [ 1, 0, 0, -1, -1, 1 ], [ 1, 0, 0, -1, -1, 2 ] ], 0 ], - [ [ [ -1, 0, -1, -1, -1, 2 ], [ "Rest" ], [ 1, 0, 0, -1, -1, 1 ], [ 1, 0, 0, -1, -1, 2 ] ], 0 ], - [ [ [ -1, 0, -1, -1, -1, 2 ], [ "Rest" ], [ 1, -1, 0, -1, -1, 2 ], [ 1, 0, 0, -1, -1, 2 ] ], 1.25 ], - [ [ [ -1, 0, -1, -1, -1, 2 ], [ "Rest" ], [ 1, 0, 0, -1, -2, 2 ], [ 1, 0, 0, -1, -1, 2 ] ], 0.75 ], - [ [ [ -1, 0, -1, -1, -1, 2 ], [ "Rest" ], [ 0, 0, 0, -1, 0, 2 ], [ 1, 0, 0, -1, -1, 2 ] ], 1.5 ] - ], - [ - [ [ [ -1, 0, -1, -1, -1, 2 ], [ "Rest" ], [ 0, 0, 0, -1, 0, 2 ], [ "Rest" ] ], 0 ], - [ [ [ -1, 0, 0, -1, 0, 1 ], [ "Rest" ], [ 0, 0, 0, -1, 0, 2 ], [ "Rest" ] ], 0 ], - [ [ [ -1, 0, 0, -1, 0, 1 ], [ -1, 0, 0, -1, 0, 2 ], [ 0, 0, 0, -1, 0, 2 ], [ "Rest" ] ], 1.125 ], - [ [ [ -2, 0, 1, -1, 0, 2 ], [ -1, 0, 0, -1, 0, 2 ], [ 0, 0, 0, -1, 0, 2 ], [ "Rest" ] ], 2 ], - [ [ [ -1, 0, 0, -2, 0, 2 ], [ -1, 0, 0, -1, 0, 2 ], [ 0, 0, 0, -1, 0, 2 ], [ "Rest" ] ], 0.875 ], - [ [ [ 0, 0, 0, -2, 0, 2 ], [ -1, 0, 0, -1, 0, 2 ], [ 0, 0, 0, -1, 0, 2 ], [ "Rest" ] ], 0 ], - [ [ [ 0, 0, 0, -2, 0, 2 ], [ -1, 0, 1, -1, 0, 2 ], [ 0, 0, 0, -1, 0, 2 ], [ "Rest" ] ], 1.75 ] - ], - [ - [ [ [ 0, 0, 0, -2, 0, 2 ], [ -1, 0, 1, -1, 0, 2 ], [ 0, 0, 0, -1, 0, 2 ], [ 1, 0, 0, -1, -1, 2 ] ], 3 ], - [ [ [ 0, 0, 0, -2, 0, 2 ], [ -1, 0, 1, -1, 0, 2 ], [ 0, 0, 1, -1, -1, 2 ], [ 1, 0, 0, -1, -1, 2 ] ], 0 ], - [ [ [ 0, 0, 0, -2, 0, 2 ], [ 0, 0, -1, -1, -1, 2 ], [ 0, 0, 1, -1, -1, 2 ], [ 1, 0, 0, -1, -1, 2 ] ], 0.875 ], - [ [ [ 0, 0, 0, -2, 0, 2 ], [ -1, 1, 0, -1, -1, 2 ], [ 0, 0, 1, -1, -1, 2 ], [ 1, 0, 0, -1, -1, 2 ] ], 0 ], - [ [ [ 0, 0, 0, -2, 0, 2 ], [ -1, 1, 0, -1, -1, 2 ], [ 1, 0, 0, -1, -1, 1 ], [ 1, 0, 0, -1, -1, 2 ] ], 1.625 ], - [ [ [ 0, 0, 0, -2, 0, 2 ], [ -1, 0, 0, -1, 0, 2 ], [ 1, 0, 0, -1, -1, 1 ], [ 1, 0, 0, -1, -1, 2 ] ], 0 ], - [ [ [ 0, 0, 0, -2, 0, 2 ], [ -1, 0, 0, -1, 0, 2 ], [ 1, 0, 0, -2, -1, 2 ], [ 1, 0, 0, -1, -1, 2 ] ], 1.125 ] - ], - [ - [ [ [ 0, 0, 0, -2, 0, 2 ], [ -1, 0, 0, -1, 0, 2 ], [ -1, 0, 0, -1, 0, 3 ], [ 1, 0, 0, -1, -1, 2 ] ], 0 ], - [ [ [ 0, 0, 0, -1, 0, 1 ], [ -1, 0, 0, -1, 0, 2 ], [ -1, 0, 0, -1, 0, 3 ], [ 1, 0, 0, -1, -1, 2 ] ], 1.125 ], - [ [ [ 0, -1, 0, -1, 0, 2 ], [ -1, 0, 0, -1, 0, 2 ], [ -1, 0, 0, -1, 0, 3 ], [ 1, 0, 0, -1, -1, 2 ] ], 2.5 ] - ], - [ - [ [ [ 0, -1, 0, -1, 0, 2 ], [ -1, 0, 0, -1, 0, 2 ], [ -1, 0, 0, -1, 0, 3 ], [ -1, 0, 1, -1, 0, 3 ] ], 1.125 ], - [ [ [ 0, -1, 0, -1, 0, 2 ], [ -1, 0, 0, -1, 0, 2 ], [ -1, 0, 0, -1, 0, 3 ], [ 1, 0, 0, -2, 0, 2 ] ], 3 ] - ], - [ - [ [ [ 0, -1, 0, -1, 0, 2 ], [ -1, 0, 0, -1, 0, 2 ], [ -1, 0, 0, -1, 0, 3 ], [ "Rest" ] ], 0 ], - [ [ [ 0, -1, 0, -1, 0, 2 ], [ 0, -1, 0, -1, -1, 2 ], [ -1, 0, 0, -1, 0, 3 ], [ "Rest" ] ], 1.375 ], - [ [ [ 0, -1, 0, -1, 0, 2 ], [ 0, -2, 0, -1, 0, 2 ], [ -1, 0, 0, -1, 0, 3 ], [ "Rest" ] ], 2.5 ], - [ [ [ 0, -1, 0, -1, 0, 2 ], [ -1, -1, 1, -1, 0, 2 ], [ -1, 0, 0, -1, 0, 3 ], [ "Rest" ] ], 1 ], - [ [ [ 0, -1, 0, -1, 0, 2 ], [ -2, 0, 0, -1, 0, 3 ], [ -1, 0, 0, -1, 0, 3 ], [ "Rest" ] ], 2.125 ], - [ [ [ 0, -1, 0, -1, 0, 2 ], [ 0, -1, 0, -2, 0, 2 ], [ -1, 0, 0, -1, 0, 3 ], [ "Rest" ] ], 1.375 ] - ], - [ - [ [ [ -2, 1, 0, -1, 0, 3 ], [ 0, -1, 0, -2, 0, 2 ], [ -1, 0, 0, -1, 0, 3 ], [ "Rest" ] ], 1.625 ], - [ [ [ -2, 1, 0, -1, 0, 3 ], [ 0, -1, 0, -2, 0, 2 ], [ -1, 0, 0, -1, 0, 3 ], [ 0, -1, 0, -1, 0, 3 ] ], 0.5 ], - [ [ [ -2, 1, 0, -1, 0, 3 ], [ -1, 0, 1, -1, 0, 3 ], [ -1, 0, 0, -1, 0, 3 ], [ 0, -1, 0, -1, 0, 3 ] ], 0 ], - [ [ [ -2, 1, 0, -1, 0, 3 ], [ -1, 0, 1, -1, 0, 3 ], [ -1, 0, 0, -1, 0, 3 ], [ 0, 0, 0, -1, -1, 3 ] ], 2.5 ], - [ [ [ -2, 1, 0, -1, 0, 3 ], [ 0, -1, 0, -1, 0, 3 ], [ -1, 0, 0, -1, 0, 3 ], [ 0, 0, 0, -1, -1, 3 ] ], 0 ], - [ [ [ -2, 0, 0, -1, 1, 3 ], [ 0, -1, 0, -1, 0, 3 ], [ -1, 0, 0, -1, 0, 3 ], [ 0, 0, 0, -1, -1, 3 ] ], 1.125 ], - [ [ [ -2, 0, 0, -1, 1, 3 ], [ 0, -1, 0, -1, 0, 3 ], [ -1, 0, 0, -1, 0, 3 ], [ "Rest" ] ], 0 ], - [ [ [ -2, 0, 0, -1, 1, 3 ], [ "Rest" ], [ -1, 0, 0, -1, 0, 3 ], [ "Rest" ] ], 0 ], - [ [ [ "Rest" ], [ "Rest" ], [ -1, 0, 0, -1, 0, 3 ], [ "Rest" ] ], 0 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 0.875 ] - ] - ] -], -"last_changes": -[ - [ [ -2, 1, 0, -1, 0, 3 ], [ 0, -1, 0, -2, 0, 2 ], [ -1, 0, 0, -1, 0, 3 ], [ 0, -1, 0, -1, 0, 3 ] ], - [ [ -2, 1, 0, -1, 0, 3 ], [ -1, 0, 1, -1, 0, 3 ], [ -1, 0, 0, -1, 0, 3 ], [ 0, -1, 0, -1, 0, 3 ] ], - [ [ -2, 1, 0, -1, 0, 3 ], [ -1, 0, 1, -1, 0, 3 ], [ -1, 0, 0, -1, 0, 3 ], [ 0, 0, 0, -1, -1, 3 ] ], - [ [ -2, 1, 0, -1, 0, 3 ], [ 0, -1, 0, -1, 0, 3 ], [ -1, 0, 0, -1, 0, 3 ], [ 0, 0, 0, -1, -1, 3 ] ], - [ [ -2, 0, 0, -1, 1, 3 ], [ 0, -1, 0, -1, 0, 3 ], [ -1, 0, 0, -1, 0, 3 ], [ 0, 0, 0, -1, -1, 3 ] ] -], -"cur_uid": "6f0f638f", -"ref_uid": "781442dc", -"order_seed": 778672, -"dur_seed": 554838, -"motifs_seed": 420644, -"entrances_probs_vals": [ 0.76, 0, 0, 0.38461538461538, 3.08, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 0.76, 0, 0, 0.38461538461538, 3.08, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 0.76, 0, 0, 0.38461538461538, 3.08, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -1984, 932.50773993808 ], [ -999, 951.08359133127 ], [ -15, 1043.9628482972 ], [ 78, 1081.1145510836 ] ], -"step_probs_vals": [ 0, 1200, 0, 0, 0.076131687242798, 0.91477272727273, 0.17489711934156, 0, 0.57818930041152, 0, 1, 0 ], -"passages_weights": [ 1, 1, 1, 1, 1 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 0, 2, 3 ], [ 1, 1 ], [ ] ], - [ [ 3 ], [ 0, 2, 2, 2 ], [ 1 ] ], - [ [ 2 ], [ 0, 1, 0, 0, 0, 1 ], [ 3 ] ], - [ [ 0, 3 ], [ 2, 1, 1, 2, 1, 2 ], [ ] ], - [ [ 1, 3 ], [ 2, 0, 0 ], [ ] ], - [ [ 2, 1, 0 ], [ 3, 3 ], [ ] ], - [ [ 2, 0 ], [ 1, 1, 1, 1, 1 ], [ 3 ] ], - [ [ 2 ], [ 0, 3, 1, 3, 1, 0 ], [ ] ] -], -"sus_weights": [ 1, 1, 1 ], -"order_size": [ 5, 10 ], -"passages_size": [ 0, 5 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3/726a40c7/726a40c7_code.scd b/resources/resources_bak_2024_01_03/string_quartet_3/726a40c7/726a40c7_code.scd deleted file mode 100644 index f822edb..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3/726a40c7/726a40c7_code.scd +++ /dev/null @@ -1,946 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = true; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - if(pDistance < 0, {stepFunc.value(abs(pDistance))}, {0.001}); - //stepFunc.value(pDistance) -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_3/726a40c7/726a40c7_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_3/726a40c7/726a40c7_mus_model.json deleted file mode 100644 index 06e11db..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3/726a40c7/726a40c7_mus_model.json +++ /dev/null @@ -1,163 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ 0, -1, 0, 2, 1, -2 ], [ "Rest" ], [ "Rest" ] ], 0.5 ], - [ [ [ -1, 0, 1, 2, 0, -2 ], [ 0, -1, 0, 2, 1, -2 ], [ "Rest" ], [ "Rest" ] ], 0.625 ], - [ [ [ -1, 0, 1, 2, 0, -2 ], [ 0, -1, 0, 2, 1, -2 ], [ -1, -1, 0, 3, 1, -2 ], [ "Rest" ] ], 0.25 ], - [ [ [ -1, 0, 1, 2, 0, -2 ], [ 0, -1, 0, 2, 1, -2 ], [ -1, -1, 0, 3, 1, -2 ], [ -1, -1, 0, 3, 1, -1 ] ], 0.875 ] - ], - [ - [ [ [ 0, -1, 0, 2, 0, -2 ], [ 0, -1, 0, 2, 1, -2 ], [ -1, -1, 0, 3, 1, -2 ], [ -1, -1, 0, 3, 1, -1 ] ], 1 ] - ], - [ - [ [ [ 0, -1, 0, 2, 0, -2 ], [ 0, -1, 0, 2, 1, -2 ], [ -2, -1, 1, 3, 1, -1 ], [ -1, -1, 0, 3, 1, -1 ] ], 0.375 ] - ], - [ - [ [ [ 0, -1, 0, 2, 0, -2 ], [ 0, -1, 0, 2, 1, -2 ], [ -2, -1, 1, 3, 1, -1 ], [ -2, -1, 1, 3, 1, 0 ] ], 0.625 ] - ], - [ - [ [ [ 0, -1, 0, 2, 0, -2 ], [ 0, -1, 0, 2, 1, -2 ], [ -2, -1, 1, 3, 1, -1 ], [ 1, -1, 0, 2, 0, -2 ] ], 1.125 ] - ], - [ - [ [ [ 0, -1, 0, 2, 0, -2 ], [ 0, -1, 0, 2, 1, -2 ], [ -2, -1, 1, 3, 1, -1 ], [ 0, 0, 0, 2, 1, -2 ] ], 0.125 ] - ], - [ - [ [ [ 0, -1, 0, 2, 0, -2 ], [ 0, -1, 0, 2, 1, -2 ], [ -2, -1, 1, 3, 1, -1 ], [ 0, -1, 0, 2, 1, -1 ] ], 0.75 ] - ], - [ - [ [ [ -1, 0, 0, 2, 1, -2 ], [ 0, -1, 0, 2, 1, -2 ], [ -2, -1, 1, 3, 1, -1 ], [ 0, -1, 0, 2, 1, -1 ] ], 0.625 ] - ], - [ - [ [ [ -1, 0, 0, 2, 1, -2 ], [ 0, -2, 0, 2, 1, -1 ], [ -2, -1, 1, 3, 1, -1 ], [ 0, -1, 0, 2, 1, -1 ] ], 0.875 ] - ], - [ - [ [ [ -1, 0, 0, 2, 1, -2 ], [ 0, -2, 0, 2, 1, -1 ], [ -2, -1, 1, 3, 1, -1 ], [ 1, -2, -1, 2, 1, -1 ] ], 1.125 ] - ], - [ - [ [ [ -1, 0, 0, 2, 1, -2 ], [ 0, -2, 0, 2, 1, -1 ], [ -1, 0, 1, 2, 1, -2 ], [ 1, -2, -1, 2, 1, -1 ] ], 0.375 ] - ], - [ - [ [ [ -1, 0, 0, 2, 1, -2 ], [ 0, -2, 0, 2, 1, -1 ], [ -1, 0, 1, 2, 1, -2 ], [ 1, 0, 0, 2, 1, -3 ] ], 0.875 ] - ], - [ - [ [ [ -1, 0, 0, 2, 1, -2 ], [ 0, -2, 0, 2, 1, -1 ], [ -1, 0, 1, 2, 1, -2 ], [ 0, 0, 1, 2, 1, -2 ] ], 0.5 ] - ], - [ - [ [ [ 0, -2, 0, 2, 0, -1 ], [ 0, -2, 0, 2, 1, -1 ], [ -1, 0, 1, 2, 1, -2 ], [ 0, 0, 1, 2, 1, -2 ] ], 0.75 ] - ], - [ - [ [ [ 0, -2, 0, 2, 0, -1 ], [ 0, 0, 1, 2, 1, -3 ], [ -1, 0, 1, 2, 1, -2 ], [ 0, 0, 1, 2, 1, -2 ] ], 1.125 ] - ], - [ - [ [ [ -2, 0, 1, 3, 1, -2 ], [ 0, 0, 1, 2, 1, -3 ], [ -1, 0, 1, 2, 1, -2 ], [ 0, 0, 1, 2, 1, -2 ] ], 0.625 ] - ], - [ - [ [ [ -2, 0, 1, 3, 1, -2 ], [ -1, 0, 1, 3, 0, -2 ], [ -1, 0, 1, 2, 1, -2 ], [ 0, 0, 1, 2, 1, -2 ] ], 0.5 ] - ], - [ - [ [ [ -2, 0, 1, 3, 1, -2 ], [ -1, 0, 1, 3, 0, -2 ], [ -1, 0, 0, 3, 0, -2 ], [ 0, 0, 1, 2, 1, -2 ] ], 1.125 ] - ], - [ - [ [ [ -2, 0, 1, 3, 1, -2 ], [ -2, 1, 1, 3, 1, -2 ], [ -1, 0, 0, 3, 0, -2 ], [ 0, 0, 1, 2, 1, -2 ] ], 0.125 ] - ], - [ - [ [ [ -2, 0, 1, 3, 1, -2 ], [ -2, 1, 1, 3, 1, -2 ], [ -2, 1, 0, 3, 1, -2 ], [ 0, 0, 1, 2, 1, -2 ] ], 0.125 ] - ], - [ - [ [ [ -3, 1, 0, 4, 1, -2 ], [ -2, 1, 1, 3, 1, -2 ], [ -2, 1, 0, 3, 1, -2 ], [ 0, 0, 1, 2, 1, -2 ] ], 0.25 ] - ], - [ - [ [ [ -3, 2, 1, 3, 1, -2 ], [ -2, 1, 1, 3, 1, -2 ], [ -2, 1, 0, 3, 1, -2 ], [ 0, 0, 1, 2, 1, -2 ] ], 0.5 ] - ], - [ - [ [ [ -2, 0, 2, 2, 1, -2 ], [ -2, 1, 1, 3, 1, -2 ], [ -2, 1, 0, 3, 1, -2 ], [ 0, 0, 1, 2, 1, -2 ] ], 0.875 ] - ], - [ - [ [ [ -2, 0, 2, 2, 1, -2 ], [ -2, 1, 1, 3, 1, -2 ], [ -2, 1, 0, 3, 1, -2 ], [ -1, 1, 0, 3, 1, -2 ] ], 0.75 ] - ], - [ - [ [ [ -2, 1, 0, 3, 1, -3 ], [ -2, 1, 1, 3, 1, -2 ], [ -2, 1, 0, 3, 1, -2 ], [ -1, 1, 0, 3, 1, -2 ] ], 0 ] - ], - [ - [ [ [ -3, 1, 1, 3, 1, -2 ], [ -2, 1, 1, 3, 1, -2 ], [ -2, 1, 0, 3, 1, -2 ], [ -1, 1, 0, 3, 1, -2 ] ], 0.5 ] - ], - [ - [ [ [ -2, 0, 0, 3, 1, -2 ], [ -2, 1, 1, 3, 1, -2 ], [ -2, 1, 0, 3, 1, -2 ], [ -1, 1, 0, 3, 1, -2 ] ], 0.75 ] - ], - [ - [ [ [ -2, 0, 0, 3, 1, -2 ], [ -2, 1, 1, 3, 1, -2 ], [ -1, 0, -1, 3, 1, -2 ], [ -1, 1, 0, 3, 1, -2 ] ], 0.875 ] - ], - [ - [ [ [ -2, 0, 0, 3, 1, -2 ], [ -2, 1, 1, 3, 1, -2 ], [ -1, 0, -1, 3, 1, -2 ], [ -2, 1, 1, 3, 1, -1 ] ], 0.75 ] - ], - [ - [ [ [ -2, 0, 0, 3, 1, -2 ], [ -2, 1, 1, 3, 1, -2 ], [ -3, 1, 1, 4, 1, -2 ], [ -2, 1, 1, 3, 1, -1 ] ], 0.125 ], - [ [ [ -2, 0, 0, 3, 1, -2 ], [ -2, 1, 1, 3, 1, -2 ], [ -3, 1, 1, 4, 1, -2 ], [ "Rest" ] ], 1 ], - [ [ [ -2, 0, 0, 3, 1, -2 ], [ "Rest" ], [ -3, 1, 1, 4, 1, -2 ], [ "Rest" ] ], 0.875 ], - [ [ [ "Rest" ], [ "Rest" ], [ -3, 1, 1, 4, 1, -2 ], [ "Rest" ] ], 0 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 1.75 ] - ] - ] -], -"last_changes": -[ - [ [ -3, 1, 1, 3, 1, -2 ], [ -2, 1, 1, 3, 1, -2 ], [ -2, 1, 0, 3, 1, -2 ], [ -1, 1, 0, 3, 1, -2 ] ], - [ [ -2, 0, 0, 3, 1, -2 ], [ -2, 1, 1, 3, 1, -2 ], [ -2, 1, 0, 3, 1, -2 ], [ -1, 1, 0, 3, 1, -2 ] ], - [ [ -2, 0, 0, 3, 1, -2 ], [ -2, 1, 1, 3, 1, -2 ], [ -1, 0, -1, 3, 1, -2 ], [ -1, 1, 0, 3, 1, -2 ] ], - [ [ -2, 0, 0, 3, 1, -2 ], [ -2, 1, 1, 3, 1, -2 ], [ -1, 0, -1, 3, 1, -2 ], [ -2, 1, 1, 3, 1, -1 ] ], - [ [ -2, 0, 0, 3, 1, -2 ], [ -2, 1, 1, 3, 1, -2 ], [ -3, 1, 1, 4, 1, -2 ], [ -2, 1, 1, 3, 1, -1 ] ] -], -"cur_uid": "726a40c7", -"ref_uid": "5ec14635", -"order_seed": 439818, -"dur_seed": 544932, -"motifs_seed": 109123, -"entrances_probs_vals": [ 0, 0, 0, 0, 1.2087912087912, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 0, 0, 0, 0, 1.2087912087912, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 0, 0, 0, 0, 1.2087912087912, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -2170, 338 ], [ -2373.9938080495, 1453 ], [ -1650, 1676 ], [ -1370.8978328173, 1694 ] ], -"step_probs_vals": [ 0, 1200, 0, 0, 0.063786008230453, 0.92613636363636, 0.12757201646091, 0, 0.54732510288066, 0, 0.71604938271605, 0, 1, 0 ], -"passages_weights": [ 1, 0, 0.2, 0.74, 0.68 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 1, 0, 2 ], [ 3 ], [ ] ], - [ [ 3, 1, 2 ], [ 0 ], [ ] ], - [ [ 0, 1, 3 ], [ 2 ], [ ] ], - [ [ 0, 1, 2 ], [ 3 ], [ ] ], - [ [ 1, 0, 2 ], [ 3 ], [ ] ], - [ [ 2, 0, 1 ], [ 3 ], [ ] ], - [ [ 2, 0, 1 ], [ 3 ], [ ] ], - [ [ 2, 3, 1 ], [ 0 ], [ ] ], - [ [ 0, 3, 2 ], [ 1 ], [ ] ], - [ [ 1, 2, 0 ], [ 3 ], [ ] ], - [ [ 1, 3, 0 ], [ 2 ], [ ] ], - [ [ 2, 0, 1 ], [ 3 ], [ ] ], - [ [ 1, 0, 2 ], [ 3 ], [ ] ], - [ [ 1, 3, 2 ], [ 0 ], [ ] ], - [ [ 2, 0, 3 ], [ 1 ], [ ] ], - [ [ 1, 3, 2 ], [ 0 ], [ ] ], - [ [ 3, 0, 2 ], [ 1 ], [ ] ], - [ [ 3, 1, 0 ], [ 2 ], [ ] ], - [ [ 0, 2, 3 ], [ 1 ], [ ] ], - [ [ 0, 3, 1 ], [ 2 ], [ ] ], - [ [ 2, 3, 1 ], [ 0 ], [ ] ], - [ [ 3, 1, 2 ], [ 0 ], [ ] ], - [ [ 2, 3, 1 ], [ 0 ], [ ] ], - [ [ 1, 0, 2 ], [ 3 ], [ ] ], - [ [ 2, 1, 3 ], [ 0 ], [ ] ], - [ [ 3, 2, 1 ], [ 0 ], [ ] ], - [ [ 1, 2, 3 ], [ 0 ], [ ] ], - [ [ 0, 3, 1 ], [ 2 ], [ ] ], - [ [ 1, 2, 0 ], [ 3 ], [ ] ], - [ [ 1, 0, 3 ], [ 2 ], [ ] ] -], -"sus_weights": [ 0, 0, 0.61 ], -"order_size": [ 30, 30 ], -"passages_size": [ 0, 0 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3/75316bf0/75316bf0_code.scd b/resources/resources_bak_2024_01_03/string_quartet_3/75316bf0/75316bf0_code.scd deleted file mode 100644 index 49436ca..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3/75316bf0/75316bf0_code.scd +++ /dev/null @@ -1,973 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array2) - hsArrayToCents.value(array1); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -/* -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance) -}; -*/ - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = true; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - //if(pDistance >= 0, {stepFunc.value(abs(pDistance))}, {0.01}); - stepFunc.value(pDistance) -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - //tuples = dims.collect({[0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength.asInteger - minMotifLength.asInteger).rand + minMotifLength.asInteger).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - //noProgIns = (popSize - noSusIns).rand + 1; - noProgIns = (popSize - noSusIns); - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength.asInteger - minProgLength.asInteger).rand + minProgLength.asInteger).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0.01); - - - - if(rangeScore.value(candidate.collect({0}), voices[ins], ranges[ins][1] - 500, ranges[ins][1], 0, true) == 1, { - isInRangeScore = 1 - rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0] + 500, ranges[ins][1] - 500, 0, true); - isInRangeScore = isInRangeScore * rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true) - }, { - isInRangeScore = rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true); - }); - - - //isInRangeScore = rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true); - //old way - worked but actually by accident (I think) - //isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - - - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_3/75316bf0/75316bf0_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_3/75316bf0/75316bf0_mus_model.json deleted file mode 100644 index e03d000..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3/75316bf0/75316bf0_mus_model.json +++ /dev/null @@ -1,550 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ 2, -1, -2, 2, -3, 0 ], [ "Rest" ], [ "Rest" ] ], 0.625 ], - [ [ [ "Rest" ], [ 2, -1, -2, 2, -3, 0 ], [ 2, -1, -2, 1, -3, 0 ], [ "Rest" ] ], 1 ], - [ [ [ "Rest" ], [ 2, -1, -2, 2, -3, 0 ], [ 2, -1, -2, 1, -3, 0 ], [ 1, 0, -2, 2, -3, 0 ] ], 1.5 ], - [ [ [ 1, -2, -2, 2, -3, 0 ], [ 2, -1, -2, 2, -3, 0 ], [ 2, -1, -2, 1, -3, 0 ], [ 1, 0, -2, 2, -3, 0 ] ], 1.875 ] - ], - [ - [ [ [ 1, -2, -2, 2, -3, 0 ], [ 2, -1, -2, 2, -3, 0 ], [ 2, -1, -2, 1, -3, 0 ], [ 2, -2, -1, 2, -3, 0 ] ], 1.625 ], - [ [ [ 1, -2, -2, 2, -3, 0 ], [ 3, -2, -2, 1, -3, 0 ], [ 2, -1, -2, 1, -3, 0 ], [ 2, -2, -1, 2, -3, 0 ] ], 1.5 ] - ], - [ - [ [ [ 1, -2, -2, 2, -3, 0 ], [ 3, -2, -2, 1, -3, 0 ], [ 2, -3, -2, 2, -3, 0 ], [ 2, -2, -1, 2, -3, 0 ] ], 1.5 ], - [ [ [ 1, -2, -2, 2, -3, 0 ], [ 3, -2, -2, 1, -3, 0 ], [ 2, -3, -2, 2, -3, 0 ], [ 3, -3, -2, 2, -3, 0 ] ], 0.875 ] - ], - [ - [ [ [ 2, -3, -3, 2, -3, 0 ], [ 3, -2, -2, 1, -3, 0 ], [ 2, -3, -2, 2, -3, 0 ], [ 3, -3, -2, 2, -3, 0 ] ], 1.125 ], - [ [ [ 2, -3, -3, 2, -3, 0 ], [ 3, -2, -2, 1, -3, 0 ], [ 3, -3, -2, 1, -3, 0 ], [ 3, -3, -2, 2, -3, 0 ] ], 1.75 ] - ], - [ - [ [ [ 2, -3, -3, 2, -3, 0 ], [ 3, -2, -2, 1, -3, 0 ], [ 3, -3, -2, 1, -3, 0 ], [ 4, -4, -3, 2, -3, 0 ] ], 1.5 ], - [ [ [ 2, -3, -3, 2, -3, 0 ], [ 4, -3, -3, 1, -3, 0 ], [ 3, -3, -2, 1, -3, 0 ], [ 4, -4, -3, 2, -3, 0 ] ], 1.5 ] - ], - [ - [ [ [ 2, -3, -3, 2, -3, 0 ], [ 3, -3, -2, 2, -3, 0 ], [ 3, -3, -2, 1, -3, 0 ], [ 4, -4, -3, 2, -3, 0 ] ], 1.75 ], - [ [ [ 2, -3, -3, 2, -3, 0 ], [ 3, -3, -2, 2, -3, 0 ], [ 3, -4, -3, 2, -3, 0 ], [ 4, -4, -3, 2, -3, 0 ] ], 1.5 ] - ], - [ - [ [ [ 2, -3, -3, 2, -3, 0 ], [ 3, -3, -2, 2, -3, 0 ], [ 2, -2, -3, 2, -3, 0 ], [ 4, -4, -3, 2, -3, 0 ] ], 0.5 ] - ], - [ - [ [ [ 2, -3, -3, 2, -3, 0 ], [ 4, -4, -4, 2, -3, 0 ], [ 2, -2, -3, 2, -3, 0 ], [ 4, -4, -3, 2, -3, 0 ] ], 0.5 ], - [ [ [ 2, -3, -3, 2, -3, 0 ], [ 4, -4, -4, 2, -3, 0 ], [ 2, -4, -3, 3, -3, 0 ], [ 4, -4, -3, 2, -3, 0 ] ], 0.75 ], - [ [ [ 3, -4, -4, 2, -3, 0 ], [ 4, -4, -4, 2, -3, 0 ], [ 2, -4, -3, 3, -3, 0 ], [ 4, -4, -3, 2, -3, 0 ] ], 0.625 ] - ], - [ - [ [ [ 3, -4, -4, 2, -3, 0 ], [ 4, -4, -4, 2, -3, 0 ], [ 3, -5, -3, 2, -3, 0 ], [ 4, -4, -3, 2, -3, 0 ] ], 0.625 ] - ], - [ - [ [ [ 1, -3, -4, 2, -3, 0 ], [ 4, -4, -4, 2, -3, 0 ], [ 3, -5, -3, 2, -3, 0 ], [ 4, -4, -3, 2, -3, 0 ] ], 1.25 ], - [ [ [ 1, -3, -4, 2, -3, 0 ], [ 4, -4, -4, 2, -3, 0 ], [ 2, -4, -4, 3, -3, 0 ], [ 4, -4, -3, 2, -3, 0 ] ], 1.375 ], - [ [ [ 1, -3, -4, 2, -3, 0 ], [ 4, -4, -4, 2, -3, 0 ], [ 2, -4, -4, 3, -3, 0 ], [ 5, -4, -4, 1, -3, 0 ] ], 0.75 ] - ], - [ - [ [ [ 1, -3, -4, 2, -3, 0 ], [ 4, -4, -4, 2, -3, 0 ], [ 3, -4, -4, 2, -3, 0 ], [ 5, -4, -4, 1, -3, 0 ] ], 1.375 ] - ], - [ - [ [ [ 1, -3, -4, 2, -3, 0 ], [ 4, -4, -4, 2, -3, 0 ], [ 3, -4, -4, 2, -3, 0 ], [ 4, -3, -5, 2, -3, 0 ] ], 1.5 ], - [ [ [ 1, -3, -4, 2, -3, 0 ], [ 3, -2, -4, 2, -3, 0 ], [ 3, -4, -4, 2, -3, 0 ], [ 4, -3, -5, 2, -3, 0 ] ], 0.5 ] - ], - [ - [ [ [ 1, -3, -4, 2, -3, 0 ], [ 3, -2, -4, 2, -3, 0 ], [ 3, -4, -4, 2, -3, 0 ], [ 3, -3, -4, 3, -3, 0 ] ], 1.75 ], - [ [ [ 1, -3, -4, 2, -3, 0 ], [ 3, -2, -4, 2, -3, 0 ], [ 2, -2, -4, 2, -3, 0 ], [ 3, -3, -4, 3, -3, 0 ] ], 1.625 ] - ], - [ - [ [ [ 1, -2, -4, 2, -4, 0 ], [ 3, -2, -4, 2, -3, 0 ], [ 2, -2, -4, 2, -3, 0 ], [ 3, -3, -4, 3, -3, 0 ] ], 0.625 ] - ], - [ - [ [ [ 1, -2, -4, 2, -4, 0 ], [ 1, -2, -4, 3, -3, 0 ], [ 2, -2, -4, 2, -3, 0 ], [ 3, -3, -4, 3, -3, 0 ] ], 0.875 ], - [ [ [ 1, -4, -4, 3, -3, 0 ], [ 1, -2, -4, 3, -3, 0 ], [ 2, -2, -4, 2, -3, 0 ], [ 3, -3, -4, 3, -3, 0 ] ], 1.625 ] - ], - [ - [ [ [ 1, -4, -4, 3, -3, 0 ], [ 2, -4, -3, 3, -3, 0 ], [ 2, -2, -4, 2, -3, 0 ], [ 3, -3, -4, 3, -3, 0 ] ], 1.625 ] - ], - [ - [ [ [ 1, -4, -4, 3, -3, 0 ], [ 2, -4, -3, 3, -3, 0 ], [ 2, -3, -4, 3, -3, 0 ], [ 3, -3, -4, 3, -3, 0 ] ], 0.5 ] - ], - [ - [ [ [ 1, -4, -4, 3, -3, 0 ], [ 2, -4, -3, 3, -3, 0 ], [ 2, -4, -4, 3, -3, 0 ], [ 3, -3, -4, 3, -3, 0 ] ], 0.75 ] - ], - [ - [ [ [ 1, -4, -4, 3, -3, 0 ], [ 2, -4, -3, 3, -3, 0 ], [ 1, -4, -3, 4, -3, 0 ], [ 3, -3, -4, 3, -3, 0 ] ], 0.75 ], - [ [ [ 0, -4, -3, 4, -3, 0 ], [ 2, -4, -3, 3, -3, 0 ], [ 1, -4, -3, 4, -3, 0 ], [ 3, -3, -4, 3, -3, 0 ] ], 1.25 ], - [ [ [ 0, -4, -3, 4, -3, 0 ], [ 2, -4, -3, 3, -3, 0 ], [ 1, -4, -3, 4, -3, 0 ], [ 3, -4, -3, 3, -3, 0 ] ], 1.25 ] - ], - [ - [ [ [ 0, -4, -3, 4, -3, 0 ], [ 3, -4, -3, 2, -3, 0 ], [ 1, -4, -3, 4, -3, 0 ], [ 3, -4, -3, 3, -3, 0 ] ], 1 ], - [ [ [ 0, -4, -3, 4, -3, 0 ], [ 3, -4, -3, 2, -3, 0 ], [ 2, -4, -3, 3, -3, 0 ], [ 3, -4, -3, 3, -3, 0 ] ], 0.375 ], - [ [ [ 1, -4, -3, 3, -3, 0 ], [ 3, -4, -3, 2, -3, 0 ], [ 2, -4, -3, 3, -3, 0 ], [ 3, -4, -3, 3, -3, 0 ] ], 1.375 ] - ], - [ - [ [ [ 1, -4, -3, 3, -3, 0 ], [ 3, -4, -3, 2, -3, 0 ], [ 2, -4, -3, 3, -3, 0 ], [ 4, -4, -3, 2, -3, 0 ] ], 1.625 ], - [ [ [ 2, -4, -3, 2, -3, 0 ], [ 3, -4, -3, 2, -3, 0 ], [ 2, -4, -3, 3, -3, 0 ], [ 4, -4, -3, 2, -3, 0 ] ], 1.625 ] - ], - [ - [ [ [ 2, -4, -3, 2, -3, 0 ], [ 3, -4, -3, 2, -3, 0 ], [ 2, -4, -3, 3, -3, 0 ], [ 3, -4, -3, 2, -3, 1 ] ], 1.625 ], - [ [ [ 2, -4, -3, 2, -3, 0 ], [ 3, -4, -3, 2, -3, 0 ], [ 3, -5, -3, 2, -3, 0 ], [ 3, -4, -3, 2, -3, 1 ] ], 1.75 ] - ], - [ - [ [ [ 2, -4, -3, 2, -3, 0 ], [ 3, -4, -3, 2, -3, 0 ], [ 2, -3, -3, 2, -3, 0 ], [ 3, -4, -3, 2, -3, 1 ] ], 1.75 ], - [ [ [ 2, -4, -3, 2, -3, 0 ], [ 3, -4, -3, 2, -3, 0 ], [ 2, -3, -3, 2, -3, 0 ], [ 3, -4, -3, 3, -3, 0 ] ], 1.75 ] - ], - [ - [ [ [ 2, -4, -3, 2, -3, 0 ], [ 2, -2, -3, 2, -3, 0 ], [ 2, -3, -3, 2, -3, 0 ], [ 3, -4, -3, 3, -3, 0 ] ], 1 ] - ], - [ - [ [ [ 2, -5, -3, 3, -3, 0 ], [ 2, -2, -3, 2, -3, 0 ], [ 2, -3, -3, 2, -3, 0 ], [ 3, -4, -3, 3, -3, 0 ] ], 1.625 ], - [ [ [ 2, -5, -3, 3, -3, 0 ], [ 2, -2, -3, 2, -3, 0 ], [ 2, -4, -3, 3, -3, 0 ], [ 3, -4, -3, 3, -3, 0 ] ], 1.75 ], - [ [ [ 2, -5, -3, 3, -3, 0 ], [ 2, -3, -3, 3, -3, 0 ], [ 2, -4, -3, 3, -3, 0 ], [ 3, -4, -3, 3, -3, 0 ] ], 1.625 ] - ], - [ - [ [ [ 1, -3, -3, 3, -3, 0 ], [ 2, -3, -3, 3, -3, 0 ], [ 2, -4, -3, 3, -3, 0 ], [ 3, -4, -3, 3, -3, 0 ] ], 1 ], - [ [ [ 1, -3, -3, 3, -3, 0 ], [ 2, -3, -3, 3, -3, 0 ], [ 2, -4, -3, 3, -3, 0 ], [ 2, -2, -3, 3, -3, 0 ] ], 1 ], - [ [ [ 1, -3, -3, 3, -3, 0 ], [ 2, -3, -3, 3, -3, 0 ], [ 1, -2, -3, 3, -3, 0 ], [ 2, -2, -3, 3, -3, 0 ] ], 1.25 ] - ], - [ - [ [ [ 1, -3, -3, 3, -3, 0 ], [ 2, -3, -3, 3, -3, 0 ], [ 2, -3, -4, 3, -3, 0 ], [ 2, -2, -3, 3, -3, 0 ] ], 0.875 ], - [ [ [ 1, -3, -3, 3, -3, 0 ], [ 2, -3, -3, 3, -3, 0 ], [ 2, -3, -4, 3, -3, 0 ], [ 3, -3, -4, 3, -3, 0 ] ], 1.625 ], - [ [ [ 1, -3, -4, 3, -3, 0 ], [ 2, -3, -3, 3, -3, 0 ], [ 2, -3, -4, 3, -3, 0 ], [ 3, -3, -4, 3, -3, 0 ] ], 0.875 ] - ], - [ - [ [ [ 1, -3, -4, 3, -3, 0 ], [ 2, -3, -3, 3, -3, 0 ], [ 2, -4, -4, 3, -3, 0 ], [ 3, -3, -4, 3, -3, 0 ] ], 0.75 ], - [ [ [ 1, -3, -4, 3, -3, 0 ], [ 3, -4, -4, 3, -3, 0 ], [ 2, -4, -4, 3, -3, 0 ], [ 3, -3, -4, 3, -3, 0 ] ], 0.5 ], - [ [ [ 1, -3, -4, 3, -3, 0 ], [ 3, -4, -4, 3, -3, 0 ], [ 2, -4, -4, 3, -3, 0 ], [ 2, -3, -4, 4, -3, 0 ] ], 1.125 ] - ], - [ - [ [ [ 1, -3, -4, 3, -3, 0 ], [ 3, -4, -4, 3, -3, 0 ], [ 1, -2, -4, 3, -3, 0 ], [ 2, -3, -4, 4, -3, 0 ] ], 1.625 ] - ], - [ - [ [ [ 1, -3, -4, 3, -3, 0 ], [ 2, -2, -4, 3, -3, 0 ], [ 1, -2, -4, 3, -3, 0 ], [ 2, -3, -4, 4, -3, 0 ] ], 1.75 ] - ], - [ - [ [ [ 1, -3, -4, 3, -3, 0 ], [ 2, -2, -4, 3, -3, 0 ], [ 1, -2, -4, 3, -3, 0 ], [ 2, -2, -3, 3, -3, 0 ] ], 1.75 ], - [ [ [ 1, -3, -4, 3, -3, 0 ], [ 2, -2, -4, 3, -3, 0 ], [ 2, -3, -5, 3, -3, 0 ], [ 2, -2, -3, 3, -3, 0 ] ], 0.75 ] - ], - [ - [ [ [ 1, -3, -4, 3, -3, 0 ], [ 2, -2, -4, 3, -3, 0 ], [ 2, -3, -5, 3, -3, 0 ], [ 3, -3, -4, 3, -3, 0 ] ], 0.375 ], - [ [ [ 1, -3, -4, 3, -3, 0 ], [ 2, -3, -4, 3, -3, 0 ], [ 2, -3, -5, 3, -3, 0 ], [ 3, -3, -4, 3, -3, 0 ] ], 1.125 ] - ], - [ - [ [ [ 1, -3, -4, 3, -3, 0 ], [ 2, -3, -4, 3, -4, 0 ], [ 2, -3, -5, 3, -3, 0 ], [ 3, -3, -4, 3, -3, 0 ] ], 0.5 ], - [ [ [ 1, -3, -4, 2, -3, 0 ], [ 2, -3, -4, 3, -4, 0 ], [ 2, -3, -5, 3, -3, 0 ], [ 3, -3, -4, 3, -3, 0 ] ], 1.75 ], - [ [ [ 1, -3, -4, 2, -3, 0 ], [ 2, -3, -4, 3, -4, 0 ], [ 1, -3, -4, 4, -3, 0 ], [ 3, -3, -4, 3, -3, 0 ] ], 1.25 ] - ], - [ - [ [ [ 1, -3, -4, 2, -3, 0 ], [ 0, -2, -4, 4, -3, 0 ], [ 1, -3, -4, 4, -3, 0 ], [ 3, -3, -4, 3, -3, 0 ] ], 1 ], - [ [ [ -1, -2, -4, 4, -3, 0 ], [ 0, -2, -4, 4, -3, 0 ], [ 1, -3, -4, 4, -3, 0 ], [ 3, -3, -4, 3, -3, 0 ] ], 1.75 ], - [ [ [ -1, -2, -4, 4, -3, 0 ], [ 0, -2, -4, 4, -3, 0 ], [ 1, -3, -4, 4, -3, 0 ], [ 2, -3, -4, 4, -3, 0 ] ], 0.875 ] - ], - [ - [ [ [ -1, -2, -4, 4, -3, 0 ], [ 0, -2, -4, 4, -3, 0 ], [ 0, -1, -4, 4, -3, 0 ], [ 2, -3, -4, 4, -3, 0 ] ], 1.375 ], - [ [ [ -1, -2, -4, 4, -3, 0 ], [ 0, -2, -4, 4, -3, 0 ], [ 0, -1, -4, 4, -3, 0 ], [ 1, -1, -4, 4, -3, 0 ] ], 1.25 ] - ], - [ - [ [ [ -1, -2, -4, 4, -3, 0 ], [ 1, -2, -4, 3, -3, 0 ], [ 0, -1, -4, 4, -3, 0 ], [ 1, -1, -4, 4, -3, 0 ] ], 0.625 ], - [ [ [ -1, -2, -4, 4, -3, 0 ], [ 1, -2, -4, 3, -3, 0 ], [ 0, -1, -4, 4, -3, 0 ], [ 1, -2, -3, 4, -3, 0 ] ], 0.625 ], - [ [ [ -1, -2, -4, 4, -3, 0 ], [ 1, -2, -4, 3, -3, 0 ], [ 0, -2, -4, 4, -3, 0 ], [ 1, -2, -3, 4, -3, 0 ] ], 0.5 ] - ], - [ - [ [ [ -1, -2, -4, 4, -3, 0 ], [ 0, -2, -3, 4, -3, 0 ], [ 0, -2, -4, 4, -3, 0 ], [ 1, -2, -3, 4, -3, 0 ] ], 0.75 ], - [ [ [ -1, -2, -4, 4, -3, 0 ], [ 0, -2, -3, 4, -3, 0 ], [ -1, -2, -3, 5, -3, 0 ], [ 1, -2, -3, 4, -3, 0 ] ], 1.125 ] - ], - [ - [ [ [ -1, -2, -4, 4, -3, 0 ], [ 1, -3, -4, 4, -3, 0 ], [ -1, -2, -3, 5, -3, 0 ], [ 1, -2, -3, 4, -3, 0 ] ], 1.625 ], - [ [ [ -1, -2, -4, 4, -3, 0 ], [ 1, -3, -4, 4, -3, 0 ], [ -1, -2, -3, 5, -3, 0 ], [ 2, -3, -4, 4, -3, 0 ] ], 0.875 ], - [ [ [ -1, -2, -4, 4, -3, 0 ], [ 1, -3, -4, 4, -3, 0 ], [ 0, -2, -3, 4, -3, 0 ], [ 2, -3, -4, 4, -3, 0 ] ], 1.25 ] - ], - [ - [ [ [ -1, -2, -4, 4, -3, 0 ], [ 1, -3, -4, 4, -3, 0 ], [ 1, -3, -4, 4, -4, 0 ], [ 2, -3, -4, 4, -3, 0 ] ], 1 ] - ], - [ - [ [ [ -1, -2, -4, 4, -3, 0 ], [ 1, -3, -4, 4, -3, 0 ], [ 1, -3, -4, 4, -4, 0 ], [ 1, -1, -4, 4, -3, 0 ] ], 1.5 ] - ], - [ - [ [ [ -1, -2, -4, 4, -3, 0 ], [ 1, -2, -4, 4, -4, 0 ], [ 1, -3, -4, 4, -4, 0 ], [ 1, -1, -4, 4, -3, 0 ] ], 1 ], - [ [ [ 1, -3, -4, 3, -4, 0 ], [ 1, -2, -4, 4, -4, 0 ], [ 1, -3, -4, 4, -4, 0 ], [ 1, -1, -4, 4, -3, 0 ] ], 1.25 ], - [ [ [ 1, -3, -4, 3, -4, 0 ], [ 1, -2, -4, 4, -4, 0 ], [ 1, -3, -4, 4, -4, 0 ], [ 2, -2, -4, 4, -4, 0 ] ], 0.5 ] - ], - [ - [ [ [ 1, -3, -4, 3, -4, 0 ], [ 1, -2, -4, 4, -4, 0 ], [ 2, -3, -4, 3, -4, 0 ], [ 2, -2, -4, 4, -4, 0 ] ], 1 ] - ], - [ - [ [ [ 1, -3, -4, 3, -4, 0 ], [ 2, -2, -4, 3, -4, 0 ], [ 2, -3, -4, 3, -4, 0 ], [ 2, -2, -4, 4, -4, 0 ] ], 0.875 ], - [ [ [ 0, -2, -4, 3, -4, 0 ], [ 2, -2, -4, 3, -4, 0 ], [ 2, -3, -4, 3, -4, 0 ], [ 2, -2, -4, 4, -4, 0 ] ], 1.75 ] - ], - [ - [ [ [ 0, -2, -4, 3, -4, 0 ], [ 2, -2, -4, 3, -4, 0 ], [ 2, -3, -4, 3, -4, 0 ], [ 2, -1, -4, 3, -4, 0 ] ], 1.75 ], - [ [ [ 0, -2, -4, 3, -4, 0 ], [ 2, -2, -4, 3, -4, 0 ], [ 1, -1, -4, 3, -4, 0 ], [ 2, -1, -4, 3, -4, 0 ] ], 1.75 ], - [ [ [ 1, -2, -4, 3, -4, 0 ], [ 2, -2, -4, 3, -4, 0 ], [ 1, -1, -4, 3, -4, 0 ], [ 2, -1, -4, 3, -4, 0 ] ], 1.125 ] - ], - [ - [ [ [ 1, -2, -4, 3, -4, 0 ], [ 1, 0, -4, 3, -4, 0 ], [ 1, -1, -4, 3, -4, 0 ], [ 2, -1, -4, 3, -4, 0 ] ], 0.875 ] - ], - [ - [ [ [ 0, 0, -4, 3, -4, 0 ], [ 1, 0, -4, 3, -4, 0 ], [ 1, -1, -4, 3, -4, 0 ], [ 2, -1, -4, 3, -4, 0 ] ], 1.75 ], - [ [ [ 0, 0, -4, 3, -4, 0 ], [ 1, 0, -4, 3, -4, 0 ], [ 0, 1, -4, 3, -4, 0 ], [ 2, -1, -4, 3, -4, 0 ] ], 0.625 ] - ], - [ - [ [ [ -1, 1, -4, 3, -4, 0 ], [ 1, 0, -4, 3, -4, 0 ], [ 0, 1, -4, 3, -4, 0 ], [ 2, -1, -4, 3, -4, 0 ] ], 0.75 ], - [ [ [ -1, 1, -4, 3, -4, 0 ], [ 1, 0, -4, 3, -4, 0 ], [ 1, 0, -5, 3, -4, 0 ], [ 2, -1, -4, 3, -4, 0 ] ], 0.75 ] - ], - [ - [ [ [ -1, 1, -4, 3, -4, 0 ], [ 1, 0, -4, 3, -4, 0 ], [ 1, 0, -5, 3, -4, 0 ], [ 1, 1, -4, 3, -4, 0 ] ], 1.5 ], - [ [ [ -1, 1, -4, 3, -4, 0 ], [ 1, 0, -4, 3, -4, 0 ], [ 0, 0, -4, 4, -4, 0 ], [ 1, 1, -4, 3, -4, 0 ] ], 1.25 ], - [ [ [ -1, 0, -4, 3, -4, 0 ], [ 1, 0, -4, 3, -4, 0 ], [ 0, 0, -4, 4, -4, 0 ], [ 1, 1, -4, 3, -4, 0 ] ], 0.875 ] - ], - [ - [ [ [ -1, 0, -4, 4, -4, -1 ], [ 1, 0, -4, 3, -4, 0 ], [ 0, 0, -4, 4, -4, 0 ], [ 1, 1, -4, 3, -4, 0 ] ], 0.75 ], - [ [ [ -1, 0, -4, 4, -4, -1 ], [ 1, 0, -4, 3, -4, 0 ], [ 0, 0, -4, 4, -4, 0 ], [ 0, 1, -4, 4, -4, 0 ] ], 1 ], - [ [ [ -1, 0, -4, 4, -4, -1 ], [ 0, 0, -3, 4, -4, 0 ], [ 0, 0, -4, 4, -4, 0 ], [ 0, 1, -4, 4, -4, 0 ] ], 1.5 ] - ], - [ - [ [ [ -1, 0, -4, 4, -4, -1 ], [ 1, 0, -5, 4, -4, -1 ], [ 0, 0, -4, 4, -4, 0 ], [ 0, 1, -4, 4, -4, 0 ] ], 1.625 ], - [ [ [ -1, 0, -4, 4, -4, -1 ], [ 1, 0, -5, 4, -4, -1 ], [ 0, 0, -4, 4, -4, 0 ], [ 2, -1, -4, 4, -4, -1 ] ], 0.5 ], - [ [ [ -1, 0, -4, 4, -4, -1 ], [ 1, 0, -5, 4, -4, -1 ], [ 1, -1, -4, 4, -4, -1 ], [ 2, -1, -4, 4, -4, -1 ] ], 0.75 ] - ], - [ - [ [ [ -1, 0, -4, 4, -4, -1 ], [ 2, -2, -4, 4, -4, -1 ], [ 1, -1, -4, 4, -4, -1 ], [ 2, -1, -4, 4, -4, -1 ] ], 0.5 ], - [ [ [ 0, -1, -5, 4, -4, -1 ], [ 2, -2, -4, 4, -4, -1 ], [ 1, -1, -4, 4, -4, -1 ], [ 2, -1, -4, 4, -4, -1 ] ], 1.375 ], - [ [ [ 0, -1, -5, 4, -4, -1 ], [ 2, -2, -4, 4, -4, -1 ], [ 1, -1, -5, 4, -4, -1 ], [ 2, -1, -4, 4, -4, -1 ] ], 0.625 ] - ], - [ - [ [ [ 0, -1, -5, 4, -4, -1 ], [ 1, -1, -4, 4, -4, -1 ], [ 1, -1, -5, 4, -4, -1 ], [ 2, -1, -4, 4, -4, -1 ] ], 0.625 ], - [ [ [ 0, -1, -4, 4, -4, -1 ], [ 1, -1, -4, 4, -4, -1 ], [ 1, -1, -5, 4, -4, -1 ], [ 2, -1, -4, 4, -4, -1 ] ], 1 ], - [ [ [ 0, -1, -4, 4, -4, -1 ], [ 1, -1, -4, 4, -4, -1 ], [ 0, 0, -4, 4, -4, -1 ], [ 2, -1, -4, 4, -4, -1 ] ], 1 ] - ], - [ - [ [ [ 0, -1, -4, 4, -4, -1 ], [ 1, -1, -4, 4, -4, -1 ], [ 0, -1, -4, 5, -4, -1 ], [ 2, -1, -4, 4, -4, -1 ] ], 1 ], - [ [ [ 0, -2, -4, 4, -4, -1 ], [ 1, -1, -4, 4, -4, -1 ], [ 0, -1, -4, 5, -4, -1 ], [ 2, -1, -4, 4, -4, -1 ] ], 1.375 ] - ], - [ - [ [ [ 0, -2, -4, 4, -4, -1 ], [ 1, -1, -4, 4, -4, -1 ], [ 2, -2, -4, 4, -4, -1 ], [ 2, -1, -4, 4, -4, -1 ] ], 1.25 ], - [ [ [ 0, -2, -4, 4, -4, -1 ], [ 1, -1, -4, 4, -4, -1 ], [ 2, -2, -4, 4, -4, -1 ], [ 3, -3, -4, 4, -4, -1 ] ], 0.875 ] - ], - [ - [ [ [ 0, -3, -4, 4, -3, -1 ], [ 1, -1, -4, 4, -4, -1 ], [ 2, -2, -4, 4, -4, -1 ], [ 3, -3, -4, 4, -4, -1 ] ], 0.875 ] - ], - [ - [ [ [ 0, -2, -4, 4, -4, -1 ], [ 1, -1, -4, 4, -4, -1 ], [ 2, -2, -4, 4, -4, -1 ], [ 3, -3, -4, 4, -4, -1 ] ], 0.875 ], - [ [ [ 0, -2, -4, 4, -4, -1 ], [ 1, -1, -4, 4, -4, -1 ], [ 2, -2, -4, 4, -4, -1 ], [ 2, -1, -4, 4, -4, -1 ] ], 1.5 ], - [ [ [ 0, -2, -4, 4, -4, -1 ], [ 1, -1, -4, 4, -4, -1 ], [ 1, 0, -4, 4, -4, -1 ], [ 2, -1, -4, 4, -4, -1 ] ], 0.875 ] - ], - [ - [ [ [ 0, -2, -4, 4, -4, -1 ], [ 1, -1, -4, 4, -4, -1 ], [ 2, -3, -4, 4, -4, -1 ], [ 2, -1, -4, 4, -4, -1 ] ], 1.5 ], - [ [ [ 0, -2, -4, 4, -4, -1 ], [ 1, -1, -4, 4, -4, -1 ], [ 2, -3, -4, 4, -4, -1 ], [ 2, -2, -4, 4, -4, 0 ] ], 0.375 ] - ], - [ - [ [ [ 0, -2, -4, 4, -4, -1 ], [ 1, -1, -4, 4, -4, -1 ], [ 2, -3, -4, 4, -4, -1 ], [ 1, -1, -4, 5, -4, -1 ] ], 0.5 ], - [ [ [ 0, -2, -4, 4, -4, -1 ], [ 1, -1, -4, 4, -4, -1 ], [ 0, 0, -4, 4, -4, -1 ], [ 1, -1, -4, 5, -4, -1 ] ], 0.75 ] - ], - [ - [ [ [ 0, -2, -4, 4, -4, -1 ], [ 1, -1, -4, 4, -4, -1 ], [ 1, -1, -5, 4, -4, -1 ], [ 1, -1, -4, 5, -4, -1 ] ], 0.5 ] - ], - [ - [ [ [ 0, -2, -4, 4, -4, -1 ], [ 1, -1, -4, 4, -4, -1 ], [ 1, -2, -4, 4, -3, -1 ], [ 1, -1, -4, 5, -4, -1 ] ], 0.5 ], - [ [ [ 0, -2, -4, 4, -4, -1 ], [ 2, -2, -5, 4, -4, -1 ], [ 1, -2, -4, 4, -3, -1 ], [ 1, -1, -4, 5, -4, -1 ] ], 1.125 ], - [ [ [ 0, -2, -4, 4, -4, -1 ], [ 2, -2, -5, 4, -4, -1 ], [ 1, -2, -4, 4, -3, -1 ], [ 2, -1, -4, 4, -4, -1 ] ], 1.625 ] - ], - [ - [ [ [ 0, -2, -4, 4, -4, -1 ], [ 2, -2, -5, 4, -4, -1 ], [ 1, -1, -4, 4, -4, -1 ], [ 2, -1, -4, 4, -4, -1 ] ], 0.875 ] - ], - [ - [ [ [ 0, -2, -4, 4, -4, -1 ], [ 0, 0, -4, 4, -4, -1 ], [ 1, -1, -4, 4, -4, -1 ], [ 2, -1, -4, 4, -4, -1 ] ], 1.375 ], - [ [ [ -1, 0, -4, 4, -4, -1 ], [ 0, 0, -4, 4, -4, -1 ], [ 1, -1, -4, 4, -4, -1 ], [ 2, -1, -4, 4, -4, -1 ] ], 0.875 ] - ], - [ - [ [ [ -1, 0, -4, 4, -4, -1 ], [ 1, -1, -5, 4, -4, -1 ], [ 1, -1, -4, 4, -4, -1 ], [ 2, -1, -4, 4, -4, -1 ] ], 1.5 ], - [ [ [ -1, 0, -4, 4, -4, -1 ], [ 1, -1, -5, 4, -4, -1 ], [ 1, -1, -4, 4, -4, -1 ], [ 1, -1, -4, 5, -4, -1 ] ], 0.5 ], - [ [ [ 0, -1, -5, 4, -4, -1 ], [ 1, -1, -5, 4, -4, -1 ], [ 1, -1, -4, 4, -4, -1 ], [ 1, -1, -4, 5, -4, -1 ] ], 1.375 ] - ], - [ - [ [ [ 0, -1, -5, 4, -4, -1 ], [ 1, -1, -5, 4, -4, -1 ], [ 1, -1, -4, 4, -4, -1 ], [ 3, -1, -5, 4, -4, -2 ] ], 0.625 ], - [ [ [ 0, -1, -5, 4, -4, -1 ], [ 1, -1, -5, 4, -4, -1 ], [ 2, -2, -5, 4, -4, -1 ], [ 3, -1, -5, 4, -4, -2 ] ], 1.5 ] - ], - [ - [ [ [ 0, -1, -5, 4, -4, -1 ], [ 2, -3, -5, 4, -4, -1 ], [ 2, -2, -5, 4, -4, -1 ], [ 3, -1, -5, 4, -4, -2 ] ], 1.5 ], - [ [ [ 1, -2, -5, 4, -4, -2 ], [ 2, -3, -5, 4, -4, -1 ], [ 2, -2, -5, 4, -4, -1 ], [ 3, -1, -5, 4, -4, -2 ] ], 0.5 ], - [ [ [ 1, -2, -5, 4, -4, -2 ], [ 2, -3, -5, 4, -4, -1 ], [ 2, -2, -5, 4, -4, -1 ], [ 3, -2, -5, 4, -4, -1 ] ], 1.25 ] - ], - [ - [ [ [ 1, -2, -5, 4, -4, -2 ], [ 2, -2, -5, 4, -5, -1 ], [ 2, -2, -5, 4, -4, -1 ], [ 3, -2, -5, 4, -4, -1 ] ], 0.625 ], - [ [ [ 1, -3, -5, 4, -4, -1 ], [ 2, -2, -5, 4, -5, -1 ], [ 2, -2, -5, 4, -4, -1 ], [ 3, -2, -5, 4, -4, -1 ] ], 0.75 ], - [ [ [ 1, -3, -5, 4, -4, -1 ], [ 2, -2, -5, 4, -5, -1 ], [ 2, -3, -5, 4, -4, -1 ], [ 3, -2, -5, 4, -4, -1 ] ], 1.625 ] - ], - [ - [ [ [ 1, -2, -5, 4, -5, -1 ], [ 2, -2, -5, 4, -5, -1 ], [ 2, -3, -5, 4, -4, -1 ], [ 3, -2, -5, 4, -4, -1 ] ], 1.5 ], - [ [ [ 1, -2, -5, 4, -5, -1 ], [ 2, -2, -5, 4, -5, -1 ], [ 3, -2, -5, 4, -5, -1 ], [ 3, -2, -5, 4, -4, -1 ] ], 0.5 ], - [ [ [ 1, -2, -5, 4, -5, -1 ], [ 2, -2, -5, 4, -5, -1 ], [ 3, -2, -5, 4, -5, -1 ], [ 3, -2, -4, 4, -5, -1 ] ], 1.5 ] - ], - [ - [ [ [ 1, -2, -5, 4, -5, -1 ], [ 2, -2, -5, 4, -5, -1 ], [ 2, -2, -4, 4, -5, -1 ], [ 3, -2, -4, 4, -5, -1 ] ], 1.375 ], - [ [ [ 1, -2, -5, 4, -5, -1 ], [ 1, -2, -4, 5, -5, -1 ], [ 2, -2, -4, 4, -5, -1 ], [ 3, -2, -4, 4, -5, -1 ] ], 0.625 ], - [ [ [ 0, -2, -4, 5, -5, -1 ], [ 1, -2, -4, 5, -5, -1 ], [ 2, -2, -4, 4, -5, -1 ], [ 3, -2, -4, 4, -5, -1 ] ], 0.75 ] - ], - [ - [ [ [ 0, -2, -4, 5, -5, -1 ], [ 1, -1, -4, 4, -5, -1 ], [ 2, -2, -4, 4, -5, -1 ], [ 3, -2, -4, 4, -5, -1 ] ], 0.875 ], - [ [ [ 0, -2, -4, 5, -5, -1 ], [ 1, -1, -4, 4, -5, -1 ], [ 2, -2, -4, 4, -5, -1 ], [ 4, -2, -4, 3, -5, -1 ] ], 1 ] - ], - [ - [ [ [ 1, -2, -4, 4, -5, -1 ], [ 1, -1, -4, 4, -5, -1 ], [ 2, -2, -4, 4, -5, -1 ], [ 4, -2, -4, 3, -5, -1 ] ], 0.75 ] - ], - [ - [ [ [ 1, -2, -4, 4, -5, -1 ], [ 1, -1, -4, 4, -5, -1 ], [ 2, -2, -4, 4, -5, -1 ], [ 2, -1, -4, 4, -4, -1 ] ], 0.75 ] - ], - [ - [ [ [ 1, -2, -4, 4, -5, -1 ], [ 2, -1, -4, 4, -5, -1 ], [ 2, -2, -4, 4, -5, -1 ], [ 2, -1, -4, 4, -4, -1 ] ], 0.875 ], - [ [ [ 1, -2, -4, 4, -5, -1 ], [ 2, -1, -4, 4, -5, -1 ], [ 1, -1, -4, 4, -5, -1 ], [ 2, -1, -4, 4, -4, -1 ] ], 1.25 ], - [ [ [ 0, -1, -4, 4, -5, -1 ], [ 2, -1, -4, 4, -5, -1 ], [ 1, -1, -4, 4, -5, -1 ], [ 2, -1, -4, 4, -4, -1 ] ], 1.125 ] - ], - [ - [ [ [ 1, -1, -4, 3, -5, -1 ], [ 2, -1, -4, 4, -5, -1 ], [ 1, -1, -4, 4, -5, -1 ], [ 2, -1, -4, 4, -4, -1 ] ], 1 ], - [ [ [ 1, -1, -4, 3, -5, -1 ], [ 2, -1, -4, 4, -5, -1 ], [ 1, -1, -4, 4, -5, -1 ], [ 2, 0, -4, 4, -5, -1 ] ], 1.375 ] - ], - [ - [ [ [ 0, -1, -3, 4, -5, -1 ], [ 2, -1, -4, 4, -5, -1 ], [ 1, -1, -4, 4, -5, -1 ], [ 2, 0, -4, 4, -5, -1 ] ], 0.75 ], - [ [ [ 0, -1, -3, 4, -5, -1 ], [ 2, -1, -4, 4, -5, -1 ], [ 2, -1, -4, 3, -5, -1 ], [ 2, 0, -4, 4, -5, -1 ] ], 1.5 ], - [ [ [ 0, -1, -3, 4, -5, -1 ], [ 2, -1, -4, 4, -5, -1 ], [ 2, -1, -4, 3, -5, -1 ], [ 3, -2, -4, 4, -5, -1 ] ], 0.5 ] - ], - [ - [ [ [ 1, -2, -4, 4, -5, -1 ], [ 2, -1, -4, 4, -5, -1 ], [ 2, -1, -4, 3, -5, -1 ], [ 3, -2, -4, 4, -5, -1 ] ], 1.375 ], - [ [ [ 1, -2, -4, 4, -5, -1 ], [ 2, -1, -4, 4, -5, -1 ], [ 2, -2, -4, 4, -5, -1 ], [ 3, -2, -4, 4, -5, -1 ] ], 0.875 ], - [ [ [ 1, -2, -4, 4, -5, -1 ], [ 3, -2, -5, 4, -5, -1 ], [ 2, -2, -4, 4, -5, -1 ], [ 3, -2, -4, 4, -5, -1 ] ], 0.5 ] - ], - [ - [ [ [ 1, -2, -4, 4, -5, -1 ], [ 3, -2, -5, 4, -5, -1 ], [ 2, -2, -4, 4, -5, -1 ], [ 4, -3, -5, 4, -5, -1 ] ], 0.875 ] - ], - [ - [ [ [ 1, -2, -4, 4, -5, -1 ], [ 2, -2, -4, 5, -5, -1 ], [ 2, -2, -4, 4, -5, -1 ], [ 4, -3, -5, 4, -5, -1 ] ], 1 ], - [ [ [ 2, -3, -5, 4, -5, -1 ], [ 2, -2, -4, 5, -5, -1 ], [ 2, -2, -4, 4, -5, -1 ], [ 4, -3, -5, 4, -5, -1 ] ], 1.5 ] - ], - [ - [ [ [ 2, -3, -5, 4, -5, -1 ], [ 2, -2, -4, 5, -5, -1 ], [ 2, -2, -4, 4, -5, -1 ], [ 3, -3, -4, 5, -5, -1 ] ], 1.375 ], - [ [ [ 1, -3, -4, 5, -5, -1 ], [ 2, -2, -4, 5, -5, -1 ], [ 2, -2, -4, 4, -5, -1 ], [ 3, -3, -4, 5, -5, -1 ] ], 1.25 ], - [ [ [ 1, -3, -4, 5, -5, -1 ], [ 2, -2, -4, 5, -5, -1 ], [ 2, -3, -4, 5, -5, -1 ], [ 3, -3, -4, 5, -5, -1 ] ], 0.5 ] - ], - [ - [ [ [ 1, -3, -4, 5, -5, -1 ], [ 2, -2, -4, 5, -5, -1 ], [ 1, -2, -4, 5, -5, -1 ], [ 3, -3, -4, 5, -5, -1 ] ], 0.75 ], - [ [ [ 1, -3, -4, 5, -5, -1 ], [ 2, -3, -4, 5, -5, -1 ], [ 1, -2, -4, 5, -5, -1 ], [ 3, -3, -4, 5, -5, -1 ] ], 1.5 ] - ], - [ - [ [ [ 1, -3, -4, 5, -5, -1 ], [ 2, -4, -4, 5, -5, -1 ], [ 1, -2, -4, 5, -5, -1 ], [ 3, -3, -4, 5, -5, -1 ] ], 1.75 ], - [ [ [ 1, -3, -4, 5, -5, -1 ], [ 2, -4, -4, 5, -5, -1 ], [ 2, -3, -5, 5, -5, -1 ], [ 3, -3, -4, 5, -5, -1 ] ], 1.125 ], - [ [ [ 1, -4, -4, 5, -5, -1 ], [ 2, -4, -4, 5, -5, -1 ], [ 2, -3, -5, 5, -5, -1 ], [ 3, -3, -4, 5, -5, -1 ] ], 1.75 ] - ], - [ - [ [ [ 2, -4, -4, 4, -5, -1 ], [ 2, -4, -4, 5, -5, -1 ], [ 2, -3, -5, 5, -5, -1 ], [ 3, -3, -4, 5, -5, -1 ] ], 1.25 ], - [ [ [ 2, -4, -4, 4, -5, -1 ], [ 2, -4, -4, 5, -5, -1 ], [ 2, -3, -5, 5, -5, -1 ], [ 3, -3, -5, 5, -5, -1 ] ], 1.5 ] - ], - [ - [ [ [ 1, -3, -5, 5, -5, -1 ], [ 2, -4, -4, 5, -5, -1 ], [ 2, -3, -5, 5, -5, -1 ], [ 3, -3, -5, 5, -5, -1 ] ], 1.375 ], - [ [ [ 1, -3, -5, 5, -5, -1 ], [ 3, -4, -5, 5, -5, -1 ], [ 2, -3, -5, 5, -5, -1 ], [ 3, -3, -5, 5, -5, -1 ] ], 1.625 ] - ], - [ - [ [ [ 1, -4, -5, 5, -5, -1 ], [ 3, -4, -5, 5, -5, -1 ], [ 2, -3, -5, 5, -5, -1 ], [ 3, -3, -5, 5, -5, -1 ] ], 1 ] - ], - [ - [ [ [ 1, -4, -5, 5, -5, -1 ], [ 3, -4, -5, 5, -5, -1 ], [ 3, -4, -6, 5, -5, -1 ], [ 3, -3, -5, 5, -5, -1 ] ], 1 ] - ], - [ - [ [ [ 1, -4, -5, 5, -5, -1 ], [ 3, -4, -5, 5, -5, -1 ], [ 3, -3, -6, 5, -5, -1 ], [ 3, -3, -5, 5, -5, -1 ] ], 1.75 ] - ], - [ - [ [ [ 1, -4, -5, 5, -5, -1 ], [ 3, -4, -5, 5, -5, -1 ], [ 4, -5, -5, 5, -5, -1 ], [ 3, -3, -5, 5, -5, -1 ] ], 1.375 ], - [ [ [ 1, -4, -5, 5, -5, -1 ], [ 3, -4, -5, 5, -5, -1 ], [ 4, -5, -5, 5, -5, -1 ], [ 4, -4, -6, 5, -5, -1 ] ], 0.75 ] - ], - [ - [ [ [ 1, -4, -5, 5, -5, -1 ], [ 3, -4, -5, 5, -5, -1 ], [ 3, -3, -5, 5, -5, -1 ], [ 4, -4, -6, 5, -5, -1 ] ], 1.5 ] - ], - [ - [ [ [ 1, -4, -5, 5, -5, -1 ], [ 3, -4, -5, 5, -5, -1 ], [ 3, -4, -5, 6, -5, -1 ], [ 4, -4, -6, 5, -5, -1 ] ], 1.375 ], - [ [ [ 1, -4, -5, 5, -5, -1 ], [ 3, -5, -5, 5, -5, -1 ], [ 3, -4, -5, 6, -5, -1 ], [ 4, -4, -6, 5, -5, -1 ] ], 1.375 ], - [ [ [ 1, -4, -5, 5, -5, -1 ], [ 3, -5, -5, 5, -5, -1 ], [ 3, -4, -5, 6, -5, -1 ], [ 2, -4, -5, 5, -5, 0 ] ], 1.25 ] - ], - [ - [ [ [ 1, -5, -5, 5, -5, 0 ], [ 3, -5, -5, 5, -5, -1 ], [ 3, -4, -5, 6, -5, -1 ], [ 2, -4, -5, 5, -5, 0 ] ], 0.5 ], - [ [ [ 1, -5, -5, 5, -5, 0 ], [ 3, -5, -5, 5, -5, -1 ], [ 4, -4, -5, 4, -5, 0 ], [ 2, -4, -5, 5, -5, 0 ] ], 1 ] - ], - [ - [ [ [ 2, -5, -5, 4, -5, 0 ], [ 3, -5, -5, 5, -5, -1 ], [ 4, -4, -5, 4, -5, 0 ], [ 2, -4, -5, 5, -5, 0 ] ], 1.375 ], - [ [ [ 2, -5, -5, 4, -5, 0 ], [ 2, -3, -5, 4, -5, 0 ], [ 4, -4, -5, 4, -5, 0 ], [ 2, -4, -5, 5, -5, 0 ] ], 1 ] - ], - [ - [ [ [ 2, -5, -5, 4, -5, 0 ], [ 2, -3, -5, 4, -5, 0 ], [ 4, -4, -5, 4, -5, 0 ], [ 3, -4, -5, 4, -5, 0 ] ], 1.625 ] - ], - [ - [ [ [ 1, -4, -5, 4, -5, 0 ], [ 2, -3, -5, 4, -5, 0 ], [ 4, -4, -5, 4, -5, 0 ], [ 3, -4, -5, 4, -5, 0 ] ], 1.375 ], - [ [ [ 1, -4, -5, 4, -5, 0 ], [ 2, -3, -5, 4, -5, 0 ], [ 4, -4, -5, 4, -5, 0 ], [ 2, -2, -5, 4, -5, 0 ] ], 1.75 ] - ], - [ - [ [ [ 2, -4, -5, 3, -5, 0 ], [ 2, -3, -5, 4, -5, 0 ], [ 4, -4, -5, 4, -5, 0 ], [ 2, -2, -5, 4, -5, 0 ] ], 1.375 ], - [ [ [ 2, -4, -5, 3, -5, 0 ], [ 3, -4, -6, 4, -5, 0 ], [ 4, -4, -5, 4, -5, 0 ], [ 2, -2, -5, 4, -5, 0 ] ], 1.25 ], - [ [ [ 2, -4, -5, 3, -5, 0 ], [ 3, -4, -6, 4, -5, 0 ], [ 4, -4, -5, 4, -5, 0 ], [ 3, -4, -4, 4, -5, 0 ] ], 0.75 ] - ], - [ - [ [ [ 2, -4, -5, 3, -5, 0 ], [ 3, -4, -6, 4, -5, 0 ], [ 4, -4, -6, 4, -5, 0 ], [ 3, -4, -4, 4, -5, 0 ] ], 1.125 ], - [ [ [ 2, -4, -5, 3, -5, 0 ], [ 3, -4, -6, 4, -5, 0 ], [ 4, -4, -6, 4, -5, 0 ], [ 4, -4, -6, 3, -5, 0 ] ], 0.875 ] - ], - [ - [ [ [ 2, -4, -5, 3, -5, 0 ], [ 3, -4, -7, 4, -5, 0 ], [ 4, -4, -6, 4, -5, 0 ], [ 4, -4, -6, 3, -5, 0 ] ], 1.375 ], - [ [ [ 3, -5, -6, 3, -5, 0 ], [ 3, -4, -7, 4, -5, 0 ], [ 4, -4, -6, 4, -5, 0 ], [ 4, -4, -6, 3, -5, 0 ] ], 1.75 ] - ], - [ - [ [ [ 3, -5, -6, 3, -5, 0 ], [ 3, -4, -7, 4, -5, 0 ], [ 5, -5, -7, 4, -5, 0 ], [ 4, -4, -6, 3, -5, 0 ] ], 1.125 ], - [ [ [ 3, -5, -6, 3, -5, 0 ], [ 3, -4, -7, 4, -5, 0 ], [ 5, -5, -7, 4, -5, 0 ], [ 5, -5, -7, 3, -5, 0 ] ], 1.5 ] - ], - [ - [ [ [ 3, -5, -6, 3, -5, 0 ], [ 3, -4, -7, 4, -5, 0 ], [ 5, -5, -7, 4, -5, 0 ], [ 4, -5, -6, 4, -5, 0 ] ], 0.625 ], - [ [ [ 3, -5, -6, 3, -5, 0 ], [ 5, -5, -6, 2, -5, 0 ], [ 5, -5, -7, 4, -5, 0 ], [ 4, -5, -6, 4, -5, 0 ] ], 1.375 ], - [ [ [ 3, -5, -6, 3, -5, 0 ], [ 5, -5, -6, 2, -5, 0 ], [ 5, -4, -6, 3, -5, 0 ], [ 4, -5, -6, 4, -5, 0 ] ], 1.375 ] - ], - [ - [ [ [ 3, -5, -6, 3, -5, 0 ], [ 5, -5, -6, 2, -5, 0 ], [ 5, -4, -6, 3, -5, 0 ], [ 5, -5, -6, 3, -5, 0 ] ], 0.75 ] - ], - [ - [ [ [ 3, -5, -6, 3, -5, 0 ], [ 5, -5, -6, 2, -5, 0 ], [ 5, -4, -6, 3, -5, 0 ], [ 6, -5, -6, 2, -5, 0 ] ], 0.5 ], - [ [ [ 4, -5, -6, 2, -5, 0 ], [ 5, -5, -6, 2, -5, 0 ], [ 5, -4, -6, 3, -5, 0 ], [ 6, -5, -6, 2, -5, 0 ] ], 1.125 ] - ], - [ - [ [ [ 4, -5, -6, 2, -5, 0 ], [ 5, -5, -6, 2, -5, 0 ], [ 5, -4, -6, 3, -5, 0 ], [ 4, -4, -6, 3, -5, 0 ] ], 1.25 ], - [ [ [ 4, -5, -6, 2, -5, 0 ], [ 4, -4, -7, 3, -5, 0 ], [ 5, -4, -6, 3, -5, 0 ], [ 4, -4, -6, 3, -5, 0 ] ], 1.25 ], - [ [ [ 4, -5, -6, 2, -5, 0 ], [ "Rest" ], [ 5, -4, -6, 3, -5, 0 ], [ 4, -4, -6, 3, -5, 0 ] ], 0.5 ], - [ [ [ "Rest" ], [ "Rest" ], [ 5, -4, -6, 3, -5, 0 ], [ 4, -4, -6, 3, -5, 0 ] ], 1.75 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ 4, -4, -6, 3, -5, 0 ] ], 1.125 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 7.25 ] - ] - ] -], -"last_changes": -[ - [ [ 3, -5, -6, 3, -5, 0 ], [ 5, -5, -6, 2, -5, 0 ], [ 5, -4, -6, 3, -5, 0 ], [ 5, -5, -6, 3, -5, 0 ] ], - [ [ 3, -5, -6, 3, -5, 0 ], [ 5, -5, -6, 2, -5, 0 ], [ 5, -4, -6, 3, -5, 0 ], [ 6, -5, -6, 2, -5, 0 ] ], - [ [ 4, -5, -6, 2, -5, 0 ], [ 5, -5, -6, 2, -5, 0 ], [ 5, -4, -6, 3, -5, 0 ], [ 6, -5, -6, 2, -5, 0 ] ], - [ [ 4, -5, -6, 2, -5, 0 ], [ 5, -5, -6, 2, -5, 0 ], [ 5, -4, -6, 3, -5, 0 ], [ 4, -4, -6, 3, -5, 0 ] ], - [ [ 4, -5, -6, 2, -5, 0 ], [ 4, -4, -7, 3, -5, 0 ], [ 5, -4, -6, 3, -5, 0 ], [ 4, -4, -6, 3, -5, 0 ] ] -], -"cur_uid": "75316bf0", -"ref_uid": "55bd25a1", -"order_seed": 144453, -"dur_seed": 681001, -"motifs_seed": 933698, -"entrances_probs_vals": [ 0, 0, 0, 0.41, 1.84, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 0, 0, 0, 0.41, 1.84, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 0, 0, 0, 0.41, 1.84, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -2430, -293 ], [ -869, 1211 ], [ -832, 1285 ], [ -702, 1211 ] ], -"step_probs_vals": [ -1200, 1200, 0.0020576131687243, 0.068181818181818, 0.074074074074074, 0.0625, 0.20576131687243, 0.0625, 0.45679012345679, 0.011363636363636, 0.53086419753086, 0, 0.54320987654321, 0.92045454545455, 0.58641975308642, 0.92613636363636, 0.61316872427983, 0, 0.98971193415638, 0 ], -"passages_weights": [ 0.48, 0.46, 0.48, 1, 1 ], -"hd_exp": 9, -"hd_invert": 0, -"order": -[ - [ [ 1 ], [ 2, 3, 0 ], [ ] ], - [ [ 0, 2 ], [ 3, 1 ], [ ] ], - [ [ 1, 0 ], [ 2, 3 ], [ ] ], - [ [ 1, 3 ], [ 0, 2 ], [ ] ], - [ [ 0, 2 ], [ 3, 1 ], [ ] ], - [ [ 3, 0 ], [ 1, 2 ], [ ] ], - [ [ 1, 0, 3 ], [ 2 ], [ ] ], - [ [ 3 ], [ 1, 2, 0 ], [ ] ], - [ [ 0, 1, 3 ], [ 2 ], [ ] ], - [ [ 1 ], [ 0, 2, 3 ], [ ] ], - [ [ 3, 0, 1 ], [ 2 ], [ ] ], - [ [ 0, 2 ], [ 3, 1 ], [ ] ], - [ [ 0, 1 ], [ 3, 2 ], [ ] ], - [ [ 2, 1, 3 ], [ 0 ], [ ] ], - [ [ 2, 3 ], [ 1, 0 ], [ ] ], - [ [ 0, 3, 2 ], [ 1 ], [ ] ], - [ [ 1, 3, 0 ], [ 2 ], [ ] ], - [ [ 3, 0, 1 ], [ 2 ], [ ] ], - [ [ 1 ], [ 2, 0, 3 ], [ ] ], - [ [ 3 ], [ 1, 2, 0 ], [ ] ], - [ [ 2, 1 ], [ 3, 0 ], [ ] ], - [ [ 0, 1 ], [ 3, 2 ], [ ] ], - [ [ 1, 0 ], [ 2, 3 ], [ ] ], - [ [ 3, 0, 2 ], [ 1 ], [ ] ], - [ [ 3 ], [ 0, 2, 1 ], [ ] ], - [ [ 1 ], [ 0, 3, 2 ], [ ] ], - [ [ 1 ], [ 2, 3, 0 ], [ ] ], - [ [ 0 ], [ 2, 1, 3 ], [ ] ], - [ [ 1, 0, 3 ], [ 2 ], [ ] ], - [ [ 0, 2, 3 ], [ 1 ], [ ] ], - [ [ 0, 1 ], [ 3, 2 ], [ ] ], - [ [ 2, 0 ], [ 3, 1 ], [ ] ], - [ [ 3 ], [ 1, 0, 2 ], [ ] ], - [ [ 2 ], [ 1, 0, 3 ], [ ] ], - [ [ 1, 0 ], [ 2, 3 ], [ ] ], - [ [ 0 ], [ 1, 3, 2 ], [ ] ], - [ [ 0, 3 ], [ 1, 2 ], [ ] ], - [ [ 0 ], [ 1, 3, 2 ], [ ] ], - [ [ 3, 1, 0 ], [ 2 ], [ ] ], - [ [ 1, 2, 0 ], [ 3 ], [ ] ], - [ [ 2 ], [ 1, 0, 3 ], [ ] ], - [ [ 0, 3, 1 ], [ 2 ], [ ] ], - [ [ 2, 3 ], [ 1, 0 ], [ ] ], - [ [ 1 ], [ 3, 2, 0 ], [ ] ], - [ [ 2, 0, 3 ], [ 1 ], [ ] ], - [ [ 3, 1 ], [ 0, 2 ], [ ] ], - [ [ 3, 1 ], [ 0, 2 ], [ ] ], - [ [ 1 ], [ 3, 2, 0 ], [ ] ], - [ [ 2 ], [ 0, 3, 1 ], [ ] ], - [ [ 0 ], [ 1, 3, 2 ], [ ] ], - [ [ 3 ], [ 1, 0, 2 ], [ ] ], - [ [ 3 ], [ 1, 0, 2 ], [ ] ], - [ [ 1, 3 ], [ 2, 0 ], [ ] ], - [ [ 1, 0 ], [ 2, 3 ], [ ] ], - [ [ 2, 3, 1 ], [ 0 ], [ ] ], - [ [ 1 ], [ 0, 3, 2 ], [ ] ], - [ [ 0, 1 ], [ 2, 3 ], [ ] ], - [ [ 1, 0 ], [ 3, 2 ], [ ] ], - [ [ 0, 3, 1 ], [ 2 ], [ ] ], - [ [ 0 ], [ 2, 1, 3 ], [ ] ], - [ [ 3, 1, 0 ], [ 2 ], [ ] ], - [ [ 3, 2 ], [ 1, 0 ], [ ] ], - [ [ 2 ], [ 1, 3, 0 ], [ ] ], - [ [ 0, 1 ], [ 3, 2 ], [ ] ], - [ [ 2 ], [ 1, 0, 3 ], [ ] ], - [ [ 3 ], [ 1, 0, 2 ], [ ] ], - [ [ 1 ], [ 0, 2, 3 ], [ ] ], - [ [ 3 ], [ 2, 1, 0 ], [ ] ], - [ [ 2, 0 ], [ 1, 3 ], [ ] ], - [ [ 3, 1, 2 ], [ 0 ], [ ] ], - [ [ 2, 0, 1 ], [ 3 ], [ ] ], - [ [ 3 ], [ 1, 2, 0 ], [ ] ], - [ [ 2, 1 ], [ 0, 3 ], [ ] ], - [ [ 1 ], [ 0, 2, 3 ], [ ] ], - [ [ 3 ], [ 0, 2, 1 ], [ ] ], - [ [ 0, 1, 2 ], [ 3 ], [ ] ], - [ [ 3, 2 ], [ 1, 0 ], [ ] ], - [ [ 1 ], [ 3, 0, 2 ], [ ] ], - [ [ 0, 3 ], [ 2, 1 ], [ ] ], - [ [ 3 ], [ 1, 2, 0 ], [ ] ], - [ [ 2, 1 ], [ 0, 3 ], [ ] ], - [ [ 3, 2 ], [ 0, 1 ], [ ] ], - [ [ 3, 1, 2 ], [ 0 ], [ ] ], - [ [ 0, 1, 3 ], [ 2 ], [ ] ], - [ [ 3, 1, 0 ], [ 2 ], [ ] ], - [ [ 0, 1 ], [ 2, 3 ], [ ] ], - [ [ 0, 3, 1 ], [ 2 ], [ ] ], - [ [ 0 ], [ 2, 1, 3 ], [ ] ], - [ [ 3, 1 ], [ 0, 2 ], [ ] ], - [ [ 3, 2 ], [ 0, 1 ], [ ] ], - [ [ 0, 1, 2 ], [ 3 ], [ ] ], - [ [ 2, 1 ], [ 0, 3 ], [ ] ], - [ [ 2 ], [ 0, 1, 3 ], [ ] ], - [ [ 0, 1 ], [ 2, 3 ], [ ] ], - [ [ 3, 2 ], [ 1, 0 ], [ ] ], - [ [ 1, 0 ], [ 2, 3 ], [ ] ], - [ [ 0 ], [ 3, 1, 2 ], [ ] ], - [ [ 2, 1, 0 ], [ 3 ], [ ] ], - [ [ 1, 2 ], [ 3, 0 ], [ ] ], - [ [ 0, 2 ], [ 3, 1 ], [ ] ] -], -"sus_weights": [ 0.35, 0.37, 0.38 ], -"order_size": [ 100, 100 ], -"passages_size": [ 0, 0 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3/781442dc/781442dc_code.scd b/resources/resources_bak_2024_01_03/string_quartet_3/781442dc/781442dc_code.scd deleted file mode 100644 index c194eef..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3/781442dc/781442dc_code.scd +++ /dev/null @@ -1,945 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance); -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_3/781442dc/781442dc_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_3/781442dc/781442dc_mus_model.json deleted file mode 100644 index d2de366..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3/781442dc/781442dc_mus_model.json +++ /dev/null @@ -1,117 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ] ], 0.25 ], - [ [ [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ] ], 0.5 ], - [ [ [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 0 ], - [ [ [ 1, 0, -1, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 0.125 ], - [ [ [ 0, 0, 0, 0, 0, 1 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 1 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 1, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 1.375 ] - ], - [ - [ [ [ 0, 0, 0, 0, 0, 1 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 1, 0 ], [ 0, -1, 0, 0, 0, 1 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 1 ], [ -1, 0, 0, 0, 1, 1 ], [ 0, 0, 0, 0, 1, 0 ], [ 0, -1, 0, 0, 0, 1 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 1 ], [ -1, 0, 0, 0, 1, 1 ], [ -1, 0, 0, 1, 0, 1 ], [ 0, -1, 0, 0, 0, 1 ] ], 0.25 ], - [ [ [ 0, 0, 0, 0, 0, 1 ], [ -1, 0, 0, 0, 1, 1 ], [ -1, 0, 0, 1, 0, 1 ], [ 0, 0, 0, 0, -1, 1 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 0, 1 ], [ -1, 0, 0, 0, 1, 1 ], [ -1, 0, 0, 0, 0, 2 ], [ 0, 0, 0, 0, -1, 1 ] ], 0.875 ] - ], - [ - [ [ [ 0, 0, 0, 0, 0, 1 ], [ -1, 0, 0, 0, 1, 1 ], [ -1, 0, 0, 0, 0, 2 ], [ "Rest" ] ], 0 ], - [ [ [ 0, -1, 0, 0, 0, 2 ], [ -1, 0, 0, 0, 1, 1 ], [ -1, 0, 0, 0, 0, 2 ], [ "Rest" ] ], 0 ], - [ [ [ 0, -1, 0, 0, 0, 2 ], [ -1, 0, -1, 0, 0, 2 ], [ -1, 0, 0, 0, 0, 2 ], [ "Rest" ] ], 0.25 ], - [ [ [ -1, 0, 0, 0, 1, 2 ], [ -1, 0, -1, 0, 0, 2 ], [ -1, 0, 0, 0, 0, 2 ], [ "Rest" ] ], 0.25 ], - [ [ [ -1, 0, 1, 0, 0, 2 ], [ -1, 0, -1, 0, 0, 2 ], [ -1, 0, 0, 0, 0, 2 ], [ "Rest" ] ], 0.25 ], - [ [ [ -2, 0, 1, 0, 0, 2 ], [ -1, 0, -1, 0, 0, 2 ], [ -1, 0, 0, 0, 0, 2 ], [ "Rest" ] ], 1.375 ] - ], - [ - [ [ [ -2, 0, 1, 0, 0, 2 ], [ -1, 0, -1, 0, 0, 2 ], [ -1, 0, 0, 0, 0, 2 ], [ 0, 0, 0, 0, -1, 1 ] ], 0.5 ], - [ [ [ -2, 0, 1, 0, 0, 2 ], [ -1, 0, 1, 0, 0, 1 ], [ -1, 0, 0, 0, 0, 2 ], [ 0, 0, 0, 0, -1, 1 ] ], 0 ], - [ [ [ -2, 0, 1, 0, 0, 2 ], [ -1, 0, 1, 0, 0, 1 ], [ 1, 0, 0, 0, -1, 0 ], [ 0, 0, 0, 0, -1, 1 ] ], 0.625 ], - [ [ [ -2, 0, 1, 0, 0, 2 ], [ 0, 0, -1, 0, -1, 1 ], [ 1, 0, 0, 0, -1, 0 ], [ 0, 0, 0, 0, -1, 1 ] ], 0 ], - [ [ [ -2, 0, 1, 0, 0, 2 ], [ 0, 0, -1, 0, -1, 1 ], [ 1, -1, 0, 0, -1, 1 ], [ 0, 0, 0, 0, -1, 1 ] ], 1 ] - ], - [ - [ [ [ -1, 1, 0, 0, -1, 1 ], [ 0, 0, -1, 0, -1, 1 ], [ 1, -1, 0, 0, -1, 1 ], [ 0, 0, 0, 0, -1, 1 ] ], 0 ], - [ [ [ -1, 1, 0, 0, -1, 1 ], [ 1, -1, 0, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 1 ], [ 0, 0, 0, 0, -1, 1 ] ], 0.625 ], - [ [ [ 0, -1, 1, 0, -1, 1 ], [ 1, -1, 0, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 1 ], [ 0, 0, 0, 0, -1, 1 ] ], 0.625 ], - [ [ [ 0, 0, -1, 0, -1, 1 ], [ 1, -1, 0, 0, -1, 0 ], [ 1, -1, 0, 0, -1, 1 ], [ 0, 0, 0, 0, -1, 1 ] ], 0 ], - [ [ [ 0, 0, -1, 0, -1, 1 ], [ 1, -1, 0, -1, -1, 1 ], [ 1, -1, 0, 0, -1, 1 ], [ 0, 0, 0, 0, -1, 1 ] ], 1.125 ] - ], - [ - [ [ [ 0, 0, -1, 0, -1, 1 ], [ 1, -1, 0, -1, -1, 1 ], [ 1, -1, 0, 0, -1, 1 ], [ "Rest" ] ], 0 ], - [ [ [ 0, 0, -1, 0, -1, 1 ], [ 1, -1, 0, -1, -1, 1 ], [ 1, -1, 0, -1, -1, 2 ], [ "Rest" ] ], 0.625 ], - [ [ [ 0, 0, -1, 0, -1, 1 ], [ 1, -1, 0, -1, -1, 1 ], [ 2, -1, -1, -1, -1, 1 ], [ "Rest" ] ], 0.5 ], - [ [ [ 0, 0, -1, 0, -1, 1 ], [ 1, -1, 0, -1, -1, 1 ], [ 1, 0, 0, -1, -1, 1 ], [ "Rest" ] ], 1.375 ] - ], - [ - [ [ [ 0, 0, 0, -1, 0, 1 ], [ 1, -1, 0, -1, -1, 1 ], [ 1, 0, 0, -1, -1, 1 ], [ "Rest" ] ], 0 ], - [ [ [ 0, 0, 0, -1, 0, 1 ], [ 1, -1, 0, -1, -1, 1 ], [ 1, 0, 0, -1, -1, 1 ], [ 1, -1, 1, -1, -1, 1 ] ], 0.375 ], - [ [ [ 2, -1, 0, -2, -1, 1 ], [ 1, -1, 0, -1, -1, 1 ], [ 1, 0, 0, -1, -1, 1 ], [ 1, -1, 1, -1, -1, 1 ] ], 0 ], - [ [ [ 2, -1, 0, -2, -1, 1 ], [ 1, -1, 0, -1, -1, 1 ], [ 1, 0, 0, -1, -1, 1 ], [ 1, 0, -1, -1, -1, 1 ] ], 1 ] - ], - [ - [ [ [ 1, 0, 0, -1, -2, 1 ], [ 1, -1, 0, -1, -1, 1 ], [ 1, 0, 0, -1, -1, 1 ], [ 1, 0, -1, -1, -1, 1 ] ], 0 ], - [ [ [ 1, 0, 0, -1, -2, 1 ], [ 0, 0, 1, -1, -1, 1 ], [ 1, 0, 0, -1, -1, 1 ], [ 1, 0, -1, -1, -1, 1 ] ], 0.625 ], - [ [ [ 1, 0, 0, -1, -2, 1 ], [ 1, 0, -2, -1, -1, 1 ], [ 1, 0, 0, -1, -1, 1 ], [ 1, 0, -1, -1, -1, 1 ] ], 0.25 ], - [ [ [ 1, 0, 0, -1, -2, 1 ], [ 0, 1, -1, -1, -1, 1 ], [ 1, 0, 0, -1, -1, 1 ], [ 1, 0, -1, -1, -1, 1 ] ], 1.375 ] - ], - [ - [ [ [ 1, 1, -1, -1, -1, 0 ], [ 0, 1, -1, -1, -1, 1 ], [ 1, 0, 0, -1, -1, 1 ], [ 1, 0, -1, -1, -1, 1 ] ], 0.375 ], - [ [ [ 0, 0, 0, -2, -1, 1 ], [ 0, 1, -1, -1, -1, 1 ], [ 1, 0, 0, -1, -1, 1 ], [ 1, 0, -1, -1, -1, 1 ] ], 0.375 ], - [ [ [ -1, 1, -1, -1, -1, 1 ], [ 0, 1, -1, -1, -1, 1 ], [ 1, 0, 0, -1, -1, 1 ], [ 1, 0, -1, -1, -1, 1 ] ], 1.25 ] - ], - [ - [ [ [ -1, 1, -1, -1, -1, 1 ], [ 0, 1, -1, -1, -1, 1 ], [ 1, 0, 0, -1, -1, 1 ], [ 0, 0, 0, -1, -1, 2 ] ], 0 ], - [ [ [ -1, 1, -1, -1, -1, 1 ], [ 1, 0, 0, -1, -1, 0 ], [ 1, 0, 0, -1, -1, 1 ], [ 0, 0, 0, -1, -1, 2 ] ], 0 ], - [ [ [ 0, 0, 0, -1, -1, 0 ], [ 1, 0, 0, -1, -1, 0 ], [ 1, 0, 0, -1, -1, 1 ], [ 0, 0, 0, -1, -1, 2 ] ], 0.25 ], - [ [ [ 0, 0, 0, -1, -1, 0 ], [ 1, 0, 0, -1, -1, 0 ], [ 1, 0, 0, -1, -1, 1 ], [ 0, 0, 0, 0, -1, 1 ] ], 0.625 ], - [ [ [ 0, 0, 0, -1, -1, 0 ], [ 1, 0, 0, -1, -1, 0 ], [ 1, 0, 0, -1, -1, 1 ], [ 1, 0, 0, -1, -1, 2 ] ], 1.375 ], - [ [ [ 0, 0, 0, -1, -1, 0 ], [ "Rest" ], [ 1, 0, 0, -1, -1, 1 ], [ 1, 0, 0, -1, -1, 2 ] ], 0 ], - [ [ [ 0, 0, 0, -1, -1, 0 ], [ "Rest" ], [ 1, 0, 0, -1, -1, 1 ], [ "Rest" ] ], 0 ], - [ [ [ 0, 0, 0, -1, -1, 0 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 0 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 5.625 ] - ] - ] -], -"last_changes": -[ - [ [ -1, 1, -1, -1, -1, 1 ], [ 0, 1, -1, -1, -1, 1 ], [ 1, 0, 0, -1, -1, 1 ], [ 0, 0, 0, -1, -1, 2 ] ], - [ [ -1, 1, -1, -1, -1, 1 ], [ 1, 0, 0, -1, -1, 0 ], [ 1, 0, 0, -1, -1, 1 ], [ 0, 0, 0, -1, -1, 2 ] ], - [ [ 0, 0, 0, -1, -1, 0 ], [ 1, 0, 0, -1, -1, 0 ], [ 1, 0, 0, -1, -1, 1 ], [ 0, 0, 0, -1, -1, 2 ] ], - [ [ 0, 0, 0, -1, -1, 0 ], [ 1, 0, 0, -1, -1, 0 ], [ 1, 0, 0, -1, -1, 1 ], [ 0, 0, 0, 0, -1, 1 ] ], - [ [ 0, 0, 0, -1, -1, 0 ], [ 1, 0, 0, -1, -1, 0 ], [ 1, 0, 0, -1, -1, 1 ], [ 1, 0, 0, -1, -1, 2 ] ] -], -"cur_uid": "781442dc", -"ref_uid": "nil", -"order_seed": 479669, -"dur_seed": 398026, -"motifs_seed": 801394, -"entrances_probs_vals": [ 0.43, 0, 0, 0, 0.85164835164835, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 1, 0, 0.99206349206349, 0.16483516483516, 0.66, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 1, 0, 0.95238095238095, 0, 1.043956043956, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -1983.9009287926, 1100 ], [ -999, 1322.600619195 ], [ -14.860681114551, 1676 ], [ 78.018575851393, 1694 ] ], -"step_probs_vals": [ 0, 1200, 0, 0.5, 0.076131687242798, 0.91477272727273, 0.17489711934156, 0, 0.57818930041152, 0, 1, 0 ], -"passages_weights": [ 0.54, 0.47, 0.52, 0.57, 0.58 ], -"hd_exp": -0.22, -"hd_invert": 0, -"order": -[ - [ [ 3, 1 ], [ 2, 0, 0, 2 ], [ ] ], - [ [ 0 ], [ 3, 1, 2, 3, 2 ], [ ] ], - [ [ 2 ], [ 0, 1, 0, 0, 0 ], [ 3 ] ], - [ [ 0, 3 ], [ 1, 2, 1, 2 ], [ ] ], - [ [ 2, 3 ], [ 0, 1, 0, 0, 1 ], [ ] ], - [ [ 1, 0 ], [ 2, 2, 2 ], [ 3 ] ], - [ [ 1, 2 ], [ 0, 3, 0, 3 ], [ ] ], - [ [ 3, 2 ], [ 0, 1, 1, 1 ], [ ] ], - [ [ 1, 2, 3 ], [ 0, 0, 0 ], [ ] ], - [ [ 2 ], [ 3, 1, 0, 3, 3 ], [ ] ] -], -"sus_weights": [ 0.44, 0.41, 0.28 ], -"order_size": [ 10, 10 ], -"passages_size": [ 2, 4 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3/7c2de94c/7c2de94c_code.scd b/resources/resources_bak_2024_01_03/string_quartet_3/7c2de94c/7c2de94c_code.scd deleted file mode 100644 index dc13462..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3/7c2de94c/7c2de94c_code.scd +++ /dev/null @@ -1,945 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array1) - hsArrayToCents.value(array2); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = true; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - if(pDistance < 0, {stepFunc.value(pDistance)}, {0}); -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength - minMotifLength).rand + minMotifLength).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength - minProgLength).rand + minProgLength).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[-3, 0, 0, 0, 0, 0], [-3, 0, 0, 0, 0, 0], [-3, 0, 0, 0, 0, 0], [-3, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[-3, 0, 0, 0, 0, 0], [-3, 0, 0, 0, 0, 0], [-3, 0, 0, 0, 0, 0], [-3, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_3/7c2de94c/7c2de94c_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_3/7c2de94c/7c2de94c_mus_model.json deleted file mode 100644 index 37e7285..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3/7c2de94c/7c2de94c_mus_model.json +++ /dev/null @@ -1,163 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ "Rest" ], [ 1, -1, 0, 0, 0, 0 ], [ "Rest" ] ], 0.125 ], - [ [ [ "Rest" ], [ "Rest" ], [ 1, -1, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ] ], 1.125 ], - [ [ [ "Rest" ], [ 1, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ] ], 1.125 ], - [ [ [ -1, 0, 1, 0, 0, 1 ], [ 1, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ] ], 0.875 ] - ], - [ - [ [ [ 1, 0, 0, -1, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ] ], 0.375 ] - ], - [ - [ [ [ 1, 0, 0, -1, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 2, -1, 0, -1, 0, 0 ] ], 1 ] - ], - [ - [ [ [ 1, 0, 0, -1, 0, 0 ], [ 3, -1, 0, -1, -1, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 2, -1, 0, -1, 0, 0 ] ], 0.75 ] - ], - [ - [ [ [ 0, -1, 0, 1, 0, 0 ], [ 3, -1, 0, -1, -1, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 2, -1, 0, -1, 0, 0 ] ], 0.375 ] - ], - [ - [ [ [ 0, -1, 0, 1, 0, 0 ], [ 2, 0, 0, -1, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 2, -1, 0, -1, 0, 0 ] ], 0.125 ] - ], - [ - [ [ [ 0, -1, 0, 1, 0, 0 ], [ 2, 0, 0, -1, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, -1, 1, 0, 0, 0 ] ], 0.75 ] - ], - [ - [ [ [ 0, -1, 0, 1, 0, 0 ], [ 2, 0, 0, -1, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, -1, -1, 1, 0, 0 ] ], 0.375 ] - ], - [ - [ [ [ 0, -1, 0, 0, 0, -1 ], [ 2, 0, 0, -1, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, -1, -1, 1, 0, 0 ] ], 0.5 ] - ], - [ - [ [ [ 0, -1, 0, 0, 0, -1 ], [ 2, -1, -1, 1, 0, -1 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, -1, -1, 1, 0, 0 ] ], 0 ] - ], - [ - [ [ [ 0, -1, 0, 0, 0, -1 ], [ 2, -1, -1, 1, 0, -1 ], [ 2, 0, 0, 0, 0, -1 ], [ 1, -1, -1, 1, 0, 0 ] ], 1 ] - ], - [ - [ [ [ 0, -1, 0, 0, 0, -1 ], [ 3, -1, 0, 0, 0, -2 ], [ 2, 0, 0, 0, 0, -1 ], [ 1, -1, -1, 1, 0, 0 ] ], 0.5 ] - ], - [ - [ [ [ 0, -1, 0, 0, 0, -1 ], [ 2, -1, 1, 0, 0, -1 ], [ 2, 0, 0, 0, 0, -1 ], [ 1, -1, -1, 1, 0, 0 ] ], 0.875 ] - ], - [ - [ [ [ 0, -1, 0, 0, 0, -1 ], [ 2, -1, 1, 0, 0, -1 ], [ 2, 0, 0, 0, 0, -1 ], [ 3, -1, 0, 0, 0, -2 ] ], 1.125 ] - ], - [ - [ [ [ 0, -1, 0, 0, 0, -1 ], [ 2, -1, 1, 0, 0, -1 ], [ 3, -1, 1, 0, 0, -2 ], [ 3, -1, 0, 0, 0, -2 ] ], 0.625 ] - ], - [ - [ [ [ 1, -1, 1, 0, 0, -2 ], [ 2, -1, 1, 0, 0, -1 ], [ 3, -1, 1, 0, 0, -2 ], [ 3, -1, 0, 0, 0, -2 ] ], 0.125 ] - ], - [ - [ [ [ 1, -1, 1, 0, 0, -2 ], [ 2, -1, 1, 0, 0, -1 ], [ 3, -1, 1, 0, 0, -2 ], [ 3, -1, 1, -1, 0, -1 ] ], 0.5 ] - ], - [ - [ [ [ 1, -1, 1, 0, 0, -2 ], [ 2, -1, 1, 0, 0, -1 ], [ 3, -1, 1, 0, 0, -2 ], [ 2, -1, 2, 0, 0, -1 ] ], 0.25 ] - ], - [ - [ [ [ 1, -1, 1, 0, 0, -2 ], [ 2, -1, 1, 0, 0, -1 ], [ -1, 0, 1, 0, 0, -1 ], [ 2, -1, 2, 0, 0, -1 ] ], 0.75 ] - ], - [ - [ [ [ 1, -1, 1, 0, 0, -2 ], [ 2, -1, 1, 0, 0, -1 ], [ -1, 0, 2, 0, 0, -1 ], [ 2, -1, 2, 0, 0, -1 ] ], 0.125 ] - ], - [ - [ [ [ 1, -1, 1, 0, 0, -2 ], [ 2, -1, 1, 0, 0, -1 ], [ 3, -1, 0, 0, 0, -2 ], [ 2, -1, 2, 0, 0, -1 ] ], 0.625 ] - ], - [ - [ [ [ 1, -1, 1, 0, 0, -2 ], [ 2, -1, 1, 0, 0, -1 ], [ 3, -1, 1, 0, 0, -2 ], [ 2, -1, 2, 0, 0, -1 ] ], 1 ] - ], - [ - [ [ [ 1, -1, 1, 0, 0, -2 ], [ 2, -1, 1, 0, 0, -1 ], [ 3, -1, 1, 0, 0, -2 ], [ 3, -1, 0, 0, 0, -2 ] ], 0.125 ] - ], - [ - [ [ [ 1, -1, 1, 0, 0, -2 ], [ 4, -1, 0, -1, 0, -2 ], [ 3, -1, 1, 0, 0, -2 ], [ 3, -1, 0, 0, 0, -2 ] ], 0.5 ] - ], - [ - [ [ [ 1, -1, 1, 0, 0, -2 ], [ 0, -1, 0, 0, 0, -1 ], [ 3, -1, 1, 0, 0, -2 ], [ 3, -1, 0, 0, 0, -2 ] ], 0.625 ] - ], - [ - [ [ [ 1, -1, 0, 1, 0, -2 ], [ 0, -1, 0, 0, 0, -1 ], [ 3, -1, 1, 0, 0, -2 ], [ 3, -1, 0, 0, 0, -2 ] ], 0.75 ] - ], - [ - [ [ [ 1, -1, 0, 1, 0, -2 ], [ 0, -1, 0, 0, 0, -1 ], [ 3, -1, 0, 1, -1, -2 ], [ 3, -1, 0, 0, 0, -2 ] ], 0.5 ] - ], - [ - [ [ [ 1, -1, 0, 1, 0, -2 ], [ 1, -2, 0, 1, 0, -2 ], [ 3, -1, 0, 1, -1, -2 ], [ 3, -1, 0, 0, 0, -2 ] ], 1 ] - ], - [ - [ [ [ 1, -1, 0, 1, 0, -2 ], [ 1, -2, 0, 1, 0, -2 ], [ 3, -1, -1, 1, 0, -2 ], [ 3, -1, 0, 0, 0, -2 ] ], 0.125 ] - ], - [ - [ [ [ 1, -1, 0, 1, 0, -2 ], [ 1, -2, 0, 1, 0, -2 ], [ 0, -1, 0, 0, 0, -1 ], [ 3, -1, 0, 0, 0, -2 ] ], 0.875 ], - [ [ [ 1, -1, 0, 1, 0, -2 ], [ 1, -2, 0, 1, 0, -2 ], [ 0, -1, 0, 0, 0, -1 ], [ "Rest" ] ], 0.375 ], - [ [ [ 1, -1, 0, 1, 0, -2 ], [ 1, -2, 0, 1, 0, -2 ], [ "Rest" ], [ "Rest" ] ], 0.5 ], - [ [ [ 1, -1, 0, 1, 0, -2 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 0.625 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 6.5 ] - ] - ] -], -"last_changes": -[ - [ [ 1, -1, 0, 1, 0, -2 ], [ 0, -1, 0, 0, 0, -1 ], [ 3, -1, 1, 0, 0, -2 ], [ 3, -1, 0, 0, 0, -2 ] ], - [ [ 1, -1, 0, 1, 0, -2 ], [ 0, -1, 0, 0, 0, -1 ], [ 3, -1, 0, 1, -1, -2 ], [ 3, -1, 0, 0, 0, -2 ] ], - [ [ 1, -1, 0, 1, 0, -2 ], [ 1, -2, 0, 1, 0, -2 ], [ 3, -1, 0, 1, -1, -2 ], [ 3, -1, 0, 0, 0, -2 ] ], - [ [ 1, -1, 0, 1, 0, -2 ], [ 1, -2, 0, 1, 0, -2 ], [ 3, -1, -1, 1, 0, -2 ], [ 3, -1, 0, 0, 0, -2 ] ], - [ [ -2, -1, 0, 1, 0, -2 ], [ -2, -2, 0, 1, 0, -2 ], [ -2, -1, 0, 0, 0, -1 ], [ -2, -1, 0, 0, 0, -2 ] ] -], -"cur_uid": "7c2de94c", -"ref_uid": "5201b8af", -"order_seed": 869423, -"dur_seed": 680450, -"motifs_seed": 533263, -"entrances_probs_vals": [ 0, 0, 0, 0, 1.2087912087912, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 0, 0, 0, 0, 1.2087912087912, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 0, 0, 0, 0, 1.2087912087912, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -2169.6594427245, 338 ], [ -2522.600619195, 1453 ], [ -1649.5356037152, 1676 ], [ -2894.1176470588, 1694 ] ], -"step_probs_vals": [ 0, 1200, 0, 0, 0.063786008230453, 0.92613636363636, 0.12757201646091, 0, 0.54732510288066, 0, 0.71604938271605, 0, 1, 0 ], -"passages_weights": [ 1, 0, 0.2, 0.74, 0.68 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 2, 3, 1 ], [ 0 ], [ ] ], - [ [ 3, 1, 2 ], [ 0 ], [ ] ], - [ [ 2, 1, 0 ], [ 3 ], [ ] ], - [ [ 2, 0, 3 ], [ 1 ], [ ] ], - [ [ 2, 1, 3 ], [ 0 ], [ ] ], - [ [ 0, 3, 2 ], [ 1 ], [ ] ], - [ [ 0, 1, 2 ], [ 3 ], [ ] ], - [ [ 1, 2, 0 ], [ 3 ], [ ] ], - [ [ 1, 2, 3 ], [ 0 ], [ ] ], - [ [ 2, 3, 0 ], [ 1 ], [ ] ], - [ [ 3, 1, 0 ], [ 2 ], [ ] ], - [ [ 0, 3, 2 ], [ 1 ], [ ] ], - [ [ 3, 2, 0 ], [ 1 ], [ ] ], - [ [ 2, 0, 1 ], [ 3 ], [ ] ], - [ [ 0, 1, 3 ], [ 2 ], [ ] ], - [ [ 3, 2, 1 ], [ 0 ], [ ] ], - [ [ 0, 1, 2 ], [ 3 ], [ ] ], - [ [ 1, 0, 2 ], [ 3 ], [ ] ], - [ [ 1, 0, 3 ], [ 2 ], [ ] ], - [ [ 3, 1, 0 ], [ 2 ], [ ] ], - [ [ 3, 0, 1 ], [ 2 ], [ ] ], - [ [ 3, 1, 0 ], [ 2 ], [ ] ], - [ [ 0, 2, 1 ], [ 3 ], [ ] ], - [ [ 2, 3, 0 ], [ 1 ], [ ] ], - [ [ 0, 2, 3 ], [ 1 ], [ ] ], - [ [ 1, 2, 3 ], [ 0 ], [ ] ], - [ [ 3, 0, 1 ], [ 2 ], [ ] ], - [ [ 0, 2, 3 ], [ 1 ], [ ] ], - [ [ 3, 0, 1 ], [ 2 ], [ ] ], - [ [ 0, 3, 1 ], [ 2 ], [ ] ] -], -"sus_weights": [ 0, 0, 0.61 ], -"order_size": [ 30, 30 ], -"passages_size": [ 0, 0 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3/7e230015/7e230015_code.scd b/resources/resources_bak_2024_01_03/string_quartet_3/7e230015/7e230015_code.scd deleted file mode 100644 index 7c7b526..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3/7e230015/7e230015_code.scd +++ /dev/null @@ -1,975 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array2) - hsArrayToCents.value(array1); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -/* -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance) -}; -*/ - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = true; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - //if(pDistance >= 0, {stepFunc.value(abs(pDistance))}, {0.01}); - stepFunc.value(pDistance) -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - //tuples = dims.collect({[0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum == 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength.asInteger - minMotifLength.asInteger).rand + minMotifLength.asInteger).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - //noProgIns = (popSize - noSusIns).rand + 1; - noProgIns = (popSize - noSusIns); - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength.asInteger - minProgLength.asInteger).rand + minProgLength.asInteger).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0.01); - - - - /* - if(rangeScore.value(candidate.collect({0}), voices[ins], ranges[ins][1] - 500, ranges[ins][1], 0, true) == 1, { - isInRangeScore = 1 - rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0] + 500, ranges[ins][1] - 500, 0, true); - isInRangeScore = isInRangeScore * rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true) - }, { - isInRangeScore = rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true); - }); - */ - - - isInRangeScore = rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true); - //old way - worked but actually by accident (I think) - //isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - - - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-10); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_3/7e230015/7e230015_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_3/7e230015/7e230015_mus_model.json deleted file mode 100644 index 7948320..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3/7e230015/7e230015_mus_model.json +++ /dev/null @@ -1,532 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ] ], 1 ], - [ [ [ "Rest" ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 1 ], - [ [ [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 1 ], - [ [ [ -1, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -1, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 1 ], - [ [ [ -2, 1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 1 ], - [ [ [ -2, 1, 0, 0, 0, 0 ], [ -1, 1, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 1, 0, 0, 0, 0 ], [ -1, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 1, 0, 0, 0, 0 ], [ -1, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ -1, 1, 0, 0, 0, 0 ] ], 1 ], - [ [ [ -1, 0, -1, 0, 0, 0 ], [ -1, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ -1, 1, 0, 0, 0, 0 ] ], 1 ], - [ [ [ -1, 0, -1, 0, 0, 0 ], [ -1, 0, 0, 0, 0, 0 ], [ 1, 0, -1, 0, 0, 0 ], [ -1, 1, 0, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -1, 0, -1, 0, 0, 0 ], [ -1, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ -1, 1, 0, 0, 0, 0 ] ], 1 ], - [ [ [ -2, 0, 0, 0, 0, 0 ], [ -1, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ -1, 1, 0, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 0, 0, 0, 0, 0 ], [ 0, 0, 0, -1, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ -1, 1, 0, 0, 0, 0 ] ], 1 ], - [ [ [ -2, 0, 0, 0, 0, 0 ], [ 0, 0, 0, -1, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, -1, 0, 0, 0 ] ], 1 ], - [ [ [ -1, 0, 0, -1, 0, 0 ], [ 0, 0, 0, -1, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, -1, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -1, 0, 0, -1, 0, 0 ], [ 0, 0, 0, -1, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, -1, 0, 0 ] ], 1 ], - [ [ [ -1, 0, 0, 0, 0, 0 ], [ 0, 0, 0, -1, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, -1, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -1, 0, 0, 0, 0, 0 ], [ -1, 0, 1, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, -1, 0, 0 ] ], 1 ], - [ [ [ -1, 0, 0, 0, 0, 0 ], [ -1, 0, 1, 0, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ 0, 1, 0, -1, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -1, 0, 0, 0, 0, 0 ], [ -1, 0, 1, 0, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -1, 0, 0, 0, 0, 0 ], [ -1, 0, 1, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -1, 1, 1, 0, 0, 0 ], [ -1, 0, 1, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ] ], 1 ], - [ [ [ -1, 1, 1, 0, 0, 0 ], [ -1, 0, 1, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ], [ 0, 1, 1, 0, 0, 0 ] ], 1 ], - [ [ [ -1, 1, 1, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ], [ 0, 1, 1, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -1, 0, 1, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ], [ 0, 1, 1, 0, 0, 0 ] ], 1 ], - [ [ [ -1, 0, 1, 0, 0, 0 ], [ -1, 1, 1, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ], [ 0, 1, 1, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -1, 0, 1, 0, 0, 0 ], [ -1, 1, 1, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ], [ 1, 0, 1, -1, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -1, 0, 1, 0, 0, 0 ], [ -1, 1, 1, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ], [ -1, 0, 2, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -1, 0, 1, 0, 0, 0 ], [ -1, 1, 1, 0, 0, 0 ], [ -1, 0, 2, 1, 0, 0 ], [ -1, 0, 2, 0, 0, 0 ] ], 1 ], - [ [ [ -1, 0, 1, 0, 0, 0 ], [ 0, -1, 2, 0, 0, 0 ], [ -1, 0, 2, 1, 0, 0 ], [ -1, 0, 2, 0, 0, 0 ] ], 1 ], - [ [ [ -1, -1, 2, 0, 0, 0 ], [ 0, -1, 2, 0, 0, 0 ], [ -1, 0, 2, 1, 0, 0 ], [ -1, 0, 2, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -1, -1, 2, 1, 0, 0 ], [ 0, -1, 2, 0, 0, 0 ], [ -1, 0, 2, 1, 0, 0 ], [ -1, 0, 2, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -1, -1, 2, 1, 0, 0 ], [ -1, 1, 2, 0, 0, 0 ], [ -1, 0, 2, 1, 0, 0 ], [ -1, 0, 2, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -1, -1, 2, 1, 0, 0 ], [ -1, 1, 2, 0, 0, 0 ], [ -1, 0, 2, 1, 0, 0 ], [ -2, 0, 2, 1, 0, 0 ] ], 1 ], - [ [ [ -2, 1, 2, 1, 0, 0 ], [ -1, 1, 2, 0, 0, 0 ], [ -1, 0, 2, 1, 0, 0 ], [ -2, 0, 2, 1, 0, 0 ] ], 1 ], - [ [ [ -2, 1, 2, 1, 0, 0 ], [ -1, -1, 2, 1, 0, 0 ], [ -1, 0, 2, 1, 0, 0 ], [ -2, 0, 2, 1, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 1, 2, 1, 0, 0 ], [ -1, -1, 2, 1, 0, 0 ], [ -1, 0, 2, 1, 0, 0 ], [ -1, -1, 1, 1, 0, 0 ] ], 1 ], - [ [ [ -1, -1, 3, 1, 0, 0 ], [ -1, -1, 2, 1, 0, 0 ], [ -1, 0, 2, 1, 0, 0 ], [ -1, -1, 1, 1, 0, 0 ] ], 1 ], - [ [ [ -1, -1, 3, 1, 0, 0 ], [ -1, -1, 2, 1, 0, 0 ], [ 0, -1, 1, 1, 0, 0 ], [ -1, -1, 1, 1, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -1, -1, 3, 1, 0, 0 ], [ -1, -1, 2, 1, 0, 0 ], [ 0, -1, 1, 1, 0, 0 ], [ -1, -1, 1, 1, 0, 1 ] ], 1 ], - [ [ [ -1, -1, 3, 1, 0, 0 ], [ 0, -2, 1, 1, 0, 0 ], [ 0, -1, 1, 1, 0, 0 ], [ -1, -1, 1, 1, 0, 1 ] ], 1 ] - ], - [ - [ [ [ -1, -1, 3, 1, 0, 0 ], [ 0, -2, 1, 1, 0, 0 ], [ 0, -2, 1, 1, 0, 1 ], [ -1, -1, 1, 1, 0, 1 ] ], 1 ] - ], - [ - [ [ [ -1, -1, 3, 1, 0, 0 ], [ 0, -2, 1, 1, 0, 0 ], [ 0, -2, 1, 1, 0, 1 ], [ 1, -3, 1, 1, 0, 0 ] ], 1 ], - [ [ [ 0, -2, 2, 1, 0, 0 ], [ 0, -2, 1, 1, 0, 0 ], [ 0, -2, 1, 1, 0, 1 ], [ 1, -3, 1, 1, 0, 0 ] ], 1 ], - [ [ [ 0, -2, 2, 1, 0, 0 ], [ 0, -2, 1, 1, 0, 0 ], [ 0, -2, 1, 2, 0, 0 ], [ 1, -3, 1, 1, 0, 0 ] ], 1 ] - ], - [ - [ [ [ 0, -2, 2, 1, 0, 0 ], [ 0, -2, 1, 1, 0, 0 ], [ 0, -2, 1, 2, 0, 0 ], [ 1, -2, 1, 1, 0, 0 ] ], 1 ] - ], - [ - [ [ [ 0, -2, 2, 1, 0, 0 ], [ 0, -2, 1, 1, 0, 0 ], [ 0, -2, 1, 2, 0, 0 ], [ 0, -2, 0, 2, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -1, -2, 1, 2, 0, 0 ], [ 0, -2, 1, 1, 0, 0 ], [ 0, -2, 1, 2, 0, 0 ], [ 0, -2, 0, 2, 0, 0 ] ], 1 ], - [ [ [ -1, -2, 1, 2, 0, 0 ], [ 0, -2, 1, 1, 0, 0 ], [ 0, -2, 1, 2, 0, 0 ], [ -1, -2, 1, 3, 0, 0 ] ], 1 ], - [ [ [ -1, -2, 1, 2, 0, 0 ], [ -1, -3, 1, 2, 0, 0 ], [ 0, -2, 1, 2, 0, 0 ], [ -1, -2, 1, 3, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -1, -2, 1, 2, 0, 0 ], [ -1, -3, 1, 2, 0, 0 ], [ 0, -2, 1, 2, 0, 0 ], [ 0, -3, 1, 2, 0, 0 ] ], 1 ], - [ [ [ -1, -2, 1, 2, 0, 0 ], [ -2, -1, 1, 2, 0, 0 ], [ 0, -2, 1, 2, 0, 0 ], [ 0, -3, 1, 2, 0, 0 ] ], 1 ], - [ [ [ -1, -2, 1, 2, 0, 0 ], [ -2, -1, 1, 2, 0, 0 ], [ 1, -2, 1, 1, 0, 0 ], [ 0, -3, 1, 2, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -1, -2, 1, 2, 0, 0 ], [ -2, -1, 1, 2, 0, 0 ], [ 1, -2, 1, 1, 0, 0 ], [ -1, -1, 1, 2, 0, 0 ] ], 1 ], - [ [ [ 0, -2, 1, 1, 0, 0 ], [ -2, -1, 1, 2, 0, 0 ], [ 1, -2, 1, 1, 0, 0 ], [ -1, -1, 1, 2, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -1, 0, 1, 2, 0, 0 ], [ -2, -1, 1, 2, 0, 0 ], [ 1, -2, 1, 1, 0, 0 ], [ -1, -1, 1, 2, 0, 0 ] ], 1 ], - [ [ [ -1, 0, 1, 2, 0, 0 ], [ -2, -1, 1, 2, 0, 0 ], [ -2, 0, 1, 2, 0, 0 ], [ -1, -1, 1, 2, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -3, -1, 1, 2, 0, 0 ], [ -2, -1, 1, 2, 0, 0 ], [ -2, 0, 1, 2, 0, 0 ], [ -1, -1, 1, 2, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -3, -1, 1, 2, 0, 0 ], [ -2, -1, 1, 2, 0, 0 ], [ -1, -1, 0, 2, 0, 0 ], [ -1, -1, 1, 2, 0, 0 ] ], 1 ], - [ [ [ -3, -1, 1, 2, 0, 0 ], [ -2, -1, 1, 2, 0, 0 ], [ -1, -1, 0, 2, 0, 0 ], [ -2, -1, 2, 2, 0, 0 ] ], 1 ], - [ [ [ -3, -1, 1, 2, 0, 0 ], [ -1, -1, 1, 1, 0, 0 ], [ -1, -1, 0, 2, 0, 0 ], [ -2, -1, 2, 2, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -3, -1, 1, 2, 0, 0 ], [ -1, -1, 1, 1, 0, 0 ], [ -1, -1, 2, 2, 0, 0 ], [ -2, -1, 2, 2, 0, 0 ] ], 1 ], - [ [ [ -3, -1, 1, 2, 0, 0 ], [ -2, -2, 2, 2, 0, 0 ], [ -1, -1, 2, 2, 0, 0 ], [ -2, -1, 2, 2, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -3, -1, 1, 2, 0, 0 ], [ -2, -2, 2, 2, 0, 0 ], [ -1, -1, 2, 2, 0, 0 ], [ -1, -2, 1, 2, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -3, -1, 1, 2, 0, 0 ], [ -2, -2, 2, 2, 0, 0 ], [ -1, -1, 2, 2, 0, 0 ], [ -2, 0, 1, 2, 0, 0 ] ], 1 ], - [ [ [ -3, -1, 1, 2, 0, 0 ], [ -2, -2, 2, 2, 0, 0 ], [ 0, -2, 1, 2, 0, 0 ], [ -2, 0, 1, 2, 0, 0 ] ], 1 ], - [ [ [ -3, -1, 1, 2, 0, 0 ], [ -2, -1, 2, 2, 0, 0 ], [ 0, -2, 1, 2, 0, 0 ], [ -2, 0, 1, 2, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -3, -1, 1, 2, 0, 0 ], [ -1, -2, 1, 2, 0, 0 ], [ 0, -2, 1, 2, 0, 0 ], [ -2, 0, 1, 2, 0, 0 ] ], 1 ], - [ [ [ -2, -2, 1, 2, 0, 0 ], [ -1, -2, 1, 2, 0, 0 ], [ 0, -2, 1, 2, 0, 0 ], [ -2, 0, 1, 2, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -2, -1, 1, 2, 0, 0 ], [ -1, -2, 1, 2, 0, 0 ], [ 0, -2, 1, 2, 0, 0 ], [ -2, 0, 1, 2, 0, 0 ] ], 1 ], - [ [ [ -2, -1, 1, 2, 0, 0 ], [ -1, -2, 1, 2, 0, 0 ], [ -1, 0, 1, 2, 0, 0 ], [ -2, 0, 1, 2, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -3, 0, 1, 2, 0, 0 ], [ -1, -2, 1, 2, 0, 0 ], [ -1, 0, 1, 2, 0, 0 ], [ -2, 0, 1, 2, 0, 0 ] ], 1 ], - [ [ [ -3, 0, 1, 2, 0, 0 ], [ -2, -1, 1, 2, 0, 0 ], [ -1, 0, 1, 2, 0, 0 ], [ -2, 0, 1, 2, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -3, 0, 1, 2, 0, 0 ], [ -3, 1, 1, 2, 0, 0 ], [ -1, 0, 1, 2, 0, 0 ], [ -2, 0, 1, 2, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -3, 0, 1, 2, 0, 0 ], [ -3, 1, 1, 2, 0, 0 ], [ -1, 0, 1, 2, 0, 0 ], [ -3, 2, 1, 2, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -3, 0, 1, 2, 0, 0 ], [ -3, 1, 1, 2, 0, 0 ], [ -2, 1, 1, 2, 0, 0 ], [ -3, 2, 1, 2, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -3, 0, 1, 2, 0, 0 ], [ -3, 1, 1, 2, 0, 0 ], [ -2, 0, 1, 2, 0, 0 ], [ -3, 2, 1, 2, 0, 0 ] ], 1 ], - [ [ [ -3, 0, 1, 2, 0, 0 ], [ -3, 1, 1, 2, 0, 0 ], [ -2, 0, 1, 2, 0, 0 ], [ -2, 1, 1, 2, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -4, 1, 1, 2, 0, 0 ], [ -3, 1, 1, 2, 0, 0 ], [ -2, 0, 1, 2, 0, 0 ], [ -2, 1, 1, 2, 0, 0 ] ], 1 ], - [ [ [ -4, 1, 1, 2, 0, 0 ], [ -2, 0, 0, 2, 0, 0 ], [ -2, 0, 1, 2, 0, 0 ], [ -2, 1, 1, 2, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -4, 1, 1, 2, 0, 0 ], [ -2, 0, 0, 2, 0, 0 ], [ -3, 1, 1, 2, 0, 0 ], [ -2, 1, 1, 2, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -4, 1, 1, 2, 0, 0 ], [ -2, 0, 0, 2, 0, 0 ], [ -2, 1, 1, 1, 0, 0 ], [ -2, 1, 1, 2, 0, 0 ] ], 1 ], - [ [ [ -4, 1, 1, 2, 0, 0 ], [ -4, 2, 1, 2, 0, 0 ], [ -2, 1, 1, 1, 0, 0 ], [ -2, 1, 1, 2, 0, 0 ] ], 1 ], - [ [ [ -3, 1, 1, 1, 0, 0 ], [ -4, 2, 1, 2, 0, 0 ], [ -2, 1, 1, 1, 0, 0 ], [ -2, 1, 1, 2, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -3, 1, 1, 1, 0, 0 ], [ -4, 2, 1, 2, 0, 0 ], [ -2, 1, 1, 1, 0, 0 ], [ -1, 1, 1, 1, 0, 0 ] ], 1 ], - [ [ [ -3, 1, 1, 1, 0, 0 ], [ -3, 2, 1, 1, 0, 0 ], [ -2, 1, 1, 1, 0, 0 ], [ -1, 1, 1, 1, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -3, 1, 1, 1, 0, 0 ], [ -3, 2, 1, 1, 0, 0 ], [ -2, 1, 1, 1, 0, 0 ], [ -2, 2, 1, 1, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -3, 1, 1, 1, 0, 0 ], [ -3, 2, 1, 1, 0, 0 ], [ -3, 3, 1, 1, 0, 0 ], [ -2, 2, 1, 1, 0, 0 ] ], 1 ], - [ [ [ -3, 1, 1, 1, 0, 0 ], [ -3, 2, 1, 1, 0, 1 ], [ -3, 3, 1, 1, 0, 0 ], [ -2, 2, 1, 1, 0, 0 ] ], 1 ], - [ [ [ -3, 2, 1, 1, 0, 0 ], [ -3, 2, 1, 1, 0, 1 ], [ -3, 3, 1, 1, 0, 0 ], [ -2, 2, 1, 1, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -3, 2, 1, 1, 0, 0 ], [ -4, 4, 1, 1, 0, 0 ], [ -3, 3, 1, 1, 0, 0 ], [ -2, 2, 1, 1, 0, 0 ] ], 1 ], - [ [ [ -3, 2, 1, 1, 0, 0 ], [ -4, 4, 1, 1, 0, 0 ], [ -3, 3, 1, 1, 0, 0 ], [ -3, 4, 1, 1, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -3, 2, 1, 1, 0, 0 ], [ -4, 4, 1, 1, 0, 0 ], [ -3, 3, 1, 1, 0, 0 ], [ -2, 3, 0, 1, 0, 0 ] ], 1 ], - [ [ [ -3, 2, 1, 1, 0, 0 ], [ -3, 3, 0, 1, 0, 0 ], [ -3, 3, 1, 1, 0, 0 ], [ -2, 3, 0, 1, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -3, 2, 1, 1, 0, 0 ], [ -4, 3, 1, 2, 0, 0 ], [ -3, 3, 1, 1, 0, 0 ], [ -2, 3, 0, 1, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -3, 2, 1, 1, 0, 0 ], [ -4, 3, 1, 2, 0, 0 ], [ -4, 3, 2, 2, 0, 0 ], [ -2, 3, 0, 1, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -3, 2, 1, 1, 0, 0 ], [ -4, 3, 1, 2, 0, 0 ], [ -3, 2, 1, 2, 0, 0 ], [ -2, 3, 0, 1, 0, 0 ] ], 1 ], - [ [ [ -3, 2, 1, 1, 0, 0 ], [ -3, 3, 1, 1, 0, 0 ], [ -3, 2, 1, 2, 0, 0 ], [ -2, 3, 0, 1, 0, 0 ] ], 1 ], - [ [ [ -3, 2, 1, 1, 0, 0 ], [ -3, 3, 1, 1, 0, 0 ], [ -3, 2, 1, 2, 0, 0 ], [ -1, 1, 1, 1, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -5, 3, 1, 2, 0, 0 ], [ -3, 3, 1, 1, 0, 0 ], [ -3, 2, 1, 2, 0, 0 ], [ -1, 1, 1, 1, 0, 0 ] ], 1 ], - [ [ [ -5, 3, 1, 2, 0, 0 ], [ -2, 2, 0, 2, 0, 0 ], [ -3, 2, 1, 2, 0, 0 ], [ -1, 1, 1, 1, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -3, 1, 1, 2, 0, 0 ], [ -2, 2, 0, 2, 0, 0 ], [ -3, 2, 1, 2, 0, 0 ], [ -1, 1, 1, 1, 0, 0 ] ], 1 ], - [ [ [ -3, 1, 1, 2, 0, 0 ], [ -2, 1, 1, 2, 0, 0 ], [ -3, 2, 1, 2, 0, 0 ], [ -1, 1, 1, 1, 0, 0 ] ], 1 ], - [ [ [ -3, 1, 1, 2, 0, 0 ], [ -2, 1, 1, 2, 0, 0 ], [ -2, 1, 1, 1, 0, 0 ], [ -1, 1, 1, 1, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -3, 1, 1, 2, 0, 0 ], [ -3, 2, 1, 2, 0, 0 ], [ -2, 1, 1, 1, 0, 0 ], [ -1, 1, 1, 1, 0, 0 ] ], 1 ], - [ [ [ -3, 1, 1, 2, 0, 0 ], [ -3, 2, 1, 2, 0, 0 ], [ -2, 1, 1, 1, 1, 0 ], [ -1, 1, 1, 1, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -3, 1, 1, 2, 0, 0 ], [ -3, 2, 1, 2, 0, 0 ], [ -2, 1, 1, 1, 1, 0 ], [ -2, 1, 1, 2, 1, 0 ] ], 1 ], - [ [ [ -2, 1, 2, 1, 1, 0 ], [ -3, 2, 1, 2, 0, 0 ], [ -2, 1, 1, 1, 1, 0 ], [ -2, 1, 1, 2, 1, 0 ] ], 1 ], - [ [ [ -2, 1, 2, 1, 1, 0 ], [ -3, 1, 1, 1, 1, 0 ], [ -2, 1, 1, 1, 1, 0 ], [ -2, 1, 1, 2, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 1, 2, 1, 1, 0 ], [ -4, 1, 2, 2, 1, 0 ], [ -2, 1, 1, 1, 1, 0 ], [ -2, 1, 1, 2, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 1, 2, 1, 1, 0 ], [ -3, 1, 2, 1, 1, 0 ], [ -2, 1, 1, 1, 1, 0 ], [ -2, 1, 1, 2, 1, 0 ] ], 1 ], - [ [ [ -2, 1, 2, 1, 1, 0 ], [ -3, 1, 2, 1, 1, 0 ], [ -2, 1, 1, 1, 1, 0 ], [ -3, 2, 2, 1, 1, 0 ] ], 1 ], - [ [ [ -2, 1, 2, 1, 1, 0 ], [ -3, 1, 2, 1, 1, 0 ], [ -3, 1, 2, 2, 1, 0 ], [ -3, 2, 2, 1, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 1, 2, 1, 1, 0 ], [ -4, 3, 2, 1, 1, 0 ], [ -3, 1, 2, 2, 1, 0 ], [ -3, 2, 2, 1, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -3, 3, 2, 1, 1, 0 ], [ -4, 3, 2, 1, 1, 0 ], [ -3, 1, 2, 2, 1, 0 ], [ -3, 2, 2, 1, 1, 0 ] ], 1 ], - [ [ [ -3, 3, 2, 1, 1, 0 ], [ -4, 2, 2, 1, 1, 0 ], [ -3, 1, 2, 2, 1, 0 ], [ -3, 2, 2, 1, 1, 0 ] ], 1 ], - [ [ [ -3, 3, 2, 1, 1, 0 ], [ -4, 2, 2, 1, 1, 0 ], [ -4, 3, 2, 1, 1, 0 ], [ -3, 2, 2, 1, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -3, 3, 2, 1, 1, 0 ], [ -5, 4, 2, 1, 1, 0 ], [ -4, 3, 2, 1, 1, 0 ], [ -3, 2, 2, 1, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -4, 4, 2, 1, 1, 0 ], [ -5, 4, 2, 1, 1, 0 ], [ -4, 3, 2, 1, 1, 0 ], [ -3, 2, 2, 1, 1, 0 ] ], 1 ], - [ [ [ -4, 4, 2, 1, 1, 0 ], [ -5, 4, 2, 1, 1, 0 ], [ -4, 3, 2, 1, 1, 0 ], [ -3, 3, 2, 1, 1, 0 ] ], 1 ], - [ [ [ -4, 4, 2, 1, 1, 0 ], [ -4, 3, 1, 1, 1, 0 ], [ -4, 3, 2, 1, 1, 0 ], [ -3, 3, 2, 1, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -4, 4, 2, 1, 1, 0 ], [ -4, 3, 1, 1, 1, 0 ], [ -4, 3, 2, 1, 1, 0 ], [ -3, 3, 1, 1, 2, 0 ] ], 1 ], - [ [ [ -3, 3, 1, 1, 1, 0 ], [ -4, 3, 1, 1, 1, 0 ], [ -4, 3, 2, 1, 1, 0 ], [ -3, 3, 1, 1, 2, 0 ] ], 1 ] - ], - [ - [ [ [ -3, 3, 1, 1, 1, 0 ], [ -4, 3, 1, 1, 1, 0 ], [ -4, 3, 2, 1, 1, 0 ], [ -3, 4, 1, 1, 1, 0 ] ], 1 ], - [ [ [ -4, 4, 1, 1, 1, 0 ], [ -4, 3, 1, 1, 1, 0 ], [ -4, 3, 2, 1, 1, 0 ], [ -3, 4, 1, 1, 1, 0 ] ], 1 ], - [ [ [ -4, 4, 1, 1, 1, 0 ], [ -4, 3, 1, 1, 1, 0 ], [ -3, 3, 1, 1, 1, 0 ], [ -3, 4, 1, 1, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -4, 4, 1, 1, 1, 0 ], [ -4, 4, 1, 1, 0, 0 ], [ -3, 3, 1, 1, 1, 0 ], [ -3, 4, 1, 1, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -4, 4, 1, 1, 1, 0 ], [ -4, 4, 1, 1, 0, 0 ], [ -3, 3, 1, 1, 1, 0 ], [ -4, 5, 1, 1, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -4, 4, 1, 1, 1, 0 ], [ -4, 4, 1, 1, 0, 0 ], [ -3, 3, 1, 1, 1, 0 ], [ -3, 4, 1, 1, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 3, 1, 1, 0, 0 ], [ -4, 4, 1, 1, 0, 0 ], [ -3, 3, 1, 1, 1, 0 ], [ -3, 4, 1, 1, 0, 0 ] ], 1 ], - [ [ [ -2, 3, 1, 1, 0, 0 ], [ -3, 3, 1, 1, 0, 0 ], [ -3, 3, 1, 1, 1, 0 ], [ -3, 4, 1, 1, 0, 0 ] ], 1 ], - [ [ [ -2, 3, 1, 1, 0, 0 ], [ -3, 3, 1, 1, 0, 0 ], [ -3, 3, 1, 1, 1, 0 ], [ -2, 3, 1, 1, 1, -1 ] ], 1 ] - ], - [ - [ [ [ -2, 3, 1, 1, 0, 0 ], [ -3, 3, 0, 1, 1, 0 ], [ -3, 3, 1, 1, 1, 0 ], [ -2, 3, 1, 1, 1, -1 ] ], 1 ] - ], - [ - [ [ [ -2, 3, 1, 1, 0, 0 ], [ -2, 3, 1, 1, 0, -1 ], [ -3, 3, 1, 1, 1, 0 ], [ -2, 3, 1, 1, 1, -1 ] ], 1 ], - [ [ [ -2, 3, 1, 1, 0, 0 ], [ -2, 3, 1, 1, 0, -1 ], [ -3, 4, 1, 1, 0, 0 ], [ -2, 3, 1, 1, 1, -1 ] ], 1 ] - ], - [ - [ [ [ -2, 3, 1, 1, 0, 0 ], [ -3, 3, 1, 1, 1, 0 ], [ -3, 4, 1, 1, 0, 0 ], [ -2, 3, 1, 1, 1, -1 ] ], 1 ], - [ [ [ -2, 3, 1, 1, 0, 0 ], [ -3, 3, 1, 1, 1, 0 ], [ -3, 4, 1, 1, 0, 0 ], [ -4, 4, 1, 1, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 3, 1, 1, 0, 0 ], [ -3, 3, 1, 1, 1, 0 ], [ -3, 4, 1, 1, 0, 0 ], [ -3, 3, 0, 1, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 3, 1, 1, 0, 0 ], [ -3, 3, 1, 1, 1, 0 ], [ -3, 4, 0, 1, 1, 0 ], [ -3, 3, 0, 1, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 3, 1, 1, 0, 0 ], [ -3, 4, 1, 1, 1, 0 ], [ -3, 4, 0, 1, 1, 0 ], [ -3, 3, 0, 1, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -3, 3, 1, 1, 1, 0 ], [ -3, 4, 1, 1, 1, 0 ], [ -3, 4, 0, 1, 1, 0 ], [ -3, 3, 0, 1, 1, 0 ] ], 1 ], - [ [ [ -3, 3, 1, 1, 1, 0 ], [ -3, 4, 1, 1, 1, 0 ], [ -4, 4, 1, 1, 1, 0 ], [ -3, 3, 0, 1, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -3, 4, 0, 1, 1, 0 ], [ -3, 4, 1, 1, 1, 0 ], [ -4, 4, 1, 1, 1, 0 ], [ -3, 3, 0, 1, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -3, 4, 0, 1, 1, 0 ], [ -3, 4, 1, 1, 1, 0 ], [ -4, 4, 1, 1, 1, 0 ], [ -4, 4, 0, 1, 1, 0 ] ], 1 ], - [ [ [ -4, 4, 1, 2, 1, 0 ], [ -3, 4, 1, 1, 1, 0 ], [ -4, 4, 1, 1, 1, 0 ], [ -4, 4, 0, 1, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -4, 5, 1, 1, 1, 0 ], [ -3, 4, 1, 1, 1, 0 ], [ -4, 4, 1, 1, 1, 0 ], [ -4, 4, 0, 1, 1, 0 ] ], 1 ], - [ [ [ -4, 5, 1, 1, 1, 0 ], [ -4, 5, 0, 1, 1, 0 ], [ -4, 4, 1, 1, 1, 0 ], [ -4, 4, 0, 1, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -3, 4, 0, 1, 1, 0 ], [ -4, 5, 0, 1, 1, 0 ], [ -4, 4, 1, 1, 1, 0 ], [ -4, 4, 0, 1, 1, 0 ] ], 1 ], - [ [ [ -3, 4, 0, 1, 1, 0 ], [ -4, 5, 0, 1, 1, 0 ], [ -4, 4, 1, 1, 1, 0 ], [ -4, 5, 1, 1, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -3, 4, 0, 1, 1, 0 ], [ -4, 5, 0, 1, 1, 0 ], [ -4, 4, 1, 1, 1, 0 ], [ -3, 4, 1, 1, 1, 0 ] ], 1 ], - [ [ [ -3, 4, 0, 1, 1, 0 ], [ -4, 4, 0, 1, 1, 0 ], [ -4, 4, 1, 1, 1, 0 ], [ -3, 4, 1, 1, 1, 0 ] ], 1 ], - [ [ [ -3, 4, 0, 1, 1, 0 ], [ -4, 4, 0, 1, 1, 0 ], [ -3, 3, 0, 1, 1, 0 ], [ -3, 4, 1, 1, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -3, 4, 0, 1, 1, 0 ], [ -4, 4, 0, 1, 1, 0 ], [ -3, 3, 0, 1, 1, 0 ], [ -4, 5, 0, 1, 1, 0 ] ], 1 ], - [ [ [ -5, 4, 0, 1, 1, 0 ], [ -4, 4, 0, 1, 1, 0 ], [ -3, 3, 0, 1, 1, 0 ], [ -4, 5, 0, 1, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -5, 4, 0, 1, 1, 0 ], [ -4, 4, 0, 1, 1, 0 ], [ -3, 3, 0, 1, 1, 0 ], [ -3, 4, 0, 1, 1, 0 ] ], 1 ], - [ [ [ -4, 3, 0, 1, 1, 0 ], [ -4, 4, 0, 1, 1, 0 ], [ -3, 3, 0, 1, 1, 0 ], [ -3, 4, 0, 1, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -4, 3, 0, 1, 1, 0 ], [ -4, 4, 0, 1, 1, 0 ], [ -4, 5, 0, 1, 1, 0 ], [ -3, 4, 0, 1, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -4, 3, 0, 1, 1, 0 ], [ -3, 3, -1, 1, 1, 0 ], [ -4, 5, 0, 1, 1, 0 ], [ -3, 4, 0, 1, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -6, 5, 0, 1, 1, 0 ], [ -3, 3, -1, 1, 1, 0 ], [ -4, 5, 0, 1, 1, 0 ], [ -3, 4, 0, 1, 1, 0 ] ], 1 ], - [ [ [ -6, 5, 0, 1, 1, 0 ], [ -3, 3, -1, 1, 1, 0 ], [ -4, 5, 0, 1, 1, 0 ], [ -4, 6, 0, 1, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -6, 5, 0, 1, 1, 0 ], [ -3, 3, -1, 1, 1, 0 ], [ -5, 6, -1, 1, 1, 0 ], [ -4, 6, 0, 1, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -6, 6, -1, 1, 1, 0 ], [ -3, 3, -1, 1, 1, 0 ], [ -5, 6, -1, 1, 1, 0 ], [ -4, 6, 0, 1, 1, 0 ] ], 1 ], - [ [ [ -6, 6, -1, 1, 1, 0 ], [ -3, 3, -1, 1, 1, 0 ], [ -5, 6, 0, 1, 1, 0 ], [ -4, 6, 0, 1, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -6, 6, -1, 1, 1, 0 ], [ -5, 6, -1, 1, 1, 0 ], [ -5, 6, 0, 1, 1, 0 ], [ -4, 6, 0, 1, 1, 0 ] ], 1 ], - [ [ [ -6, 6, 0, 1, 1, 0 ], [ -5, 6, -1, 1, 1, 0 ], [ -5, 6, 0, 1, 1, 0 ], [ -4, 6, 0, 1, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -6, 6, 0, 1, 1, 0 ], [ -5, 6, -1, 1, 1, 0 ], [ -5, 6, 0, 1, 1, 0 ], [ -4, 5, 0, 1, 1, 0 ] ], 1 ], - [ [ [ -6, 6, 0, 1, 1, 0 ], [ -5, 6, -1, 1, 1, 0 ], [ -4, 6, -1, 1, 1, 0 ], [ -4, 5, 0, 1, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -5, 5, -1, 1, 1, 0 ], [ -5, 6, -1, 1, 1, 0 ], [ -4, 6, -1, 1, 1, 0 ], [ -4, 5, 0, 1, 1, 0 ] ], 1 ], - [ [ [ -5, 5, -1, 1, 1, 0 ], [ -4, 5, -1, 1, 1, 0 ], [ -4, 6, -1, 1, 1, 0 ], [ -4, 5, 0, 1, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -5, 5, -1, 1, 1, 0 ], [ -4, 5, -1, 1, 1, 0 ], [ -3, 5, -2, 1, 1, 0 ], [ -4, 5, 0, 1, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -5, 5, -1, 1, 1, 0 ], [ -4, 5, -1, 1, 1, 0 ], [ -3, 5, -2, 1, 1, 0 ], [ -3, 5, -1, 1, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -4, 5, -2, 1, 1, 0 ], [ -4, 5, -1, 1, 1, 0 ], [ -3, 5, -2, 1, 1, 0 ], [ -3, 5, -1, 1, 1, 0 ] ], 1 ], - [ [ [ -4, 5, -2, 1, 1, 0 ], [ -4, 5, -1, 1, 1, 0 ], [ -3, 5, -2, 1, 1, 0 ], [ -4, 6, -1, 1, 1, 0 ] ], 1 ], - [ [ [ -4, 5, -2, 1, 1, 0 ], [ -4, 5, -1, 1, 1, 0 ], [ -4, 5, -1, 2, 1, 0 ], [ -4, 6, -1, 1, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -4, 5, -2, 1, 1, 0 ], [ -4, 5, -1, 1, 1, 0 ], [ -4, 5, -1, 2, 1, 0 ], [ -3, 5, -2, 1, 1, 0 ] ], 1 ], - [ [ [ -4, 5, -2, 1, 1, 0 ], [ -4, 5, -1, 1, 1, 0 ], [ -3, 5, -1, 1, 1, 0 ], [ -3, 5, -2, 1, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -4, 5, -2, 1, 1, 0 ], [ -4, 5, -1, 1, 1, 0 ], [ -2, 4, -2, 1, 1, 0 ], [ -3, 5, -2, 1, 1, 0 ] ], 1 ], - [ [ [ -4, 5, -2, 1, 1, 0 ], [ -4, 5, -1, 1, 1, 0 ], [ -2, 4, -2, 1, 1, 0 ], [ -3, 4, -2, 1, 1, 0 ] ], 1 ], - [ [ [ -4, 5, -2, 1, 1, 0 ], [ -3, 5, -2, 1, 1, 0 ], [ -2, 4, -2, 1, 1, 0 ], [ -3, 4, -2, 1, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -4, 5, -2, 1, 1, 0 ], [ -2, 5, -2, 0, 1, 0 ], [ -2, 4, -2, 1, 1, 0 ], [ -3, 4, -2, 1, 1, 0 ] ], 1 ], - [ [ [ -4, 5, -2, 1, 1, 0 ], [ -2, 5, -2, 0, 1, 0 ], [ -2, 4, -2, 1, 1, 0 ], [ -4, 6, -2, 1, 1, 0 ] ], 1 ], - [ [ [ -4, 5, -2, 1, 1, 0 ], [ -2, 5, -2, 0, 1, 0 ], [ -3, 5, -2, 1, 1, 0 ], [ -4, 6, -2, 1, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -5, 5, -2, 1, 1, 0 ], [ -2, 5, -2, 0, 1, 0 ], [ -3, 5, -2, 1, 1, 0 ], [ -4, 6, -2, 1, 1, 0 ] ], 1 ], - [ [ [ -5, 5, -2, 1, 1, 0 ], [ -4, 5, -2, 1, 1, 0 ], [ -3, 5, -2, 1, 1, 0 ], [ -4, 6, -2, 1, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -5, 5, -2, 1, 1, 0 ], [ -4, 5, -2, 1, 1, 0 ], [ -4, 7, -2, 1, 1, 0 ], [ -4, 6, -2, 1, 1, 0 ] ], 1 ], - [ [ [ -5, 5, -2, 1, 1, 0 ], [ -5, 6, -2, 1, 1, 0 ], [ -4, 7, -2, 1, 1, 0 ], [ -4, 6, -2, 1, 1, 0 ] ], 1 ], - [ [ [ -6, 6, -2, 1, 1, 0 ], [ -5, 6, -2, 1, 1, 0 ], [ -4, 7, -2, 1, 1, 0 ], [ -4, 6, -2, 1, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -6, 7, -2, 1, 1, 0 ], [ -5, 6, -2, 1, 1, 0 ], [ -4, 7, -2, 1, 1, 0 ], [ -4, 6, -2, 1, 1, 0 ] ], 1 ], - [ [ [ -6, 7, -2, 1, 1, 0 ], [ -5, 6, -2, 1, 1, 0 ], [ -5, 7, -2, 1, 1, 0 ], [ -4, 6, -2, 1, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -6, 7, -2, 1, 1, 0 ], [ -5, 6, -2, 1, 1, 0 ], [ -5, 7, -2, 1, 1, 0 ], [ -4, 7, -2, 1, 1, 0 ] ], 1 ], - [ [ [ -6, 7, -2, 1, 1, 0 ], [ "Rest" ], [ -5, 7, -2, 1, 1, 0 ], [ -4, 7, -2, 1, 1, 0 ] ], 1 ], - [ [ [ -6, 7, -2, 1, 1, 0 ], [ "Rest" ], [ -5, 7, -2, 1, 1, 0 ], [ "Rest" ] ], 1 ], - [ [ [ -6, 7, -2, 1, 1, 0 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 1 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 1 ] - ] - ] -], -"last_changes": -[ - [ [ -5, 5, -2, 1, 1, 0 ], [ -5, 6, -2, 1, 1, 0 ], [ -4, 7, -2, 1, 1, 0 ], [ -4, 6, -2, 1, 1, 0 ] ], - [ [ -6, 6, -2, 1, 1, 0 ], [ -5, 6, -2, 1, 1, 0 ], [ -4, 7, -2, 1, 1, 0 ], [ -4, 6, -2, 1, 1, 0 ] ], - [ [ -6, 7, -2, 1, 1, 0 ], [ -5, 6, -2, 1, 1, 0 ], [ -4, 7, -2, 1, 1, 0 ], [ -4, 6, -2, 1, 1, 0 ] ], - [ [ -6, 7, -2, 1, 1, 0 ], [ -5, 6, -2, 1, 1, 0 ], [ -5, 7, -2, 1, 1, 0 ], [ -4, 6, -2, 1, 1, 0 ] ], - [ [ -6, 7, -2, 1, 1, 0 ], [ -5, 6, -2, 1, 1, 0 ], [ -5, 7, -2, 1, 1, 0 ], [ -4, 7, -2, 1, 1, 0 ] ] -], -"cur_uid": "7e230015", -"ref_uid": "nil", -"order_seed": 389930, -"dur_seed": 736878, -"motifs_seed": 479673, -"entrances_probs_vals": [ 0, 0, 0, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 0, 0, 0, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 0, 0, 0, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -2400, 1200 ], [ -1200, 1200 ], [ -702, 1200 ], [ -702, 1200 ] ], -"step_probs_vals": [ -1200, 1200, 0.0020576131687243, 0.068181818181818, 0.074074074074074, 0.0625, 0.20576131687243, 0.0625, 0.45679012345679, 0.011363636363636, 0.53086419753086, 0, 0.54320987654321, 0.92045454545455, 0.58641975308642, 0.92613636363636, 0.61111111111111, 0, 0.78600823045268, 0.068181818181818, 0.98971193415638, 0.0625 ], -"passages_weights": [ 1, 1, 0.48, 1, 1 ], -"hd_exp": 10, -"hd_invert": 0, -"order": -[ - [ [ 2, 3, 1 ], [ 0 ], [ ] ], - [ [ 1, 3 ], [ 2, 0 ], [ ] ], - [ [ 0, 3 ], [ 2, 1 ], [ ] ], - [ [ 2, 3, 0 ], [ 1 ], [ ] ], - [ [ 1 ], [ 3, 0, 2 ], [ ] ], - [ [ 3, 1 ], [ 2, 0 ], [ ] ], - [ [ 2 ], [ 1, 3, 0 ], [ ] ], - [ [ 2, 1 ], [ 3, 0 ], [ ] ], - [ [ 0, 3 ], [ 1, 2 ], [ ] ], - [ [ 1, 2, 0 ], [ 3 ], [ ] ], - [ [ 1, 0, 3 ], [ 2 ], [ ] ], - [ [ 2 ], [ 0, 3, 1 ], [ ] ], - [ [ 3, 2 ], [ 0, 1 ], [ ] ], - [ [ 2, 1, 0 ], [ 3 ], [ ] ], - [ [ 0, 1, 2 ], [ 3 ], [ ] ], - [ [ 3 ], [ 2, 1, 0 ], [ ] ], - [ [ 3, 1, 2 ], [ 0 ], [ ] ], - [ [ 0, 3, 2 ], [ 1 ], [ ] ], - [ [ 2 ], [ 3, 0, 1 ], [ ] ], - [ [ 1 ], [ 3, 0, 2 ], [ ] ], - [ [ 2, 0 ], [ 3, 1 ], [ ] ], - [ [ 1, 3, 0 ], [ 2 ], [ ] ], - [ [ 1 ], [ 3, 0, 2 ], [ ] ], - [ [ 2, 1, 0 ], [ 3 ], [ ] ], - [ [ 0, 1, 2 ], [ 3 ], [ ] ], - [ [ 2 ], [ 0, 3, 1 ], [ ] ], - [ [ 0 ], [ 3, 1, 2 ], [ ] ], - [ [ 2, 1 ], [ 3, 0 ], [ ] ], - [ [ 1, 3 ], [ 0, 2 ], [ ] ], - [ [ 2, 1, 3 ], [ 0 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ], - [ [ 0, 3 ], [ 2, 1 ], [ ] ], - [ [ 0, 1, 2 ], [ 3 ], [ ] ], - [ [ 0 ], [ 3, 2, 1 ], [ ] ], - [ [ 2, 3 ], [ 1, 0 ], [ ] ], - [ [ 3, 1 ], [ 0, 2 ], [ ] ], - [ [ 3, 2 ], [ 0, 1 ], [ ] ], - [ [ 0, 2, 3 ], [ 1 ], [ ] ], - [ [ 1, 0, 2 ], [ 3 ], [ ] ], - [ [ 0, 3, 1 ], [ 2 ], [ ] ], - [ [ 1, 0 ], [ 2, 3 ], [ ] ], - [ [ 2, 3 ], [ 0, 1 ], [ ] ], - [ [ 0, 1, 3 ], [ 2 ], [ ] ], - [ [ 3 ], [ 2, 1, 0 ], [ ] ], - [ [ 2, 0 ], [ 3, 1 ], [ ] ], - [ [ 2, 1, 0 ], [ 3 ], [ ] ], - [ [ 3 ], [ 2, 1, 0 ], [ ] ], - [ [ 0, 2 ], [ 1, 3 ], [ ] ], - [ [ 0, 2 ], [ 3, 1 ], [ ] ], - [ [ 0, 2, 3 ], [ 1 ], [ ] ], - [ [ 0, 1, 3 ], [ 2 ], [ ] ], - [ [ 0 ], [ 2, 1, 3 ], [ ] ], - [ [ 3, 2 ], [ 0, 1 ], [ ] ], - [ [ 3 ], [ 0, 1, 2 ], [ ] ], - [ [ 3, 0 ], [ 1, 2 ], [ ] ], - [ [ 2 ], [ 3, 0, 1 ], [ ] ], - [ [ 0, 2, 3 ], [ 1 ], [ ] ], - [ [ 0 ], [ 1, 3, 2 ], [ ] ], - [ [ 2, 0, 3 ], [ 1 ], [ ] ], - [ [ 3 ], [ 0, 1, 2 ], [ ] ], - [ [ 3, 2, 0 ], [ 1 ], [ ] ], - [ [ 2 ], [ 0, 3, 1 ], [ ] ], - [ [ 1, 2 ], [ 3, 0 ], [ ] ], - [ [ 1 ], [ 3, 0, 2 ], [ ] ], - [ [ 0, 2, 3 ], [ 1 ], [ ] ], - [ [ 0, 2, 1 ], [ 3 ], [ ] ], - [ [ 1, 2, 0 ], [ 3 ], [ ] ], - [ [ 2 ], [ 0, 1, 3 ], [ ] ], - [ [ 0, 2, 3 ], [ 1 ], [ ] ], - [ [ 0, 3 ], [ 1, 2 ], [ ] ], - [ [ 2, 0 ], [ 1, 3 ], [ ] ], - [ [ 2, 1, 0 ], [ 3 ], [ ] ], - [ [ 1, 0, 3 ], [ 2 ], [ ] ], - [ [ 3, 0, 2 ], [ 1 ], [ ] ], - [ [ 1, 3 ], [ 0, 2 ], [ ] ], - [ [ 3, 2, 1 ], [ 0 ], [ ] ], - [ [ 1, 2 ], [ 3, 0 ], [ ] ], - [ [ 2, 3 ], [ 0, 1 ], [ ] ], - [ [ 1, 2 ], [ 0, 3 ], [ ] ], - [ [ 0 ], [ 3, 1, 2 ], [ ] ], - [ [ 1, 2 ], [ 3, 0 ], [ ] ], - [ [ 2, 1 ], [ 3, 0 ], [ ] ], - [ [ 0, 3, 1 ], [ 2 ], [ ] ], - [ [ 3, 0, 2 ], [ 1 ], [ ] ], - [ [ 2, 1 ], [ 0, 3 ], [ ] ], - [ [ 1, 0, 3 ], [ 2 ], [ ] ], - [ [ 3, 1 ], [ 0, 2 ], [ ] ], - [ [ 3, 2 ], [ 1, 0 ], [ ] ], - [ [ 0, 1 ], [ 3, 2 ], [ ] ], - [ [ 2, 3 ], [ 0, 1 ], [ ] ], - [ [ 3, 1, 0 ], [ 2 ], [ ] ], - [ [ 1, 0, 2 ], [ 3 ], [ ] ], - [ [ 1 ], [ 0, 3, 2 ], [ ] ], - [ [ 0, 1 ], [ 3, 2 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ], - [ [ 0 ], [ 1, 3, 2 ], [ ] ], - [ [ 2, 3 ], [ 0, 1 ], [ ] ], - [ [ 3 ], [ 2, 1, 0 ], [ ] ], - [ [ 3, 1 ], [ 0, 2 ], [ ] ], - [ [ 0, 2, 1 ], [ 3 ], [ ] ] -], -"sus_weights": [ 0.35, 0.37, 0.38 ], -"order_size": [ 100, 100 ], -"passages_size": [ 0, 0 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3/tmp/tmp_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_3/tmp/tmp_mus_model.json deleted file mode 100644 index 487fc67..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3/tmp/tmp_mus_model.json +++ /dev/null @@ -1,532 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ] ], 1 ], - [ [ [ "Rest" ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 1 ], - [ [ [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 2.375 ], - [ [ [ -1, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 1.625 ] - ], - [ - [ [ [ -1, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, -1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 1 ], - [ [ [ 0, 0, 0, -1, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, -1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 3.5 ] - ], - [ - [ [ [ 0, 0, 0, -1, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ -1, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 1 ], - [ [ [ 0, 0, 0, -1, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ -1, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 2.5 ] - ], - [ - [ [ [ 0, 0, 0, -1, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ], [ -1, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 1.375 ] - ], - [ - [ [ [ 0, 0, 0, -1, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ], [ -1, 0, 0, 0, 0, 0 ], [ 0, 0, 1, -1, 0, 0 ] ], 1 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ], [ -1, 0, 0, 0, 0, 0 ], [ 0, 0, 1, -1, 0, 0 ] ], 1 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ], [ 0, -1, 1, 0, 0, 0 ], [ 0, 0, 1, -1, 0, 0 ] ], 1.875 ] - ], - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ], [ 1, 0, 1, -1, 0, 0 ], [ 0, 0, 1, -1, 0, 0 ] ], 1 ], - [ [ [ 1, -1, 1, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ], [ 1, 0, 1, -1, 0, 0 ], [ 0, 0, 1, -1, 0, 0 ] ], 3.375 ] - ], - [ - [ [ [ 1, -1, 1, 0, 0, 0 ], [ 2, -1, 1, -1, 0, 0 ], [ 1, 0, 1, -1, 0, 0 ], [ 0, 0, 1, -1, 0, 0 ] ], 1 ], - [ [ [ 1, -1, 1, 0, 0, 0 ], [ 2, -1, 1, -1, 0, 0 ], [ 1, 0, 1, -1, 0, 0 ], [ 1, -1, 1, -1, 0, 0 ] ], 1 ], - [ [ [ 2, 0, 1, -1, 0, 0 ], [ 2, -1, 1, -1, 0, 0 ], [ 1, 0, 1, -1, 0, 0 ], [ 1, -1, 1, -1, 0, 0 ] ], 1.5 ] - ], - [ - [ [ [ 2, 0, 1, -1, 0, 0 ], [ 2, -1, 1, -1, 0, 0 ], [ 1, 0, 1, -1, 0, 0 ], [ 2, -1, 1, -2, 0, 0 ] ], 1 ], - [ [ [ 3, 0, 1, -2, 0, 0 ], [ 2, -1, 1, -1, 0, 0 ], [ 1, 0, 1, -1, 0, 0 ], [ 2, -1, 1, -2, 0, 0 ] ], 1.75 ] - ], - [ - [ [ [ 3, 0, 1, -2, 0, 0 ], [ 1, 1, 1, -2, 0, 0 ], [ 1, 0, 1, -1, 0, 0 ], [ 2, -1, 1, -2, 0, 0 ] ], 1 ], - [ [ [ 3, 0, 1, -2, 0, 0 ], [ 1, 1, 1, -2, 0, 0 ], [ 1, 0, 1, -2, 0, 0 ], [ 2, -1, 1, -2, 0, 0 ] ], 3.625 ] - ], - [ - [ [ [ 3, 0, 1, -2, 0, 0 ], [ 1, 1, 1, -2, 0, 0 ], [ 1, 0, 1, -2, 0, 0 ], [ 0, 1, 1, -2, 0, 0 ] ], 1.5 ] - ], - [ - [ [ [ 3, 0, 1, -2, 0, 0 ], [ 1, 1, 1, -2, 0, 0 ], [ 0, 2, 1, -2, 0, 0 ], [ 0, 1, 1, -2, 0, 0 ] ], 3 ] - ], - [ - [ [ [ 2, 1, 1, -2, 0, 0 ], [ 1, 1, 1, -2, 0, 0 ], [ 0, 2, 1, -2, 0, 0 ], [ 0, 1, 1, -2, 0, 0 ] ], 1 ], - [ [ [ 2, 1, 1, -2, 0, 0 ], [ 1, 1, 1, -2, 0, 0 ], [ 0, 2, 1, -2, 0, 0 ], [ -1, 3, 1, -2, 0, 0 ] ], 1 ], - [ [ [ 2, 1, 1, -2, 0, 0 ], [ 1, 2, 1, -2, 0, 0 ], [ 0, 2, 1, -2, 0, 0 ], [ -1, 3, 1, -2, 0, 0 ] ], 1.75 ] - ], - [ - [ [ [ 1, 3, 1, -2, 0, 0 ], [ 1, 2, 1, -2, 0, 0 ], [ 0, 2, 1, -2, 0, 0 ], [ -1, 3, 1, -2, 0, 0 ] ], 1 ], - [ [ [ 1, 3, 1, -2, 0, 0 ], [ 0, 3, 1, -2, 0, 0 ], [ 0, 2, 1, -2, 0, 0 ], [ -1, 3, 1, -2, 0, 0 ] ], 2.5 ] - ], - [ - [ [ [ 1, 3, 1, -2, 0, 0 ], [ 0, 3, 1, -2, 0, 0 ], [ 0, 2, 1, -2, 0, 0 ], [ 0, 2, 0, -2, 0, 0 ] ], 1.75 ] - ], - [ - [ [ [ 1, 3, 1, -2, 0, 0 ], [ 0, 3, 1, -2, 0, 0 ], [ 0, 2, 1, -2, 0, 0 ], [ 0, 1, 1, -2, 0, 0 ] ], 1.125 ] - ], - [ - [ [ [ 1, 3, 1, -2, 0, 0 ], [ 0, 3, 1, -2, 0, 0 ], [ -1, 1, 1, -1, 0, 0 ], [ 0, 1, 1, -2, 0, 0 ] ], 1 ], - [ [ [ 1, 3, 1, -2, 0, 0 ], [ 0, 2, 1, -2, 0, 0 ], [ -1, 1, 1, -1, 0, 0 ], [ 0, 1, 1, -2, 0, 0 ] ], 1 ], - [ [ [ 1, 2, 1, -2, 0, 0 ], [ 0, 2, 1, -2, 0, 0 ], [ -1, 1, 1, -1, 0, 0 ], [ 0, 1, 1, -2, 0, 0 ] ], 1.125 ] - ], - [ - [ [ [ 1, 1, 1, -2, 0, 1 ], [ 0, 2, 1, -2, 0, 0 ], [ -1, 1, 1, -1, 0, 0 ], [ 0, 1, 1, -2, 0, 0 ] ], 3.25 ] - ], - [ - [ [ [ 1, 1, 1, -2, 0, 1 ], [ 0, 1, 1, -2, 0, 1 ], [ -1, 1, 1, -1, 0, 0 ], [ 0, 1, 1, -2, 0, 0 ] ], 1.875 ] - ], - [ - [ [ [ 1, 1, 1, -2, 0, 1 ], [ 0, 1, 1, -2, 0, 1 ], [ -1, 1, 1, -1, 0, 0 ], [ -1, 1, 1, -1, 0, 1 ] ], 1 ], - [ [ [ 1, 1, 1, -1, 0, 0 ], [ 0, 1, 1, -2, 0, 1 ], [ -1, 1, 1, -1, 0, 0 ], [ -1, 1, 1, -1, 0, 1 ] ], 1 ], - [ [ [ 1, 1, 1, -1, 0, 0 ], [ 0, 1, 1, -1, 0, 0 ], [ -1, 1, 1, -1, 0, 0 ], [ -1, 1, 1, -1, 0, 1 ] ], 2.25 ] - ], - [ - [ [ [ 1, 1, 1, -1, 0, 0 ], [ 0, 1, 1, -1, 0, 0 ], [ -1, 1, 1, -1, 0, 0 ], [ 1, 0, 1, -1, 0, 0 ] ], 1 ], - [ [ [ 0, 2, 1, -1, 0, 0 ], [ 0, 1, 1, -1, 0, 0 ], [ -1, 1, 1, -1, 0, 0 ], [ 1, 0, 1, -1, 0, 0 ] ], 1 ], - [ [ [ 0, 2, 1, -1, 0, 0 ], [ 0, 1, 1, -1, 0, 0 ], [ -1, 2, 1, -1, 0, 0 ], [ 1, 0, 1, -1, 0, 0 ] ], 2.625 ] - ], - [ - [ [ [ 0, 2, 1, -1, 0, 0 ], [ 0, 1, 1, -1, 0, 0 ], [ -1, 2, 1, -1, 0, 0 ], [ -1, 3, 1, -1, 0, 0 ] ], 1 ], - [ [ [ 0, 2, 1, -1, 0, 0 ], [ -2, 3, 1, -1, 0, 0 ], [ -1, 2, 1, -1, 0, 0 ], [ -1, 3, 1, -1, 0, 0 ] ], 2.75 ] - ], - [ - [ [ [ 0, 2, 1, -1, 0, 0 ], [ -2, 3, 1, -1, 0, 0 ], [ -2, 4, 1, -1, 0, 0 ], [ -1, 3, 1, -1, 0, 0 ] ], 3.5 ] - ], - [ - [ [ [ 0, 2, 1, -1, 0, 0 ], [ -2, 3, 1, -1, 0, 0 ], [ -2, 4, 1, -1, 0, 0 ], [ -1, 3, 0, -1, 0, 0 ] ], 1 ], - [ [ [ -1, 3, 1, -1, 0, 0 ], [ -2, 3, 1, -1, 0, 0 ], [ -2, 4, 1, -1, 0, 0 ], [ -1, 3, 0, -1, 0, 0 ] ], 1 ], - [ [ [ -1, 3, 1, -1, 0, 0 ], [ -2, 3, 1, -1, 0, 0 ], [ -3, 3, 1, 0, 0, 0 ], [ -1, 3, 0, -1, 0, 0 ] ], 1.875 ] - ], - [ - [ [ [ -1, 3, 1, -1, 0, 0 ], [ -2, 3, 1, -1, 0, 0 ], [ -3, 3, 1, 0, 0, 0 ], [ -2, 3, 1, 0, 0, 0 ] ], 2.75 ] - ], - [ - [ [ [ -1, 3, 1, -1, 0, 0 ], [ -2, 3, 1, -1, 0, 0 ], [ -3, 3, 1, 0, 0, 0 ], [ -2, 3, 2, -1, 0, 0 ] ], 2.375 ] - ], - [ - [ [ [ -2, 3, 2, 0, 0, 0 ], [ -2, 3, 1, -1, 0, 0 ], [ -3, 3, 1, 0, 0, 0 ], [ -2, 3, 2, -1, 0, 0 ] ], 1 ], - [ [ [ -2, 3, 2, 0, 0, 0 ], [ -2, 3, 1, -1, 0, 0 ], [ -3, 3, 1, 0, 0, 0 ], [ -2, 3, 0, 0, 0, 0 ] ], 1 ], - [ [ [ -2, 3, 2, 0, 0, 0 ], [ -3, 3, 2, 0, 0, 0 ], [ -3, 3, 1, 0, 0, 0 ], [ -2, 3, 0, 0, 0, 0 ] ], 3.25 ] - ], - [ - [ [ [ -2, 3, 2, 0, 0, 0 ], [ -3, 3, 2, 0, 0, 0 ], [ -3, 3, 1, 0, 0, 0 ], [ -2, 3, 2, 0, -1, 0 ] ], 1 ], - [ [ [ -2, 3, 2, 0, 0, 0 ], [ -3, 4, 2, 0, 0, 0 ], [ -3, 3, 1, 0, 0, 0 ], [ -2, 3, 2, 0, -1, 0 ] ], 1 ], - [ [ [ -2, 3, 2, 0, 0, 0 ], [ -3, 4, 2, 0, 0, 0 ], [ -4, 3, 2, 1, 0, 0 ], [ -2, 3, 2, 0, -1, 0 ] ], 1.125 ] - ], - [ - [ [ [ -2, 3, 2, 0, 0, 0 ], [ -3, 4, 2, 0, 0, 0 ], [ -4, 3, 2, 1, 0, 0 ], [ -3, 2, 2, 1, 0, 0 ] ], 1 ], - [ [ [ -3, 4, 1, 0, 0, 0 ], [ -3, 4, 2, 0, 0, 0 ], [ -4, 3, 2, 1, 0, 0 ], [ -3, 2, 2, 1, 0, 0 ] ], 1.25 ] - ], - [ - [ [ [ -3, 3, 2, 1, 0, 0 ], [ -3, 4, 2, 0, 0, 0 ], [ -4, 3, 2, 1, 0, 0 ], [ -3, 2, 2, 1, 0, 0 ] ], 1 ], - [ [ [ -3, 3, 2, 1, 0, 0 ], [ -3, 4, 2, 0, 0, 0 ], [ -3, 3, 2, 0, 0, 0 ], [ -3, 2, 2, 1, 0, 0 ] ], 2.375 ] - ], - [ - [ [ [ -3, 4, 3, 0, 0, 0 ], [ -3, 4, 2, 0, 0, 0 ], [ -3, 3, 2, 0, 0, 0 ], [ -3, 2, 2, 1, 0, 0 ] ], 3 ] - ], - [ - [ [ [ -3, 4, 3, 0, 0, 0 ], [ -3, 4, 2, 0, 0, 0 ], [ -3, 4, 3, -1, 0, 0 ], [ -3, 2, 2, 1, 0, 0 ] ], 1 ], - [ [ [ -3, 4, 3, 0, 0, 0 ], [ -3, 4, 2, 0, 0, 0 ], [ -3, 4, 3, -1, 0, 0 ], [ -3, 3, 3, 0, 0, 0 ] ], 1 ], - [ [ [ -3, 4, 3, 0, 0, 0 ], [ -2, 3, 3, 0, 0, 0 ], [ -3, 4, 3, -1, 0, 0 ], [ -3, 3, 3, 0, 0, 0 ] ], 2.75 ] - ], - [ - [ [ [ -3, 4, 3, 0, 0, 0 ], [ -2, 3, 3, 0, 0, 0 ], [ -4, 4, 3, 0, 0, 0 ], [ -3, 3, 3, 0, 0, 0 ] ], 1 ], - [ [ [ -3, 4, 3, 0, 0, 0 ], [ -3, 5, 3, 0, 0, 0 ], [ -4, 4, 3, 0, 0, 0 ], [ -3, 3, 3, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -3, 4, 3, 0, 0, 0 ], [ -3, 5, 3, 0, 0, 0 ], [ -4, 4, 3, 0, 0, 0 ], [ -4, 5, 3, 0, 0, 0 ] ], 3.5 ] - ], - [ - [ [ [ -3, 4, 3, 0, 0, 0 ], [ -3, 5, 3, 0, 0, 0 ], [ -4, 4, 3, 0, 0, 0 ], [ -3, 4, 2, 0, 0, 0 ] ], 1 ], - [ [ [ -3, 4, 3, 0, 0, 0 ], [ -3, 5, 3, 0, 0, 0 ], [ -3, 3, 3, 0, 0, 0 ], [ -3, 4, 2, 0, 0, 0 ] ], 1 ], - [ [ [ -3, 4, 3, 0, 0, 0 ], [ -2, 4, 2, 0, 0, 0 ], [ -3, 3, 3, 0, 0, 0 ], [ -3, 4, 2, 0, 0, 0 ] ], 1.875 ] - ], - [ - [ [ [ -3, 4, 3, 0, 0, 0 ], [ -2, 3, 3, 0, 0, 0 ], [ -3, 3, 3, 0, 0, 0 ], [ -3, 4, 2, 0, 0, 0 ] ], 1 ], - [ [ [ -2, 3, 2, 0, 0, 0 ], [ -2, 3, 3, 0, 0, 0 ], [ -3, 3, 3, 0, 0, 0 ], [ -3, 4, 2, 0, 0, 0 ] ], 2.5 ] - ], - [ - [ [ [ -2, 4, 3, 0, 0, 0 ], [ -2, 3, 3, 0, 0, 0 ], [ -3, 3, 3, 0, 0, 0 ], [ -3, 4, 2, 0, 0, 0 ] ], 1 ], - [ [ [ -2, 4, 3, 0, 0, 0 ], [ -2, 3, 3, 0, 0, 0 ], [ -3, 4, 3, 0, 0, 0 ], [ -3, 4, 2, 0, 0, 0 ] ], 3.25 ] - ], - [ - [ [ [ -1, 3, 2, 0, 0, 0 ], [ -2, 3, 3, 0, 0, 0 ], [ -3, 4, 3, 0, 0, 0 ], [ -3, 4, 2, 0, 0, 0 ] ], 1 ], - [ [ [ -1, 3, 2, 0, 0, 0 ], [ -3, 5, 3, 0, 0, 0 ], [ -3, 4, 3, 0, 0, 0 ], [ -3, 4, 2, 0, 0, 0 ] ], 2.625 ] - ], - [ - [ [ [ -1, 3, 2, 0, 0, 0 ], [ -2, 4, 2, 0, 0, 0 ], [ -3, 4, 3, 0, 0, 0 ], [ -3, 4, 2, 0, 0, 0 ] ], 1.125 ] - ], - [ - [ [ [ -1, 3, 2, 0, 0, 0 ], [ -2, 4, 2, 0, 0, 0 ], [ -3, 4, 3, 0, 0, 0 ], [ -3, 3, 2, 0, 0, 0 ] ], 1.625 ] - ], - [ - [ [ [ -1, 3, 2, 0, 0, 0 ], [ -2, 4, 2, 0, 0, 0 ], [ -2, 3, 2, 0, 0, 0 ], [ -3, 3, 2, 0, 0, 0 ] ], 2.75 ] - ], - [ - [ [ [ -1, 3, 2, 0, 0, 0 ], [ -2, 4, 2, 0, 0, 0 ], [ -3, 4, 2, 0, 0, 0 ], [ -3, 3, 2, 0, 0, 0 ] ], 1 ], - [ [ [ -1, 3, 2, 0, 0, 0 ], [ -2, 4, 2, 0, 0, 0 ], [ -3, 4, 2, 0, 0, 0 ], [ -4, 5, 2, 0, 0, 0 ] ], 2 ] - ], - [ - [ [ [ -2, 5, 2, 0, 0, 0 ], [ -2, 4, 2, 0, 0, 0 ], [ -3, 4, 2, 0, 0, 0 ], [ -4, 5, 2, 0, 0, 0 ] ], 1 ], - [ [ [ -2, 5, 2, 0, 0, 0 ], [ -3, 5, 2, 0, 0, 0 ], [ -3, 4, 2, 0, 0, 0 ], [ -4, 5, 2, 0, 0, 0 ] ], 3.25 ] - ], - [ - [ [ [ -2, 5, 2, 0, 0, 0 ], [ -3, 5, 2, 0, 0, 0 ], [ -4, 6, 2, 0, 0, 0 ], [ -4, 5, 2, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 5, 2, 0, 0, 0 ], [ -3, 5, 2, 0, 0, 0 ], [ -3, 5, 1, 0, 0, 0 ], [ -4, 5, 2, 0, 0, 0 ] ], 1 ], - [ [ [ -2, 5, 2, 0, 0, 0 ], [ -3, 4, 2, 0, 0, 0 ], [ -3, 5, 1, 0, 0, 0 ], [ -4, 5, 2, 0, 0, 0 ] ], 1 ], - [ [ [ -1, 5, 2, -1, 0, 0 ], [ -3, 4, 2, 0, 0, 0 ], [ -3, 5, 1, 0, 0, 0 ], [ -4, 5, 2, 0, 0, 0 ] ], 1.375 ] - ], - [ - [ [ [ -1, 5, 2, -1, 0, 0 ], [ -3, 4, 2, 0, 0, 0 ], [ -3, 5, 1, 0, 0, 0 ], [ -3, 5, 2, -1, 0, 0 ] ], 1 ], - [ [ [ -1, 5, 2, -1, 0, 0 ], [ -3, 5, 1, -1, 0, 0 ], [ -3, 5, 1, 0, 0, 0 ], [ -3, 5, 2, -1, 0, 0 ] ], 1.875 ] - ], - [ - [ [ [ -1, 5, 2, -1, 0, 0 ], [ -3, 5, 1, -1, 0, 0 ], [ -3, 5, 1, 0, 0, 0 ], [ -2, 4, 1, -1, 0, 0 ] ], 2.875 ] - ], - [ - [ [ [ -1, 5, 2, -1, 0, 0 ], [ -3, 5, 1, -1, 0, 0 ], [ -2, 5, 1, -1, 0, 0 ], [ -2, 4, 1, -1, 0, 0 ] ], 1 ], - [ [ [ -1, 5, 2, -1, 0, 0 ], [ -2, 4, 2, -1, 0, 0 ], [ -2, 5, 1, -1, 0, 0 ], [ -2, 4, 1, -1, 0, 0 ] ], 1 ], - [ [ [ 0, 3, 1, -1, 0, 0 ], [ -2, 4, 2, -1, 0, 0 ], [ -2, 5, 1, -1, 0, 0 ], [ -2, 4, 1, -1, 0, 0 ] ], 3.25 ] - ], - [ - [ [ [ 0, 3, 1, -1, 0, 0 ], [ -1, 3, 1, -1, 0, 0 ], [ -2, 5, 1, -1, 0, 0 ], [ -2, 4, 1, -1, 0, 0 ] ], 1 ], - [ [ [ 0, 3, 1, -1, 0, 0 ], [ -1, 3, 1, -1, 0, 0 ], [ -2, 5, 1, -1, 0, 0 ], [ -2, 3, 1, -1, 0, 0 ] ], 1.625 ] - ], - [ - [ [ [ 0, 3, 1, -1, 0, 0 ], [ -1, 3, 1, -1, 0, 0 ], [ -2, 5, 1, -1, 0, 0 ], [ -3, 5, 1, -1, 0, 0 ] ], 1 ], - [ [ [ 0, 3, 1, -1, 0, 0 ], [ -2, 4, 1, -1, 0, 0 ], [ -2, 5, 1, -1, 0, 0 ], [ -3, 5, 1, -1, 0, 0 ] ], 2.375 ] - ], - [ - [ [ [ 0, 3, 1, -1, 0, 0 ], [ -3, 6, 1, -1, 0, 0 ], [ -2, 5, 1, -1, 0, 0 ], [ -3, 5, 1, -1, 0, 0 ] ], 2.375 ] - ], - [ - [ [ [ 0, 3, 1, -1, 0, 0 ], [ -3, 6, 1, -1, 0, 0 ], [ -2, 4, 1, -1, 0, 0 ], [ -3, 5, 1, -1, 0, 0 ] ], 3.125 ] - ], - [ - [ [ [ 0, 3, 1, -1, 0, 0 ], [ -3, 6, 1, -1, 0, 0 ], [ -1, 3, 0, -1, 0, 0 ], [ -3, 5, 1, -1, 0, 0 ] ], 1 ], - [ [ [ 0, 3, 1, -1, 0, 0 ], [ -1, 4, 1, -1, 0, 0 ], [ -1, 3, 0, -1, 0, 0 ], [ -3, 5, 1, -1, 0, 0 ] ], 1 ], - [ [ [ 0, 3, 1, -1, 0, 0 ], [ -1, 4, 1, -1, 0, 0 ], [ -1, 3, 0, -1, 0, 0 ], [ -1, 3, 1, -1, 0, 0 ] ], 3.25 ] - ], - [ - [ [ [ 1, 2, 1, -1, 0, 0 ], [ -1, 4, 1, -1, 0, 0 ], [ -1, 3, 0, -1, 0, 0 ], [ -1, 3, 1, -1, 0, 0 ] ], 1 ], - [ [ [ 1, 2, 1, -1, 0, 0 ], [ 0, 3, 0, -1, 0, 0 ], [ -1, 3, 0, -1, 0, 0 ], [ -1, 3, 1, -1, 0, 0 ] ], 1.75 ] - ], - [ - [ [ [ 0, 4, 1, -1, 0, 0 ], [ 0, 3, 0, -1, 0, 0 ], [ -1, 3, 0, -1, 0, 0 ], [ -1, 3, 1, -1, 0, 0 ] ], 1 ], - [ [ [ 0, 4, 1, -1, 0, 0 ], [ 0, 2, 1, -1, 0, 0 ], [ -1, 3, 0, -1, 0, 0 ], [ -1, 3, 1, -1, 0, 0 ] ], 1 ], - [ [ [ 0, 4, 1, -1, 0, 0 ], [ 0, 2, 1, -1, 0, 0 ], [ -1, 2, 1, -1, 0, 0 ], [ -1, 3, 1, -1, 0, 0 ] ], 1.75 ] - ], - [ - [ [ [ 0, 4, 1, -1, 0, 0 ], [ -2, 4, 1, -1, 0, 0 ], [ -1, 2, 1, -1, 0, 0 ], [ -1, 3, 1, -1, 0, 0 ] ], 1 ], - [ [ [ 0, 4, 1, -1, 0, 0 ], [ -2, 4, 1, -1, 0, 0 ], [ -2, 3, 1, -1, 0, 0 ], [ -1, 3, 1, -1, 0, 0 ] ], 2.375 ] - ], - [ - [ [ [ 0, 4, 1, -1, 0, 0 ], [ -2, 4, 1, -1, 0, 0 ], [ -2, 3, 1, -1, 0, 0 ], [ 0, 3, 1, -2, 0, 0 ] ], 1 ], - [ [ [ 0, 3, 1, -1, 0, 0 ], [ -2, 4, 1, -1, 0, 0 ], [ -2, 3, 1, -1, 0, 0 ], [ 0, 3, 1, -2, 0, 0 ] ], 1 ], - [ [ [ 0, 3, 1, -1, 0, 0 ], [ -1, 3, 1, -1, 0, 0 ], [ -2, 3, 1, -1, 0, 0 ], [ 0, 3, 1, -2, 0, 0 ] ], 3.25 ] - ], - [ - [ [ [ 0, 3, 1, -1, 0, 0 ], [ -1, 3, 1, -2, 0, 0 ], [ -2, 3, 1, -1, 0, 0 ], [ 0, 3, 1, -2, 0, 0 ] ], 1.375 ] - ], - [ - [ [ [ 0, 3, 1, -1, 0, 0 ], [ -1, 3, 1, -1, 0, -1 ], [ -2, 3, 1, -1, 0, 0 ], [ 0, 3, 1, -2, 0, 0 ] ], 1 ], - [ [ [ 0, 3, 1, -1, 0, 0 ], [ -1, 3, 1, -1, 0, -1 ], [ -2, 3, 1, -1, 0, 0 ], [ 0, 3, 1, -1, 0, -1 ] ], 1 ], - [ [ [ 0, 3, 1, -1, 0, 0 ], [ -1, 3, 1, -1, 0, -1 ], [ -2, 4, 1, -1, 0, 0 ], [ 0, 3, 1, -1, 0, -1 ] ], 1.25 ] - ], - [ - [ [ [ 0, 3, 1, -1, 0, 0 ], [ -1, 2, 1, -1, 0, 0 ], [ -2, 4, 1, -1, 0, 0 ], [ 0, 3, 1, -1, 0, -1 ] ], 2.75 ] - ], - [ - [ [ [ -1, 3, 1, 0, 0, -1 ], [ -1, 2, 1, -1, 0, 0 ], [ -2, 4, 1, -1, 0, 0 ], [ 0, 3, 1, -1, 0, -1 ] ], 1 ], - [ [ [ -1, 3, 1, 0, 0, -1 ], [ -1, 3, 1, -1, 0, 0 ], [ -2, 4, 1, -1, 0, 0 ], [ 0, 3, 1, -1, 0, -1 ] ], 1 ], - [ [ [ -1, 3, 1, 0, 0, -1 ], [ -1, 3, 1, -1, 0, 0 ], [ -1, 3, 1, -1, 0, -1 ], [ 0, 3, 1, -1, 0, -1 ] ], 1.5 ] - ], - [ - [ [ [ -1, 3, 1, 0, 0, -1 ], [ -2, 3, 1, 0, 0, -1 ], [ -1, 3, 1, -1, 0, -1 ], [ 0, 3, 1, -1, 0, -1 ] ], 1.625 ] - ], - [ - [ [ [ 0, 4, 1, -1, 0, -1 ], [ -2, 3, 1, 0, 0, -1 ], [ -1, 3, 1, -1, 0, -1 ], [ 0, 3, 1, -1, 0, -1 ] ], 1 ], - [ [ [ 0, 4, 1, -1, 0, -1 ], [ -2, 3, 1, 0, 0, -1 ], [ -1, 3, 1, -1, 0, -1 ], [ -1, 4, 1, -1, 0, -1 ] ], 1 ], - [ [ [ 0, 4, 1, -1, 0, -1 ], [ -2, 4, 1, -1, 0, -1 ], [ -1, 3, 1, -1, 0, -1 ], [ -1, 4, 1, -1, 0, -1 ] ], 3 ] - ], - [ - [ [ [ 0, 4, 1, -1, 0, -1 ], [ -2, 4, 1, -1, 0, -1 ], [ -1, 3, 1, -1, 0, -1 ], [ -2, 4, 1, 0, 0, -1 ] ], 1 ], - [ [ [ 1, 3, 0, -1, 0, -1 ], [ -2, 4, 1, -1, 0, -1 ], [ -1, 3, 1, -1, 0, -1 ], [ -2, 4, 1, 0, 0, -1 ] ], 2.625 ] - ], - [ - [ [ [ 1, 3, 0, -1, 0, -1 ], [ -2, 4, 1, -1, 0, -1 ], [ -1, 3, 1, -1, 0, -1 ], [ -1, 4, 2, -1, 0, -1 ] ], 1 ], - [ [ [ 0, 3, 1, -1, 0, -1 ], [ -2, 4, 1, -1, 0, -1 ], [ -1, 3, 1, -1, 0, -1 ], [ -1, 4, 2, -1, 0, -1 ] ], 1 ], - [ [ [ 0, 3, 1, -1, 0, -1 ], [ -2, 4, 1, -1, 0, -1 ], [ -1, 4, 1, -1, 0, -1 ], [ -1, 4, 2, -1, 0, -1 ] ], 2.75 ] - ], - [ - [ [ [ 0, 3, 1, -1, 0, -1 ], [ -3, 4, 2, 0, 0, -1 ], [ -1, 4, 1, -1, 0, -1 ], [ -1, 4, 2, -1, 0, -1 ] ], 2.375 ] - ], - [ - [ [ [ 0, 3, 1, -1, 0, -1 ], [ -3, 4, 2, 0, 0, -1 ], [ -1, 4, 1, -1, 0, -1 ], [ -1, 4, 2, 0, 0, -2 ] ], 3.375 ] - ], - [ - [ [ [ 0, 3, 1, -1, 0, -1 ], [ -3, 4, 2, 0, 0, -1 ], [ -1, 4, 1, -1, 0, -1 ], [ -1, 3, 2, -1, 0, -1 ] ], 2.875 ] - ], - [ - [ [ [ -1, 5, 1, -1, 0, -1 ], [ -3, 4, 2, 0, 0, -1 ], [ -1, 4, 1, -1, 0, -1 ], [ -1, 3, 2, -1, 0, -1 ] ], 1 ], - [ [ [ -1, 5, 1, -1, 0, -1 ], [ -2, 4, 2, -1, 0, -1 ], [ -1, 4, 1, -1, 0, -1 ], [ -1, 3, 2, -1, 0, -1 ] ], 1 ], - [ [ [ -1, 5, 1, -1, 0, -1 ], [ -2, 4, 2, -1, 0, -1 ], [ -1, 4, 1, -1, 0, -1 ], [ -1, 3, 1, -1, 0, -1 ] ], 1.875 ] - ], - [ - [ [ [ -1, 5, 1, -1, 0, -1 ], [ -2, 4, 1, -1, 0, -1 ], [ -1, 4, 1, -1, 0, -1 ], [ -1, 3, 1, -1, 0, -1 ] ], 3.25 ] - ], - [ - [ [ [ -1, 5, 1, -1, 0, -1 ], [ -2, 5, 1, -1, -1, -1 ], [ -1, 4, 1, -1, 0, -1 ], [ -1, 3, 1, -1, 0, -1 ] ], 1 ], - [ [ [ -1, 5, 1, -1, 0, -1 ], [ -2, 5, 1, -1, -1, -1 ], [ -2, 5, 1, -1, 0, -1 ], [ -1, 3, 1, -1, 0, -1 ] ], 3.625 ] - ], - [ - [ [ [ -1, 5, 1, -1, 0, -1 ], [ -1, 4, 1, -1, 0, -1 ], [ -2, 5, 1, -1, 0, -1 ], [ -1, 3, 1, -1, 0, -1 ] ], 1 ], - [ [ [ -1, 5, 1, -1, 0, -1 ], [ -1, 4, 1, -1, 0, -1 ], [ -2, 5, 1, -1, 0, -1 ], [ -2, 4, 1, -1, 0, -1 ] ], 3.25 ] - ], - [ - [ [ [ -1, 5, 1, -1, 0, -1 ], [ -1, 4, 1, -1, 0, -1 ], [ -2, 5, 1, -1, 0, -1 ], [ -3, 6, 1, -1, 0, -1 ] ], 1.375 ] - ], - [ - [ [ [ -1, 5, 1, -1, 0, -1 ], [ -1, 4, 1, -1, 0, -1 ], [ -3, 7, 1, -1, 0, -1 ], [ -3, 6, 1, -1, 0, -1 ] ], 1.125 ] - ], - [ - [ [ [ -1, 5, 1, -1, 0, -1 ], [ -2, 6, 1, -1, 0, -1 ], [ -3, 7, 1, -1, 0, -1 ], [ -3, 6, 1, -1, 0, -1 ] ], 1.5 ] - ], - [ - [ [ [ -2, 7, 1, -1, 0, -1 ], [ -2, 6, 1, -1, 0, -1 ], [ -3, 7, 1, -1, 0, -1 ], [ -3, 6, 1, -1, 0, -1 ] ], 1 ], - [ [ [ -2, 7, 1, -1, 0, -1 ], [ -2, 6, 1, -1, 0, -1 ], [ -2, 6, 0, -1, 0, -1 ], [ -3, 6, 1, -1, 0, -1 ] ], 2.375 ] - ], - [ - [ [ [ -1, 6, 0, -1, 0, -1 ], [ -2, 6, 1, -1, 0, -1 ], [ -2, 6, 0, -1, 0, -1 ], [ -3, 6, 1, -1, 0, -1 ] ], 3.625 ] - ], - [ - [ [ [ -1, 6, 0, -1, 0, -1 ], [ -2, 6, 1, -1, 0, -1 ], [ -2, 6, 0, -1, 0, -1 ], [ -2, 5, 0, -1, 0, -1 ] ], 1 ], - [ [ [ -4, 6, 1, 0, 0, -1 ], [ -2, 6, 1, -1, 0, -1 ], [ -2, 6, 0, -1, 0, -1 ], [ -2, 5, 0, -1, 0, -1 ] ], 2.125 ] - ], - [ - [ [ [ -3, 6, 1, -1, 0, -1 ], [ -2, 6, 1, -1, 0, -1 ], [ -2, 6, 0, -1, 0, -1 ], [ -2, 5, 0, -1, 0, -1 ] ], 1 ], - [ [ [ -3, 6, 1, -1, 0, -1 ], [ -1, 5, 0, -1, 0, -1 ], [ -2, 6, 0, -1, 0, -1 ], [ -2, 5, 0, -1, 0, -1 ] ], 3.375 ] - ], - [ - [ [ [ -3, 6, 0, -1, 0, -1 ], [ -1, 5, 0, -1, 0, -1 ], [ -2, 6, 0, -1, 0, -1 ], [ -2, 5, 0, -1, 0, -1 ] ], 1 ], - [ [ [ -3, 6, 0, -1, 0, -1 ], [ -1, 5, 0, -1, 0, -1 ], [ -2, 6, 0, -1, 0, -1 ], [ -3, 7, 0, -1, 0, -1 ] ], 1.625 ] - ], - [ - [ [ [ -3, 6, 0, -1, 0, -1 ], [ -1, 5, 0, -1, 0, -1 ], [ -2, 6, 0, -1, 0, -1 ], [ -2, 6, -1, -1, 0, -1 ] ], 1 ], - [ [ [ -3, 6, 0, -1, 0, -1 ], [ -2, 7, 0, -1, 0, -1 ], [ -2, 6, 0, -1, 0, -1 ], [ -2, 6, -1, -1, 0, -1 ] ], 1 ], - [ [ [ -3, 6, 0, -1, 0, -1 ], [ -2, 7, 0, -1, 0, -1 ], [ -2, 6, 0, -1, 1, -1 ], [ -2, 6, -1, -1, 0, -1 ] ], 1.75 ] - ], - [ - [ [ [ -3, 6, 0, -1, 0, -1 ], [ -2, 7, 0, -1, 0, -1 ], [ -2, 6, 0, -1, 1, -1 ], [ -2, 6, 0, -1, 0, -1 ] ], 1 ], - [ [ [ -3, 7, 0, -1, 0, -1 ], [ -2, 7, 0, -1, 0, -1 ], [ -2, 6, 0, -1, 1, -1 ], [ -2, 6, 0, -1, 0, -1 ] ], 2.625 ] - ], - [ - [ [ [ -3, 7, 0, -1, 0, -1 ], [ -2, 7, 0, -1, 0, -1 ], [ -2, 6, 0, -1, 1, -1 ], [ -3, 6, 0, -1, 1, -1 ] ], 1 ], - [ [ [ -2, 6, 0, -1, 1, -2 ], [ -2, 7, 0, -1, 0, -1 ], [ -2, 6, 0, -1, 1, -1 ], [ -3, 6, 0, -1, 1, -1 ] ], 2.25 ] - ], - [ - [ [ [ -2, 6, 0, -1, 1, -2 ], [ -2, 7, 0, -1, 0, -1 ], [ -3, 7, 0, -1, 1, -1 ], [ -3, 6, 0, -1, 1, -1 ] ], 2.125 ] - ], - [ - [ [ [ -2, 6, 0, -1, 1, -2 ], [ -2, 7, -1, -1, 1, -1 ], [ -3, 7, 0, -1, 1, -1 ], [ -3, 6, 0, -1, 1, -1 ] ], 1.375 ] - ], - [ - [ [ [ -3, 6, -1, -1, 1, -1 ], [ -2, 7, -1, -1, 1, -1 ], [ -3, 7, 0, -1, 1, -1 ], [ -3, 6, 0, -1, 1, -1 ] ], 1 ], - [ [ [ -3, 6, -1, -1, 1, -1 ], [ -2, 7, -1, -1, 1, -1 ], [ -3, 7, 0, -1, 1, -1 ], [ -3, 7, -1, -1, 1, -1 ] ], 1.5 ] - ], - [ - [ [ [ -3, 6, -1, -1, 1, -1 ], [ -2, 7, -1, -1, 1, -1 ], [ -2, 6, -1, -1, 1, -1 ], [ -3, 7, -1, -1, 1, -1 ] ], 3.125 ] - ], - [ - [ [ [ -1, 7, -1, -1, 1, -1 ], [ -2, 7, -1, -1, 1, -1 ], [ -2, 6, -1, -1, 1, -1 ], [ -3, 7, -1, -1, 1, -1 ] ], 1 ], - [ [ [ -1, 7, -1, -1, 1, -1 ], [ -2, 7, -1, -1, 1, -1 ], [ -3, 8, -1, -1, 1, -1 ], [ -3, 7, -1, -1, 1, -1 ] ], 2.625 ] - ], - [ - [ [ [ -1, 7, -1, -1, 1, -1 ], [ -2, 7, -1, -2, 1, -1 ], [ -3, 8, -1, -1, 1, -1 ], [ -3, 7, -1, -1, 1, -1 ] ], 1 ], - [ [ [ -2, 9, -1, -1, 1, -1 ], [ -2, 7, -1, -2, 1, -1 ], [ -3, 8, -1, -1, 1, -1 ], [ -3, 7, -1, -1, 1, -1 ] ], 2.625 ] - ], - [ - [ [ [ -2, 9, -1, -1, 1, -1 ], [ -2, 7, -1, -2, 1, -1 ], [ -3, 8, -1, -1, 1, -1 ], [ -4, 9, -1, -1, 1, -1 ] ], 1 ], - [ [ [ -2, 9, -1, -1, 1, -1 ], [ -2, 7, -1, -2, 1, -1 ], [ -4, 10, -1, -1, 1, -1 ], [ -4, 9, -1, -1, 1, -1 ] ], 3.5 ] - ], - [ - [ [ [ -2, 9, -1, -2, 1, -1 ], [ -2, 7, -1, -2, 1, -1 ], [ -4, 10, -1, -1, 1, -1 ], [ -4, 9, -1, -1, 1, -1 ] ], 1 ], - [ [ [ -2, 9, -1, -2, 1, -1 ], [ -4, 8, -1, -1, 1, -1 ], [ -4, 10, -1, -1, 1, -1 ], [ -4, 9, -1, -1, 1, -1 ] ], 3.125 ] - ], - [ - [ [ [ -2, 9, -1, -2, 1, -1 ], [ -4, 8, -1, -1, 1, -1 ], [ -3, 9, -2, -1, 1, -1 ], [ -4, 9, -1, -1, 1, -1 ] ], 1.25 ] - ], - [ - [ [ [ -2, 9, -1, -2, 1, -1 ], [ -4, 8, -1, -1, 1, -1 ], [ -3, 9, -2, -1, 1, -1 ], [ -3, 9, -1, -2, 1, -1 ] ], 3.125 ] - ], - [ - [ [ [ -2, 8, -1, -2, 1, -1 ], [ -4, 8, -1, -1, 1, -1 ], [ -3, 9, -2, -1, 1, -1 ], [ -3, 9, -1, -2, 1, -1 ] ], 1 ], - [ [ [ -2, 8, -1, -2, 1, -1 ], [ -4, 8, -1, -1, 1, -1 ], [ -3, 9, -2, -1, 1, -1 ], [ -3, 8, -1, -2, 1, -1 ] ], 1 ], - [ [ [ -2, 8, -1, -2, 1, -1 ], [ -4, 8, -1, -1, 1, -1 ], [ -3, 8, -1, -1, 1, -1 ], [ -3, 8, -1, -2, 1, -1 ] ], 2.375 ] - ], - [ - [ [ [ -2, 8, -1, -2, 1, -1 ], [ -4, 8, -1, -1, 1, -1 ], [ -3, 8, -1, -1, 1, -1 ], [ -4, 8, 0, -1, 1, -1 ] ], 1 ], - [ [ [ -2, 8, -1, -2, 1, -1 ], [ -4, 8, -1, -1, 1, -1 ], [ -2, 8, -1, -2, 0, -1 ], [ -4, 8, 0, -1, 1, -1 ] ], 2.875 ] - ], - [ - [ [ [ -2, 8, -1, -2, 1, -1 ], [ -4, 8, -1, -1, 1, -1 ], [ -3, 8, -1, -2, 1, 0 ], [ -4, 8, 0, -1, 1, -1 ] ], 1 ], - [ [ [ -2, 8, -1, -2, 1, -1 ], [ -4, 8, -1, -1, 1, -1 ], [ -3, 8, -1, -2, 1, 0 ], [ -3, 8, 0, -2, 1, -1 ] ], 1 ], - [ [ [ -2, 8, -1, -2, 1, -1 ], [ -3, 8, -1, -2, 1, -1 ], [ -3, 8, -1, -2, 1, 0 ], [ -3, 8, 0, -2, 1, -1 ] ], 1.625 ] - ], - [ - [ [ [ -2, 8, -1, -2, 1, -1 ], [ -4, 8, -1, -2, 1, 0 ], [ -3, 8, -1, -2, 1, 0 ], [ -3, 8, 0, -2, 1, -1 ] ], 1 ], - [ [ [ -2, 8, -1, -2, 1, -1 ], [ -4, 8, -1, -2, 1, 0 ], [ -3, 8, -1, -2, 1, 0 ], [ -3, 8, -1, -2, 0, -1 ] ], 1 ], - [ [ [ -2, 8, -1, -2, 1, -1 ], [ -4, 8, -1, -2, 1, 0 ], [ -3, 8, -1, -2, 1, -1 ], [ -3, 8, -1, -2, 0, -1 ] ], 1.875 ] - ], - [ - [ [ [ -2, 7, -1, -2, 1, -1 ], [ -4, 8, -1, -2, 1, 0 ], [ -3, 8, -1, -2, 1, -1 ], [ -3, 8, -1, -2, 0, -1 ] ], 1 ], - [ [ [ -2, 7, -1, -2, 1, -1 ], [ -4, 8, -1, -1, 1, -1 ], [ -3, 8, -1, -2, 1, -1 ], [ -3, 8, -1, -2, 0, -1 ] ], 2.125 ] - ], - [ - [ [ [ -2, 7, -1, -2, 1, -1 ], [ -4, 8, -1, -1, 1, -1 ], [ -2, 8, 0, -2, 0, -1 ], [ -3, 8, -1, -2, 0, -1 ] ], 1 ], - [ [ [ -2, 7, -1, -2, 1, -1 ], [ -3, 8, -1, -2, 1, -1 ], [ -2, 8, 0, -2, 0, -1 ], [ -3, 8, -1, -2, 0, -1 ] ], 1 ], - [ [ [ -2, 8, -1, -2, 0, -1 ], [ -3, 8, -1, -2, 1, -1 ], [ -2, 8, 0, -2, 0, -1 ], [ -3, 8, -1, -2, 0, -1 ] ], 1.75 ] - ], - [ - [ [ [ -3, 8, -1, -2, 1, 0 ], [ -3, 8, -1, -2, 1, -1 ], [ -2, 8, 0, -2, 0, -1 ], [ -3, 8, -1, -2, 0, -1 ] ], 1 ], - [ [ [ -3, 8, -1, -2, 1, 0 ], [ -3, 8, -1, -2, 1, -1 ], [ -2, 8, -1, -2, 1, -1 ], [ -3, 8, -1, -2, 0, -1 ] ], 3.375 ] - ], - [ - [ [ [ -3, 8, -1, -2, 1, 0 ], [ -3, 8, -1, -2, 1, -1 ], [ -2, 8, -1, -2, 1, -1 ], [ -3, 8, -2, -2, 1, -1 ] ], 2.125 ], - [ [ [ -3, 8, -1, -2, 1, 0 ], [ "Rest" ], [ -2, 8, -1, -2, 1, -1 ], [ -3, 8, -2, -2, 1, -1 ] ], 1 ], - [ [ [ -3, 8, -1, -2, 1, 0 ], [ "Rest" ], [ -2, 8, -1, -2, 1, -1 ], [ "Rest" ] ], 1 ], - [ [ [ -3, 8, -1, -2, 1, 0 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 1 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 3.25 ] - ] - ] -], -"last_changes": -[ - [ [ -2, 7, -1, -2, 1, -1 ], [ -3, 8, -1, -2, 1, -1 ], [ -2, 8, 0, -2, 0, -1 ], [ -3, 8, -1, -2, 0, -1 ] ], - [ [ -2, 8, -1, -2, 0, -1 ], [ -3, 8, -1, -2, 1, -1 ], [ -2, 8, 0, -2, 0, -1 ], [ -3, 8, -1, -2, 0, -1 ] ], - [ [ -3, 8, -1, -2, 1, 0 ], [ -3, 8, -1, -2, 1, -1 ], [ -2, 8, 0, -2, 0, -1 ], [ -3, 8, -1, -2, 0, -1 ] ], - [ [ -3, 8, -1, -2, 1, 0 ], [ -3, 8, -1, -2, 1, -1 ], [ -2, 8, -1, -2, 1, -1 ], [ -3, 8, -1, -2, 0, -1 ] ], - [ [ -3, 8, -1, -2, 1, 0 ], [ -3, 8, -1, -2, 1, -1 ], [ -2, 8, -1, -2, 1, -1 ], [ -3, 8, -2, -2, 1, -1 ] ] -], -"cur_uid": "tmp", -"ref_uid": "nil", -"order_seed": 389930, -"dur_seed": 362766, -"motifs_seed": 479673, -"entrances_probs_vals": [ 0, 0, 2.9365079365079, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 0, 0, 2.7380952380952, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 0, 0, 2.7380952380952, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -2400, 1200 ], [ -1200, 1200 ], [ -702, 1200 ], [ -702, 1200 ] ], -"step_probs_vals": [ -1200, 1200, 0.0020576131687243, 0.068181818181818, 0.074074074074074, 0.0625, 0.20576131687243, 0.0625, 0.45679012345679, 0.011363636363636, 0.53086419753086, 0, 0.54320987654321, 0.92045454545455, 0.58641975308642, 0.92613636363636, 0.61111111111111, 0, 0.78600823045268, 0.068181818181818, 0.98971193415638, 0.0625 ], -"passages_weights": [ 1, 1, 0.48, 1, 1 ], -"hd_exp": 10, -"hd_invert": 0, -"order": -[ - [ [ 2, 3, 1 ], [ 0 ], [ ] ], - [ [ 1, 3 ], [ 2, 0 ], [ ] ], - [ [ 0, 3 ], [ 2, 1 ], [ ] ], - [ [ 2, 3, 0 ], [ 1 ], [ ] ], - [ [ 1 ], [ 3, 0, 2 ], [ ] ], - [ [ 3, 1 ], [ 2, 0 ], [ ] ], - [ [ 2 ], [ 1, 3, 0 ], [ ] ], - [ [ 2, 1 ], [ 3, 0 ], [ ] ], - [ [ 0, 3 ], [ 1, 2 ], [ ] ], - [ [ 1, 2, 0 ], [ 3 ], [ ] ], - [ [ 1, 0, 3 ], [ 2 ], [ ] ], - [ [ 2 ], [ 0, 3, 1 ], [ ] ], - [ [ 3, 2 ], [ 0, 1 ], [ ] ], - [ [ 2, 1, 0 ], [ 3 ], [ ] ], - [ [ 0, 1, 2 ], [ 3 ], [ ] ], - [ [ 3 ], [ 2, 1, 0 ], [ ] ], - [ [ 3, 1, 2 ], [ 0 ], [ ] ], - [ [ 0, 3, 2 ], [ 1 ], [ ] ], - [ [ 2 ], [ 3, 0, 1 ], [ ] ], - [ [ 1 ], [ 3, 0, 2 ], [ ] ], - [ [ 2, 0 ], [ 3, 1 ], [ ] ], - [ [ 1, 3, 0 ], [ 2 ], [ ] ], - [ [ 1 ], [ 3, 0, 2 ], [ ] ], - [ [ 2, 1, 0 ], [ 3 ], [ ] ], - [ [ 0, 1, 2 ], [ 3 ], [ ] ], - [ [ 2 ], [ 0, 3, 1 ], [ ] ], - [ [ 0 ], [ 3, 1, 2 ], [ ] ], - [ [ 2, 1 ], [ 3, 0 ], [ ] ], - [ [ 1, 3 ], [ 0, 2 ], [ ] ], - [ [ 2, 1, 3 ], [ 0 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ], - [ [ 0, 3 ], [ 2, 1 ], [ ] ], - [ [ 0, 1, 2 ], [ 3 ], [ ] ], - [ [ 0 ], [ 3, 2, 1 ], [ ] ], - [ [ 2, 3 ], [ 1, 0 ], [ ] ], - [ [ 3, 1 ], [ 0, 2 ], [ ] ], - [ [ 3, 2 ], [ 0, 1 ], [ ] ], - [ [ 0, 2, 3 ], [ 1 ], [ ] ], - [ [ 1, 0, 2 ], [ 3 ], [ ] ], - [ [ 0, 3, 1 ], [ 2 ], [ ] ], - [ [ 1, 0 ], [ 2, 3 ], [ ] ], - [ [ 2, 3 ], [ 0, 1 ], [ ] ], - [ [ 0, 1, 3 ], [ 2 ], [ ] ], - [ [ 3 ], [ 2, 1, 0 ], [ ] ], - [ [ 2, 0 ], [ 3, 1 ], [ ] ], - [ [ 2, 1, 0 ], [ 3 ], [ ] ], - [ [ 3 ], [ 2, 1, 0 ], [ ] ], - [ [ 0, 2 ], [ 1, 3 ], [ ] ], - [ [ 0, 2 ], [ 3, 1 ], [ ] ], - [ [ 0, 2, 3 ], [ 1 ], [ ] ], - [ [ 0, 1, 3 ], [ 2 ], [ ] ], - [ [ 0 ], [ 2, 1, 3 ], [ ] ], - [ [ 3, 2 ], [ 0, 1 ], [ ] ], - [ [ 3 ], [ 0, 1, 2 ], [ ] ], - [ [ 3, 0 ], [ 1, 2 ], [ ] ], - [ [ 2 ], [ 3, 0, 1 ], [ ] ], - [ [ 0, 2, 3 ], [ 1 ], [ ] ], - [ [ 0 ], [ 1, 3, 2 ], [ ] ], - [ [ 2, 0, 3 ], [ 1 ], [ ] ], - [ [ 3 ], [ 0, 1, 2 ], [ ] ], - [ [ 3, 2, 0 ], [ 1 ], [ ] ], - [ [ 2 ], [ 0, 3, 1 ], [ ] ], - [ [ 1, 2 ], [ 3, 0 ], [ ] ], - [ [ 1 ], [ 3, 0, 2 ], [ ] ], - [ [ 0, 2, 3 ], [ 1 ], [ ] ], - [ [ 0, 2, 1 ], [ 3 ], [ ] ], - [ [ 1, 2, 0 ], [ 3 ], [ ] ], - [ [ 2 ], [ 0, 1, 3 ], [ ] ], - [ [ 0, 2, 3 ], [ 1 ], [ ] ], - [ [ 0, 3 ], [ 1, 2 ], [ ] ], - [ [ 2, 0 ], [ 1, 3 ], [ ] ], - [ [ 2, 1, 0 ], [ 3 ], [ ] ], - [ [ 1, 0, 3 ], [ 2 ], [ ] ], - [ [ 3, 0, 2 ], [ 1 ], [ ] ], - [ [ 1, 3 ], [ 0, 2 ], [ ] ], - [ [ 3, 2, 1 ], [ 0 ], [ ] ], - [ [ 1, 2 ], [ 3, 0 ], [ ] ], - [ [ 2, 3 ], [ 0, 1 ], [ ] ], - [ [ 1, 2 ], [ 0, 3 ], [ ] ], - [ [ 0 ], [ 3, 1, 2 ], [ ] ], - [ [ 1, 2 ], [ 3, 0 ], [ ] ], - [ [ 2, 1 ], [ 3, 0 ], [ ] ], - [ [ 0, 3, 1 ], [ 2 ], [ ] ], - [ [ 3, 0, 2 ], [ 1 ], [ ] ], - [ [ 2, 1 ], [ 0, 3 ], [ ] ], - [ [ 1, 0, 3 ], [ 2 ], [ ] ], - [ [ 3, 1 ], [ 0, 2 ], [ ] ], - [ [ 3, 2 ], [ 1, 0 ], [ ] ], - [ [ 0, 1 ], [ 3, 2 ], [ ] ], - [ [ 2, 3 ], [ 0, 1 ], [ ] ], - [ [ 3, 1, 0 ], [ 2 ], [ ] ], - [ [ 1, 0, 2 ], [ 3 ], [ ] ], - [ [ 1 ], [ 0, 3, 2 ], [ ] ], - [ [ 0, 1 ], [ 3, 2 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ], - [ [ 0 ], [ 1, 3, 2 ], [ ] ], - [ [ 2, 3 ], [ 0, 1 ], [ ] ], - [ [ 3 ], [ 2, 1, 0 ], [ ] ], - [ [ 3, 1 ], [ 0, 2 ], [ ] ], - [ [ 0, 2, 1 ], [ 3 ], [ ] ] -], -"sus_weights": [ 0.35, 0.37, 0.38 ], -"order_size": [ 100, 100 ], -"passages_size": [ 0, 0 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise.json b/resources/resources_bak_2024_01_03/string_quartet_3_rise.json deleted file mode 100644 index f1e7021..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise.json +++ /dev/null @@ -1,21 +0,0 @@ -{ -"ledger": -[ - "4874dd07", - "44490863", - "4bf1af12", - "6522664c", - "7ede7adb", - "521654f8", - "6db2efcc", - "4b40ed47", - "4e9f1dcc", - "78a94ed1", - "531df78c", - "7276dc78", - "43214be8", - "7c30c182", - "4ef018fc", - "615c4008" -] -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise.json_bak b/resources/resources_bak_2024_01_03/string_quartet_3_rise.json_bak deleted file mode 100644 index 3b179c3..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise.json_bak +++ /dev/null @@ -1,20 +0,0 @@ -{ -"ledger": -[ - "4874dd07", - "44490863", - "4bf1af12", - "6522664c", - "7ede7adb", - "521654f8", - "6db2efcc", - "4b40ed47", - "4e9f1dcc", - "78a94ed1", - "531df78c", - "7276dc78", - "43214be8", - "7c30c182", - "4ef018fc" -] -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/43214be8/43214be8_code.scd b/resources/resources_bak_2024_01_03/string_quartet_3_rise/43214be8/43214be8_code.scd deleted file mode 100644 index 42b64ff..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/43214be8/43214be8_code.scd +++ /dev/null @@ -1,981 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array2) - hsArrayToCents.value(array1); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -/* -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance) -}; -*/ - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = true; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - //if(pDistance >= 0, {stepFunc.value(abs(pDistance))}, {0.01}); - stepFunc.value(pDistance) -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - //tuples = dims.collect({[0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum == 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength.asInteger - minMotifLength.asInteger).rand + minMotifLength.asInteger).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - //noProgIns = (popSize - noSusIns).rand + 1; - noProgIns = (popSize - noSusIns); - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength.asInteger - minProgLength.asInteger).rand + minProgLength.asInteger).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0.01); - - - - /* - if(rangeScore.value(candidate.collect({0}), voices[ins], ranges[ins][1] - 500, ranges[ins][1], 0, true) == 1, { - isInRangeScore = 1 - rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0] + 500, ranges[ins][1] - 500, 0, true); - isInRangeScore = isInRangeScore * rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true) - }, { - isInRangeScore = rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true); - }); - */ - - - isInRangeScore = rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true); - //old way - worked but actually by accident (I think) - //isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - - - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - /* - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - */ - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - //lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - lastState = if(o == 0, {lastXChanges.last.deepCopy}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - /* - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - */ - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - //# voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - # voices, durs = seq.flatten2(if(oneShot, {2}, {3})).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(2).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/43214be8/43214be8_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_3_rise/43214be8/43214be8_mus_model.json deleted file mode 100644 index ec6964f..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/43214be8/43214be8_mus_model.json +++ /dev/null @@ -1,158 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ -7, 6, 4, -1, 1, 2 ], [ -5, 5, 4, 0, 0, 2 ], [ -6, 6, 4, 0, 0, 2 ], [ -6, 6, 4, 0, 1, 2 ] ], 1 ], - [ [ [ -6, 6, 4, -1, 0, 2 ], [ -5, 5, 4, 0, 0, 2 ], [ -6, 6, 4, 0, 0, 2 ], [ -6, 6, 4, 0, 1, 2 ] ], 1 ], - [ [ [ -6, 6, 4, -1, 0, 2 ], [ -5, 5, 4, 0, 0, 2 ], [ -6, 6, 4, 0, 0, 2 ], [ -7, 6, 5, 0, 0, 2 ] ], 1 ] - ], - [ - [ [ [ -6, 6, 4, -1, 0, 2 ], [ -5, 6, 3, 0, 0, 2 ], [ -6, 6, 4, 0, 0, 2 ], [ -7, 6, 5, 0, 0, 2 ] ], 1 ], - [ [ [ -6, 6, 4, -1, 0, 2 ], [ -5, 6, 3, 0, 0, 2 ], [ -6, 6, 4, 0, 0, 2 ], [ -7, 6, 4, 1, 0, 2 ] ], 1 ], - [ [ [ -6, 6, 3, 0, 0, 2 ], [ -5, 6, 3, 0, 0, 2 ], [ -6, 6, 4, 0, 0, 2 ], [ -7, 6, 4, 1, 0, 2 ] ], 1 ] - ], - [ - [ [ [ -6, 6, 3, 0, 0, 2 ], [ -5, 6, 3, 0, 0, 2 ], [ -5, 6, 2, 0, 0, 2 ], [ -7, 6, 4, 1, 0, 2 ] ], 1 ], - [ [ [ -6, 6, 3, 0, 0, 2 ], [ -5, 6, 3, 0, 0, 2 ], [ -5, 6, 2, 0, 0, 2 ], [ -6, 7, 3, 0, 0, 2 ] ], 1 ] - ], - [ - [ [ [ -6, 6, 3, 0, 0, 2 ], [ -5, 6, 2, -1, 0, 2 ], [ -5, 6, 2, 0, 0, 2 ], [ -6, 7, 3, 0, 0, 2 ] ], 1 ], - [ [ [ -6, 6, 2, 1, 0, 2 ], [ -5, 6, 2, -1, 0, 2 ], [ -5, 6, 2, 0, 0, 2 ], [ -6, 7, 3, 0, 0, 2 ] ], 1 ] - ], - [ - [ [ [ -6, 6, 2, 1, 0, 2 ], [ -5, 6, 2, -1, 0, 2 ], [ -6, 7, 2, 1, 0, 2 ], [ -6, 7, 3, 0, 0, 2 ] ], 1 ], - [ [ [ -6, 6, 2, 1, 0, 2 ], [ -7, 6, 2, 2, 0, 2 ], [ -6, 7, 2, 1, 0, 2 ], [ -6, 7, 3, 0, 0, 2 ] ], 1 ], - [ [ [ -6, 6, 2, 1, 0, 2 ], [ -7, 6, 2, 2, 0, 2 ], [ -6, 7, 2, 1, 0, 2 ], [ -5, 6, 2, 1, -1, 2 ] ], 1 ] - ], - [ - [ [ [ -6, 6, 2, 1, 0, 2 ], [ -7, 6, 2, 2, 0, 2 ], [ -5, 6, 2, 1, -1, 1 ], [ -5, 6, 2, 1, -1, 2 ] ], 1 ] - ], - [ - [ [ [ -6, 6, 2, 1, 0, 2 ], [ -7, 6, 2, 2, 0, 2 ], [ -6, 6, 2, 2, -1, 2 ], [ -5, 6, 2, 1, -1, 2 ] ], 1 ], - [ [ [ -6, 6, 2, 1, 0, 2 ], [ -7, 6, 2, 2, 0, 2 ], [ -6, 6, 2, 2, -1, 2 ], [ -7, 5, 2, 2, 0, 2 ] ], 1 ] - ], - [ - [ [ [ -6, 6, 2, 1, 0, 2 ], [ -7, 6, 2, 2, 0, 2 ], [ -7, 5, 2, 3, 0, 2 ], [ -7, 5, 2, 2, 0, 2 ] ], 1 ], - [ [ [ -8, 6, 2, 2, 0, 2 ], [ -7, 6, 2, 2, 0, 2 ], [ -7, 5, 2, 3, 0, 2 ], [ -7, 5, 2, 2, 0, 2 ] ], 1 ], - [ [ [ -8, 6, 2, 2, 0, 2 ], [ -7, 5, 2, 2, -1, 2 ], [ -7, 5, 2, 3, 0, 2 ], [ -7, 5, 2, 2, 0, 2 ] ], 1 ] - ], - [ - [ [ [ -7, 6, 2, 2, -1, 2 ], [ -7, 5, 2, 2, -1, 2 ], [ -7, 5, 2, 3, 0, 2 ], [ -7, 5, 2, 2, 0, 2 ] ], 1 ] - ], - [ - [ [ [ -7, 6, 2, 2, -1, 2 ], [ -7, 5, 2, 2, -1, 2 ], [ -6, 6, 1, 2, -1, 2 ], [ -7, 5, 2, 2, 0, 2 ] ], 1 ], - [ [ [ -7, 6, 2, 2, -1, 2 ], [ -6, 6, 2, 2, -2, 2 ], [ -6, 6, 1, 2, -1, 2 ], [ -7, 5, 2, 2, 0, 2 ] ], 1 ] - ], - [ - [ [ [ -7, 6, 2, 2, -1, 2 ], [ -5, 5, 1, 2, -1, 2 ], [ -6, 6, 1, 2, -1, 2 ], [ -7, 5, 2, 2, 0, 2 ] ], 1 ] - ], - [ - [ [ [ -7, 6, 2, 2, -1, 2 ], [ -5, 5, 1, 2, -1, 2 ], [ -6, 6, 1, 2, -1, 2 ], [ -6, 5, 2, 2, -1, 2 ] ], 1 ] - ], - [ - [ [ [ -7, 6, 2, 2, -1, 2 ], [ -5, 5, 1, 2, -1, 2 ], [ -6, 6, 1, 2, -1, 2 ], [ -6, 6, 2, 2, -1, 2 ] ], 1 ], - [ [ [ -6, 5, 1, 2, 0, 2 ], [ -5, 5, 1, 2, -1, 2 ], [ -6, 6, 1, 2, -1, 2 ], [ -6, 6, 2, 2, -1, 2 ] ], 1 ] - ], - [ - [ [ [ -6, 5, 1, 2, 0, 2 ], [ -5, 5, 1, 2, -1, 2 ], [ -5, 5, 0, 2, 0, 2 ], [ -6, 6, 2, 2, -1, 2 ] ], 1 ], - [ [ [ -6, 5, 1, 2, 0, 2 ], [ -5, 5, 1, 2, -1, 2 ], [ -5, 5, 0, 2, 0, 2 ], [ -6, 6, 1, 2, 0, 2 ] ], 1 ] - ], - [ - [ [ [ -6, 5, 1, 2, 0, 2 ], [ -5, 5, 1, 2, -1, 2 ], [ -7, 6, 2, 2, 0, 2 ], [ -6, 6, 1, 2, 0, 2 ] ], 1 ] - ], - [ - [ [ [ -6, 5, 1, 3, -1, 2 ], [ -5, 5, 1, 2, -1, 2 ], [ -7, 6, 2, 2, 0, 2 ], [ -6, 6, 1, 2, 0, 2 ] ], 1 ], - [ [ [ -6, 5, 1, 3, -1, 2 ], [ -5, 5, 1, 2, -1, 2 ], [ -7, 5, 1, 3, -1, 2 ], [ -6, 6, 1, 2, 0, 2 ] ], 1 ] - ], - [ - [ [ [ -7, 5, 1, 2, -2, 2 ], [ -5, 5, 1, 2, -1, 2 ], [ -7, 5, 1, 3, -1, 2 ], [ -6, 6, 1, 2, 0, 2 ] ], 1 ] - ], - [ - [ [ [ -7, 5, 1, 2, -2, 2 ], [ -5, 5, 1, 2, -1, 2 ], [ -7, 5, 1, 3, -1, 2 ], [ -6, 5, 1, 2, -1, 2 ] ], 1 ], - [ [ [ -7, 5, 1, 2, -2, 2 ], [ -7, 5, 1, 3, -2, 2 ], [ -7, 5, 1, 3, -1, 2 ], [ -6, 5, 1, 2, -1, 2 ] ], 1 ], - [ [ [ -7, 5, 1, 2, -1, 2 ], [ -7, 5, 1, 3, -2, 2 ], [ -7, 5, 1, 3, -1, 2 ], [ -6, 5, 1, 2, -1, 2 ] ], 1 ] - ], - [ - [ [ [ -7, 5, 1, 2, -1, 2 ], [ -7, 5, 1, 3, -2, 2 ], [ -5, 5, 1, 1, -1, 2 ], [ -6, 5, 1, 2, -1, 2 ] ], 1 ], - [ [ [ -6, 5, 1, 2, -2, 2 ], [ -7, 5, 1, 3, -2, 2 ], [ -5, 5, 1, 1, -1, 2 ], [ -6, 5, 1, 2, -1, 2 ] ], 1 ], - [ [ [ -6, 5, 1, 2, -2, 2 ], [ -7, 5, 1, 3, -1, 2 ], [ -5, 5, 1, 1, -1, 2 ], [ -6, 5, 1, 2, -1, 2 ] ], 1 ] - ], - [ - [ [ [ -8, 5, 0, 3, -1, 2 ], [ -7, 5, 1, 3, -1, 2 ], [ -5, 5, 1, 1, -1, 2 ], [ -6, 5, 1, 2, -1, 2 ] ], 1 ], - [ [ [ -8, 5, 0, 3, -1, 2 ], [ -7, 5, 1, 3, -1, 2 ], [ -6, 6, 1, 2, -1, 2 ], [ -6, 5, 1, 2, -1, 2 ] ], 1 ] - ], - [ - [ [ [ -7, 6, 1, 2, -2, 2 ], [ -7, 5, 1, 3, -1, 2 ], [ -6, 6, 1, 2, -1, 2 ], [ -6, 5, 1, 2, -1, 2 ] ], 1 ] - ], - [ - [ [ [ -7, 6, 1, 2, -2, 2 ], [ -7, 5, 1, 3, -1, 2 ], [ -6, 6, 1, 2, -1, 2 ], [ -7, 6, 1, 3, -1, 2 ] ], 1 ] - ], - [ - [ [ [ -8, 4, 1, 3, -1, 2 ], [ -7, 5, 1, 3, -1, 2 ], [ -6, 6, 1, 2, -1, 2 ], [ -7, 6, 1, 3, -1, 2 ] ], 1 ], - [ [ [ -8, 4, 1, 3, -1, 2 ], [ -7, 5, 1, 3, -1, 2 ], [ -6, 6, 1, 2, -1, 2 ], [ -6, 5, 1, 3, -1, 2 ] ], 1 ] - ], - [ - [ [ [ -9, 5, 1, 4, -1, 2 ], [ -7, 5, 1, 3, -1, 2 ], [ -6, 6, 1, 2, -1, 2 ], [ -6, 5, 1, 3, -1, 2 ] ], 1 ] - ], - [ - [ [ [ -9, 5, 1, 4, -1, 2 ], [ -7, 5, 1, 3, -1, 2 ], [ -6, 6, 1, 2, -1, 2 ], [ -6, 5, 1, 4, -2, 2 ] ], 1 ], - [ [ [ -9, 5, 1, 4, -1, 2 ], [ -7, 5, 1, 4, -2, 2 ], [ -6, 6, 1, 2, -1, 2 ], [ -6, 5, 1, 4, -2, 2 ] ], 1 ] - ] - ] -], -"last_changes": -[ - [ [ -9, 8, 0, 5, -2, 2 ], [ -8, 7, 0, 5, -2, 2 ], [ -9, 7, 1, 5, -2, 2 ], [ -8, 7, 1, 5, -2, 2 ] ], - [ [ -9, 8, 0, 5, -2, 2 ], [ -8, 7, 0, 5, -2, 2 ], [ -9, 7, 1, 5, -2, 2 ], [ -9, 7, 0, 6, -2, 2 ] ], - [ [ -9, 8, 0, 5, -2, 2 ], [ -8, 7, 0, 5, -2, 2 ], [ -9, 7, 0, 5, -2, 2 ], [ -9, 7, 0, 6, -2, 2 ] ], - [ [ -9, 8, 0, 5, -2, 2 ], [ -8, 7, 0, 5, -2, 2 ], [ -9, 7, 0, 5, -2, 2 ], [ -7, 7, 0, 4, -2, 2 ] ], - [ [ -8, 7, -1, 5, -2, 2 ], [ -8, 7, 0, 5, -2, 2 ], [ -9, 7, 0, 5, -2, 2 ], [ -7, 7, 0, 4, -2, 2 ] ] -], -"cur_uid": "43214be8", -"ref_uid": "7276dc78", -"order_seed": 553436, -"dur_seed": 804010, -"motifs_seed": 337121, -"entrances_probs_vals": [ 0, 0, 0, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 0, 0, 0, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 0, 0, 0, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -2400, 1200 ], [ -1200, 1200 ], [ -702, 1200 ], [ -702, 1200 ] ], -"step_probs_vals": [ 0, 1200, 0.0061728395061728, 0.10227272727273, 0.074074074074074, 0.10227272727273, 0.2037037037037, 0.090909090909091, 0.45679012345679, 0.011363636363636, 0.53086419753086, 0, 0.54320987654321, 0.92045454545455, 0.58641975308642, 0.92613636363636, 0.61111111111111, 0, 0.7880658436214, 0.034090909090909, 1, 0.034090909090909 ], -"passages_weights": [ 0.08, 0.47, 0.43, 1, 1 ], -"hd_exp": 10, -"hd_invert": 0, -"order": -[ - [ [ 3 ], [ 1, 2, 0 ], [ ] ], - [ [ 3, 2, 0 ], [ 1 ], [ ] ], - [ [ 0 ], [ 3, 2, 1 ], [ ] ], - [ [ 1 ], [ 3, 2, 0 ], [ ] ], - [ [ 0, 1, 3 ], [ 2 ], [ ] ], - [ [ 2, 0, 3 ], [ 1 ], [ ] ], - [ [ 1 ], [ 2, 3, 0 ], [ ] ], - [ [ 0, 1, 2 ], [ 3 ], [ ] ], - [ [ 2 ], [ 3, 0, 1 ], [ ] ], - [ [ 3 ], [ 0, 1, 2 ], [ ] ], - [ [ 0, 3, 2 ], [ 1 ], [ ] ], - [ [ 1, 3, 0 ], [ 2 ], [ ] ], - [ [ 1 ], [ 2, 0, 3 ], [ ] ], - [ [ 0, 1, 2 ], [ 3 ], [ ] ], - [ [ 1, 3 ], [ 2, 0 ], [ ] ], - [ [ 3, 1 ], [ 0, 2 ], [ ] ], - [ [ 0, 3, 1 ], [ 2 ], [ ] ], - [ [ 1, 2 ], [ 3, 0 ], [ ] ], - [ [ 3 ], [ 0, 2, 1 ], [ ] ], - [ [ 3, 0, 2 ], [ 1 ], [ ] ], - [ [ 2 ], [ 0, 3, 1 ], [ ] ], - [ [ 0, 2, 3 ], [ 1 ], [ ] ], - [ [ 3, 1, 2 ], [ 0 ], [ ] ], - [ [ 0, 1, 2 ], [ 3 ], [ ] ], - [ [ 1 ], [ 2, 3, 0 ], [ ] ] -], -"sus_weights": [ 0.35, 0.37, 0.38 ], -"order_size": [ 25, 25.244897959184 ], -"passages_size": [ 0, 0 ], -"motif_edited": "true", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/43214be8/lilypond/part_I.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/43214be8/lilypond/part_I.ly deleted file mode 100644 index e9eae1a..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/43214be8/lilypond/part_I.ly +++ /dev/null @@ -1,48 +0,0 @@ -{ - { gis'1^\markup { \pad-markup #0.2 "-11"} } - \bar "|" - { fis1^\markup { \pad-markup #0.2 "+24"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 5↑" }} } - \bar "|" - { c'1^\markup { \pad-markup #0.2 "+7"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 7↑" }} ~ } - \bar "|" - { c'2 fis'2^\markup { \pad-markup #0.2 "-46"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }} ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 } - \bar "|" - { b'1^\markup { \pad-markup #0.2 "-17"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 11↓" }} ~ } - \bar "|" - { b'2 g2^\markup { \pad-markup #0.2 "+1"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↓" }} ~ } - \bar "|" - { g1 ~ } - \bar "|" - { g1 ~ } - \bar "|" - { g1 ~ } - \bar "|" - { g2 cis'2^\markup { \pad-markup #0.2 "+50"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }} } - \bar "|" - { a'1^\markup { \pad-markup #0.2 "-48"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }} ~ } - \bar "|" - { a'2 ais'2^\markup { \pad-markup #0.2 "+17"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }} ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 } - \bar "|" - { ais1^\markup { \pad-markup #0.2 "-37"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }} ~ } - \bar "|" - { ais1 ~ } - \bar "|" - { ais1 ~ } - \bar "|" - { ais1 ~ } - \bar "|" - { ais2 d'2^\markup { \pad-markup #0.2 "+34"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↑" }} ~ } - \bar "|" - { d'2 g'2^\markup { \pad-markup #0.2 "+32"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }} ~ } - \bar "|" - { g'2 b'2^\markup { \pad-markup #0.2 "+50"}} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/43214be8/lilypond/part_II.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/43214be8/lilypond/part_II.ly deleted file mode 100644 index bd2901a..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/43214be8/lilypond/part_II.ly +++ /dev/null @@ -1,48 +0,0 @@ -{ - { d'1^\markup { \pad-markup #0.2 "+38"} ~ } - \bar "|" - { d'1 ~ } - \bar "|" - { d'1 } - \bar "|" - { g'1^\markup { \pad-markup #0.2 "-35"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↓" }} ~ } - \bar "|" - { g'1 } - \bar "|" - { b'1^\markup { \pad-markup #0.2 "+36"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }} ~ } - \bar "|" - { b'2 d'2^\markup { \pad-markup #0.2 "+42"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 13↓" }} } - \bar "|" - { a'1^\markup { \pad-markup #0.2 "-48"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 11↓" }} } - \bar "|" - { f'1^\markup { \pad-markup #0.2 "-30"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 7↑" }} ~ } - \bar "|" - { f'1 } - \bar "|" - { f'1^\markup { \pad-markup #0.2 "-35"} ~ } - \bar "|" - { f'1 ~ } - \bar "|" - { f'1 } - \bar "|" - { b'1^\markup { \pad-markup #0.2 "+28"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↓" }} } - \bar "|" - { d'1^\markup { \pad-markup #0.2 "+3"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 5↑" }} } - \bar "|" - { g1^\markup { \pad-markup #0.2 "+32"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }} ~ } - \bar "|" - { g1 ~ } - \bar "|" - { g2 c'2^\markup { \pad-markup #0.2 "-5"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↓" }} ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'2 f'2^\markup { \pad-markup #0.2 "-35"} ~ } - \bar "|" - { f'1 ~ } - \bar "|" - { f'1 ~ } - \bar "|" - { f'1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/43214be8/lilypond/part_III.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/43214be8/lilypond/part_III.ly deleted file mode 100644 index 192a5db..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/43214be8/lilypond/part_III.ly +++ /dev/null @@ -1,48 +0,0 @@ -{ - { g'1^\markup { \pad-markup #0.2 "+36"} ~ } - \bar "|" - { g'2 b'2^\markup { \pad-markup #0.2 "-48"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 5↓" }} ~ } - \bar "|" - { b'1 ~ } - \bar "|" - { b'1 } - \bar "|" - { a1^\markup { \pad-markup #0.2 "-3"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 7↓" }} ~ } - \bar "|" - { a2 d'2^\markup { \pad-markup #0.2 "+3"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↑" }} ~ } - \bar "|" - { d'1 ~ } - \bar "|" - { d'1 ~ } - \bar "|" - { d'1 } - \bar "|" - { cis1^\markup { \pad-markup #0.2 "+50"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 11↓" }} ~ } - \bar "|" - { cis2 dis'2^\markup { \pad-markup #0.2 "+0"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 11↓" }} } - \bar "|" - { ais'1^\markup { \pad-markup #0.2 "-37"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↓" }} ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'2 d2^\markup { \pad-markup #0.2 "-19"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↑" }} ~ } - \bar "|" - { d1 ~ } - \bar "|" - { d2 g2^\markup { \pad-markup #0.2 "+32"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 7↑" }} ~ } - \bar "|" - { g1 ~ } - \bar "|" - { g1 ~ } - \bar "|" - { g1 ~ } - \bar "|" - { g1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/43214be8/lilypond/part_IV.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/43214be8/lilypond/part_IV.ly deleted file mode 100644 index 534e787..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/43214be8/lilypond/part_IV.ly +++ /dev/null @@ -1,48 +0,0 @@ -{ - { ais,2^\markup { \pad-markup #0.2 "+21"} f2^\markup { \pad-markup #0.2 "-31"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 7↓" }} ~ } - \bar "|" - { f1 ~ } - \bar "|" - { f2 b2^\markup { \pad-markup #0.2 "-48"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }} ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b2 e'2^\markup { \pad-markup #0.2 "+34"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 7↑" }} ~ } - \bar "|" - { e'1 ~ } - \bar "|" - { e'1 ~ } - \bar "|" - { e'1 ~ } - \bar "|" - { e'2 d2^\markup { \pad-markup #0.2 "+3"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }} ~ } - \bar "|" - { d2 a2^\markup { \pad-markup #0.2 "-48"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↑" }} ~ } - \bar "|" - { a1 ~ } - \bar "|" - { a1 ~ } - \bar "|" - { a2 dis'2^\markup { \pad-markup #0.2 "+15"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 11↑" }} ~ } - \bar "|" - { dis'1 ~ } - \bar "|" - { dis'2 g'2^\markup { \pad-markup #0.2 "+32"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 7↑" }} ~ } - \bar "|" - { g'2 e,2^\markup { \pad-markup #0.2 "+12"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 11↓" }} ~ } - \bar "|" - { e,1 } - \bar "|" - { ais,1^\markup { \pad-markup #0.2 "-37"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }} } - \bar "|" - { e1^\markup { \pad-markup #0.2 "+12"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 7↓" }} } - \bar "|" - { dis,1^\markup { \pad-markup #0.2 "+46"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 5↓" }} } - \bar "|" - { b,1^\markup { \pad-markup #0.2 "+14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 11↓" }} } - \bar "|" - { c,1^\markup { \pad-markup #0.2 "+30"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↓" }} } - \bar "|" - { f,1^\markup { \pad-markup #0.2 "+1"}} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/44490863/44490863_code.scd b/resources/resources_bak_2024_01_03/string_quartet_3_rise/44490863/44490863_code.scd deleted file mode 100644 index 23ccdf1..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/44490863/44490863_code.scd +++ /dev/null @@ -1,981 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array2) - hsArrayToCents.value(array1); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -/* -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance) -}; -*/ - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = true; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - //if(pDistance >= 0, {stepFunc.value(abs(pDistance))}, {0.01}); - stepFunc.value(pDistance) -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - //tuples = dims.collect({[0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum == 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength.asInteger - minMotifLength.asInteger).rand + minMotifLength.asInteger).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - //noProgIns = (popSize - noSusIns).rand + 1; - noProgIns = (popSize - noSusIns); - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength.asInteger - minProgLength.asInteger).rand + minProgLength.asInteger).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0.01); - - - - /* - if(rangeScore.value(candidate.collect({0}), voices[ins], ranges[ins][1] - 500, ranges[ins][1], 0, true) == 1, { - isInRangeScore = 1 - rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0] + 500, ranges[ins][1] - 500, 0, true); - isInRangeScore = isInRangeScore * rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true) - }, { - isInRangeScore = rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true); - }); - */ - - - isInRangeScore = rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true); - //old way - worked but actually by accident (I think) - //isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - - - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - /* - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - */ - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - //lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - lastState = if(o == 0, {lastXChanges.last.deepCopy}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - /* - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - */ - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - //# voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - # voices, durs = seq.flatten2(if(oneShot, {2}, {3})).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/44490863/44490863_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_3_rise/44490863/44490863_mus_model.json deleted file mode 100644 index b1d0e34..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/44490863/44490863_mus_model.json +++ /dev/null @@ -1,154 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ -1, 2, 0, 0, 1, 0 ], [ -1, 2, 1, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ -1, 1, 1, 0, 0, 0 ] ], 1 ], - [ [ [ 0, 1, 1, 0, 0, 0 ], [ -1, 2, 1, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ -1, 1, 1, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ 0, 1, 1, 0, 0, 0 ], [ -1, 1, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ -1, 1, 1, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ 0, 1, 1, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ -1, 1, 1, 0, 0, 0 ] ], 1 ], - [ [ [ -1, 0, 1, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ -1, 1, 1, 0, 0, 0 ] ], 1 ], - [ [ [ -1, 0, 1, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ], [ 0, 1, 1, 0, 0, 0 ], [ -1, 1, 1, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 2, 1, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ], [ 0, 1, 1, 0, 0, 0 ], [ -1, 1, 1, 0, 0, 0 ] ], 1 ], - [ [ [ -2, 2, 1, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ], [ 0, 1, 1, 0, 0, 0 ], [ -1, 2, 1, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 2, 1, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ], [ 0, 1, 1, 0, 0, 0 ], [ 1, 0, 1, -1, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 2, 1, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ], [ 0, 1, 1, 0, 0, 0 ], [ 0, 0, 2, 0, 0, 0 ] ], 1 ], - [ [ [ -2, 2, 1, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ], [ -1, 1, 1, 0, 0, 0 ], [ 0, 0, 2, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 2, 1, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ], [ -1, 1, 1, 0, 0, 0 ], [ 0, 1, 1, 0, 0, 0 ] ], 1 ], - [ [ [ -2, 1, 1, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ], [ -1, 1, 1, 0, 0, 0 ], [ 0, 1, 1, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 1, 1, 0, 0, 0 ], [ -1, 2, 1, 0, 0, 0 ], [ -1, 1, 1, 0, 0, 0 ], [ 0, 1, 1, 0, 0, 0 ] ], 1 ], - [ [ [ -2, 1, 1, 0, 0, 0 ], [ -1, 2, 1, 0, 0, 0 ], [ -1, 1, 1, 0, 0, 0 ], [ -2, 2, 1, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 1, 1, 0, 0, 0 ], [ -1, 2, 1, 0, 0, 0 ], [ -2, 3, 1, 0, 0, 0 ], [ -2, 2, 1, 0, 0, 0 ] ], 1 ], - [ [ [ -2, 2, 0, 0, 0, 0 ], [ -1, 2, 1, 0, 0, 0 ], [ -2, 3, 1, 0, 0, 0 ], [ -2, 2, 1, 0, 0, 0 ] ], 1 ], - [ [ [ -2, 2, 0, 0, 0, 0 ], [ -1, 2, 1, 0, 0, 0 ], [ -2, 3, 1, 0, 0, 0 ], [ -2, 2, 2, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 2, 0, 0, 0, 0 ], [ -1, 2, 1, 0, 0, 0 ], [ -1, 2, 0, 0, 0, 0 ], [ -2, 2, 2, 0, 0, 0 ] ], 1 ], - [ [ [ -2, 2, 1, 0, 0, 0 ], [ -1, 2, 1, 0, 0, 0 ], [ -1, 2, 0, 0, 0, 0 ], [ -2, 2, 2, 0, 0, 0 ] ], 1 ], - [ [ [ -2, 2, 1, 0, 0, 0 ], [ -1, 2, 1, 0, 0, 0 ], [ -1, 2, 0, 0, 0, 0 ], [ -2, 3, 1, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -3, 4, 1, 0, 0, 0 ], [ -1, 2, 1, 0, 0, 0 ], [ -1, 2, 0, 0, 0, 0 ], [ -2, 3, 1, 0, 0, 0 ] ], 1 ], - [ [ [ -3, 4, 1, 0, 0, 0 ], [ -1, 2, 1, 0, 0, 0 ], [ -2, 3, 2, 0, 0, 0 ], [ -2, 3, 1, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -3, 4, 1, 0, 0, 0 ], [ -1, 2, 1, 0, 0, 0 ], [ -2, 3, 2, 0, 0, 0 ], [ -2, 4, 2, 0, 0, 0 ] ], 1 ], - [ [ [ -2, 2, 2, 0, 0, 0 ], [ -1, 2, 1, 0, 0, 0 ], [ -2, 3, 2, 0, 0, 0 ], [ -2, 4, 2, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 2, 2, 0, 0, 0 ], [ -1, 2, 1, 0, 0, 0 ], [ -1, 2, 1, 0, 1, 0 ], [ -2, 4, 2, 0, 0, 0 ] ], 1 ], - [ [ [ -2, 3, 1, 0, 0, 0 ], [ -1, 2, 1, 0, 0, 0 ], [ -1, 2, 1, 0, 1, 0 ], [ -2, 4, 2, 0, 0, 0 ] ], 1 ], - [ [ [ -2, 3, 1, 0, 0, 0 ], [ -1, 2, 1, 0, 0, 0 ], [ -1, 2, 1, 0, 1, 0 ], [ -2, 2, 1, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 3, 1, 0, 0, 0 ], [ -2, 3, 1, 0, 1, 0 ], [ -1, 2, 1, 0, 1, 0 ], [ -2, 2, 1, 0, 0, 0 ] ], 1 ], - [ [ [ -2, 3, 1, 0, 0, 0 ], [ -2, 3, 1, 0, 1, 0 ], [ -1, 2, 1, 0, 0, 0 ], [ -2, 2, 1, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 3, 2, 0, 1, 0 ], [ -2, 3, 1, 0, 1, 0 ], [ -1, 2, 1, 0, 0, 0 ], [ -2, 2, 1, 0, 0, 0 ] ], 1 ], - [ [ [ -2, 3, 2, 0, 1, 0 ], [ -2, 3, 1, 0, 1, 0 ], [ -1, 2, 1, 0, 0, 0 ], [ -2, 3, 1, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 3, 2, 0, 1, 0 ], [ -2, 3, 1, 0, 1, 0 ], [ -1, 2, 1, 0, 0, 0 ], [ -1, 2, 1, 0, 1, 0 ] ], 1 ], - [ [ [ -2, 2, 1, 0, 1, 0 ], [ -2, 3, 1, 0, 1, 0 ], [ -1, 2, 1, 0, 0, 0 ], [ -1, 2, 1, 0, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 2, 1, 0, 1, 0 ], [ -2, 3, 1, 0, 1, 0 ], [ -1, 2, 0, 0, 1, 0 ], [ -1, 2, 1, 0, 1, 0 ] ], 1 ], - [ [ [ -2, 2, 1, 0, 1, 0 ], [ -2, 2, 1, 1, 1, 0 ], [ -1, 2, 0, 0, 1, 0 ], [ -1, 2, 1, 0, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 2, 1, 0, 1, 0 ], [ -2, 2, 1, 1, 1, 0 ], [ -1, 2, 0, 0, 1, 0 ], [ -3, 2, 1, 1, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 2, 1, 0, 1, 0 ], [ -1, 2, 1, 0, 1, 0 ], [ -1, 2, 0, 0, 1, 0 ], [ -3, 2, 1, 1, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 2, 1, 0, 1, 0 ], [ -1, 2, 1, 0, 1, 0 ], [ -2, 2, 1, 1, 1, 0 ], [ -3, 2, 1, 1, 1, 0 ] ], 1 ], - [ [ [ -2, 1, 1, 1, 1, 0 ], [ -1, 2, 1, 0, 1, 0 ], [ -2, 2, 1, 1, 1, 0 ], [ -3, 2, 1, 1, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 1, 1, 1, 1, 0 ], [ -1, 2, 1, 0, 1, 0 ], [ -2, 1, 1, 2, 1, 0 ], [ -3, 2, 1, 1, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 1, 1, 1, 1, 0 ], [ -1, 2, 1, 0, 1, 0 ], [ -2, 1, 1, 2, 1, 0 ], [ -3, 1, 2, 2, 1, 0 ] ], 1 ], - [ [ [ -2, 1, 1, 1, 1, 0 ], [ -4, 2, 1, 2, 1, 0 ], [ -2, 1, 1, 2, 1, 0 ], [ -3, 1, 2, 2, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 1, 1, 1, 1, 0 ], [ -4, 2, 1, 2, 1, 0 ], [ -3, 2, 2, 2, 1, 0 ], [ -3, 1, 2, 2, 1, 0 ] ], 1 ], - [ [ [ -2, 0, 2, 2, 1, 0 ], [ -4, 2, 1, 2, 1, 0 ], [ -3, 2, 2, 2, 1, 0 ], [ -3, 1, 2, 2, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -5, 1, 2, 2, 1, 0 ], [ -4, 2, 1, 2, 1, 0 ], [ -3, 2, 2, 2, 1, 0 ], [ -3, 1, 2, 2, 1, 0 ] ], 1 ] - ] - ] -], -"last_changes": -[ - [ [ -2, 1, 1, 1, 1, 0 ], [ -1, 2, 1, 0, 1, 0 ], [ -2, 1, 1, 2, 1, 0 ], [ -3, 1, 2, 2, 1, 0 ] ], - [ [ -2, 1, 1, 1, 1, 0 ], [ -4, 2, 1, 2, 1, 0 ], [ -2, 1, 1, 2, 1, 0 ], [ -3, 1, 2, 2, 1, 0 ] ], - [ [ -2, 1, 1, 1, 1, 0 ], [ -4, 2, 1, 2, 1, 0 ], [ -3, 2, 2, 2, 1, 0 ], [ -3, 1, 2, 2, 1, 0 ] ], - [ [ -2, 0, 2, 2, 1, 0 ], [ -4, 2, 1, 2, 1, 0 ], [ -3, 2, 2, 2, 1, 0 ], [ -3, 1, 2, 2, 1, 0 ] ], - [ [ -5, 1, 2, 2, 1, 0 ], [ -4, 2, 1, 2, 1, 0 ], [ -3, 2, 2, 2, 1, 0 ], [ -3, 1, 2, 2, 1, 0 ] ] -], -"cur_uid": "44490863", -"ref_uid": "4874dd07", -"order_seed": 903957, -"dur_seed": 360025, -"motifs_seed": 692248, -"entrances_probs_vals": [ 0, 0, 0, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 0, 0, 0, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 0, 0, 0, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -2400, 1200 ], [ -1200, 1200 ], [ -702, 1200 ], [ -702, 1200 ] ], -"step_probs_vals": [ 0, 1200, 0.0061728395061728, 0.10227272727273, 0.074074074074074, 0.10227272727273, 0.2037037037037, 0.090909090909091, 0.45679012345679, 0.011363636363636, 0.53086419753086, 0, 0.54320987654321, 0.92045454545455, 0.58641975308642, 0.92613636363636, 0.61111111111111, 0, 0.7880658436214, 0.034090909090909, 1, 0.034090909090909 ], -"passages_weights": [ 1, 0.47, 0.43, 1, 1 ], -"hd_exp": 10, -"hd_invert": 0, -"order": -[ - [ [ 3, 2 ], [ 1, 0 ], [ ] ], - [ [ 3, 2, 0 ], [ 1 ], [ ] ], - [ [ 3 ], [ 1, 0, 2 ], [ ] ], - [ [ 1, 2 ], [ 0, 3 ], [ ] ], - [ [ 1, 2, 0 ], [ 3 ], [ ] ], - [ [ 0, 1 ], [ 3, 2 ], [ ] ], - [ [ 2, 1 ], [ 3, 0 ], [ ] ], - [ [ 0, 2 ], [ 1, 3 ], [ ] ], - [ [ 1 ], [ 2, 0, 3 ], [ ] ], - [ [ 1 ], [ 2, 0, 3 ], [ ] ], - [ [ 3, 1 ], [ 0, 2 ], [ ] ], - [ [ 2, 1 ], [ 3, 0 ], [ ] ], - [ [ 1 ], [ 2, 0, 3 ], [ ] ], - [ [ 3, 0 ], [ 1, 2 ], [ ] ], - [ [ 1, 2 ], [ 0, 3 ], [ ] ], - [ [ 1, 2 ], [ 3, 0 ], [ ] ], - [ [ 0, 3 ], [ 2, 1 ], [ ] ], - [ [ 2, 0, 1 ], [ 3 ], [ ] ], - [ [ 2, 0, 3 ], [ 1 ], [ ] ], - [ [ 1, 3 ], [ 2, 0 ], [ ] ], - [ [ 1, 0, 3 ], [ 2 ], [ ] ], - [ [ 2, 0 ], [ 3, 1 ], [ ] ], - [ [ 1, 3 ], [ 2, 0 ], [ ] ], - [ [ 1, 2, 3 ], [ 0 ], [ ] ] -], -"sus_weights": [ 0.35, 0.37, 0.38 ], -"order_size": [ 5.0408163265306, 25.244897959184 ], -"passages_size": [ 0, 0 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/44490863/lilypond/part_I.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/44490863/lilypond/part_I.ly deleted file mode 100644 index a351af0..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/44490863/lilypond/part_I.ly +++ /dev/null @@ -1,48 +0,0 @@ -{ - { b1^\markup { \pad-markup #0.2 "-12"} ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b2 fis'2^\markup { \pad-markup #0.2 "-10"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }} } - \bar "|" - { fis'2^\markup { \pad-markup #0.2 "+17"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 7↓" }} gis'2^\markup { \pad-markup #0.2 "-27"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 5↑" }} ~ } - \bar "|" - { gis'2 b'2^\markup { \pad-markup #0.2 "-12"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 1↑" }} ~ } - \bar "|" - { b'1 } - \bar "|" - { fis1^\markup { \pad-markup #0.2 "-10"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }} ~ } - \bar "|" - { fis2 ais2^\markup { \pad-markup #0.2 "-23"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 5↑" }} ~ } - \bar "|" - { ais1 } - \bar "|" - { cis'1^\markup { \pad-markup #0.2 "-8"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }} ~ } - \bar "|" - { cis'2 c''2^\markup { \pad-markup #0.2 "-20"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }} ~ } - \bar "|" - { c''1 ~ } - \bar "|" - { c''2 fis2^\markup { \pad-markup #0.2 "-10"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }} ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis2 cis'2^\markup { \pad-markup #0.2 "-8"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 11↓" }} } - \bar "|" - { b'1^\markup { \pad-markup #0.2 "+42"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↓" }} ~ } - \bar "|" - { b'1 } - \bar "|" - { a1^\markup { \pad-markup #0.2 "+10"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }} ~ } - \bar "|" - { a1 ~ } - \bar "|" - { a2 e'2^\markup { \pad-markup #0.2 "-36"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 5↑" }} ~ } - \bar "|" - { e'1 ~ } - \bar "|" - { e'1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/44490863/lilypond/part_II.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/44490863/lilypond/part_II.ly deleted file mode 100644 index 93d3bf8..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/44490863/lilypond/part_II.ly +++ /dev/null @@ -1,48 +0,0 @@ -{ - { g'1^\markup { \pad-markup #0.2 "+2"} ~ } - \bar "|" - { g'1 ~ } - \bar "|" - { g'2 b'2^\markup { \pad-markup #0.2 "-12"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }} ~ } - \bar "|" - { b'1 ~ } - \bar "|" - { b'1 } - \bar "|" - { b1^\markup { \pad-markup #0.2 "-12"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }} ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b2 cis'2^\markup { \pad-markup #0.2 "-8"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↑" }} ~ } - \bar "|" - { cis'1 } - \bar "|" - { d'1^\markup { \pad-markup #0.2 "+4"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }} ~ } - \bar "|" - { d'1 } - \bar "|" - { f'1^\markup { \pad-markup #0.2 "-22"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 5↑" }} ~ } - \bar "|" - { f'2 b'2^\markup { \pad-markup #0.2 "+42"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 11↑" }} ~ } - \bar "|" - { b'1 ~ } - \bar "|" - { b'2 fis'2^\markup { \pad-markup #0.2 "-10"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }} ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 } - \bar "|" - { gis'1^\markup { \pad-markup #0.2 "-45"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↓" }} ~ } - \bar "|" - { gis'1 } - \bar "|" - { a'1^\markup { \pad-markup #0.2 "+10"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }} } - \bar "|" - { c''1^\markup { \pad-markup #0.2 "-23"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↑" }} ~ } - \bar "|" - { c''2 b'2^\markup { \pad-markup #0.2 "-34"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 5↑" }} ~ } - \bar "|" - { b'1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/44490863/lilypond/part_III.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/44490863/lilypond/part_III.ly deleted file mode 100644 index 606adf0..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/44490863/lilypond/part_III.ly +++ /dev/null @@ -1,48 +0,0 @@ -{ - { fis'1^\markup { \pad-markup #0.2 "-10"} } - \bar "|" - { g2^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 1↑" }} e'2^\markup { \pad-markup #0.2 "-14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }} ~ } - \bar "|" - { e'1 ~ } - \bar "|" - { e'1 ~ } - \bar "|" - { e'1 ~ } - \bar "|" - { e'1 ~ } - \bar "|" - { e'2 fis'2^\markup { \pad-markup #0.2 "-10"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }} ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 } - \bar "|" - { fis'1^\markup { \pad-markup #0.2 "+43"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 11↑" }} ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'2 a'2^\markup { \pad-markup #0.2 "+10"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↑" }} ~ } - \bar "|" - { a'2 b'2^\markup { \pad-markup #0.2 "+42"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }} ~ } - \bar "|" - { b'1 ~ } - \bar "|" - { b'1 } - \bar "|" - { g1^\markup { \pad-markup #0.2 "-21"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↑" }} ~ } - \bar "|" - { g1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/44490863/lilypond/part_IV.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/44490863/lilypond/part_IV.ly deleted file mode 100644 index b3eb4c8..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/44490863/lilypond/part_IV.ly +++ /dev/null @@ -1,48 +0,0 @@ -{ - { gis'2^\markup { \pad-markup #0.2 "-45"} b'2^\markup { \pad-markup #0.2 "-12"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }} ~ } - \bar "|" - { b'1 } - \bar "|" - { e1^\markup { \pad-markup #0.2 "-14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }} } - \bar "|" - { fis1^\markup { \pad-markup #0.2 "-10"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↑" }} ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis1 } - \bar "|" - { b,1^\markup { \pad-markup #0.2 "-12"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 1↑" }} ~ } - \bar "|" - { b,1 } - \bar "|" - { d1^\markup { \pad-markup #0.2 "+4"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 5↓" }} ~ } - \bar "|" - { d2 fis2^\markup { \pad-markup #0.2 "-10"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }} ~ } - \bar "|" - { fis2 gis2^\markup { \pad-markup #0.2 "-6"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↑" }} ~ } - \bar "|" - { gis1 } - \bar "|" - { ais1^\markup { \pad-markup #0.2 "-23"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 5↑" }} } - \bar "|" - { cis'1^\markup { \pad-markup #0.2 "-8"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↑" }} ~ } - \bar "|" - { cis'1 } - \bar "|" - { ais'1^\markup { \pad-markup #0.2 "+30"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 5↑" }} ~ } - \bar "|" - { ais'2 b2^\markup { \pad-markup #0.2 "+42"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }} ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b2 d'2^\markup { \pad-markup #0.2 "+8"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↓" }} ~ } - \bar "|" - { d'1 ~ } - \bar "|" - { d'1 } - \bar "|" - { a'2^\markup { \pad-markup #0.2 "-38"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↓" }} e,2^\markup { \pad-markup #0.2 "-36"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }}} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4874dd07/4874dd07_code.scd b/resources/resources_bak_2024_01_03/string_quartet_3_rise/4874dd07/4874dd07_code.scd deleted file mode 100644 index c4e3d1b..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4874dd07/4874dd07_code.scd +++ /dev/null @@ -1,979 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array2) - hsArrayToCents.value(array1); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -/* -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance) -}; -*/ - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = true; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - //if(pDistance >= 0, {stepFunc.value(abs(pDistance))}, {0.01}); - stepFunc.value(pDistance) -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - //tuples = dims.collect({[0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum == 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength.asInteger - minMotifLength.asInteger).rand + minMotifLength.asInteger).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - //noProgIns = (popSize - noSusIns).rand + 1; - noProgIns = (popSize - noSusIns); - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength.asInteger - minProgLength.asInteger).rand + minProgLength.asInteger).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0.01); - - - - /* - if(rangeScore.value(candidate.collect({0}), voices[ins], ranges[ins][1] - 500, ranges[ins][1], 0, true) == 1, { - isInRangeScore = 1 - rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0] + 500, ranges[ins][1] - 500, 0, true); - isInRangeScore = isInRangeScore * rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true) - }, { - isInRangeScore = rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true); - }); - */ - - - isInRangeScore = rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true); - //old way - worked but actually by accident (I think) - //isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - - - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - /* - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - */ - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - /* - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - */ - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4874dd07/4874dd07_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_3_rise/4874dd07/4874dd07_mus_model.json deleted file mode 100644 index 74fb11d..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4874dd07/4874dd07_mus_model.json +++ /dev/null @@ -1,121 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 1 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ] ], 1 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ -1, 0, 0, 0, 0, 0 ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ] ], 1 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ -1, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -1, 2, 0, 0, 0, 0 ], [ -1, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 1 ], - [ [ [ -1, 2, 0, 0, 0, 0 ], [ -1, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ -1, 1, 0, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -1, 2, 0, 0, 0, 0 ], [ -1, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ -2, 3, 0, 0, 0, 0 ] ], 1 ], - [ [ [ -1, 2, 0, 0, 0, 0 ], [ -1, 0, 0, 0, 0, 0 ], [ -1, 3, 0, 0, 0, 0 ], [ -2, 3, 0, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -1, 2, 0, 0, 0, 0 ], [ -1, 0, 0, 0, 0, 0 ], [ -1, 3, 0, 0, 0, 0 ], [ -1, 0, 0, 1, 0, 0 ] ], 1 ], - [ [ [ -1, 2, 0, 0, 0, 0 ], [ -1, 0, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ], [ -1, 0, 0, 1, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -1, 2, 0, 0, 0, 0 ], [ -1, 1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ], [ -1, 0, 0, 1, 0, 0 ] ], 1 ], - [ [ [ -1, 0, 0, 0, 0, 0 ], [ -1, 1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ], [ -1, 0, 0, 1, 0, 0 ] ], 1 ], - [ [ [ -1, 0, 0, 0, 0, 0 ], [ -1, 1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -1, 0, 0, 0, 0, 0 ], [ -1, 1, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 1 ], - [ [ [ -1, 0, 0, 0, 0, 0 ], [ 0, 0, -1, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 1 ], - [ [ [ -1, 0, 0, 0, 0, 0 ], [ 0, 0, -1, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ 0, -1, 0, 0, 0, 0 ], [ 0, 0, -1, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ] ], 1 ], - [ [ [ 0, -1, 0, 0, 0, 0 ], [ 0, 0, -1, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ] ], 1 ], - [ [ [ 0, -1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -1, 1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -1, 1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ] ], 1 ], - [ [ [ 1, -1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ] ], 1 ], - [ [ [ 1, -1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, -1, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ 1, -1, 0, 0, 0, 0 ], [ -1, 0, 0, 0, 0, 0 ], [ 0, -1, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ] ], 1 ], - [ [ [ 1, -1, 0, 0, 0, 0 ], [ -1, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ] ], 1 ], - [ [ [ 1, 0, 0, 0, 0, 0 ], [ -1, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ 1, 0, 0, 0, 0, 0 ], [ -1, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 1, 0, 0 ] ], 1 ], - [ [ [ 1, 0, 0, 0, 0, 0 ], [ -1, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 0, 0, 0, 1, 0, 0 ] ], 1 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ -1, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 0, 0, 0, 1, 0, 0 ] ], 1 ] - ], - [ - [ [ [ 0, 0, 0, 0, 0, 0 ], [ -1, 1, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 0, 0, 0, 1, 0, 0 ] ], 1 ], - [ [ [ 0, 0, 0, 0, 0, 0 ], [ -1, 1, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ 0, -1, 0, 0, 0, 0 ], [ -1, 1, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ 0, -1, 0, 0, 0, 0 ], [ -1, 2, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ] ], 1 ], - [ [ [ -1, 1, 0, 0, 0, 0 ], [ -1, 2, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -1, 1, 0, 0, 0, 0 ], [ -1, 2, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ -1, 1, 1, 0, 0, 0 ] ], 1 ], - [ [ [ -1, 2, 1, 0, 0, 0 ], [ -1, 2, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ -1, 1, 1, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -1, 2, 0, 0, 1, 0 ], [ -1, 2, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ -1, 1, 1, 0, 0, 0 ] ], 1 ] - ] - ] -], -"last_changes": -[ - [ [ 0, -1, 0, 0, 0, 0 ], [ -1, 2, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ] ], - [ [ -1, 1, 0, 0, 0, 0 ], [ -1, 2, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ] ], - [ [ -1, 1, 0, 0, 0, 0 ], [ -1, 2, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ -1, 1, 1, 0, 0, 0 ] ], - [ [ -1, 2, 1, 0, 0, 0 ], [ -1, 2, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ -1, 1, 1, 0, 0, 0 ] ], - [ [ -1, 2, 0, 0, 1, 0 ], [ -1, 2, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ -1, 1, 1, 0, 0, 0 ] ] -], -"cur_uid": "4874dd07", -"ref_uid": "nil", -"order_seed": 701987, -"dur_seed": 150121, -"motifs_seed": 970221, -"entrances_probs_vals": [ 0, 0, 0, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 0, 0, 0, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 0, 0, 0, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -2400, 1200 ], [ -1200, 1200 ], [ -702, 1200 ], [ -702, 1200 ] ], -"step_probs_vals": [ 0, 1200, 0.0061728395061728, 0.10227272727273, 0.074074074074074, 0.10227272727273, 0.2037037037037, 0.090909090909091, 0.45679012345679, 0.011363636363636, 0.53086419753086, 0, 0.54320987654321, 0.92045454545455, 0.58641975308642, 0.92613636363636, 0.61111111111111, 0, 0.7880658436214, 0.034090909090909, 1, 0.034090909090909 ], -"passages_weights": [ 1, 0.47, 0.43, 1, 1 ], -"hd_exp": 10, -"hd_invert": 0, -"order": -[ - [ [ 0, 3 ], [ 1, 2 ], [ ] ], - [ [ 2, 1 ], [ 0, 3 ], [ ] ], - [ [ 0, 1 ], [ 3, 2 ], [ ] ], - [ [ 1, 0 ], [ 3, 2 ], [ ] ], - [ [ 2 ], [ 1, 0, 3 ], [ ] ], - [ [ 0 ], [ 2, 1, 3 ], [ ] ], - [ [ 3 ], [ 0, 2, 1 ], [ ] ], - [ [ 3, 1, 2 ], [ 0 ], [ ] ], - [ [ 1 ], [ 3, 0, 2 ], [ ] ], - [ [ 3 ], [ 1, 2, 0 ], [ ] ], - [ [ 1 ], [ 3, 2, 0 ], [ ] ], - [ [ 2, 0 ], [ 1, 3 ], [ ] ], - [ [ 2, 1, 3 ], [ 0 ], [ ] ], - [ [ 2, 3 ], [ 1, 0 ], [ ] ], - [ [ 2, 1 ], [ 3, 0 ], [ ] ], - [ [ 1, 2, 3 ], [ 0 ], [ ] ] -], -"sus_weights": [ 0.35, 0.37, 0.38 ], -"order_size": [ 4.8265306122449, 25 ], -"passages_size": [ 0, 0 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4874dd07/lilypond/part_I.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/4874dd07/lilypond/part_I.ly deleted file mode 100644 index 63f4a0e..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4874dd07/lilypond/part_I.ly +++ /dev/null @@ -1,38 +0,0 @@ -{ - { r2 c'2^\markup { \pad-markup #0.2 "+0"} ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'2 g2^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 1↑" }} } - \bar "|" - { a1^\markup { \pad-markup #0.2 "+6"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }} } - \bar "|" - { ais1^\markup { \pad-markup #0.2 "-31"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 7↑" }} ~ } - \bar "|" - { ais1 } - \bar "|" - { c'1^\markup { \pad-markup #0.2 "+0"} ~ } - \bar "|" - { c'2 f'2^\markup { \pad-markup #0.2 "-2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }} ~ } - \bar "|" - { f'1 ~ } - \bar "|" - { f'1 } - \bar "|" - { g'1^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }} ~ } - \bar "|" - { g'1 ~ } - \bar "|" - { g'1 } - \bar "|" - { ais'1^\markup { \pad-markup #0.2 "-31"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↑" }} ~ } - \bar "|" - { ais'1 } - \bar "|" - { c''1^\markup { \pad-markup #0.2 "+0"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }} ~ } - \bar "|" - { c''1 } - \bar "|" - { b1^\markup { \pad-markup #0.2 "-12"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }}} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4874dd07/lilypond/part_II.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/4874dd07/lilypond/part_II.ly deleted file mode 100644 index 8b4aa3d..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4874dd07/lilypond/part_II.ly +++ /dev/null @@ -1,38 +0,0 @@ -{ - { r1 } - \bar "|" - { r2 g'2^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }} ~ } - \bar "|" - { g'1 ~ } - \bar "|" - { g'2 a'2^\markup { \pad-markup #0.2 "+6"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }} ~ } - \bar "|" - { a'2 c''2^\markup { \pad-markup #0.2 "+0"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }} ~ } - \bar "|" - { c''1 ~ } - \bar "|" - { c''2 g'2^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }} ~ } - \bar "|" - { g'1 ~ } - \bar "|" - { g'2 c''2^\markup { \pad-markup #0.2 "+0"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }} ~ } - \bar "|" - { c''1 ~ } - \bar "|" - { c''1 } - \bar "|" - { f1^\markup { \pad-markup #0.2 "-2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }} } - \bar "|" - { c'1^\markup { \pad-markup #0.2 "+0"} ~ } - \bar "|" - { c'2 g'2^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }} ~ } - \bar "|" - { g'1 ~ } - \bar "|" - { g'1 ~ } - \bar "|" - { g'1 ~ } - \bar "|" - { g'1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4874dd07/lilypond/part_III.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/4874dd07/lilypond/part_III.ly deleted file mode 100644 index f3dc391..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4874dd07/lilypond/part_III.ly +++ /dev/null @@ -1,38 +0,0 @@ -{ - { r1 } - \bar "|" - { c1^\markup { \pad-markup #0.2 "+0"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }} ~ } - \bar "|" - { c1 ~ } - \bar "|" - { c1 ~ } - \bar "|" - { c1 } - \bar "|" - { g1^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }} ~ } - \bar "|" - { g1 } - \bar "|" - { gis1^\markup { \pad-markup #0.2 "+14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↓" }} ~ } - \bar "|" - { gis1 } - \bar "|" - { c'1^\markup { \pad-markup #0.2 "+0"} ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'2 c2^\markup { \pad-markup #0.2 "+0"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }} ~ } - \bar "|" - { c1 ~ } - \bar "|" - { c1 ~ } - \bar "|" - { c2 g2^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 1↑" }} ~ } - \bar "|" - { g1 } - \bar "|" - { d'1^\markup { \pad-markup #0.2 "+4"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↑" }} ~ } - \bar "|" - { d'1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4874dd07/lilypond/part_IV.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/4874dd07/lilypond/part_IV.ly deleted file mode 100644 index c4f4ab6..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4874dd07/lilypond/part_IV.ly +++ /dev/null @@ -1,38 +0,0 @@ -{ - { c'1^\markup { \pad-markup #0.2 "+0"} ~ } - \bar "|" - { c'1 } - \bar "|" - { d'1^\markup { \pad-markup #0.2 "+4"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↑" }} ~ } - \bar "|" - { d'1 ~ } - \bar "|" - { d'1 ~ } - \bar "|" - { d'2 c2^\markup { \pad-markup #0.2 "+0"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 1↑" }} ~ } - \bar "|" - { c1 ~ } - \bar "|" - { c1 } - \bar "|" - { f1^\markup { \pad-markup #0.2 "-2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }} ~ } - \bar "|" - { f2 g2^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↑" }} ~ } - \bar "|" - { g2 f'2^\markup { \pad-markup #0.2 "-2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↓" }} ~ } - \bar "|" - { f'1 ~ } - \bar "|" - { f'2 c''2^\markup { \pad-markup #0.2 "+0"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }} ~ } - \bar "|" - { c''1 } - \bar "|" - { c'1^\markup { \pad-markup #0.2 "+0"} ~ } - \bar "|" - { c'2 f2^\markup { \pad-markup #0.2 "-2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↓" }} ~ } - \bar "|" - { f2 g2^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 1↑" }} ~ } - \bar "|" - { g2 fis'2^\markup { \pad-markup #0.2 "-10"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 5↑" }}} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4b40ed47/4b40ed47_code.scd b/resources/resources_bak_2024_01_03/string_quartet_3_rise/4b40ed47/4b40ed47_code.scd deleted file mode 100644 index 42b64ff..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4b40ed47/4b40ed47_code.scd +++ /dev/null @@ -1,981 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array2) - hsArrayToCents.value(array1); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -/* -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance) -}; -*/ - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = true; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - //if(pDistance >= 0, {stepFunc.value(abs(pDistance))}, {0.01}); - stepFunc.value(pDistance) -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - //tuples = dims.collect({[0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum == 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength.asInteger - minMotifLength.asInteger).rand + minMotifLength.asInteger).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - //noProgIns = (popSize - noSusIns).rand + 1; - noProgIns = (popSize - noSusIns); - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength.asInteger - minProgLength.asInteger).rand + minProgLength.asInteger).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0.01); - - - - /* - if(rangeScore.value(candidate.collect({0}), voices[ins], ranges[ins][1] - 500, ranges[ins][1], 0, true) == 1, { - isInRangeScore = 1 - rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0] + 500, ranges[ins][1] - 500, 0, true); - isInRangeScore = isInRangeScore * rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true) - }, { - isInRangeScore = rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true); - }); - */ - - - isInRangeScore = rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true); - //old way - worked but actually by accident (I think) - //isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - - - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - /* - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - */ - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - //lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - lastState = if(o == 0, {lastXChanges.last.deepCopy}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - /* - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - */ - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - //# voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - # voices, durs = seq.flatten2(if(oneShot, {2}, {3})).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(2).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4b40ed47/4b40ed47_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_3_rise/4b40ed47/4b40ed47_mus_model.json deleted file mode 100644 index 85dcea4..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4b40ed47/4b40ed47_mus_model.json +++ /dev/null @@ -1,86 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ -4, 2, 4, 2, 1, 0 ], [ -3, 2, 3, 2, 1, -1 ], [ -4, 2, 3, 2, 1, 0 ], [ -3, 2, 3, 2, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -4, 2, 4, 2, 1, 0 ], [ -3, 2, 3, 2, 1, -1 ], [ -5, 2, 4, 2, 1, 1 ], [ -3, 2, 3, 2, 0, 0 ] ], 1 ], - [ [ [ -4, 2, 4, 2, 1, 0 ], [ -3, 2, 3, 2, 1, -1 ], [ -5, 2, 4, 2, 1, 1 ], [ -3, 2, 3, 2, 2, -1 ] ], 1 ] - ], - [ - [ [ [ -4, 2, 4, 2, 1, 0 ], [ -4, 1, 4, 2, 1, 1 ], [ -5, 2, 4, 2, 1, 1 ], [ -3, 2, 3, 2, 2, -1 ] ], 1 ], - [ [ [ -5, 2, 5, 2, 1, 1 ], [ -4, 1, 4, 2, 1, 1 ], [ -5, 2, 4, 2, 1, 1 ], [ -3, 2, 3, 2, 2, -1 ] ], 1 ], - [ [ [ -5, 2, 5, 2, 1, 1 ], [ -4, 1, 4, 2, 1, 1 ], [ -5, 2, 4, 2, 1, 1 ], [ -5, 1, 4, 2, 1, 1 ] ], 1 ] - ], - [ - [ [ [ -5, 2, 5, 2, 1, 1 ], [ -4, 1, 4, 2, 1, 1 ], [ -3, 1, 4, 2, 1, 0 ], [ -5, 1, 4, 2, 1, 1 ] ], 1 ] - ], - [ - [ [ [ -5, 2, 5, 2, 1, 1 ], [ -4, 1, 4, 2, 1, 1 ], [ -3, 1, 4, 2, 1, 0 ], [ -5, 1, 4, 3, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -5, 2, 5, 2, 1, 1 ], [ -4, 1, 4, 2, 1, 1 ], [ -4, 1, 5, 2, 1, 1 ], [ -5, 1, 4, 3, 1, 0 ] ], 1 ], - [ [ [ -5, 1, 4, 4, 1, 0 ], [ -4, 1, 4, 2, 1, 1 ], [ -4, 1, 5, 2, 1, 1 ], [ -5, 1, 4, 3, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -5, 1, 4, 4, 1, 0 ], [ -4, 1, 4, 2, 1, 1 ], [ -6, 1, 4, 3, 1, 1 ], [ -5, 1, 4, 3, 1, 0 ] ], 1 ], - [ [ [ -5, 1, 4, 4, 1, 0 ], [ -4, 1, 4, 2, 1, 1 ], [ -6, 1, 4, 3, 1, 1 ], [ -4, 1, 4, 2, 1, 0 ] ], 1 ], - [ [ [ -5, 2, 4, 2, 1, 1 ], [ -4, 1, 4, 2, 1, 1 ], [ -6, 1, 4, 3, 1, 1 ], [ -4, 1, 4, 2, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -5, 2, 4, 2, 1, 1 ], [ -4, 1, 4, 3, 1, 0 ], [ -6, 1, 4, 3, 1, 1 ], [ -4, 1, 4, 2, 1, 0 ] ], 1 ], - [ [ [ -4, 1, 5, 2, 1, 0 ], [ -4, 1, 4, 3, 1, 0 ], [ -6, 1, 4, 3, 1, 1 ], [ -4, 1, 4, 2, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -4, 0, 4, 3, 1, 1 ], [ -4, 1, 4, 3, 1, 0 ], [ -6, 1, 4, 3, 1, 1 ], [ -4, 1, 4, 2, 1, 0 ] ], 1 ], - [ [ [ -4, 0, 4, 3, 1, 1 ], [ -4, 1, 4, 3, 0, 1 ], [ -6, 1, 4, 3, 1, 1 ], [ -4, 1, 4, 2, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -4, 0, 4, 3, 1, 1 ], [ -4, 1, 4, 3, 0, 1 ], [ -5, 1, 4, 2, 1, 1 ], [ -4, 1, 4, 2, 1, 0 ] ], 1 ], - [ [ [ -4, 0, 4, 3, 1, 1 ], [ -3, 1, 4, 1, 1, 0 ], [ -5, 1, 4, 2, 1, 1 ], [ -4, 1, 4, 2, 1, 0 ] ], 1 ], - [ [ [ -3, 1, 4, 2, 1, 0 ], [ -3, 1, 4, 1, 1, 0 ], [ -5, 1, 4, 2, 1, 1 ], [ -4, 1, 4, 2, 1, 0 ] ], 1 ] - ] - ] -], -"last_changes": -[ - [ [ -4, 0, 4, 3, 1, 1 ], [ -4, 1, 4, 3, 1, 0 ], [ -6, 1, 4, 3, 1, 1 ], [ -4, 1, 4, 2, 1, 0 ] ], - [ [ -4, 0, 4, 3, 1, 1 ], [ -4, 1, 4, 3, 0, 1 ], [ -6, 1, 4, 3, 1, 1 ], [ -4, 1, 4, 2, 1, 0 ] ], - [ [ -4, 0, 4, 3, 1, 1 ], [ -4, 1, 4, 3, 0, 1 ], [ -5, 1, 4, 2, 1, 1 ], [ -4, 1, 4, 2, 1, 0 ] ], - [ [ -4, 0, 4, 3, 1, 1 ], [ -3, 1, 4, 1, 1, 0 ], [ -5, 1, 4, 2, 1, 1 ], [ -4, 1, 4, 2, 1, 0 ] ], - [ [ -3, 1, 4, 2, 1, 0 ], [ -3, 1, 4, 1, 1, 0 ], [ -5, 1, 4, 2, 1, 1 ], [ -4, 1, 4, 2, 1, 0 ] ] -], -"cur_uid": "4b40ed47", -"ref_uid": "6db2efcc", -"order_seed": 401316, -"dur_seed": 325935, -"motifs_seed": 749229, -"entrances_probs_vals": [ 0, 0, 0, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 0, 0, 0, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 0, 0, 0, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -2400, 1200 ], [ -1200, 1200 ], [ -702, 1200 ], [ -702, 1200 ] ], -"step_probs_vals": [ 0, 1200, 0.0061728395061728, 0.10227272727273, 0.074074074074074, 0.10227272727273, 0.2037037037037, 0.090909090909091, 0.45679012345679, 0.011363636363636, 0.53086419753086, 0, 0.54320987654321, 0.92045454545455, 0.58641975308642, 0.92613636363636, 0.61111111111111, 0, 0.7880658436214, 0.034090909090909, 1, 0.034090909090909 ], -"passages_weights": [ 1, 0.47, 0.43, 1, 0.4 ], -"hd_exp": 4, -"hd_invert": 0, -"order": -[ - [ [ 0, 1, 2 ], [ 3 ], [ ] ], - [ [ 0, 1 ], [ 2, 3 ], [ ] ], - [ [ 2 ], [ 1, 0, 3 ], [ ] ], - [ [ 0, 1, 3 ], [ 2 ], [ ] ], - [ [ 1, 2, 0 ], [ 3 ], [ ] ], - [ [ 1, 3 ], [ 2, 0 ], [ ] ], - [ [ 1 ], [ 2, 3, 0 ], [ ] ], - [ [ 3, 2 ], [ 1, 0 ], [ ] ], - [ [ 2, 3 ], [ 0, 1 ], [ ] ], - [ [ 3 ], [ 2, 1, 0 ], [ ] ] -], -"sus_weights": [ 0.35, 0.37, 0.38 ], -"order_size": [ 10.091836734694, 10.091836734694 ], -"passages_size": [ 0, 0 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4b40ed47/lilypond/part_I.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/4b40ed47/lilypond/part_I.ly deleted file mode 100644 index 669e421..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4b40ed47/lilypond/part_I.ly +++ /dev/null @@ -1,22 +0,0 @@ -{ - { a'1^\markup { \pad-markup #0.2 "+1"} } - \bar "|" - { c''1^\markup { \pad-markup #0.2 "-37"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 11↑" }} ~ } - \bar "|" - { c''2 gis2^\markup { \pad-markup #0.2 "-23"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }} ~ } - \bar "|" - { gis2 a2^\markup { \pad-markup #0.2 "+5"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 7↑" }} ~ } - \bar "|" - { a1 ~ } - \bar "|" - { a2 b2^\markup { \pad-markup #0.2 "+36"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 13↓" }} ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4b40ed47/lilypond/part_II.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/4b40ed47/lilypond/part_II.ly deleted file mode 100644 index 1c18623..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4b40ed47/lilypond/part_II.ly +++ /dev/null @@ -1,22 +0,0 @@ -{ - { dis'2^\markup { \pad-markup #0.2 "-48"} dis'2^\markup { \pad-markup #0.2 "-21"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↑" }} ~ } - \bar "|" - { dis'1 ~ } - \bar "|" - { dis'1 } - \bar "|" - { b'1^\markup { \pad-markup #0.2 "+36"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 13↓" }} } - \bar "|" - { c''1^\markup { \pad-markup #0.2 "-37"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }} } - \bar "|" - { f1^\markup { \pad-markup #0.2 "+46"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 7↑" }} ~ } - \bar "|" - { f1 ~ } - \bar "|" - { f1 ~ } - \bar "|" - { f2 gis2^\markup { \pad-markup #0.2 "-23"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 13↑" }} ~ } - \bar "|" - { gis1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4b40ed47/lilypond/part_III.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/4b40ed47/lilypond/part_III.ly deleted file mode 100644 index 370f202..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4b40ed47/lilypond/part_III.ly +++ /dev/null @@ -1,22 +0,0 @@ -{ - { fis'1^\markup { \pad-markup #0.2 "+11"} ~ } - \bar "|" - { fis'2 gis'2^\markup { \pad-markup #0.2 "-23"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↓" }} ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'2 a'2^\markup { \pad-markup #0.2 "+5"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 13↓" }} ~ } - \bar "|" - { a'1 } - \bar "|" - { c''1^\markup { \pad-markup #0.2 "-6"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 11↓" }} } - \bar "|" - { d'1^\markup { \pad-markup #0.2 "-33"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 7↓" }}} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4b40ed47/lilypond/part_IV.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/4b40ed47/lilypond/part_IV.ly deleted file mode 100644 index 34d5f50..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4b40ed47/lilypond/part_IV.ly +++ /dev/null @@ -1,22 +0,0 @@ -{ - { fis'1^\markup { \pad-markup #0.2 "+38"} ~ } - \bar "|" - { fis'1 } - \bar "|" - { g'1^\markup { \pad-markup #0.2 "-35"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 5↑" }} ~ } - \bar "|" - { g'1 ~ } - \bar "|" - { g'2 g'2^\markup { \pad-markup #0.2 "-26"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 7↑" }} ~ } - \bar "|" - { g'1 } - \bar "|" - { dis'1^\markup { \pad-markup #0.2 "-21"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↑" }} } - \bar "|" - { dis'2^\markup { \pad-markup #0.2 "+22"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 5↑" }} ais'2^\markup { \pad-markup #0.2 "+44"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↓" }} ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'2 b'2^\markup { \pad-markup #0.2 "+36"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }}} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4bf1af12/4bf1af12_code.scd b/resources/resources_bak_2024_01_03/string_quartet_3_rise/4bf1af12/4bf1af12_code.scd deleted file mode 100644 index 42b64ff..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4bf1af12/4bf1af12_code.scd +++ /dev/null @@ -1,981 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array2) - hsArrayToCents.value(array1); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -/* -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance) -}; -*/ - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = true; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - //if(pDistance >= 0, {stepFunc.value(abs(pDistance))}, {0.01}); - stepFunc.value(pDistance) -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - //tuples = dims.collect({[0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum == 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength.asInteger - minMotifLength.asInteger).rand + minMotifLength.asInteger).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - //noProgIns = (popSize - noSusIns).rand + 1; - noProgIns = (popSize - noSusIns); - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength.asInteger - minProgLength.asInteger).rand + minProgLength.asInteger).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0.01); - - - - /* - if(rangeScore.value(candidate.collect({0}), voices[ins], ranges[ins][1] - 500, ranges[ins][1], 0, true) == 1, { - isInRangeScore = 1 - rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0] + 500, ranges[ins][1] - 500, 0, true); - isInRangeScore = isInRangeScore * rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true) - }, { - isInRangeScore = rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true); - }); - */ - - - isInRangeScore = rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true); - //old way - worked but actually by accident (I think) - //isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - - - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - /* - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - */ - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - //lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - lastState = if(o == 0, {lastXChanges.last.deepCopy}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - /* - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - */ - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - //# voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - # voices, durs = seq.flatten2(if(oneShot, {2}, {3})).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(2).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4bf1af12/4bf1af12_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_3_rise/4bf1af12/4bf1af12_mus_model.json deleted file mode 100644 index 8d43276..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4bf1af12/4bf1af12_mus_model.json +++ /dev/null @@ -1,87 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ -5, 1, 2, 2, 1, 0 ], [ -4, 2, 1, 2, 1, 0 ], [ -3, 2, 2, 2, 1, 0 ], [ -3, 2, 1, 2, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -5, 1, 2, 2, 1, 0 ], [ -3, 0, 2, 2, 1, 0 ], [ -3, 2, 2, 2, 1, 0 ], [ -3, 2, 1, 2, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -5, 1, 2, 2, 1, 0 ], [ -3, 0, 2, 2, 1, 0 ], [ -2, 1, 1, 2, 1, 0 ], [ -3, 2, 1, 2, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -5, 1, 2, 2, 1, 0 ], [ -3, 0, 2, 2, 1, 0 ], [ -2, 1, 1, 2, 1, 0 ], [ -2, 0, 2, 2, 1, 0 ] ], 1 ], - [ [ [ -4, 0, 2, 2, 1, 0 ], [ -3, 0, 2, 2, 1, 0 ], [ -2, 1, 1, 2, 1, 0 ], [ -2, 0, 2, 2, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -4, 0, 2, 2, 1, 0 ], [ -3, 0, 2, 2, 1, 0 ], [ -2, 1, 1, 2, 1, 0 ], [ -3, 1, 2, 2, 1, 0 ] ], 1 ], - [ [ [ -4, 0, 2, 2, 1, 0 ], [ -3, 0, 2, 2, 1, 0 ], [ -2, 0, 2, 2, 1, 0 ], [ -3, 1, 2, 2, 1, 0 ] ], 1 ], - [ [ [ -4, 1, 2, 2, 1, 0 ], [ -3, 0, 2, 2, 1, 0 ], [ -2, 0, 2, 2, 1, 0 ], [ -3, 1, 2, 2, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -4, 1, 2, 2, 1, 0 ], [ -4, 2, 2, 2, 1, 0 ], [ -2, 0, 2, 2, 1, 0 ], [ -3, 1, 2, 2, 1, 0 ] ], 1 ], - [ [ [ -4, 1, 2, 2, 1, 0 ], [ -4, 2, 2, 2, 1, 0 ], [ -3, 2, 2, 2, 1, 0 ], [ -3, 1, 2, 2, 1, 0 ] ], 1 ], - [ [ [ -4, 1, 2, 2, 1, 0 ], [ -4, 2, 2, 2, 1, 0 ], [ -3, 2, 2, 2, 1, 0 ], [ -3, 1, 3, 2, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -4, 1, 2, 2, 1, 0 ], [ -4, 2, 2, 2, 1, 0 ], [ -3, 1, 2, 2, 1, 0 ], [ -3, 1, 3, 2, 1, 0 ] ], 1 ], - [ [ [ -4, 1, 2, 2, 1, 0 ], [ -4, 1, 2, 3, 1, 0 ], [ -3, 1, 2, 2, 1, 0 ], [ -3, 1, 3, 2, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -4, 1, 2, 2, 1, 0 ], [ -4, 1, 2, 3, 1, 0 ], [ -3, 2, 2, 2, 1, 0 ], [ -3, 1, 3, 2, 1, 0 ] ], 1 ], - [ [ [ -4, 1, 2, 2, 1, 0 ], [ -4, 1, 2, 3, 1, 0 ], [ -3, 2, 2, 2, 1, 0 ], [ -2, 0, 2, 2, 1, 0 ] ], 1 ], - [ [ [ -4, 1, 2, 2, 1, 0 ], [ -3, 1, 2, 2, 1, 0 ], [ -3, 2, 2, 2, 1, 0 ], [ -2, 0, 2, 2, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -4, 2, 2, 2, 1, 0 ], [ -3, 1, 2, 2, 1, 0 ], [ -3, 2, 2, 2, 1, 0 ], [ -2, 0, 2, 2, 1, 0 ] ], 1 ], - [ [ [ -4, 2, 2, 2, 1, 0 ], [ -4, 1, 2, 2, 1, 0 ], [ -3, 2, 2, 2, 1, 0 ], [ -2, 0, 2, 2, 1, 0 ] ], 1 ], - [ [ [ -4, 2, 2, 2, 1, 0 ], [ -4, 1, 2, 2, 1, 0 ], [ -3, 2, 2, 2, 1, 0 ], [ -3, 1, 2, 2, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -4, 2, 2, 2, 1, 0 ], [ -4, 1, 2, 2, 1, 0 ], [ -2, 1, 1, 2, 1, 0 ], [ -3, 1, 2, 2, 1, 0 ] ], 1 ], - [ [ [ -4, 2, 2, 2, 1, 0 ], [ -4, 2, 1, 2, 1, 0 ], [ -2, 1, 1, 2, 1, 0 ], [ -3, 1, 2, 2, 1, 0 ] ], 1 ] - ] - ] -], -"last_changes": -[ - [ [ -4, 2, 2, 2, 1, 0 ], [ -3, 1, 2, 2, 1, 0 ], [ -3, 2, 2, 2, 1, 0 ], [ -2, 0, 2, 2, 1, 0 ] ], - [ [ -4, 2, 2, 2, 1, 0 ], [ -4, 1, 2, 2, 1, 0 ], [ -3, 2, 2, 2, 1, 0 ], [ -2, 0, 2, 2, 1, 0 ] ], - [ [ -4, 2, 2, 2, 1, 0 ], [ -4, 1, 2, 2, 1, 0 ], [ -3, 2, 2, 2, 1, 0 ], [ -3, 1, 2, 2, 1, 0 ] ], - [ [ -4, 2, 2, 2, 1, 0 ], [ -4, 1, 2, 2, 1, 0 ], [ -2, 1, 1, 2, 1, 0 ], [ -3, 1, 2, 2, 1, 0 ] ], - [ [ -4, 2, 2, 2, 1, 0 ], [ -4, 2, 1, 2, 1, 0 ], [ -2, 1, 1, 2, 1, 0 ], [ -3, 1, 2, 2, 1, 0 ] ] -], -"cur_uid": "4bf1af12", -"ref_uid": 44490863, -"order_seed": 556699, -"dur_seed": 515215, -"motifs_seed": 916157, -"entrances_probs_vals": [ 0, 0, 0, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 0, 0, 0, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 0, 0, 0, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -2400, 1200 ], [ -1200, 1200 ], [ -702, 1200 ], [ -702, 1200 ] ], -"step_probs_vals": [ 0, 1200, 0.0061728395061728, 0.10227272727273, 0.074074074074074, 0.10227272727273, 0.2037037037037, 0.090909090909091, 0.45679012345679, 0.011363636363636, 0.53086419753086, 0, 0.54320987654321, 0.92045454545455, 0.58641975308642, 0.92613636363636, 0.61111111111111, 0, 0.7880658436214, 0.034090909090909, 1, 0.034090909090909 ], -"passages_weights": [ 1, 0.47, 0.43, 1, 0.9 ], -"hd_exp": 9, -"hd_invert": 0, -"order": -[ - [ [ 0, 1, 2 ], [ 3 ], [ ] ], - [ [ 3, 0, 2 ], [ 1 ], [ ] ], - [ [ 3, 0, 1 ], [ 2 ], [ ] ], - [ [ 1, 2 ], [ 3, 0 ], [ ] ], - [ [ 1 ], [ 3, 2, 0 ], [ ] ], - [ [ 0 ], [ 1, 2, 3 ], [ ] ], - [ [ 3, 0 ], [ 2, 1 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ], - [ [ 2 ], [ 0, 1, 3 ], [ ] ], - [ [ 0, 3 ], [ 2, 1 ], [ ] ] -], -"sus_weights": [ 0.35, 0.37, 0.38 ], -"order_size": [ 10, 10.091836734694 ], -"passages_size": [ 0, 0 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4bf1af12/lilypond/part_I.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/4bf1af12/lilypond/part_I.ly deleted file mode 100644 index 28e0f1c..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4bf1af12/lilypond/part_I.ly +++ /dev/null @@ -1,22 +0,0 @@ -{ - { g'1^\markup { \pad-markup #0.2 "-21"} ~ } - \bar "|" - { g'2 a'2^\markup { \pad-markup #0.2 "-38"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }} ~ } - \bar "|" - { a'2 e'2^\markup { \pad-markup #0.2 "-36"} ~ } - \bar "|" - { e'1 ~ } - \bar "|" - { e'1 } - \bar "|" - { g'1^\markup { \pad-markup #0.2 "+50"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }} ~ } - \bar "|" - { g'1 } - \bar "|" - { a'1^\markup { \pad-markup #0.2 "-38"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }} ~ } - \bar "|" - { a'1 } - \bar "|" - { e'1^\markup { \pad-markup #0.2 "-36"}} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4bf1af12/lilypond/part_II.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/4bf1af12/lilypond/part_II.ly deleted file mode 100644 index e6c2955..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4bf1af12/lilypond/part_II.ly +++ /dev/null @@ -1,22 +0,0 @@ -{ - { b'1^\markup { \pad-markup #0.2 "-34"} } - \bar "|" - { c''1^\markup { \pad-markup #0.2 "-23"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↓" }} ~ } - \bar "|" - { c''1 } - \bar "|" - { a'1^\markup { \pad-markup #0.2 "-38"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }} ~ } - \bar "|" - { a'2 b'2^\markup { \pad-markup #0.2 "-34"} ~ } - \bar "|" - { b'2 e'2^\markup { \pad-markup #0.2 "-36"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }} ~ } - \bar "|" - { e'2 b'2^\markup { \pad-markup #0.2 "-34"} ~ } - \bar "|" - { b'1 ~ } - \bar "|" - { b'1 ~ } - \bar "|" - { b'2 c''2^\markup { \pad-markup #0.2 "-23"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 5↓" }}} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4bf1af12/lilypond/part_III.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/4bf1af12/lilypond/part_III.ly deleted file mode 100644 index 9111a1e..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4bf1af12/lilypond/part_III.ly +++ /dev/null @@ -1,22 +0,0 @@ -{ - { g2^\markup { \pad-markup #0.2 "-21"} a2^\markup { \pad-markup #0.2 "-38"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }} ~ } - \bar "|" - { a1 ~ } - \bar "|" - { a1 ~ } - \bar "|" - { a1 } - \bar "|" - { b1^\markup { \pad-markup #0.2 "-34"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }} ~ } - \bar "|" - { b1 } - \bar "|" - { cis'1^\markup { \pad-markup #0.2 "+32"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↑" }} ~ } - \bar "|" - { cis'2 e'2^\markup { \pad-markup #0.2 "-36"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }} ~ } - \bar "|" - { e'2 e2^\markup { \pad-markup #0.2 "-36"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }} ~ } - \bar "|" - { e1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4bf1af12/lilypond/part_IV.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/4bf1af12/lilypond/part_IV.ly deleted file mode 100644 index 5c0d977..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4bf1af12/lilypond/part_IV.ly +++ /dev/null @@ -1,22 +0,0 @@ -{ - { e,1^\markup { \pad-markup #0.2 "-36"} ~ } - \bar "|" - { e,1 } - \bar "|" - { a,1^\markup { \pad-markup #0.2 "-38"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }} ~ } - \bar "|" - { a,2 e2^\markup { \pad-markup #0.2 "-36"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }} ~ } - \bar "|" - { e1 ~ } - \bar "|" - { e1 ~ } - \bar "|" - { e1 ~ } - \bar "|" - { e1 } - \bar "|" - { b1^\markup { \pad-markup #0.2 "-34"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 1↑" }} ~ } - \bar "|" - { b1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4c745666/4c745666_code.scd b/resources/resources_bak_2024_01_03/string_quartet_3_rise/4c745666/4c745666_code.scd deleted file mode 100644 index 0b55c37..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4c745666/4c745666_code.scd +++ /dev/null @@ -1,977 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array2) - hsArrayToCents.value(array1); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -/* -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance) -}; -*/ - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = true; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - //if(pDistance >= 0, {stepFunc.value(abs(pDistance))}, {0.01}); - stepFunc.value(pDistance) -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - //tuples = dims.collect({[0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum == 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength.asInteger - minMotifLength.asInteger).rand + minMotifLength.asInteger).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - //noProgIns = (popSize - noSusIns).rand + 1; - noProgIns = (popSize - noSusIns); - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength.asInteger - minProgLength.asInteger).rand + minProgLength.asInteger).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0.01); - - - - /* - if(rangeScore.value(candidate.collect({0}), voices[ins], ranges[ins][1] - 500, ranges[ins][1], 0, true) == 1, { - isInRangeScore = 1 - rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0] + 500, ranges[ins][1] - 500, 0, true); - isInRangeScore = isInRangeScore * rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true) - }, { - isInRangeScore = rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true); - }); - */ - - - isInRangeScore = rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true); - //old way - worked but actually by accident (I think) - //isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - - - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - /* - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - */ - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4c745666/4c745666_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_3_rise/4c745666/4c745666_mus_model.json deleted file mode 100644 index 06875fc..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4c745666/4c745666_mus_model.json +++ /dev/null @@ -1,166 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ] ], 1 ], - [ [ [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ] ], 1 ], - [ [ [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ] ], 1 ], - [ [ [ 0, 0, 0, 1, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ 0, 0, 0, 1, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, -1, 0 ], [ 0, 1, 0, 0, 0, 0 ] ], 1 ], - [ [ [ 1, 1, 0, 0, 0, -1 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, -1, 0 ], [ 0, 1, 0, 0, 0, 0 ] ], 1 ], - [ [ [ 1, 1, 0, 0, 0, -1 ], [ -1, 1, 0, 1, 0, 0 ], [ 0, 1, 0, 0, -1, 0 ], [ 0, 1, 0, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ 1, 1, 0, 0, 0, -1 ], [ -1, 1, 0, 1, 0, 0 ], [ -1, 2, 0, 1, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ] ], 1 ], - [ [ [ 1, 0, 0, 0, 0, 0 ], [ -1, 1, 0, 1, 0, 0 ], [ -1, 2, 0, 1, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ 1, 0, 0, 0, 0, 0 ], [ -1, 1, 0, 1, 0, 0 ], [ -1, 2, 0, 1, 0, 0 ], [ -1, 1, 0, 1, 1, 0 ] ], 1 ] - ], - [ - [ [ [ 1, 0, 0, 0, 0, 0 ], [ -1, 1, 0, 1, 0, 0 ], [ -1, 2, 0, 1, 0, 0 ], [ -2, 2, 0, 1, 1, 0 ] ], 1 ], - [ [ [ 1, 0, 0, 0, 0, 0 ], [ -1, 2, 0, 1, -1, 0 ], [ -1, 2, 0, 1, 0, 0 ], [ -2, 2, 0, 1, 1, 0 ] ], 1 ], - [ [ [ -2, 2, 0, 2, 0, 0 ], [ -1, 2, 0, 1, -1, 0 ], [ -1, 2, 0, 1, 0, 0 ], [ -2, 2, 0, 1, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 2, 0, 2, 0, 0 ], [ -1, 2, 0, 1, -1, 0 ], [ -3, 3, 0, 1, 1, 0 ], [ -2, 2, 0, 1, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 2, 0, 2, 0, 0 ], [ -1, 2, 0, 1, -1, 0 ], [ -3, 3, 0, 1, 1, 0 ], [ -1, 2, 0, 1, 0, 0 ] ], 1 ], - [ [ [ -2, 2, 0, 2, 0, 0 ], [ -2, 3, 0, 1, 0, 0 ], [ -3, 3, 0, 1, 1, 0 ], [ -1, 2, 0, 1, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 2, 0, 2, 0, 0 ], [ -2, 3, 0, 1, 0, 0 ], [ -2, 2, 1, 1, 0, 0 ], [ -1, 2, 0, 1, 0, 0 ] ], 1 ], - [ [ [ -3, 2, 0, 1, 0, 0 ], [ -2, 3, 0, 1, 0, 0 ], [ -2, 2, 1, 1, 0, 0 ], [ -1, 2, 0, 1, 0, 0 ] ], 1 ], - [ [ [ -3, 2, 0, 1, 0, 0 ], [ -1, 2, -1, 1, 0, 0 ], [ -2, 2, 1, 1, 0, 0 ], [ -1, 2, 0, 1, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -3, 2, 0, 1, 0, 0 ], [ -1, 2, -1, 1, 0, 0 ], [ 0, 2, -1, 0, 0, 0 ], [ -1, 2, 0, 1, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -3, 2, 0, 1, 0, 0 ], [ -1, 2, -1, 1, 0, 0 ], [ -3, 2, 0, 1, 1, 0 ], [ -1, 2, 0, 1, 0, 0 ] ], 1 ], - [ [ [ -3, 2, 0, 1, 0, 0 ], [ -1, 2, -1, 1, 0, 0 ], [ -3, 2, 0, 1, 1, 0 ], [ -1, 2, 0, 1, 0, -1 ] ], 1 ], - [ [ [ -3, 2, 0, 1, 0, 0 ], [ -2, 2, 0, 1, 0, 1 ], [ -3, 2, 0, 1, 1, 0 ], [ -1, 2, 0, 1, 0, -1 ] ], 1 ] - ], - [ - [ [ [ -3, 2, 0, 1, 0, 0 ], [ -1, 2, 0, 1, 1, -1 ], [ -3, 2, 0, 1, 1, 0 ], [ -1, 2, 0, 1, 0, -1 ] ], 1 ], - [ [ [ -3, 2, 0, 1, 0, 0 ], [ -1, 2, 0, 1, 1, -1 ], [ -3, 2, 0, 1, 1, 0 ], [ -1, 2, 0, 0, 1, 0 ] ], 1 ], - [ [ [ -2, 2, 0, 1, 1, -1 ], [ -1, 2, 0, 1, 1, -1 ], [ -3, 2, 0, 1, 1, 0 ], [ -1, 2, 0, 0, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 2, 0, 1, 1, -1 ], [ -1, 2, 0, 1, 1, -1 ], [ -3, 2, 0, 1, 1, 0 ], [ -2, 2, 0, 1, 2, 0 ] ], 1 ], - [ [ [ -2, 2, 0, 1, 1, -1 ], [ -1, 2, 0, 1, 0, 0 ], [ -3, 2, 0, 1, 1, 0 ], [ -2, 2, 0, 1, 2, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 1, 0, 1, 2, 0 ], [ -1, 2, 0, 1, 0, 0 ], [ -3, 2, 0, 1, 1, 0 ], [ -2, 2, 0, 1, 2, 0 ] ], 1 ], - [ [ [ -2, 1, 0, 1, 2, 0 ], [ -1, 2, 0, 1, 0, 0 ], [ -4, 3, 0, 1, 2, 0 ], [ -2, 2, 0, 1, 2, 0 ] ], 1 ], - [ [ [ -2, 1, 0, 1, 2, 0 ], [ -2, 2, 0, 0, 2, 0 ], [ -4, 3, 0, 1, 2, 0 ], [ -2, 2, 0, 1, 2, 0 ] ], 1 ] - ], - [ - [ [ [ -3, 2, 0, 0, 2, 0 ], [ -2, 2, 0, 0, 2, 0 ], [ -4, 3, 0, 1, 2, 0 ], [ -2, 2, 0, 1, 2, 0 ] ], 1 ] - ], - [ - [ [ [ -3, 2, 0, 0, 2, 0 ], [ -2, 3, 0, 0, 2, 0 ], [ -4, 3, 0, 1, 2, 0 ], [ -2, 2, 0, 1, 2, 0 ] ], 1 ], - [ [ [ -3, 3, 0, 0, 2, 0 ], [ -2, 3, 0, 0, 2, 0 ], [ -4, 3, 0, 1, 2, 0 ], [ -2, 2, 0, 1, 2, 0 ] ], 1 ] - ], - [ - [ [ [ -3, 3, 0, 0, 2, 0 ], [ -2, 3, 0, 0, 2, 0 ], [ -4, 3, 0, 1, 2, 0 ], [ -1, 3, 0, 0, 2, -1 ] ], 1 ], - [ [ [ -3, 3, 0, 0, 2, 0 ], [ -2, 3, 1, 0, 2, 0 ], [ -4, 3, 0, 1, 2, 0 ], [ -1, 3, 0, 0, 2, -1 ] ], 1 ], - [ [ [ -3, 3, 0, 0, 2, 0 ], [ -2, 3, 1, 0, 2, 0 ], [ -2, 3, 0, 0, 1, 0 ], [ -1, 3, 0, 0, 2, -1 ] ], 1 ] - ], - [ - [ [ [ -3, 3, 0, 0, 2, 0 ], [ -4, 3, 0, 1, 1, 0 ], [ -2, 3, 0, 0, 1, 0 ], [ -1, 3, 0, 0, 2, -1 ] ], 1 ], - [ [ [ -3, 3, 0, 0, 1, 1 ], [ -4, 3, 0, 1, 1, 0 ], [ -2, 3, 0, 0, 1, 0 ], [ -1, 3, 0, 0, 2, -1 ] ], 1 ] - ], - [ - [ [ [ -3, 3, 0, 0, 1, 1 ], [ -2, 3, 0, 0, 0, 0 ], [ -2, 3, 0, 0, 1, 0 ], [ -1, 3, 0, 0, 2, -1 ] ], 1 ], - [ [ [ -3, 3, 0, 1, 1, 0 ], [ -2, 3, 0, 0, 0, 0 ], [ -2, 3, 0, 0, 1, 0 ], [ -1, 3, 0, 0, 2, -1 ] ], 1 ], - [ [ [ -3, 3, 0, 1, 1, 0 ], [ -2, 3, 0, 0, 0, 0 ], [ -2, 3, 0, 0, 1, 0 ], [ -2, 3, 0, 0, 2, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 3, 0, 1, 0, 0 ], [ -2, 3, 0, 0, 0, 0 ], [ -2, 3, 0, 0, 1, 0 ], [ -2, 3, 0, 0, 2, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 3, 0, 1, 0, 0 ], [ -2, 3, 0, 0, 0, 0 ], [ -2, 3, 0, 0, 1, 0 ], [ -1, 3, 0, 1, 0, -1 ] ], 1 ], - [ [ [ -2, 3, 0, 1, 0, 0 ], [ -2, 3, 0, 0, 0, 0 ], [ -1, 3, 0, 0, 0, 0 ], [ -1, 3, 0, 1, 0, -1 ] ], 1 ], - [ [ [ -2, 3, 0, 1, 0, 0 ], [ -2, 3, 0, 1, -1, 0 ], [ -1, 3, 0, 0, 0, 0 ], [ -1, 3, 0, 1, 0, -1 ] ], 1 ] - ], - [ - [ [ [ -1, 3, -1, 1, -1, 0 ], [ -2, 3, 0, 1, -1, 0 ], [ -1, 3, 0, 0, 0, 0 ], [ -1, 3, 0, 1, 0, -1 ] ], 1 ], - [ [ [ -1, 3, -1, 1, -1, 0 ], [ -2, 3, 0, 1, -1, 0 ], [ -2, 3, 0, 1, -1, 1 ], [ -1, 3, 0, 1, 0, -1 ] ], 1 ] - ], - [ - [ [ [ -1, 3, -1, 1, -1, 0 ], [ -2, 3, 0, 1, -1, 0 ], [ -2, 3, 0, 1, -1, 1 ], [ -2, 3, 0, 2, -1, 0 ] ], 1 ], - [ [ [ -2, 3, -1, 1, -1, 0 ], [ -2, 3, 0, 1, -1, 0 ], [ -2, 3, 0, 1, -1, 1 ], [ -2, 3, 0, 2, -1, 0 ] ], 1 ], - [ [ [ -2, 3, -1, 1, -1, 0 ], [ -2, 3, 0, 1, -1, 0 ], [ -3, 4, 0, 1, -1, 0 ], [ -2, 3, 0, 2, -1, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 3, -1, 1, -1, 0 ], [ -2, 4, 0, 1, -1, 0 ], [ -3, 4, 0, 1, -1, 0 ], [ -2, 3, 0, 2, -1, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 3, -1, 1, -1, 0 ], [ -2, 4, 0, 1, -1, 0 ], [ -3, 4, 0, 1, -1, 0 ], [ 0, 3, -1, 0, -1, 0 ] ], 1 ], - [ [ [ -2, 3, -1, 1, -1, 0 ], [ -2, 4, 0, 1, -1, 0 ], [ -2, 3, -1, 1, 0, 0 ], [ 0, 3, -1, 0, -1, 0 ] ], 1 ], - [ [ [ -2, 3, -1, 1, -1, 0 ], [ -2, 4, 0, 1, -1, 0 ], [ "Rest" ], [ 0, 3, -1, 0, -1, 0 ] ], 1 ], - [ [ [ -2, 3, -1, 1, -1, 0 ], [ -2, 4, 0, 1, -1, 0 ], [ "Rest" ], [ "Rest" ] ], 1 ], - [ [ [ -2, 3, -1, 1, -1, 0 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 1 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 3 ] - ] - ] -], -"last_changes": -[ - [ [ 0, 0, -1, 0, -1, 2 ], [ 0, -1, -1, 1, -1, 2 ], [ 1, 0, -1, 0, -1, 1 ], [ 0, -1, -1, 1, -1, 1 ] ], - [ [ 0, 0, -1, 1, -1, 1 ], [ 0, -1, -1, 1, -1, 2 ], [ 1, 0, -1, 0, -1, 1 ], [ 0, -1, -1, 1, -1, 1 ] ], - [ [ 0, 0, -1, 1, -1, 1 ], [ 0, -1, -1, 1, -1, 2 ], [ 0, -1, -1, 2, -1, 1 ], [ 0, -1, -1, 1, -1, 1 ] ], - [ [ 0, 0, -1, 1, -1, 1 ], [ 1, -1, -1, 0, -1, 1 ], [ 0, -1, -1, 2, -1, 1 ], [ 0, -1, -1, 1, -1, 1 ] ], - [ [ 0, 0, -1, 1, -1, 1 ], [ 1, 0, -1, 0, -1, 1 ], [ 0, -1, -1, 2, -1, 1 ], [ 0, -1, -1, 1, -1, 1 ] ] -], -"cur_uid": "4c745666", -"ref_uid": "nil", -"order_seed": 885120, -"dur_seed": 331456, -"motifs_seed": 712350, -"entrances_probs_vals": [ 0, 0, 0, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 0, 0, 0, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 0, 0, 0, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -2400, 1200 ], [ -1200, 1200 ], [ -702, 1200 ], [ -702, 1200 ] ], -"step_probs_vals": [ 0, 1200, 0.0020576131687243, 0.068181818181818, 0.074074074074074, 0.0625, 0.20576131687243, 0.0625, 0.45679012345679, 0.011363636363636, 0.53086419753086, 0, 0.54320987654321, 0.92045454545455, 0.58641975308642, 0.92613636363636, 0.61111111111111, 0, 0.78600823045268, 0.068181818181818, 0.98971193415638, 0.0625 ], -"passages_weights": [ 1, 1, 1, 1, 0.1 ], -"hd_exp": 1, -"hd_invert": 0, -"order": -[ - [ [ 3, 1, 0 ], [ 2 ], [ ] ], - [ [ 2, 3 ], [ 1, 0 ], [ ] ], - [ [ 0 ], [ 3, 1, 2 ], [ ] ], - [ [ 3, 0 ], [ 1, 2 ], [ ] ], - [ [ 0 ], [ 3, 1, 2 ], [ ] ], - [ [ 1, 0 ], [ 3, 2 ], [ ] ], - [ [ 2, 0, 1 ], [ 3 ], [ ] ], - [ [ 0, 3 ], [ 2, 1 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ], - [ [ 1, 0, 3 ], [ 2 ], [ ] ], - [ [ 2, 1 ], [ 0, 3 ], [ ] ], - [ [ 0 ], [ 1, 2, 3 ], [ ] ], - [ [ 2 ], [ 1, 0, 3 ], [ ] ], - [ [ 3, 2, 1 ], [ 0 ], [ ] ], - [ [ 3, 0, 1 ], [ 2 ], [ ] ], - [ [ 0, 2, 1 ], [ 3 ], [ ] ], - [ [ 0, 2, 1 ], [ 3 ], [ ] ], - [ [ 2, 0 ], [ 1, 3 ], [ ] ], - [ [ 1 ], [ 2, 0, 3 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ], - [ [ 2, 3 ], [ 0, 1 ], [ ] ], - [ [ 2, 1, 3 ], [ 0 ], [ ] ], - [ [ 0, 3 ], [ 2, 1 ], [ ] ], - [ [ 0, 3, 2 ], [ 1 ], [ ] ] -], -"sus_weights": [ 0.35, 0.37, 0.38 ], -"order_size": [ 24.724489795918, 25 ], -"passages_size": [ 0, 0 ], -"motif_edited": "true", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4e9f1dcc/4e9f1dcc_code.scd b/resources/resources_bak_2024_01_03/string_quartet_3_rise/4e9f1dcc/4e9f1dcc_code.scd deleted file mode 100644 index 42b64ff..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4e9f1dcc/4e9f1dcc_code.scd +++ /dev/null @@ -1,981 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array2) - hsArrayToCents.value(array1); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -/* -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance) -}; -*/ - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = true; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - //if(pDistance >= 0, {stepFunc.value(abs(pDistance))}, {0.01}); - stepFunc.value(pDistance) -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - //tuples = dims.collect({[0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum == 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength.asInteger - minMotifLength.asInteger).rand + minMotifLength.asInteger).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - //noProgIns = (popSize - noSusIns).rand + 1; - noProgIns = (popSize - noSusIns); - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength.asInteger - minProgLength.asInteger).rand + minProgLength.asInteger).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0.01); - - - - /* - if(rangeScore.value(candidate.collect({0}), voices[ins], ranges[ins][1] - 500, ranges[ins][1], 0, true) == 1, { - isInRangeScore = 1 - rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0] + 500, ranges[ins][1] - 500, 0, true); - isInRangeScore = isInRangeScore * rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true) - }, { - isInRangeScore = rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true); - }); - */ - - - isInRangeScore = rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true); - //old way - worked but actually by accident (I think) - //isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - - - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - /* - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - */ - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - //lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - lastState = if(o == 0, {lastXChanges.last.deepCopy}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - /* - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - */ - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - //# voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - # voices, durs = seq.flatten2(if(oneShot, {2}, {3})).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(2).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4e9f1dcc/4e9f1dcc_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_3_rise/4e9f1dcc/4e9f1dcc_mus_model.json deleted file mode 100644 index 38e73bd..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4e9f1dcc/4e9f1dcc_mus_model.json +++ /dev/null @@ -1,86 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ -3, 1, 4, 2, 1, 0 ], [ -4, 1, 5, 2, 1, 1 ], [ -5, 1, 4, 2, 1, 1 ], [ -4, 1, 4, 2, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -6, 1, 4, 2, 1, 2 ], [ -4, 1, 5, 2, 1, 1 ], [ -5, 1, 4, 2, 1, 1 ], [ -4, 1, 4, 2, 1, 0 ] ], 1 ], - [ [ [ -6, 1, 4, 2, 1, 2 ], [ -4, 1, 5, 2, 1, 1 ], [ -5, 1, 4, 2, 1, 1 ], [ -4, 1, 5, 2, 0, 1 ] ], 1 ] - ], - [ - [ [ [ -6, 1, 4, 2, 1, 2 ], [ -4, 1, 4, 2, 0, 1 ], [ -5, 1, 4, 2, 1, 1 ], [ -4, 1, 5, 2, 0, 1 ] ], 1 ], - [ [ [ -6, 1, 4, 2, 1, 2 ], [ -4, 1, 4, 2, 0, 1 ], [ -5, 1, 5, 2, 0, 2 ], [ -4, 1, 5, 2, 0, 1 ] ], 1 ] - ], - [ - [ [ [ -6, 1, 4, 2, 1, 2 ], [ -4, 1, 5, 2, -1, 2 ], [ -5, 1, 5, 2, 0, 2 ], [ -4, 1, 5, 2, 0, 1 ] ], 1 ], - [ [ [ -5, 1, 4, 2, 0, 2 ], [ -4, 1, 5, 2, -1, 2 ], [ -5, 1, 5, 2, 0, 2 ], [ -4, 1, 5, 2, 0, 1 ] ], 1 ] - ], - [ - [ [ [ -4, 0, 5, 2, 0, 1 ], [ -4, 1, 5, 2, -1, 2 ], [ -5, 1, 5, 2, 0, 2 ], [ -4, 1, 5, 2, 0, 1 ] ], 1 ] - ], - [ - [ [ [ -4, 0, 5, 2, 0, 1 ], [ -3, 1, 5, 2, 0, 0 ], [ -5, 1, 5, 2, 0, 2 ], [ -4, 1, 5, 2, 0, 1 ] ], 1 ], - [ [ [ -5, 2, 5, 2, 0, 1 ], [ -3, 1, 5, 2, 0, 0 ], [ -5, 1, 5, 2, 0, 2 ], [ -4, 1, 5, 2, 0, 1 ] ], 1 ] - ], - [ - [ [ [ -5, 2, 5, 2, 0, 1 ], [ -3, 1, 5, 2, 0, 0 ], [ -5, 1, 5, 2, 0, 2 ], [ -4, 1, 5, 2, -1, 2 ] ], 1 ], - [ [ [ -5, 2, 5, 2, 0, 1 ], [ -5, 1, 5, 2, 0, 3 ], [ -5, 1, 5, 2, 0, 2 ], [ -4, 1, 5, 2, -1, 2 ] ], 1 ], - [ [ [ -4, 1, 5, 1, 0, 2 ], [ -5, 1, 5, 2, 0, 3 ], [ -5, 1, 5, 2, 0, 2 ], [ -4, 1, 5, 2, -1, 2 ] ], 1 ] - ], - [ - [ [ [ -4, 1, 5, 1, 0, 2 ], [ -6, 1, 5, 2, 0, 2 ], [ -5, 1, 5, 2, 0, 2 ], [ -4, 1, 5, 2, -1, 2 ] ], 1 ], - [ [ [ -4, 1, 5, 1, 0, 2 ], [ -6, 1, 5, 2, 0, 2 ], [ -5, 1, 5, 2, 0, 2 ], [ -5, 2, 5, 2, 0, 2 ] ], 1 ], - [ [ [ -4, 0, 5, 2, 0, 2 ], [ -6, 1, 5, 2, 0, 2 ], [ -5, 1, 5, 2, 0, 2 ], [ -5, 2, 5, 2, 0, 2 ] ], 1 ] - ], - [ - [ [ [ -4, 0, 5, 2, 0, 2 ], [ -6, 2, 5, 2, 0, 2 ], [ -5, 1, 5, 2, 0, 2 ], [ -5, 2, 5, 2, 0, 2 ] ], 1 ] - ], - [ - [ [ [ -4, 0, 5, 2, 0, 2 ], [ -5, 1, 4, 2, 0, 2 ], [ -5, 1, 5, 2, 0, 2 ], [ -5, 2, 5, 2, 0, 2 ] ], 1 ], - [ [ [ -6, 1, 5, 1, 0, 2 ], [ -5, 1, 4, 2, 0, 2 ], [ -5, 1, 5, 2, 0, 2 ], [ -5, 2, 5, 2, 0, 2 ] ], 1 ], - [ [ [ -6, 1, 5, 1, 0, 2 ], [ -5, 1, 4, 2, 0, 2 ], [ -5, 1, 5, 2, 0, 2 ], [ -5, 1, 5, 2, 0, 3 ] ], 1 ] - ] - ] -], -"last_changes": -[ - [ [ -4, 0, 5, 2, 0, 2 ], [ -6, 1, 5, 2, 0, 2 ], [ -5, 1, 5, 2, 0, 2 ], [ -5, 2, 5, 2, 0, 2 ] ], - [ [ -4, 0, 5, 2, 0, 2 ], [ -6, 2, 5, 2, 0, 2 ], [ -5, 1, 5, 2, 0, 2 ], [ -5, 2, 5, 2, 0, 2 ] ], - [ [ -4, 0, 5, 2, 0, 2 ], [ -5, 1, 4, 2, 0, 2 ], [ -5, 1, 5, 2, 0, 2 ], [ -5, 2, 5, 2, 0, 2 ] ], - [ [ -6, 1, 5, 1, 0, 2 ], [ -5, 1, 4, 2, 0, 2 ], [ -5, 1, 5, 2, 0, 2 ], [ -5, 2, 5, 2, 0, 2 ] ], - [ [ -6, 1, 5, 1, 0, 2 ], [ -5, 1, 4, 2, 0, 2 ], [ -5, 1, 5, 2, 0, 2 ], [ -5, 1, 5, 2, 0, 3 ] ] -], -"cur_uid": "4e9f1dcc", -"ref_uid": "4b40ed47", -"order_seed": 207247, -"dur_seed": 435476, -"motifs_seed": 299289, -"entrances_probs_vals": [ 0, 0, 0, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 0, 0, 0, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 0, 0, 0, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -2400, 1200 ], [ -1200, 1200 ], [ -702, 1200 ], [ -702, 1200 ] ], -"step_probs_vals": [ 0, 1200, 0.0061728395061728, 0.10227272727273, 0.074074074074074, 0.10227272727273, 0.2037037037037, 0.090909090909091, 0.45679012345679, 0.011363636363636, 0.53086419753086, 0, 0.54320987654321, 0.92045454545455, 0.58641975308642, 0.92613636363636, 0.61111111111111, 0, 0.7880658436214, 0.034090909090909, 1, 0.034090909090909 ], -"passages_weights": [ 1, 0.47, 0.43, 1, 0.3 ], -"hd_exp": 3, -"hd_invert": 0, -"order": -[ - [ [ 0, 2, 3 ], [ 1 ], [ ] ], - [ [ 1, 2 ], [ 0, 3 ], [ ] ], - [ [ 0, 3 ], [ 1, 2 ], [ ] ], - [ [ 3, 2 ], [ 1, 0 ], [ ] ], - [ [ 3, 1, 2 ], [ 0 ], [ ] ], - [ [ 2, 3 ], [ 1, 0 ], [ ] ], - [ [ 2 ], [ 3, 1, 0 ], [ ] ], - [ [ 2 ], [ 1, 3, 0 ], [ ] ], - [ [ 3, 0, 2 ], [ 1 ], [ ] ], - [ [ 2 ], [ 1, 0, 3 ], [ ] ] -], -"sus_weights": [ 0.35, 0.37, 0.38 ], -"order_size": [ 10.091836734694, 10.091836734694 ], -"passages_size": [ 0, 0 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4e9f1dcc/lilypond/part_I.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/4e9f1dcc/lilypond/part_I.ly deleted file mode 100644 index bca81dd..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4e9f1dcc/lilypond/part_I.ly +++ /dev/null @@ -1,22 +0,0 @@ -{ - { b1^\markup { \pad-markup #0.2 "+36"} } - \bar "|" - { fis'1^\markup { \pad-markup #0.2 "+12"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 11↓" }} ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 } - \bar "|" - { a'1^\markup { \pad-markup #0.2 "+1"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 11↓" }} ~ } - \bar "|" - { a'1 } - \bar "|" - { ais'1^\markup { \pad-markup #0.2 "-46"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↑" }} ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'2 b'2^\markup { \pad-markup #0.2 "-7"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 13↑" }}} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4e9f1dcc/lilypond/part_II.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/4e9f1dcc/lilypond/part_II.ly deleted file mode 100644 index 48f81fd..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4e9f1dcc/lilypond/part_II.ly +++ /dev/null @@ -1,22 +0,0 @@ -{ - { gis1^\markup { \pad-markup #0.2 "-23"} ~ } - \bar "|" - { gis1 } - \bar "|" - { dis'1^\markup { \pad-markup #0.2 "-48"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 13↑" }} ~ } - \bar "|" - { dis'1 ~ } - \bar "|" - { dis'1 ~ } - \bar "|" - { dis'1 ~ } - \bar "|" - { dis'1 ~ } - \bar "|" - { dis'1 ~ } - \bar "|" - { dis'1 ~ } - \bar "|" - { dis'1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4e9f1dcc/lilypond/part_III.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/4e9f1dcc/lilypond/part_III.ly deleted file mode 100644 index 6a243ff..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4e9f1dcc/lilypond/part_III.ly +++ /dev/null @@ -1,22 +0,0 @@ -{ - { c''1^\markup { \pad-markup #0.2 "-37"} ~ } - \bar "|" - { c''2 d'2^\markup { \pad-markup #0.2 "+25"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 11↓" }} ~ } - \bar "|" - { d'2 a'2^\markup { \pad-markup #0.2 "+1"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 11↓" }} ~ } - \bar "|" - { a'1 } - \bar "|" - { ais'1^\markup { \pad-markup #0.2 "-29"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 13↓" }} ~ } - \bar "|" - { ais'2 b'2^\markup { \pad-markup #0.2 "-7"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 13↑" }} ~ } - \bar "|" - { b'2 dis2^\markup { \pad-markup #0.2 "-48"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 1↑" }} ~ } - \bar "|" - { dis1 } - \bar "|" - { ais2^\markup { \pad-markup #0.2 "-46"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }} b2^\markup { \pad-markup #0.2 "-34"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 5↓" }} ~ } - \bar "|" - { b1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4e9f1dcc/lilypond/part_IV.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/4e9f1dcc/lilypond/part_IV.ly deleted file mode 100644 index a370cf4..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4e9f1dcc/lilypond/part_IV.ly +++ /dev/null @@ -1,22 +0,0 @@ -{ - { b'2^\markup { \pad-markup #0.2 "+36"} e2^\markup { \pad-markup #0.2 "+17"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 13↑" }} ~ } - \bar "|" - { e1 ~ } - \bar "|" - { e1 } - \bar "|" - { b2^\markup { \pad-markup #0.2 "-34"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 5↓" }} b2^\markup { \pad-markup #0.2 "+10"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↓" }} ~ } - \bar "|" - { b2 cis'2^\markup { \pad-markup #0.2 "+14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↑" }} ~ } - \bar "|" - { cis'1 } - \bar "|" - { f'1^\markup { \pad-markup #0.2 "-17"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 7↓" }} ~ } - \bar "|" - { f'2 gis'2^\markup { \pad-markup #0.2 "-50"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↓" }} ~ } - \bar "|" - { gis'1 } - \bar "|" - { f,1^\markup { \pad-markup #0.2 "-17"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 7↓" }}} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4ef018fc/4ef018fc_code.scd b/resources/resources_bak_2024_01_03/string_quartet_3_rise/4ef018fc/4ef018fc_code.scd deleted file mode 100644 index 57e638d..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4ef018fc/4ef018fc_code.scd +++ /dev/null @@ -1,945 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array2) - hsArrayToCents.value(array1); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = true; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance); -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength.asInteger - minMotifLength.asInteger).rand + minMotifLength.asInteger).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - noProgIns = (popSize - noSusIns).rand + 1; - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength.asInteger - minProgLength.asInteger).rand + minProgLength.asInteger).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0); - isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4ef018fc/4ef018fc_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_3_rise/4ef018fc/4ef018fc_mus_model.json deleted file mode 100644 index 71a4e25..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4ef018fc/4ef018fc_mus_model.json +++ /dev/null @@ -1,79 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ] ], 3.75 ], - [ [ [ 0, 0, 0, 0, 1, 0 ], [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ] ], 0.75 ] - ], - [ - [ [ [ 0, 0, 0, 0, 1, 0 ], [ 0, 0, -1, 0, 1, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ] ], 0 ], - [ [ [ 0, 0, 0, 0, 1, 0 ], [ 0, 0, -1, 0, 1, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, -1, 0, 0, 1, 0 ] ], 0.75 ], - [ [ [ 0, 0, 0, 0, 1, 0 ], [ 0, 0, -1, 0, 1, 0 ], [ -1, 0, 0, 0, 1, 0 ], [ 0, -1, 0, 0, 1, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 1, 0 ], [ 0, 0, -1, 0, 1, 0 ], [ -1, 0, 0, 0, 1, 0 ], [ 0, 0, 0, 0, 1, -1 ] ], 0.75 ] - ], - [ - [ [ [ 0, 0, 0, 0, 1, 0 ], [ 0, 0, -1, 0, 1, 0 ], [ 0, 0, 0, -1, 1, 0 ], [ 0, 0, 0, 0, 1, -1 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 1, 0 ], [ -1, 1, 0, 0, 1, 0 ], [ 0, 0, 0, -1, 1, 0 ], [ 0, 0, 0, 0, 1, -1 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 1, 0 ], [ -1, 1, 0, 0, 1, 0 ], [ 0, 0, 0, -1, 1, 0 ], [ -1, 0, 0, 0, 2, 0 ] ], 2.5 ] - ], - [ - [ [ [ 0, 0, 0, 0, 1, 0 ], [ "Rest" ], [ 0, 0, 0, -1, 1, 0 ], [ -1, 0, 0, 0, 2, 0 ] ], 0 ], - [ [ [ -1, 0, 0, 0, 2, 1 ], [ "Rest" ], [ 0, 0, 0, -1, 1, 0 ], [ -1, 0, 0, 0, 2, 0 ] ], 0.625 ], - [ [ [ -1, 0, 0, 0, 2, 1 ], [ "Rest" ], [ -2, 0, 0, 1, 2, 0 ], [ -1, 0, 0, 0, 2, 0 ] ], 0 ], - [ [ [ -1, 0, 0, 1, 2, 0 ], [ "Rest" ], [ -2, 0, 0, 1, 2, 0 ], [ -1, 0, 0, 0, 2, 0 ] ], 1.75 ] - ], - [ - [ [ [ -1, 0, 0, 1, 2, 0 ], [ "Rest" ], [ -1, 0, -1, 0, 2, 0 ], [ -1, 0, 0, 0, 2, 0 ] ], 0 ], - [ [ [ 0, 0, 0, 0, 2, 0 ], [ "Rest" ], [ -1, 0, -1, 0, 2, 0 ], [ -1, 0, 0, 0, 2, 0 ] ], 1.125 ], - [ [ [ 0, 0, 0, 0, 2, 0 ], [ -1, 0, 1, 0, 2, 0 ], [ -1, 0, -1, 0, 2, 0 ], [ -1, 0, 0, 0, 2, 0 ] ], 1.125 ], - [ [ [ 0, 0, 0, 0, 2, 0 ], [ -1, 0, 1, 0, 2, 0 ], [ -2, 1, 0, 0, 2, 0 ], [ -1, 0, 0, 0, 2, 0 ] ], 2.625 ] - ], - [ - [ [ [ 0, 0, 0, 0, 2, 0 ], [ -1, 0, 1, 0, 2, 0 ], [ -2, 1, 0, 0, 2, 0 ], [ -2, 2, 0, 0, 2, 0 ] ], 0 ], - [ [ [ -1, 2, 0, 0, 2, 0 ], [ -1, 0, 1, 0, 2, 0 ], [ -2, 1, 0, 0, 2, 0 ], [ -2, 2, 0, 0, 2, 0 ] ], 0 ], - [ [ [ -1, 2, 0, 0, 2, 0 ], [ -2, 1, 0, 1, 2, 0 ], [ -2, 1, 0, 0, 2, 0 ], [ -2, 2, 0, 0, 2, 0 ] ], 0.625 ], - [ [ [ -1, 2, 0, 0, 2, 0 ], [ -1, 1, 0, 0, 2, 0 ], [ -2, 1, 0, 0, 2, 0 ], [ -2, 2, 0, 0, 2, 0 ] ], 2.375 ], - [ [ [ -1, 2, 0, 0, 2, 0 ], [ -1, 1, 0, 0, 2, 0 ], [ -2, 1, 0, 0, 2, 0 ], [ "Rest" ] ], 0 ], - [ [ [ -1, 2, 0, 0, 2, 0 ], [ "Rest" ], [ -2, 1, 0, 0, 2, 0 ], [ "Rest" ] ], 0 ], - [ [ [ "Rest" ], [ "Rest" ], [ -2, 1, 0, 0, 2, 0 ], [ "Rest" ] ], 1.125 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 4.125 ] - ] - ] -], -"last_changes": -[ - [ [ 0, 0, 0, 0, 2, 0 ], [ -1, 0, 1, 0, 2, 0 ], [ -2, 1, 0, 0, 2, 0 ], [ -1, 0, 0, 0, 2, 0 ] ], - [ [ 0, 0, 0, 0, 2, 0 ], [ -1, 0, 1, 0, 2, 0 ], [ -2, 1, 0, 0, 2, 0 ], [ -2, 2, 0, 0, 2, 0 ] ], - [ [ -1, 2, 0, 0, 2, 0 ], [ -1, 0, 1, 0, 2, 0 ], [ -2, 1, 0, 0, 2, 0 ], [ -2, 2, 0, 0, 2, 0 ] ], - [ [ -1, 2, 0, 0, 2, 0 ], [ -2, 1, 0, 1, 2, 0 ], [ -2, 1, 0, 0, 2, 0 ], [ -2, 2, 0, 0, 2, 0 ] ], - [ [ -1, 2, 0, 0, 2, 0 ], [ -1, 1, 0, 0, 2, 0 ], [ -2, 1, 0, 0, 2, 0 ], [ -2, 2, 0, 0, 2, 0 ] ] -], -"cur_uid": "4ef018fc", -"ref_uid": "nil", -"order_seed": 612843, -"dur_seed": 369555, -"motifs_seed": 949457, -"entrances_probs_vals": [ 1, 0, 2.9365079365079, 0.47, 2.8021978021978, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 0.48, 0, 2.1031746031746, 0.44, 1.3736263736264, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 0.58, 0.95, 4.2063492063492, 0.58, 2.2252747252747, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -2021.0526315789, 338 ], [ -1055.1083591331, 1453 ], [ -386, 1675.5417956656 ], [ -219, 1694.1176470588 ] ], -"step_probs_vals": [ -1200, 1200, 0, 0, 0.39094650205761, 0, 0.43621399176955, 0.14772727272727, 0.47942386831276, 0, 0.51440329218107, 0, 0.56378600823045, 0.55113636363636, 0.62139917695473, 0, 1, 0 ], -"passages_weights": [ 0.7, 0.29, 0.66, 0.74, 0.68 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 2 ], [ 0 ], [ 1, 3 ] ], - [ [ 0 ], [ 1, 3, 2, 3 ], [ ] ], - [ [ 0 ], [ 2, 1, 3 ], [ ] ], - [ [ 3 ], [ 0, 2, 0 ], [ 1 ] ], - [ [ 3 ], [ 2, 0, 1, 2 ], [ ] ], - [ [ 2 ], [ 3, 0, 1, 1 ], [ ] ] -], -"sus_weights": [ 1, 0, 0 ], -"order_size": [ 5.0408163265306, 13.122448979592 ], -"passages_size": [ 0, 2 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4ef018fc/lilypond/part_I.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/4ef018fc/lilypond/part_I.ly deleted file mode 100644 index a915563..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4ef018fc/lilypond/part_I.ly +++ /dev/null @@ -1,26 +0,0 @@ -{ - { r1 } - \bar "|" - { r1 } - \bar "|" - { r4 ais4^\markup { \pad-markup #0.2 "+49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }} ~ ais8[ a8^\markup { \pad-markup #0.2 "+11"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↓" }}] ~ a4 } - \bar "|" - { b1^\markup { \pad-markup #0.2 "+3"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 11↑" }} ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b2. ~ b8[ cis'8^\markup { \pad-markup #0.2 "+7"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↑" }}] ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'4 ~ cis'8[ r8] r2 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4ef018fc/lilypond/part_II.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/4ef018fc/lilypond/part_II.ly deleted file mode 100644 index a3007ee..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4ef018fc/lilypond/part_II.ly +++ /dev/null @@ -1,26 +0,0 @@ -{ - { c'1^\markup { \pad-markup #0.2 "+0"} ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'2 ~ c'8[ fis8^\markup { \pad-markup #0.2 "-49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }}] ~ fis4 } - \bar "|" - { gis1^\markup { \pad-markup #0.2 "-18"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↓" }} ~ } - \bar "|" - { gis2 ~ gis16[ a8.^\markup { \pad-markup #0.2 "-29"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 7↑" }}] ~ a4 ~ } - \bar "|" - { a4 ~ a8.[ g16^\markup { \pad-markup #0.2 "+16"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 5↓" }}] ~ g2 ~ } - \bar "|" - { g2 ~ g16[ fis8.^\markup { \pad-markup #0.2 "+5"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }}] ~ fis4 ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis2. ~ fis8.[ r16] } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4ef018fc/lilypond/part_III.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/4ef018fc/lilypond/part_III.ly deleted file mode 100644 index 69c36d3..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4ef018fc/lilypond/part_III.ly +++ /dev/null @@ -1,26 +0,0 @@ -{ - { r1 } - \bar "|" - { r1 } - \bar "|" - { r4 d'2.^\markup { \pad-markup #0.2 "-35"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↓" }} } - \bar "|" - { cis'1^\markup { \pad-markup #0.2 "-47"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }} ~ } - \bar "|" - { cis'4 r2. } - \bar "|" - { r1 } - \bar "|" - { dis'1^\markup { \pad-markup #0.2 "-11"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }} ~ } - \bar "|" - { dis'2. ~ dis'8[ e'8^\markup { \pad-markup #0.2 "-27"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 7↑" }}] ~ } - \bar "|" - { e'8.[ fis'16^\markup { \pad-markup #0.2 "+5"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 1↑" }}] ~ fis'2. ~ } - \bar "|" - { fis'4 ~ fis'8[ r8] r2 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4ef018fc/lilypond/part_IV.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/4ef018fc/lilypond/part_IV.ly deleted file mode 100644 index 762d2c4..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/4ef018fc/lilypond/part_IV.ly +++ /dev/null @@ -1,26 +0,0 @@ -{ - { r1 } - \bar "|" - { r2. r8[ fis'8^\markup { \pad-markup #0.2 "-49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 11↑" }}] ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'4 g'4^\markup { \pad-markup #0.2 "+43"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 13↑" }} ~ g'16[ a'8.^\markup { \pad-markup #0.2 "-29"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 1↑" }}] ~ a'4 ~ } - \bar "|" - { a'4 ~ a'8.[ b'16^\markup { \pad-markup #0.2 "+3"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }}] ~ b'2 ~ } - \bar "|" - { b'1 ~ } - \bar "|" - { b'2. ~ b'8[ cis''8^\markup { \pad-markup #0.2 "+7"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }}] ~ } - \bar "|" - { cis''1 ~ } - \bar "|" - { cis''4 ~ cis''8[ r8] r2 } - \bar "|" - { r1 } - \bar "|" - { r1 } -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/521654f8/521654f8_code.scd b/resources/resources_bak_2024_01_03/string_quartet_3_rise/521654f8/521654f8_code.scd deleted file mode 100644 index 42b64ff..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/521654f8/521654f8_code.scd +++ /dev/null @@ -1,981 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array2) - hsArrayToCents.value(array1); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -/* -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance) -}; -*/ - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = true; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - //if(pDistance >= 0, {stepFunc.value(abs(pDistance))}, {0.01}); - stepFunc.value(pDistance) -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - //tuples = dims.collect({[0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum == 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength.asInteger - minMotifLength.asInteger).rand + minMotifLength.asInteger).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - //noProgIns = (popSize - noSusIns).rand + 1; - noProgIns = (popSize - noSusIns); - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength.asInteger - minProgLength.asInteger).rand + minProgLength.asInteger).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0.01); - - - - /* - if(rangeScore.value(candidate.collect({0}), voices[ins], ranges[ins][1] - 500, ranges[ins][1], 0, true) == 1, { - isInRangeScore = 1 - rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0] + 500, ranges[ins][1] - 500, 0, true); - isInRangeScore = isInRangeScore * rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true) - }, { - isInRangeScore = rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true); - }); - */ - - - isInRangeScore = rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true); - //old way - worked but actually by accident (I think) - //isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - - - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - /* - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - */ - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - //lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - lastState = if(o == 0, {lastXChanges.last.deepCopy}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - /* - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - */ - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - //# voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - # voices, durs = seq.flatten2(if(oneShot, {2}, {3})).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(2).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/521654f8/521654f8_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_3_rise/521654f8/521654f8_mus_model.json deleted file mode 100644 index 6106aa7..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/521654f8/521654f8_mus_model.json +++ /dev/null @@ -1,87 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ -3, 0, 1, 2, 1, 0 ], [ -3, 1, 1, 3, 1, 0 ], [ -2, 1, 0, 2, 1, 0 ], [ -2, 0, 1, 2, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -3, 0, 1, 2, 1, 0 ], [ -2, 1, 1, 2, 1, 0 ], [ -2, 1, 0, 2, 1, 0 ], [ -2, 0, 1, 2, 1, 0 ] ], 1 ], - [ [ [ -3, 1, 1, 2, 1, 0 ], [ -2, 1, 1, 2, 1, 0 ], [ -2, 1, 0, 2, 1, 0 ], [ -2, 0, 1, 2, 1, 0 ] ], 1 ], - [ [ [ -3, 1, 1, 2, 1, 0 ], [ -2, 1, 1, 2, 1, 0 ], [ -2, 1, 0, 2, 1, 0 ], [ -1, 1, 0, 2, 1, -1 ] ], 1 ] - ], - [ - [ [ [ -3, 2, 1, 2, 1, 0 ], [ -2, 1, 1, 2, 1, 0 ], [ -2, 1, 0, 2, 1, 0 ], [ -1, 1, 0, 2, 1, -1 ] ], 1 ] - ], - [ - [ [ [ -3, 2, 1, 2, 1, 0 ], [ -2, 1, 1, 2, 1, 0 ], [ -2, 1, 0, 2, 1, 0 ], [ -4, 2, 1, 2, 1, 0 ] ], 1 ], - [ [ [ -3, 2, 1, 2, 1, 0 ], [ -2, 1, 1, 2, 1, 0 ], [ -3, 2, 2, 2, 1, 0 ], [ -4, 2, 1, 2, 1, 0 ] ], 1 ], - [ [ [ -3, 2, 1, 2, 1, 0 ], [ -3, 1, 1, 2, 1, 0 ], [ -3, 2, 2, 2, 1, 0 ], [ -4, 2, 1, 2, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -3, 2, 1, 2, 1, 0 ], [ -4, 2, 3, 2, 1, 0 ], [ -3, 2, 2, 2, 1, 0 ], [ -4, 2, 1, 2, 1, 0 ] ], 1 ], - [ [ [ -5, 2, 2, 2, 1, 0 ], [ -4, 2, 3, 2, 1, 0 ], [ -3, 2, 2, 2, 1, 0 ], [ -4, 2, 1, 2, 1, 0 ] ], 1 ], - [ [ [ -5, 2, 2, 2, 1, 0 ], [ -4, 2, 3, 2, 1, 0 ], [ -3, 2, 2, 2, 1, 0 ], [ -4, 2, 2, 2, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -5, 3, 2, 2, 1, 0 ], [ -4, 2, 3, 2, 1, 0 ], [ -3, 2, 2, 2, 1, 0 ], [ -4, 2, 2, 2, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -5, 2, 3, 3, 1, 0 ], [ -4, 2, 3, 2, 1, 0 ], [ -3, 2, 2, 2, 1, 0 ], [ -4, 2, 2, 2, 1, 0 ] ], 1 ], - [ [ [ -5, 2, 3, 3, 1, 0 ], [ -4, 2, 3, 2, 1, 0 ], [ -3, 2, 2, 2, 1, 0 ], [ -4, 3, 3, 2, 1, 0 ] ], 1 ], - [ [ [ -5, 2, 3, 3, 1, 0 ], [ -4, 2, 3, 2, 1, 0 ], [ -4, 2, 3, 2, 1, 1 ], [ -4, 3, 3, 2, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -5, 2, 3, 3, 1, 0 ], [ -4, 2, 3, 2, 1, 0 ], [ -3, 3, 3, 1, 1, 0 ], [ -4, 3, 3, 2, 1, 0 ] ], 1 ], - [ [ [ -5, 2, 3, 3, 1, 0 ], [ -4, 2, 2, 3, 1, 0 ], [ -3, 3, 3, 1, 1, 0 ], [ -4, 3, 3, 2, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -5, 2, 3, 3, 1, 0 ], [ -4, 2, 2, 3, 1, 0 ], [ -3, 3, 3, 1, 1, 0 ], [ -5, 2, 3, 4, 1, 0 ] ], 1 ], - [ [ [ -5, 2, 3, 3, 1, 0 ], [ -4, 2, 2, 3, 1, 0 ], [ -4, 2, 3, 3, 1, -1 ], [ -5, 2, 3, 4, 1, 0 ] ], 1 ], - [ [ [ -5, 2, 3, 3, 1, 0 ], [ -6, 2, 4, 3, 1, 0 ], [ -4, 2, 3, 3, 1, -1 ], [ -5, 2, 3, 4, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -5, 2, 3, 3, 1, 0 ], [ -6, 2, 4, 3, 1, 0 ], [ -6, 3, 3, 4, 1, 0 ], [ -5, 2, 3, 4, 1, 0 ] ], 1 ] - ] - ] -], -"last_changes": -[ - [ [ -5, 2, 3, 3, 1, 0 ], [ -4, 2, 2, 3, 1, 0 ], [ -3, 3, 3, 1, 1, 0 ], [ -4, 3, 3, 2, 1, 0 ] ], - [ [ -5, 2, 3, 3, 1, 0 ], [ -4, 2, 2, 3, 1, 0 ], [ -3, 3, 3, 1, 1, 0 ], [ -5, 2, 3, 4, 1, 0 ] ], - [ [ -5, 2, 3, 3, 1, 0 ], [ -4, 2, 2, 3, 1, 0 ], [ -4, 2, 3, 3, 1, -1 ], [ -5, 2, 3, 4, 1, 0 ] ], - [ [ -5, 2, 3, 3, 1, 0 ], [ -6, 2, 4, 3, 1, 0 ], [ -4, 2, 3, 3, 1, -1 ], [ -5, 2, 3, 4, 1, 0 ] ], - [ [ -5, 2, 3, 3, 1, 0 ], [ -6, 2, 4, 3, 1, 0 ], [ -6, 3, 3, 4, 1, 0 ], [ -5, 2, 3, 4, 1, 0 ] ] -], -"cur_uid": "521654f8", -"ref_uid": "7ede7adb", -"order_seed": 185690, -"dur_seed": 954582, -"motifs_seed": 356283, -"entrances_probs_vals": [ 0, 0, 0, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 0, 0, 0, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 0, 0, 0, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -2400, 1200 ], [ -1200, 1200 ], [ -702, 1200 ], [ -702, 1200 ] ], -"step_probs_vals": [ 0, 1200, 0.0061728395061728, 0.10227272727273, 0.074074074074074, 0.10227272727273, 0.2037037037037, 0.090909090909091, 0.45679012345679, 0.011363636363636, 0.53086419753086, 0, 0.54320987654321, 0.92045454545455, 0.58641975308642, 0.92613636363636, 0.61111111111111, 0, 0.7880658436214, 0.034090909090909, 1, 0.034090909090909 ], -"passages_weights": [ 1, 0.47, 0.43, 1, 0.6 ], -"hd_exp": 6, -"hd_invert": 0, -"order": -[ - [ [ 1, 0, 2 ], [ 3 ], [ ] ], - [ [ 2 ], [ 1, 0, 3 ], [ ] ], - [ [ 2, 1, 3 ], [ 0 ], [ ] ], - [ [ 0 ], [ 3, 2, 1 ], [ ] ], - [ [ 2 ], [ 1, 0, 3 ], [ ] ], - [ [ 1, 2, 3 ], [ 0 ], [ ] ], - [ [ 1 ], [ 0, 3, 2 ], [ ] ], - [ [ 0, 3 ], [ 2, 1 ], [ ] ], - [ [ 0 ], [ 3, 2, 1 ], [ ] ], - [ [ 1, 0, 3 ], [ 2 ], [ ] ] -], -"sus_weights": [ 0.35, 0.37, 0.38 ], -"order_size": [ 10.091836734694, 10.091836734694 ], -"passages_size": [ 0, 0 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/521654f8/lilypond/part_I.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/521654f8/lilypond/part_I.ly deleted file mode 100644 index 4b86b39..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/521654f8/lilypond/part_I.ly +++ /dev/null @@ -1,22 +0,0 @@ -{ - { f'1^\markup { \pad-markup #0.2 "-25"} ~ } - \bar "|" - { f'2 c''2^\markup { \pad-markup #0.2 "-50"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 13↓" }} ~ } - \bar "|" - { c''2 g2^\markup { \pad-markup #0.2 "-21"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }} ~ } - \bar "|" - { g1 ~ } - \bar "|" - { g1 } - \bar "|" - { b1^\markup { \pad-markup #0.2 "-34"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }} ~ } - \bar "|" - { b2 ais'2^\markup { \pad-markup #0.2 "-46"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↑" }} ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'2 ais'2^\markup { \pad-markup #0.2 "-11"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↑" }} ~ } - \bar "|" - { ais'1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/521654f8/lilypond/part_II.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/521654f8/lilypond/part_II.ly deleted file mode 100644 index 03e091f..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/521654f8/lilypond/part_II.ly +++ /dev/null @@ -1,22 +0,0 @@ -{ - { gis'1^\markup { \pad-markup #0.2 "-9"} ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 } - \bar "|" - { b'1^\markup { \pad-markup #0.2 "-34"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }} ~ } - \bar "|" - { b'1 ~ } - \bar "|" - { b'1 ~ } - \bar "|" - { b'1 } - \bar "|" - { b'2^\markup { \pad-markup #0.2 "-8"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 13↑" }} c''2^\markup { \pad-markup #0.2 "-15"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 7↓" }} ~ } - \bar "|" - { c''1 } - \bar "|" - { e'1^\markup { \pad-markup #0.2 "-20"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↓" }}} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/521654f8/lilypond/part_III.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/521654f8/lilypond/part_III.ly deleted file mode 100644 index 8972ef2..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/521654f8/lilypond/part_III.ly +++ /dev/null @@ -1,22 +0,0 @@ -{ - { a'2^\markup { \pad-markup #0.2 "+46"} c''2^\markup { \pad-markup #0.2 "-23"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }} ~ } - \bar "|" - { c''1 ~ } - \bar "|" - { c''1 ~ } - \bar "|" - { c''2 c'2^\markup { \pad-markup #0.2 "-23"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }} } - \bar "|" - { dis'1^\markup { \pad-markup #0.2 "-48"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 5↑" }} ~ } - \bar "|" - { dis'1 ~ } - \bar "|" - { dis'1 ~ } - \bar "|" - { dis'1 } - \bar "|" - { gis'1^\markup { \pad-markup #0.2 "+34"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↓" }} ~ } - \bar "|" - { gis'2 e2^\markup { \pad-markup #0.2 "+7"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }}} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/521654f8/lilypond/part_IV.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/521654f8/lilypond/part_IV.ly deleted file mode 100644 index 25ed6e8..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/521654f8/lilypond/part_IV.ly +++ /dev/null @@ -1,22 +0,0 @@ -{ - { f1^\markup { \pad-markup #0.2 "-25"} } - \bar "|" - { c'1^\markup { \pad-markup #0.2 "-23"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }} } - \bar "|" - { g'1^\markup { \pad-markup #0.2 "-21"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↑" }} ~ } - \bar "|" - { g'1 ~ } - \bar "|" - { g'2 b,2^\markup { \pad-markup #0.2 "-34"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 1↑" }} ~ } - \bar "|" - { b,2 fis2^\markup { \pad-markup #0.2 "-33"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↑" }} } - \bar "|" - { c'1^\markup { \pad-markup #0.2 "+21"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 7↑" }} ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/531df78c/531df78c_code.scd b/resources/resources_bak_2024_01_03/string_quartet_3_rise/531df78c/531df78c_code.scd deleted file mode 100644 index 42b64ff..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/531df78c/531df78c_code.scd +++ /dev/null @@ -1,981 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array2) - hsArrayToCents.value(array1); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -/* -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance) -}; -*/ - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = true; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - //if(pDistance >= 0, {stepFunc.value(abs(pDistance))}, {0.01}); - stepFunc.value(pDistance) -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - //tuples = dims.collect({[0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum == 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength.asInteger - minMotifLength.asInteger).rand + minMotifLength.asInteger).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - //noProgIns = (popSize - noSusIns).rand + 1; - noProgIns = (popSize - noSusIns); - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength.asInteger - minProgLength.asInteger).rand + minProgLength.asInteger).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0.01); - - - - /* - if(rangeScore.value(candidate.collect({0}), voices[ins], ranges[ins][1] - 500, ranges[ins][1], 0, true) == 1, { - isInRangeScore = 1 - rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0] + 500, ranges[ins][1] - 500, 0, true); - isInRangeScore = isInRangeScore * rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true) - }, { - isInRangeScore = rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true); - }); - */ - - - isInRangeScore = rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true); - //old way - worked but actually by accident (I think) - //isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - - - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - /* - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - */ - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - //lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - lastState = if(o == 0, {lastXChanges.last.deepCopy}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - /* - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - */ - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - //# voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - # voices, durs = seq.flatten2(if(oneShot, {2}, {3})).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(2).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/531df78c/531df78c_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_3_rise/531df78c/531df78c_mus_model.json deleted file mode 100644 index 4f78cc2..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/531df78c/531df78c_mus_model.json +++ /dev/null @@ -1,157 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ -6, 2, 4, 1, 1, 2 ], [ -5, 3, 4, 1, 1, 2 ], [ -6, 3, 4, 1, 1, 2 ], [ -6, 3, 4, 2, 1, 2 ] ], 1 ], - [ [ [ -7, 4, 4, 1, 1, 2 ], [ -5, 3, 4, 1, 1, 2 ], [ -6, 3, 4, 1, 1, 2 ], [ -6, 3, 4, 2, 1, 2 ] ], 1 ], - [ [ [ -7, 4, 4, 1, 1, 2 ], [ -5, 3, 4, 1, 1, 2 ], [ -6, 3, 4, 1, 1, 2 ], [ -5, 2, 4, 1, 1, 2 ] ], 1 ] - ], - [ - [ [ [ -5, 3, 4, 0, 1, 2 ], [ -5, 3, 4, 1, 1, 2 ], [ -6, 3, 4, 1, 1, 2 ], [ -5, 2, 4, 1, 1, 2 ] ], 1 ], - [ [ [ -5, 3, 4, 0, 1, 2 ], [ -5, 3, 4, 1, 1, 2 ], [ -6, 3, 4, 1, 1, 2 ], [ -6, 4, 4, 1, 1, 2 ] ], 1 ] - ], - [ - [ [ [ -5, 3, 4, 0, 1, 2 ], [ -4, 3, 4, 0, 1, 2 ], [ -6, 3, 4, 1, 1, 2 ], [ -6, 4, 4, 1, 1, 2 ] ], 1 ] - ], - [ - [ [ [ -5, 3, 4, 0, 1, 2 ], [ -4, 3, 4, 0, 1, 2 ], [ -6, 3, 4, 1, 1, 2 ], [ -5, 3, 3, 1, 1, 2 ] ], 1 ] - ], - [ - [ [ [ -5, 3, 4, 0, 1, 2 ], [ -5, 4, 3, 1, 1, 2 ], [ -6, 3, 4, 1, 1, 2 ], [ -5, 3, 3, 1, 1, 2 ] ], 1 ] - ], - [ - [ [ [ -6, 4, 3, 1, 1, 2 ], [ -5, 4, 3, 1, 1, 2 ], [ -6, 3, 4, 1, 1, 2 ], [ -5, 3, 3, 1, 1, 2 ] ], 1 ] - ], - [ - [ [ [ -5, 3, 4, 1, 1, 2 ], [ -5, 4, 3, 1, 1, 2 ], [ -6, 3, 4, 1, 1, 2 ], [ -5, 3, 3, 1, 1, 2 ] ], 1 ], - [ [ [ -5, 3, 4, 1, 1, 2 ], [ -6, 3, 3, 1, 1, 2 ], [ -6, 3, 4, 1, 1, 2 ], [ -5, 3, 3, 1, 1, 2 ] ], 1 ], - [ [ [ -5, 3, 4, 1, 1, 2 ], [ -6, 3, 3, 1, 1, 2 ], [ -5, 2, 3, 1, 1, 2 ], [ -5, 3, 3, 1, 1, 2 ] ], 1 ] - ], - [ - [ [ [ -5, 3, 4, 1, 1, 2 ], [ -5, 2, 4, 1, 1, 2 ], [ -5, 2, 3, 1, 1, 2 ], [ -5, 3, 3, 1, 1, 2 ] ], 1 ] - ], - [ - [ [ [ -5, 3, 4, 1, 1, 2 ], [ -5, 2, 4, 1, 1, 2 ], [ -6, 4, 3, 1, 1, 2 ], [ -5, 3, 3, 1, 1, 2 ] ], 1 ] - ], - [ - [ [ [ -5, 3, 4, 1, 1, 2 ], [ -5, 2, 4, 1, 1, 2 ], [ -4, 1, 4, 1, 1, 2 ], [ -5, 3, 3, 1, 1, 2 ] ], 1 ], - [ [ [ -5, 4, 3, 1, 1, 2 ], [ -5, 2, 4, 1, 1, 2 ], [ -4, 1, 4, 1, 1, 2 ], [ -5, 3, 3, 1, 1, 2 ] ], 1 ] - ], - [ - [ [ [ -5, 4, 3, 1, 1, 2 ], [ -5, 2, 4, 1, 1, 2 ], [ -4, 2, 3, 1, 1, 2 ], [ -5, 3, 3, 1, 1, 2 ] ], 1 ] - ], - [ - [ [ [ -5, 4, 3, 1, 1, 2 ], [ -5, 2, 4, 1, 1, 2 ], [ -4, 2, 3, 1, 1, 2 ], [ -6, 5, 3, 1, 1, 2 ] ], 1 ], - [ [ [ -5, 4, 3, 1, 1, 2 ], [ -5, 4, 3, 0, 1, 2 ], [ -4, 2, 3, 1, 1, 2 ], [ -6, 5, 3, 1, 1, 2 ] ], 1 ], - [ [ [ -5, 4, 3, 1, 1, 2 ], [ -5, 4, 3, 0, 1, 2 ], [ -7, 5, 3, 1, 1, 2 ], [ -6, 5, 3, 1, 1, 2 ] ], 1 ] - ], - [ - [ [ [ -5, 4, 3, 1, 1, 2 ], [ -5, 4, 3, 0, 1, 2 ], [ -7, 5, 3, 1, 1, 2 ], [ -5, 5, 3, 0, 1, 2 ] ], 1 ], - [ [ [ -5, 4, 3, 1, 1, 2 ], [ -6, 5, 2, 1, 1, 2 ], [ -7, 5, 3, 1, 1, 2 ], [ -5, 5, 3, 0, 1, 2 ] ], 1 ], - [ [ [ -6, 5, 3, 1, 1, 2 ], [ -6, 5, 2, 1, 1, 2 ], [ -7, 5, 3, 1, 1, 2 ], [ -5, 5, 3, 0, 1, 2 ] ], 1 ] - ], - [ - [ [ [ -6, 5, 3, 1, 1, 2 ], [ -6, 5, 2, 1, 1, 2 ], [ -6, 5, 3, 0, 1, 2 ], [ -5, 5, 3, 0, 1, 2 ] ], 1 ] - ], - [ - [ [ [ -6, 5, 3, 1, 1, 2 ], [ -6, 5, 2, 1, 1, 2 ], [ -6, 5, 3, 0, 1, 2 ], [ -6, 5, 4, 1, 1, 2 ] ], 1 ], - [ [ [ -6, 5, 3, 1, 1, 2 ], [ -6, 6, 3, 0, 1, 2 ], [ -6, 5, 3, 0, 1, 2 ], [ -6, 5, 4, 1, 1, 2 ] ], 1 ] - ], - [ - [ [ [ -6, 6, 4, 0, 1, 2 ], [ -6, 6, 3, 0, 1, 2 ], [ -6, 5, 3, 0, 1, 2 ], [ -6, 5, 4, 1, 1, 2 ] ], 1 ] - ], - [ - [ [ [ -6, 6, 4, 0, 1, 2 ], [ -6, 6, 3, 0, 1, 2 ], [ -6, 5, 4, 0, 1, 2 ], [ -6, 5, 4, 1, 1, 2 ] ], 1 ], - [ [ [ -6, 6, 4, 0, 1, 2 ], [ -7, 5, 4, 1, 1, 3 ], [ -6, 5, 4, 0, 1, 2 ], [ -6, 5, 4, 1, 1, 2 ] ], 1 ] - ], - [ - [ [ [ -6, 5, 4, 0, 1, 3 ], [ -7, 5, 4, 1, 1, 3 ], [ -6, 5, 4, 0, 1, 2 ], [ -6, 5, 4, 1, 1, 2 ] ], 1 ], - [ [ [ -6, 5, 4, 0, 1, 3 ], [ -6, 6, 4, 0, 1, 2 ], [ -6, 5, 4, 0, 1, 2 ], [ -6, 5, 4, 1, 1, 2 ] ], 1 ] - ], - [ - [ [ [ -6, 5, 4, 0, 1, 3 ], [ -6, 6, 4, 0, 1, 2 ], [ -6, 5, 4, 0, 1, 2 ], [ -6, 6, 5, 0, 1, 2 ] ], 1 ], - [ [ [ -7, 5, 4, 0, 1, 2 ], [ -6, 6, 4, 0, 1, 2 ], [ -6, 5, 4, 0, 1, 2 ], [ -6, 6, 5, 0, 1, 2 ] ], 1 ] - ], - [ - [ [ [ -7, 5, 4, 0, 1, 2 ], [ -6, 6, 4, 0, 1, 2 ], [ -7, 7, 4, 0, 1, 2 ], [ -6, 6, 5, 0, 1, 2 ] ], 1 ] - ], - [ - [ [ [ -7, 5, 4, 0, 1, 2 ], [ -6, 6, 4, 0, 1, 2 ], [ -7, 7, 4, 0, 1, 2 ], [ -7, 6, 4, 0, 1, 2 ] ], 1 ], - [ [ [ -7, 5, 4, 0, 1, 2 ], [ -6, 6, 4, 0, 1, 2 ], [ -7, 6, 4, 1, 1, 2 ], [ -7, 6, 4, 0, 1, 2 ] ], 1 ] - ], - [ - [ [ [ -7, 5, 4, 0, 1, 2 ], [ -6, 6, 4, 0, 1, 2 ], [ -5, 6, 4, -1, 1, 2 ], [ -7, 6, 4, 0, 1, 2 ] ], 1 ], - [ [ [ -8, 7, 4, 0, 1, 2 ], [ -6, 6, 4, 0, 1, 2 ], [ -5, 6, 4, -1, 1, 2 ], [ -7, 6, 4, 0, 1, 2 ] ], 1 ] - ], - [ - [ [ [ -8, 7, 4, 0, 1, 2 ], [ -6, 6, 4, 0, 1, 2 ], [ -5, 6, 4, -1, 1, 2 ], [ -6, 7, 4, -1, 1, 2 ] ], 1 ], - [ [ [ -7, 7, 4, -1, 1, 2 ], [ -6, 6, 4, 0, 1, 2 ], [ -5, 6, 4, -1, 1, 2 ], [ -6, 7, 4, -1, 1, 2 ] ], 1 ], - [ [ [ -7, 7, 4, -1, 1, 2 ], [ -6, 6, 4, -1, 1, 2 ], [ -5, 6, 4, -1, 1, 2 ], [ -6, 7, 4, -1, 1, 2 ] ], 1 ] - ], - [ - [ [ [ -7, 6, 4, -1, 1, 2 ], [ -6, 6, 4, -1, 1, 2 ], [ -5, 6, 4, -1, 1, 2 ], [ -6, 7, 4, -1, 1, 2 ] ], 1 ], - [ [ [ -7, 6, 4, -1, 1, 2 ], [ -5, 6, 4, -1, 0, 2 ], [ -5, 6, 4, -1, 1, 2 ], [ -6, 7, 4, -1, 1, 2 ] ], 1 ], - [ [ [ -7, 6, 4, -1, 1, 2 ], [ -5, 6, 4, -1, 0, 2 ], [ -5, 6, 4, -1, 1, 2 ], [ -6, 6, 4, 0, 1, 2 ] ], 1 ] - ], - [ - [ [ [ -7, 6, 4, -1, 1, 2 ], [ -5, 6, 4, -1, 0, 2 ], [ -6, 6, 4, 0, 0, 2 ], [ -6, 6, 4, 0, 1, 2 ] ], 1 ], - [ [ [ -7, 6, 4, -1, 1, 2 ], [ -6, 6, 5, 0, 1, 2 ], [ -6, 6, 4, 0, 0, 2 ], [ -6, 6, 4, 0, 1, 2 ] ], 1 ] - ] - ] -], -"last_changes": -[ - [ [ -7, 6, 4, -1, 1, 2 ], [ -6, 6, 4, -1, 1, 2 ], [ -5, 6, 4, -1, 1, 2 ], [ -6, 7, 4, -1, 1, 2 ] ], - [ [ -7, 6, 4, -1, 1, 2 ], [ -5, 6, 4, -1, 0, 2 ], [ -5, 6, 4, -1, 1, 2 ], [ -6, 7, 4, -1, 1, 2 ] ], - [ [ -7, 6, 4, -1, 1, 2 ], [ -5, 6, 4, -1, 0, 2 ], [ -5, 6, 4, -1, 1, 2 ], [ -6, 6, 4, 0, 1, 2 ] ], - [ [ -7, 6, 4, -1, 1, 2 ], [ -5, 6, 4, -1, 0, 2 ], [ -6, 6, 4, 0, 0, 2 ], [ -6, 6, 4, 0, 1, 2 ] ], - [ [ -7, 6, 4, -1, 1, 2 ], [ -6, 6, 5, 0, 1, 2 ], [ -6, 6, 4, 0, 0, 2 ], [ -6, 6, 4, 0, 1, 2 ] ] -], -"cur_uid": "531df78c", -"ref_uid": "78a94ed1", -"order_seed": 561112, -"dur_seed": 221568, -"motifs_seed": 960151, -"entrances_probs_vals": [ 0, 0, 0, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 0, 0, 0, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 0, 0, 0, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -2400, 1200 ], [ -1200, 1200 ], [ -702, 1200 ], [ -702, 1200 ] ], -"step_probs_vals": [ 0, 1200, 0.0061728395061728, 0.10227272727273, 0.074074074074074, 0.10227272727273, 0.2037037037037, 0.090909090909091, 0.45679012345679, 0.011363636363636, 0.53086419753086, 0, 0.54320987654321, 0.92045454545455, 0.58641975308642, 0.92613636363636, 0.61111111111111, 0, 0.7880658436214, 0.034090909090909, 1, 0.034090909090909 ], -"passages_weights": [ 0.08, 0.47, 0.43, 1, 1 ], -"hd_exp": 10, -"hd_invert": 0, -"order": -[ - [ [ 1 ], [ 2, 0, 3 ], [ ] ], - [ [ 2, 1 ], [ 0, 3 ], [ ] ], - [ [ 0, 2, 3 ], [ 1 ], [ ] ], - [ [ 2, 1, 0 ], [ 3 ], [ ] ], - [ [ 0, 2, 3 ], [ 1 ], [ ] ], - [ [ 1, 3, 2 ], [ 0 ], [ ] ], - [ [ 3 ], [ 0, 1, 2 ], [ ] ], - [ [ 3, 2, 0 ], [ 1 ], [ ] ], - [ [ 1, 3, 0 ], [ 2 ], [ ] ], - [ [ 3, 1 ], [ 2, 0 ], [ ] ], - [ [ 1, 3, 0 ], [ 2 ], [ ] ], - [ [ 0 ], [ 3, 1, 2 ], [ ] ], - [ [ 2 ], [ 3, 1, 0 ], [ ] ], - [ [ 1, 0, 3 ], [ 2 ], [ ] ], - [ [ 0, 2 ], [ 3, 1 ], [ ] ], - [ [ 2, 1, 3 ], [ 0 ], [ ] ], - [ [ 3, 0 ], [ 2, 1 ], [ ] ], - [ [ 3, 2 ], [ 0, 1 ], [ ] ], - [ [ 1, 2 ], [ 3, 0 ], [ ] ], - [ [ 1, 3, 0 ], [ 2 ], [ ] ], - [ [ 0, 1 ], [ 3, 2 ], [ ] ], - [ [ 3, 1 ], [ 2, 0 ], [ ] ], - [ [ 2 ], [ 3, 0, 1 ], [ ] ], - [ [ 2 ], [ 0, 1, 3 ], [ ] ], - [ [ 3, 0 ], [ 2, 1 ], [ ] ] -], -"sus_weights": [ 0.35, 0.37, 0.38 ], -"order_size": [ 25, 25.244897959184 ], -"passages_size": [ 0, 0 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/531df78c/lilypond/part_I.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/531df78c/lilypond/part_I.ly deleted file mode 100644 index 0acee0f..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/531df78c/lilypond/part_I.ly +++ /dev/null @@ -1,48 +0,0 @@ -{ - { fis'1^\markup { \pad-markup #0.2 "+21"} } - \bar "|" - { d'1^\markup { \pad-markup #0.2 "-50"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↓" }} } - \bar "|" - { e'1^\markup { \pad-markup #0.2 "-46"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↑" }} } - \bar "|" - { f'1^\markup { \pad-markup #0.2 "-34"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 5↓" }} ~ } - \bar "|" - { f'1 ~ } - \bar "|" - { f'1 ~ } - \bar "|" - { f'1 ~ } - \bar "|" - { f'1 ~ } - \bar "|" - { f'2 g'2^\markup { \pad-markup #0.2 "-30"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }} ~ } - \bar "|" - { g'1 } - \bar "|" - { a'1^\markup { \pad-markup #0.2 "+1"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↑" }} ~ } - \bar "|" - { a'1 } - \bar "|" - { b'1^\markup { \pad-markup #0.2 "-44"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }} ~ } - \bar "|" - { b'1 ~ } - \bar "|" - { b'1 ~ } - \bar "|" - { b'2 c''2^\markup { \pad-markup #0.2 "-24"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 5↑" }} ~ } - \bar "|" - { c''1 } - \bar "|" - { gis1^\markup { \pad-markup #0.2 "-11"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }} ~ } - \bar "|" - { gis1 } - \bar "|" - { f'1^\markup { \pad-markup #0.2 "+22"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↓" }} ~ } - \bar "|" - { f'1 ~ } - \bar "|" - { f'2 gis'2^\markup { \pad-markup #0.2 "-11"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↑" }} ~ } - \bar "|" - { gis'1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/531df78c/lilypond/part_II.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/531df78c/lilypond/part_II.ly deleted file mode 100644 index 71926a1..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/531df78c/lilypond/part_II.ly +++ /dev/null @@ -1,48 +0,0 @@ -{ - { a1^\markup { \pad-markup #0.2 "-48"} ~ } - \bar "|" - { a1 ~ } - \bar "|" - { a1 ~ } - \bar "|" - { a1 ~ } - \bar "|" - { a1 ~ } - \bar "|" - { a2 ais2^\markup { \pad-markup #0.2 "-36"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↓" }} ~ } - \bar "|" - { ais2 c'2^\markup { \pad-markup #0.2 "-32"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↑" }} } - \bar "|" - { fis'1^\markup { \pad-markup #0.2 "+48"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↓" }} } - \bar "|" - { ais'1^\markup { \pad-markup #0.2 "-36"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 5↓" }} ~ } - \bar "|" - { ais'2 g2^\markup { \pad-markup #0.2 "-30"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }} ~ } - \bar "|" - { g1 ~ } - \bar "|" - { g2 a2^\markup { \pad-markup #0.2 "+1"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }} ~ } - \bar "|" - { a1 ~ } - \bar "|" - { a2 cis'2^\markup { \pad-markup #0.2 "-13"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }} ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'2 dis'2^\markup { \pad-markup #0.2 "-9"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↑" }} ~ } - \bar "|" - { dis'2 fis'2^\markup { \pad-markup #0.2 "-42"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 7↑" }} } - \bar "|" - { ais'1^\markup { \pad-markup #0.2 "+21"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 7↓" }} ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 } - \bar "|" - { d'1^\markup { \pad-markup #0.2 "+38"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 7↑" }}} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/531df78c/lilypond/part_III.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/531df78c/lilypond/part_III.ly deleted file mode 100644 index 95b2a0b..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/531df78c/lilypond/part_III.ly +++ /dev/null @@ -1,48 +0,0 @@ -{ - { a'1^\markup { \pad-markup #0.2 "-48"} ~ } - \bar "|" - { a'1 ~ } - \bar "|" - { a'2 b'2^\markup { \pad-markup #0.2 "-17"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }} ~ } - \bar "|" - { b'2 c''2^\markup { \pad-markup #0.2 "-32"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↑" }} ~ } - \bar "|" - { c''1 } - \bar "|" - { f1^\markup { \pad-markup #0.2 "-34"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }} } - \bar "|" - { d'1^\markup { \pad-markup #0.2 "-50"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }} ~ } - \bar "|" - { d'1 ~ } - \bar "|" - { d'1 } - \bar "|" - { d'1^\markup { \pad-markup #0.2 "-1"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↓" }} ~ } - \bar "|" - { d'2 dis'2^\markup { \pad-markup #0.2 "-16"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 5↓" }} ~ } - \bar "|" - { dis'1 ~ } - \bar "|" - { dis'2 e'2^\markup { \pad-markup #0.2 "+3"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↑" }} ~ } - \bar "|" - { e'1 } - \bar "|" - { g'1^\markup { \pad-markup #0.2 "-3"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 13↑" }} } - \bar "|" - { gis'1^\markup { \pad-markup #0.2 "-11"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↑" }} ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 } - \bar "|" - { ais1^\markup { \pad-markup #0.2 "+21"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 1↑" }} } - \bar "|" - { f'1^\markup { \pad-markup #0.2 "-31"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 11↓" }} ~ } - \bar "|" - { f'2 c''2^\markup { \pad-markup #0.2 "-24"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 5↑" }}} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/531df78c/lilypond/part_IV.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/531df78c/lilypond/part_IV.ly deleted file mode 100644 index 52220bd..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/531df78c/lilypond/part_IV.ly +++ /dev/null @@ -1,48 +0,0 @@ -{ - { d2^\markup { \pad-markup #0.2 "-50"} e2^\markup { \pad-markup #0.2 "-46"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↑" }} ~ } - \bar "|" - { e2 b2^\markup { \pad-markup #0.2 "-17"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 7↓" }} ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 } - \bar "|" - { c'2^\markup { \pad-markup #0.2 "-32"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }} a'2^\markup { \pad-markup #0.2 "-48"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 1↑" }} ~ } - \bar "|" - { a'1 ~ } - \bar "|" - { a'1 ~ } - \bar "|" - { a'2 c''2^\markup { \pad-markup #0.2 "-32"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↑" }} ~ } - \bar "|" - { c''1 ~ } - \bar "|" - { c''1 ~ } - \bar "|" - { c''1 } - \bar "|" - { g'1^\markup { \pad-markup #0.2 "-30"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 1↑" }} ~ } - \bar "|" - { g'1 } - \bar "|" - { gis'1^\markup { \pad-markup #0.2 "-11"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 5↑" }} ~ } - \bar "|" - { gis'2 a'2^\markup { \pad-markup #0.2 "+28"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 7↓" }} ~ } - \bar "|" - { a'1 } - \bar "|" - { cis1^\markup { \pad-markup #0.2 "-13"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 1↑" }} ~ } - \bar "|" - { cis1 ~ } - \bar "|" - { cis2 dis2^\markup { \pad-markup #0.2 "-9"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↑" }} ~ } - \bar "|" - { dis2 f2^\markup { \pad-markup #0.2 "+22"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }} ~ } - \bar "|" - { f2 ais,2^\markup { \pad-markup #0.2 "+21"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }} ~ } - \bar "|" - { ais,1 ~ } - \bar "|" - { ais,1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/553fbac7/553fbac7_code.scd b/resources/resources_bak_2024_01_03/string_quartet_3_rise/553fbac7/553fbac7_code.scd deleted file mode 100644 index c4e3d1b..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/553fbac7/553fbac7_code.scd +++ /dev/null @@ -1,979 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array2) - hsArrayToCents.value(array1); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -/* -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance) -}; -*/ - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = true; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - //if(pDistance >= 0, {stepFunc.value(abs(pDistance))}, {0.01}); - stepFunc.value(pDistance) -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - //tuples = dims.collect({[0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum == 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength.asInteger - minMotifLength.asInteger).rand + minMotifLength.asInteger).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - //noProgIns = (popSize - noSusIns).rand + 1; - noProgIns = (popSize - noSusIns); - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength.asInteger - minProgLength.asInteger).rand + minProgLength.asInteger).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0.01); - - - - /* - if(rangeScore.value(candidate.collect({0}), voices[ins], ranges[ins][1] - 500, ranges[ins][1], 0, true) == 1, { - isInRangeScore = 1 - rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0] + 500, ranges[ins][1] - 500, 0, true); - isInRangeScore = isInRangeScore * rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true) - }, { - isInRangeScore = rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true); - }); - */ - - - isInRangeScore = rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true); - //old way - worked but actually by accident (I think) - //isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - - - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - /* - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - */ - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - /* - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - */ - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/553fbac7/553fbac7_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_3_rise/553fbac7/553fbac7_mus_model.json deleted file mode 100644 index da17f28..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/553fbac7/553fbac7_mus_model.json +++ /dev/null @@ -1,88 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ "Rest" ], [ 0, 1, 0, 0, 0, 0 ], [ "Rest" ] ], 1 ], - [ [ [ 0, 1, 1, 0, 0, 0 ], [ "Rest" ], [ 0, 1, 0, 0, 0, 0 ], [ "Rest" ] ], 1 ], - [ [ [ 0, 1, 1, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ "Rest" ] ], 1 ], - [ [ [ 0, 1, 1, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ -1, 2, 0, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 0, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ -1, 2, 0, 0, 0, 0 ] ], 1 ], - [ [ [ -2, 0, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 1 ], - [ [ [ -2, 0, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ], [ 1, 0, -1, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 0, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 1, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 0, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ], [ 0, -1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 0, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ], [ 0, -1, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, -1, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ] ], 1 ], - [ [ [ -2, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ -1, 1, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ] ], 1 ], - [ [ [ -2, 1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ -1, 1, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ -1, 2, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ] ], 1 ], - [ [ [ -2, 1, 0, 0, 0, 0 ], [ -1, 1, 0, 0, 0, 0 ], [ -1, 2, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 1, 0, 0, 0, 0 ], [ -1, 1, 0, 0, 0, 0 ], [ -1, 2, 0, 0, 0, 0 ], [ -1, 1, 1, 0, 0, 0 ] ], 1 ], - [ [ [ -2, 1, 0, 0, 0, 0 ], [ 0, 1, 0, -1, 0, 0 ], [ -1, 2, 0, 0, 0, 0 ], [ -1, 1, 1, 0, 0, 0 ] ], 1 ], - [ [ [ -2, 1, 0, 0, 0, 0 ], [ 0, 1, 0, -1, 0, 0 ], [ 0, 1, 1, 0, 0, 0 ], [ -1, 1, 1, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 1, 0, 0, 0, 0 ], [ 0, 1, 0, -1, 0, 0 ], [ 0, 1, 1, 0, 0, 0 ], [ 1, 1, -1, -1, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 1, 0, 0, 0, 0 ], [ 0, 1, 0, -1, 0, 0 ], [ 2, 1, -1, -1, -1, 0 ], [ 1, 1, -1, -1, 0, 0 ] ], 1 ], - [ [ [ -2, 1, 0, 0, 0, 0 ], [ 1, 1, -1, -1, -1, 0 ], [ 2, 1, -1, -1, -1, 0 ], [ 1, 1, -1, -1, 0, 0 ] ], 1 ], - [ [ [ 0, 1, -1, -1, -1, 0 ], [ 1, 1, -1, -1, -1, 0 ], [ 2, 1, -1, -1, -1, 0 ], [ 1, 1, -1, -1, 0, 0 ] ], 1 ] - ] - ] -], -"last_changes": -[ - [ [ -2, 1, 0, 0, 0, 0 ], [ 0, 1, 0, -1, 0, 0 ], [ 0, 1, 1, 0, 0, 0 ], [ -1, 1, 1, 0, 0, 0 ] ], - [ [ -2, 1, 0, 0, 0, 0 ], [ 0, 1, 0, -1, 0, 0 ], [ 0, 1, 1, 0, 0, 0 ], [ 1, 1, -1, -1, 0, 0 ] ], - [ [ -2, 1, 0, 0, 0, 0 ], [ 0, 1, 0, -1, 0, 0 ], [ 2, 1, -1, -1, -1, 0 ], [ 1, 1, -1, -1, 0, 0 ] ], - [ [ -2, 1, 0, 0, 0, 0 ], [ 1, 1, -1, -1, -1, 0 ], [ 2, 1, -1, -1, -1, 0 ], [ 1, 1, -1, -1, 0, 0 ] ], - [ [ 0, 1, -1, -1, -1, 0 ], [ 1, 1, -1, -1, -1, 0 ], [ 2, 1, -1, -1, -1, 0 ], [ 1, 1, -1, -1, 0, 0 ] ] -], -"cur_uid": "553fbac7", -"ref_uid": "4874dd07", -"order_seed": 846356, -"dur_seed": 787877, -"motifs_seed": 285247, -"entrances_probs_vals": [ 0, 0, 0, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 0, 0, 0, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 0, 0, 0, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -2400, 1200 ], [ -1200, 1200 ], [ -702, 1200 ], [ -702, 1200 ] ], -"step_probs_vals": [ 0, 1200, 0.0061728395061728, 0.10227272727273, 0.074074074074074, 0.10227272727273, 0.2037037037037, 0.090909090909091, 0.45679012345679, 0.011363636363636, 0.53086419753086, 0, 0.54320987654321, 0.92045454545455, 0.58641975308642, 0.92613636363636, 0.61111111111111, 0, 0.7880658436214, 0.034090909090909, 1, 0.034090909090909 ], -"passages_weights": [ 1, 0.47, 0.43, 1, 0.9 ], -"hd_exp": 9, -"hd_invert": 0, -"order": -[ - [ [ 2 ], [ 0, 1, 3 ], [ ] ], - [ [ 1 ], [ 0, 3, 2 ], [ ] ], - [ [ 1, 3, 0 ], [ 2 ], [ ] ], - [ [ 1, 3, 0 ], [ 2 ], [ ] ], - [ [ 2, 0, 1 ], [ 3 ], [ ] ], - [ [ 3 ], [ 1, 2, 0 ], [ ] ], - [ [ 0, 3 ], [ 2, 1 ], [ ] ], - [ [ 0 ], [ 3, 1, 2 ], [ ] ], - [ [ 1, 0, 2 ], [ 3 ], [ ] ], - [ [ 3 ], [ 2, 1, 0 ], [ ] ] -], -"sus_weights": [ 0.35, 0.37, 0.38 ], -"order_size": [ 10.061224489796, 10.091836734694 ], -"passages_size": [ 0, 0 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/57ef90e6/57ef90e6_code.scd b/resources/resources_bak_2024_01_03/string_quartet_3_rise/57ef90e6/57ef90e6_code.scd deleted file mode 100644 index 0d8c24b..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/57ef90e6/57ef90e6_code.scd +++ /dev/null @@ -1,975 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array2) - hsArrayToCents.value(array1); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -/* -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance) -}; -*/ - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = true; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - //if(pDistance >= 0, {stepFunc.value(abs(pDistance))}, {0.01}); - stepFunc.value(pDistance) -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - //tuples = dims.collect({[0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum == 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength.asInteger - minMotifLength.asInteger).rand + minMotifLength.asInteger).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - //noProgIns = (popSize - noSusIns).rand + 1; - noProgIns = (popSize - noSusIns); - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength.asInteger - minProgLength.asInteger).rand + minProgLength.asInteger).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0.01); - - - - /* - if(rangeScore.value(candidate.collect({0}), voices[ins], ranges[ins][1] - 500, ranges[ins][1], 0, true) == 1, { - isInRangeScore = 1 - rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0] + 500, ranges[ins][1] - 500, 0, true); - isInRangeScore = isInRangeScore * rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true) - }, { - isInRangeScore = rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true); - }); - */ - - - isInRangeScore = rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true); - //old way - worked but actually by accident (I think) - //isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - - - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(mSeq.maxDepth - 5).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/57ef90e6/57ef90e6_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_3_rise/57ef90e6/57ef90e6_mus_model.json deleted file mode 100644 index 0f2fec3..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/57ef90e6/57ef90e6_mus_model.json +++ /dev/null @@ -1,166 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ], [ "Rest" ] ], 1 ], - [ [ [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ "Rest" ] ], 1 ], - [ [ [ "Rest" ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ] ], 1 ], - [ [ [ 0, 0, 0, 1, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ 0, 0, 0, 1, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, -1, 0 ], [ 0, 1, 0, 0, 0, 0 ] ], 1 ], - [ [ [ 1, 1, 0, 0, 0, -1 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, -1, 0 ], [ 0, 1, 0, 0, 0, 0 ] ], 1 ], - [ [ [ 1, 1, 0, 0, 0, -1 ], [ -1, 1, 0, 1, 0, 0 ], [ 0, 1, 0, 0, -1, 0 ], [ 0, 1, 0, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ 1, 1, 0, 0, 0, -1 ], [ -1, 1, 0, 1, 0, 0 ], [ -1, 2, 0, 1, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ] ], 1 ], - [ [ [ 1, 0, 0, 0, 0, 0 ], [ -1, 1, 0, 1, 0, 0 ], [ -1, 2, 0, 1, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ 1, 0, 0, 0, 0, 0 ], [ -1, 1, 0, 1, 0, 0 ], [ -1, 2, 0, 1, 0, 0 ], [ -1, 1, 0, 1, 1, 0 ] ], 1 ] - ], - [ - [ [ [ 1, 0, 0, 0, 0, 0 ], [ -1, 1, 0, 1, 0, 0 ], [ -1, 2, 0, 1, 0, 0 ], [ -2, 2, 0, 1, 1, 0 ] ], 1 ], - [ [ [ 1, 0, 0, 0, 0, 0 ], [ -1, 2, 0, 1, -1, 0 ], [ -1, 2, 0, 1, 0, 0 ], [ -2, 2, 0, 1, 1, 0 ] ], 1 ], - [ [ [ -2, 2, 0, 2, 0, 0 ], [ -1, 2, 0, 1, -1, 0 ], [ -1, 2, 0, 1, 0, 0 ], [ -2, 2, 0, 1, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 2, 0, 2, 0, 0 ], [ -1, 2, 0, 1, -1, 0 ], [ -3, 3, 0, 1, 1, 0 ], [ -2, 2, 0, 1, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 2, 0, 2, 0, 0 ], [ -1, 2, 0, 1, -1, 0 ], [ -3, 3, 0, 1, 1, 0 ], [ -1, 2, 0, 1, 0, 0 ] ], 1 ], - [ [ [ -2, 2, 0, 2, 0, 0 ], [ -2, 3, 0, 1, 0, 0 ], [ -3, 3, 0, 1, 1, 0 ], [ -1, 2, 0, 1, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 2, 0, 2, 0, 0 ], [ -2, 3, 0, 1, 0, 0 ], [ -2, 2, 1, 1, 0, 0 ], [ -1, 2, 0, 1, 0, 0 ] ], 1 ], - [ [ [ -3, 2, 0, 1, 0, 0 ], [ -2, 3, 0, 1, 0, 0 ], [ -2, 2, 1, 1, 0, 0 ], [ -1, 2, 0, 1, 0, 0 ] ], 1 ], - [ [ [ -3, 2, 0, 1, 0, 0 ], [ -1, 2, -1, 1, 0, 0 ], [ -2, 2, 1, 1, 0, 0 ], [ -1, 2, 0, 1, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -3, 2, 0, 1, 0, 0 ], [ -1, 2, -1, 1, 0, 0 ], [ 0, 2, -1, 0, 0, 0 ], [ -1, 2, 0, 1, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -3, 2, 0, 1, 0, 0 ], [ -1, 2, -1, 1, 0, 0 ], [ -3, 2, 0, 1, 1, 0 ], [ -1, 2, 0, 1, 0, 0 ] ], 1 ], - [ [ [ -3, 2, 0, 1, 0, 0 ], [ -1, 2, -1, 1, 0, 0 ], [ -3, 2, 0, 1, 1, 0 ], [ -1, 2, 0, 1, 0, -1 ] ], 1 ], - [ [ [ -3, 2, 0, 1, 0, 0 ], [ -2, 2, 0, 1, 0, 1 ], [ -3, 2, 0, 1, 1, 0 ], [ -1, 2, 0, 1, 0, -1 ] ], 1 ] - ], - [ - [ [ [ -3, 2, 0, 1, 0, 0 ], [ -1, 2, 0, 1, 1, -1 ], [ -3, 2, 0, 1, 1, 0 ], [ -1, 2, 0, 1, 0, -1 ] ], 1 ], - [ [ [ -3, 2, 0, 1, 0, 0 ], [ -1, 2, 0, 1, 1, -1 ], [ -3, 2, 0, 1, 1, 0 ], [ -1, 2, 0, 0, 1, 0 ] ], 1 ], - [ [ [ -2, 2, 0, 1, 1, -1 ], [ -1, 2, 0, 1, 1, -1 ], [ -3, 2, 0, 1, 1, 0 ], [ -1, 2, 0, 0, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 2, 0, 1, 1, -1 ], [ -1, 2, 0, 1, 1, -1 ], [ -3, 2, 0, 1, 1, 0 ], [ -2, 2, 0, 1, 2, 0 ] ], 1 ], - [ [ [ -2, 2, 0, 1, 1, -1 ], [ -1, 2, 0, 1, 0, 0 ], [ -3, 2, 0, 1, 1, 0 ], [ -2, 2, 0, 1, 2, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 1, 0, 1, 2, 0 ], [ -1, 2, 0, 1, 0, 0 ], [ -3, 2, 0, 1, 1, 0 ], [ -2, 2, 0, 1, 2, 0 ] ], 1 ], - [ [ [ -2, 1, 0, 1, 2, 0 ], [ -1, 2, 0, 1, 0, 0 ], [ -4, 3, 0, 1, 2, 0 ], [ -2, 2, 0, 1, 2, 0 ] ], 1 ], - [ [ [ -2, 1, 0, 1, 2, 0 ], [ -2, 2, 0, 0, 2, 0 ], [ -4, 3, 0, 1, 2, 0 ], [ -2, 2, 0, 1, 2, 0 ] ], 1 ] - ], - [ - [ [ [ -3, 2, 0, 0, 2, 0 ], [ -2, 2, 0, 0, 2, 0 ], [ -4, 3, 0, 1, 2, 0 ], [ -2, 2, 0, 1, 2, 0 ] ], 1 ] - ], - [ - [ [ [ -3, 2, 0, 0, 2, 0 ], [ -2, 3, 0, 0, 2, 0 ], [ -4, 3, 0, 1, 2, 0 ], [ -2, 2, 0, 1, 2, 0 ] ], 1 ], - [ [ [ -3, 3, 0, 0, 2, 0 ], [ -2, 3, 0, 0, 2, 0 ], [ -4, 3, 0, 1, 2, 0 ], [ -2, 2, 0, 1, 2, 0 ] ], 1 ] - ], - [ - [ [ [ -3, 3, 0, 0, 2, 0 ], [ -2, 3, 0, 0, 2, 0 ], [ -4, 3, 0, 1, 2, 0 ], [ -1, 3, 0, 0, 2, -1 ] ], 1 ], - [ [ [ -3, 3, 0, 0, 2, 0 ], [ -2, 3, 1, 0, 2, 0 ], [ -4, 3, 0, 1, 2, 0 ], [ -1, 3, 0, 0, 2, -1 ] ], 1 ], - [ [ [ -3, 3, 0, 0, 2, 0 ], [ -2, 3, 1, 0, 2, 0 ], [ -2, 3, 0, 0, 1, 0 ], [ -1, 3, 0, 0, 2, -1 ] ], 1 ] - ], - [ - [ [ [ -3, 3, 0, 0, 2, 0 ], [ -4, 3, 0, 1, 1, 0 ], [ -2, 3, 0, 0, 1, 0 ], [ -1, 3, 0, 0, 2, -1 ] ], 1 ], - [ [ [ -3, 3, 0, 0, 1, 1 ], [ -4, 3, 0, 1, 1, 0 ], [ -2, 3, 0, 0, 1, 0 ], [ -1, 3, 0, 0, 2, -1 ] ], 1 ] - ], - [ - [ [ [ -3, 3, 0, 0, 1, 1 ], [ -2, 3, 0, 0, 0, 0 ], [ -2, 3, 0, 0, 1, 0 ], [ -1, 3, 0, 0, 2, -1 ] ], 1 ], - [ [ [ -3, 3, 0, 1, 1, 0 ], [ -2, 3, 0, 0, 0, 0 ], [ -2, 3, 0, 0, 1, 0 ], [ -1, 3, 0, 0, 2, -1 ] ], 1 ], - [ [ [ -3, 3, 0, 1, 1, 0 ], [ -2, 3, 0, 0, 0, 0 ], [ -2, 3, 0, 0, 1, 0 ], [ -2, 3, 0, 0, 2, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 3, 0, 1, 0, 0 ], [ -2, 3, 0, 0, 0, 0 ], [ -2, 3, 0, 0, 1, 0 ], [ -2, 3, 0, 0, 2, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 3, 0, 1, 0, 0 ], [ -2, 3, 0, 0, 0, 0 ], [ -2, 3, 0, 0, 1, 0 ], [ -1, 3, 0, 1, 0, -1 ] ], 1 ], - [ [ [ -2, 3, 0, 1, 0, 0 ], [ -2, 3, 0, 0, 0, 0 ], [ -1, 3, 0, 0, 0, 0 ], [ -1, 3, 0, 1, 0, -1 ] ], 1 ], - [ [ [ -2, 3, 0, 1, 0, 0 ], [ -2, 3, 0, 1, -1, 0 ], [ -1, 3, 0, 0, 0, 0 ], [ -1, 3, 0, 1, 0, -1 ] ], 1 ] - ], - [ - [ [ [ -1, 3, -1, 1, -1, 0 ], [ -2, 3, 0, 1, -1, 0 ], [ -1, 3, 0, 0, 0, 0 ], [ -1, 3, 0, 1, 0, -1 ] ], 1 ], - [ [ [ -1, 3, -1, 1, -1, 0 ], [ -2, 3, 0, 1, -1, 0 ], [ -2, 3, 0, 1, -1, 1 ], [ -1, 3, 0, 1, 0, -1 ] ], 1 ] - ], - [ - [ [ [ -1, 3, -1, 1, -1, 0 ], [ -2, 3, 0, 1, -1, 0 ], [ -2, 3, 0, 1, -1, 1 ], [ -2, 3, 0, 2, -1, 0 ] ], 1 ], - [ [ [ -2, 3, -1, 1, -1, 0 ], [ -2, 3, 0, 1, -1, 0 ], [ -2, 3, 0, 1, -1, 1 ], [ -2, 3, 0, 2, -1, 0 ] ], 1 ], - [ [ [ -2, 3, -1, 1, -1, 0 ], [ -2, 3, 0, 1, -1, 0 ], [ -3, 4, 0, 1, -1, 0 ], [ -2, 3, 0, 2, -1, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 3, -1, 1, -1, 0 ], [ -2, 4, 0, 1, -1, 0 ], [ -3, 4, 0, 1, -1, 0 ], [ -2, 3, 0, 2, -1, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 3, -1, 1, -1, 0 ], [ -2, 4, 0, 1, -1, 0 ], [ -3, 4, 0, 1, -1, 0 ], [ 0, 3, -1, 0, -1, 0 ] ], 1 ], - [ [ [ -2, 3, -1, 1, -1, 0 ], [ -2, 4, 0, 1, -1, 0 ], [ -2, 3, -1, 1, 0, 0 ], [ 0, 3, -1, 0, -1, 0 ] ], 1 ], - [ [ [ -2, 3, -1, 1, -1, 0 ], [ -2, 4, 0, 1, -1, 0 ], [ "Rest" ], [ 0, 3, -1, 0, -1, 0 ] ], 1 ], - [ [ [ -2, 3, -1, 1, -1, 0 ], [ -2, 4, 0, 1, -1, 0 ], [ "Rest" ], [ "Rest" ] ], 1 ], - [ [ [ -2, 3, -1, 1, -1, 0 ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 1 ], - [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 3 ] - ] - ] -], -"last_changes": -[ - [ [ -2, 3, -1, 1, -1, 0 ], [ -2, 3, 0, 1, -1, 0 ], [ -2, 3, 0, 1, -1, 1 ], [ -2, 3, 0, 2, -1, 0 ] ], - [ [ -2, 3, -1, 1, -1, 0 ], [ -2, 3, 0, 1, -1, 0 ], [ -3, 4, 0, 1, -1, 0 ], [ -2, 3, 0, 2, -1, 0 ] ], - [ [ -2, 3, -1, 1, -1, 0 ], [ -2, 4, 0, 1, -1, 0 ], [ -3, 4, 0, 1, -1, 0 ], [ -2, 3, 0, 2, -1, 0 ] ], - [ [ -2, 3, -1, 1, -1, 0 ], [ -2, 4, 0, 1, -1, 0 ], [ -3, 4, 0, 1, -1, 0 ], [ 0, 3, -1, 0, -1, 0 ] ], - [ [ -2, 3, -1, 1, -1, 0 ], [ -2, 4, 0, 1, -1, 0 ], [ -2, 3, -1, 1, 0, 0 ], [ 0, 3, -1, 0, -1, 0 ] ] -], -"cur_uid": "57ef90e6", -"ref_uid": "nil", -"order_seed": 486941, -"dur_seed": 852979, -"motifs_seed": 409375, -"entrances_probs_vals": [ 0, 0, 0, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 0, 0, 0, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 0, 0, 0, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -2400, 1200 ], [ -1200, 1200 ], [ -702, 1200 ], [ -702, 1200 ] ], -"step_probs_vals": [ 0, 1200, 0.0020576131687243, 0.068181818181818, 0.074074074074074, 0.0625, 0.20576131687243, 0.0625, 0.45679012345679, 0.011363636363636, 0.53086419753086, 0, 0.54320987654321, 0.92045454545455, 0.58641975308642, 0.92613636363636, 0.61111111111111, 0, 0.78600823045268, 0.068181818181818, 0.98971193415638, 0.0625 ], -"passages_weights": [ 1, 1, 1, 1, 0.1 ], -"hd_exp": 1, -"hd_invert": 0, -"order": -[ - [ [ 1, 2 ], [ 3, 0 ], [ ] ], - [ [ 3 ], [ 2, 0, 1 ], [ ] ], - [ [ 1, 3 ], [ 2, 0 ], [ ] ], - [ [ 0, 1, 2 ], [ 3 ], [ ] ], - [ [ 2 ], [ 3, 1, 0 ], [ ] ], - [ [ 3, 0, 1 ], [ 2 ], [ ] ], - [ [ 2, 0 ], [ 3, 1 ], [ ] ], - [ [ 3 ], [ 2, 0, 1 ], [ ] ], - [ [ 3, 0, 1 ], [ 2 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ], - [ [ 2 ], [ 1, 3, 0 ], [ ] ], - [ [ 2, 0 ], [ 3, 1 ], [ ] ], - [ [ 3 ], [ 0, 2, 1 ], [ ] ], - [ [ 2, 1, 3 ], [ 0 ], [ ] ], - [ [ 2, 3 ], [ 1, 0 ], [ ] ], - [ [ 0 ], [ 3, 1, 2 ], [ ] ], - [ [ 2, 3 ], [ 1, 0 ], [ ] ], - [ [ 2 ], [ 1, 0, 3 ], [ ] ], - [ [ 2, 3, 1 ], [ 0 ], [ ] ], - [ [ 0 ], [ 3, 2, 1 ], [ ] ], - [ [ 1, 3 ], [ 0, 2 ], [ ] ], - [ [ 1 ], [ 3, 0, 2 ], [ ] ], - [ [ 0, 2, 3 ], [ 1 ], [ ] ], - [ [ 0, 1 ], [ 3, 2 ], [ ] ] -], -"sus_weights": [ 0.35, 0.37, 0.38 ], -"order_size": [ 24.896551724138, 24.896551724138 ], -"passages_size": [ 0, 0 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/615c4008/615c4008_code.scd b/resources/resources_bak_2024_01_03/string_quartet_3_rise/615c4008/615c4008_code.scd deleted file mode 100644 index 070e09d..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/615c4008/615c4008_code.scd +++ /dev/null @@ -1,992 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array2) - hsArrayToCents.value(array1); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -/* -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance) -}; -*/ - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = true; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - //if(pDistance >= 0, {stepFunc.value(abs(pDistance))}, {0.01}); - stepFunc.value(pDistance) -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - //tuples = dims.collect({[0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum == 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - //[chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - //[minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength.asInteger - minMotifLength.asInteger).rand + minMotifLength.asInteger).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - - //noProgIns = (popSize - noSusIns).rand + 1; - noProgIns = (popSize - noSusIns); - noSilentIns = popSize - noSusIns - noProgIns; - - /* - noSilentIns = (popSize - noSusIns).rand.clip(0, 1); - noProgIns = popSize - noSusIns - noSilentIns; - */ - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength.asInteger - minProgLength.asInteger).rand + minProgLength.asInteger).collect({prog.choose}).scramble); - //prog = ((maxProgLength.asInteger - minProgLength.asInteger).rand + minProgLength.asInteger).collect({prog.choose}); - - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - //candidates.select({arg item; (item ++ voices).asSet.size >= 4}); - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0.01); - //recentlySoundedScore = inclusionScore.value(lastXChanges.flatten.collect({arg item; item.drop(1)}), candidate.drop(1), 0.01); - - /* - if(rangeScore.value(candidate.collect({0}), voices[ins], ranges[ins][1] - 500, ranges[ins][1], 0, true) == 1, { - isInRangeScore = 1 - rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0] + 500, ranges[ins][1] - 500, 0, true); - isInRangeScore = isInRangeScore * rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true) - }, { - isInRangeScore = rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true); - }); - */ - - - isInRangeScore = rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true); - //old way - worked but actually by accident (I think) - //isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - - - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}).postln; - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - nProbs.round(0.001).postln; - [candidates, nProbs.round(0.001)].flop.postln; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - /* - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - */ - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - //lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - lastState = if(o == 0, {lastXChanges.last.deepCopy}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - /* - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - */ - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - //# voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - # voices, durs = seq.flatten2(if(oneShot, {2}, {3})).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(2).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/615c4008/615c4008_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_3_rise/615c4008/615c4008_mus_model.json deleted file mode 100644 index 65a90eb..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/615c4008/615c4008_mus_model.json +++ /dev/null @@ -1,267 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ -9, 5, 1, 4, -1, 2 ], [ -8, 5, 2, 4, -2, 2 ], [ -6, 6, 1, 2, -1, 2 ], [ -6, 5, 1, 4, -2, 2 ] ], 0.25 ], - [ [ [ -9, 6, 1, 4, -2, 2 ], [ -8, 5, 2, 4, -2, 2 ], [ -6, 6, 1, 2, -1, 2 ], [ -6, 5, 1, 4, -2, 2 ] ], 0 ], - [ [ [ -9, 6, 1, 4, -2, 2 ], [ -8, 5, 2, 4, -2, 2 ], [ -7, 6, 1, 4, -2, 2 ], [ -6, 5, 1, 4, -2, 2 ] ], 0 ], - [ [ [ -9, 6, 1, 4, -2, 2 ], [ -7, 4, 1, 4, -2, 2 ], [ -7, 6, 1, 4, -2, 2 ], [ -6, 5, 1, 4, -2, 2 ] ], 0.25 ], - [ [ [ -9, 6, 1, 4, -2, 2 ], [ -8, 6, 1, 4, -2, 2 ], [ -7, 6, 1, 4, -2, 2 ], [ -6, 5, 1, 4, -2, 2 ] ], 0.25 ], - [ [ [ -9, 6, 1, 4, -2, 2 ], [ -7, 5, 1, 4, -2, 2 ], [ -7, 6, 1, 4, -2, 2 ], [ -6, 5, 1, 4, -2, 2 ] ], 0.25 ] - ], - [ - [ [ [ -9, 6, 1, 4, -2, 2 ], [ -8, 7, 1, 4, -2, 2 ], [ -7, 6, 1, 4, -2, 2 ], [ -6, 5, 1, 4, -2, 2 ] ], 0 ], - [ [ [ -9, 6, 1, 4, -2, 2 ], [ -8, 7, 1, 4, -2, 2 ], [ -7, 6, 1, 4, -2, 2 ], [ -7, 7, 1, 4, -2, 2 ] ], 0 ], - [ [ [ -9, 7, 1, 4, -2, 2 ], [ -8, 7, 1, 4, -2, 2 ], [ -7, 6, 1, 4, -2, 2 ], [ -7, 7, 1, 4, -2, 2 ] ], 0.25 ], - [ [ [ -9, 7, 1, 4, -2, 2 ], [ -7, 6, 0, 4, -2, 2 ], [ -7, 6, 1, 4, -2, 2 ], [ -7, 7, 1, 4, -2, 2 ] ], 0.25 ] - ], - [ - [ [ [ -9, 7, 1, 4, -2, 2 ], [ -7, 6, 0, 4, -2, 2 ], [ -8, 7, 0, 4, -2, 2 ], [ -7, 7, 1, 4, -2, 2 ] ], 0 ], - [ [ [ -9, 7, 1, 4, -2, 2 ], [ -7, 6, 0, 4, -2, 2 ], [ -8, 7, 0, 4, -2, 2 ], [ -6, 6, 0, 4, -2, 2 ] ], 0.25 ], - [ [ [ -8, 6, 0, 4, -2, 2 ], [ -7, 6, 0, 4, -2, 2 ], [ -8, 7, 0, 4, -2, 2 ], [ -6, 6, 0, 4, -2, 2 ] ], 0.25 ] - ], - [ - [ [ [ -8, 6, 0, 4, -2, 2 ], [ -7, 7, 0, 4, -2, 2 ], [ -8, 7, 0, 4, -2, 2 ], [ -6, 6, 0, 4, -2, 2 ] ], 0.25 ], - [ [ [ -9, 7, 0, 4, -2, 2 ], [ -7, 7, 0, 4, -2, 2 ], [ -8, 7, 0, 4, -2, 2 ], [ -6, 6, 0, 4, -2, 2 ] ], 0.25 ], - [ [ [ -9, 7, 0, 4, -2, 2 ], [ -7, 7, 0, 4, -2, 2 ], [ -8, 7, 0, 4, -2, 2 ], [ -8, 8, 0, 4, -2, 2 ] ], 0 ], - [ [ [ -8, 7, 0, 3, -2, 2 ], [ -7, 7, 0, 4, -2, 2 ], [ -8, 7, 0, 4, -2, 2 ], [ -8, 8, 0, 4, -2, 2 ] ], 0 ], - [ [ [ -8, 7, 0, 3, -2, 2 ], [ -6, 7, 0, 3, -2, 2 ], [ -8, 7, 0, 4, -2, 2 ], [ -8, 8, 0, 4, -2, 2 ] ], 0.25 ], - [ [ [ -8, 7, 0, 3, -2, 2 ], [ -6, 7, 0, 3, -2, 2 ], [ -8, 7, 0, 4, -2, 2 ], [ -7, 7, 0, 3, -2, 2 ] ], 0 ], - [ [ [ -8, 7, 0, 3, -2, 2 ], [ -7, 7, 1, 4, -2, 2 ], [ -8, 7, 0, 4, -2, 2 ], [ -7, 7, 0, 3, -2, 2 ] ], 0.25 ] - ], - [ - [ [ [ -8, 7, 0, 3, -2, 2 ], [ -7, 7, 1, 4, -2, 2 ], [ -8, 7, 0, 4, -2, 2 ], [ -7, 7, 0, 4, -2, 2 ] ], 0.25 ], - [ [ [ -8, 7, 0, 3, -2, 2 ], [ -7, 6, 0, 4, -2, 2 ], [ -8, 7, 0, 4, -2, 2 ], [ -7, 7, 0, 4, -2, 2 ] ], 0.25 ], - [ [ [ -8, 7, 0, 3, -2, 2 ], [ -8, 8, 0, 4, -2, 2 ], [ -8, 7, 0, 4, -2, 2 ], [ -7, 7, 0, 4, -2, 2 ] ], 0 ], - [ [ [ -8, 7, 0, 3, -2, 2 ], [ -8, 8, 0, 4, -2, 2 ], [ -8, 7, 0, 4, -2, 2 ], [ -6, 7, 0, 3, -2, 2 ] ], 0.25 ], - [ [ [ -8, 7, 0, 3, -2, 2 ], [ -8, 8, 0, 4, -2, 2 ], [ -8, 7, 0, 4, -2, 2 ], [ -7, 7, 1, 4, -2, 2 ] ], 0.25 ], - [ [ [ -8, 7, 0, 3, -2, 2 ], [ -8, 8, 0, 4, -2, 2 ], [ -8, 7, 0, 4, -2, 2 ], [ -6, 6, 0, 4, -2, 2 ] ], 0.25 ] - ], - [ - [ [ [ -8, 7, 0, 3, -2, 2 ], [ -8, 8, 0, 4, -2, 2 ], [ -8, 7, 0, 4, -2, 2 ], [ -7, 8, 0, 3, -2, 2 ] ], 0 ], - [ [ [ -8, 7, 0, 3, -2, 2 ], [ -8, 8, 0, 3, -2, 2 ], [ -8, 7, 0, 4, -2, 2 ], [ -7, 8, 0, 3, -2, 2 ] ], 0 ], - [ [ [ -8, 7, 0, 3, -2, 2 ], [ -8, 8, 0, 3, -2, 2 ], [ -7, 7, 0, 3, -2, 2 ], [ -7, 8, 0, 3, -2, 2 ] ], 0.25 ], - [ [ [ -8, 7, 0, 3, -2, 2 ], [ -8, 7, 0, 3, -2, 3 ], [ -7, 7, 0, 3, -2, 2 ], [ -7, 8, 0, 3, -2, 2 ] ], 0 ], - [ [ [ -8, 7, 0, 3, -2, 2 ], [ -8, 7, 0, 3, -2, 3 ], [ -7, 7, 0, 3, -2, 2 ], [ -7, 7, 0, 3, -2, 3 ] ], 0.25 ], - [ [ [ -8, 7, 0, 3, -2, 2 ], [ -8, 7, 0, 3, -2, 3 ], [ -7, 7, 0, 3, -2, 2 ], [ -7, 7, 0, 4, -2, 2 ] ], 0.25 ] - ], - [ - [ [ [ -8, 7, 0, 3, -2, 2 ], [ -8, 7, 0, 3, -2, 3 ], [ -8, 7, 0, 3, -1, 3 ], [ -7, 7, 0, 4, -2, 2 ] ], 0 ], - [ [ [ -8, 7, 0, 3, -2, 2 ], [ -8, 7, 0, 3, -2, 3 ], [ -8, 7, 0, 3, -1, 3 ], [ -6, 7, 0, 3, -2, 2 ] ], 0 ], - [ [ [ -9, 7, 0, 3, -1, 3 ], [ -8, 7, 0, 3, -2, 3 ], [ -8, 7, 0, 3, -1, 3 ], [ -6, 7, 0, 3, -2, 2 ] ], 0.25 ] - ], - [ - [ [ [ -9, 7, 0, 3, -1, 3 ], [ -8, 7, 0, 3, -2, 3 ], [ -7, 7, 1, 3, -2, 2 ], [ -6, 7, 0, 3, -2, 2 ] ], 0 ], - [ [ [ -9, 7, 0, 3, -1, 3 ], [ -7, 7, 0, 3, -2, 2 ], [ -7, 7, 1, 3, -2, 2 ], [ -6, 7, 0, 3, -2, 2 ] ], 0.25 ], - [ [ [ -9, 7, 0, 3, -1, 3 ], [ -7, 7, 0, 3, -2, 2 ], [ -7, 7, 0, 3, -1, 2 ], [ -6, 7, 0, 3, -2, 2 ] ], 0.25 ], - [ [ [ -9, 7, 0, 3, -1, 3 ], [ -7, 7, 0, 3, -2, 2 ], [ -8, 8, 0, 3, -2, 2 ], [ -6, 7, 0, 3, -2, 2 ] ], 0.25 ], - [ [ [ -9, 7, 0, 3, -1, 3 ], [ -8, 7, 0, 3, -1, 3 ], [ -8, 8, 0, 3, -2, 2 ], [ -6, 7, 0, 3, -2, 2 ] ], 0.25 ] - ], - [ - [ [ [ -9, 7, 0, 3, -1, 3 ], [ -8, 7, 0, 3, -1, 3 ], [ -8, 8, 0, 3, -2, 2 ], [ -7, 7, 0, 3, -1, 3 ] ], 0.25 ], - [ [ [ -9, 7, 0, 3, -1, 3 ], [ -8, 8, 0, 3, -2, 3 ], [ -8, 8, 0, 3, -2, 2 ], [ -7, 7, 0, 3, -1, 3 ] ], 0.25 ], - [ [ [ -9, 7, 0, 3, -1, 3 ], [ -8, 8, 0, 3, -2, 3 ], [ -8, 8, 0, 3, -2, 2 ], [ -7, 8, 0, 3, -2, 3 ] ], 0.25 ], - [ [ [ -9, 7, 0, 3, -1, 3 ], [ -8, 8, 0, 4, -2, 2 ], [ -8, 8, 0, 3, -2, 2 ], [ -7, 8, 0, 3, -2, 3 ] ], 0.25 ], - [ [ [ -9, 7, 0, 3, -1, 3 ], [ -7, 8, 0, 3, -2, 2 ], [ -8, 8, 0, 3, -2, 2 ], [ -7, 8, 0, 3, -2, 3 ] ], 0.25 ] - ], - [ - [ [ [ -9, 7, 0, 3, -1, 3 ], [ -8, 8, 1, 3, -2, 2 ], [ -8, 8, 0, 3, -2, 2 ], [ -7, 8, 0, 3, -2, 3 ] ], 0 ], - [ [ [ -9, 7, 0, 3, -1, 3 ], [ -8, 8, 1, 3, -2, 2 ], [ -8, 8, 0, 3, -2, 2 ], [ -7, 8, 0, 4, -2, 2 ] ], 0 ], - [ [ [ -8, 8, -1, 3, -2, 2 ], [ -8, 8, 1, 3, -2, 2 ], [ -8, 8, 0, 3, -2, 2 ], [ -7, 8, 0, 4, -2, 2 ] ], 0.25 ], - [ [ [ -8, 8, -1, 3, -2, 2 ], [ -7, 7, 0, 3, -2, 2 ], [ -8, 8, 0, 3, -2, 2 ], [ -7, 8, 0, 4, -2, 2 ] ], 0 ], - [ [ [ -9, 8, 0, 4, -2, 2 ], [ -7, 7, 0, 3, -2, 2 ], [ -8, 8, 0, 3, -2, 2 ], [ -7, 8, 0, 4, -2, 2 ] ], 0.25 ], - [ [ [ -9, 8, 0, 3, -2, 2 ], [ -7, 7, 0, 3, -2, 2 ], [ -8, 8, 0, 3, -2, 2 ], [ -7, 8, 0, 4, -2, 2 ] ], 0.25 ] - ], - [ - [ [ [ -9, 8, 0, 3, -2, 2 ], [ -7, 7, 0, 3, -2, 2 ], [ -8, 8, 0, 4, -2, 2 ], [ -7, 8, 0, 4, -2, 2 ] ], 0 ], - [ [ [ -9, 8, 0, 4, -2, 1 ], [ -7, 7, 0, 3, -2, 2 ], [ -8, 8, 0, 4, -2, 2 ], [ -7, 8, 0, 4, -2, 2 ] ], 0.625 ], - [ [ [ -9, 8, 0, 4, -2, 1 ], [ -9, 8, 0, 4, -2, 2 ], [ -8, 8, 0, 4, -2, 2 ], [ -7, 8, 0, 4, -2, 2 ] ], 0 ], - [ [ [ -10, 8, 0, 4, -2, 2 ], [ -9, 8, 0, 4, -2, 2 ], [ -8, 8, 0, 4, -2, 2 ], [ -7, 8, 0, 4, -2, 2 ] ], 0.25 ], - [ [ [ -10, 8, 0, 4, -2, 2 ], [ -9, 9, 0, 4, -2, 2 ], [ -8, 8, 0, 4, -2, 2 ], [ -7, 8, 0, 4, -2, 2 ] ], 0.25 ], - [ [ [ -10, 8, 0, 4, -2, 2 ], [ -8, 8, -1, 4, -2, 2 ], [ -8, 8, 0, 4, -2, 2 ], [ -7, 8, 0, 4, -2, 2 ] ], 0.25 ], - [ [ [ -10, 8, 0, 4, -2, 2 ], [ -8, 8, -1, 4, -2, 2 ], [ -8, 7, 0, 4, -2, 2 ], [ -7, 8, 0, 4, -2, 2 ] ], 0.25 ] - ], - [ - [ [ [ -9, 8, 0, 3, -2, 2 ], [ -8, 8, -1, 4, -2, 2 ], [ -8, 7, 0, 4, -2, 2 ], [ -7, 8, 0, 4, -2, 2 ] ], 0 ], - [ [ [ -9, 8, 0, 3, -2, 2 ], [ -8, 8, -1, 4, -2, 2 ], [ -9, 9, 0, 4, -2, 2 ], [ -7, 8, 0, 4, -2, 2 ] ], 0 ], - [ [ [ -9, 8, 0, 3, -2, 2 ], [ -9, 8, 0, 4, -2, 2 ], [ -9, 9, 0, 4, -2, 2 ], [ -7, 8, 0, 4, -2, 2 ] ], 0.25 ], - [ [ [ -9, 8, 0, 3, -2, 2 ], [ -8, 8, 0, 3, -2, 2 ], [ -9, 9, 0, 4, -2, 2 ], [ -7, 8, 0, 4, -2, 2 ] ], 0.25 ], - [ [ [ -9, 8, 0, 3, -2, 2 ], [ -8, 8, 0, 4, -2, 2 ], [ -9, 9, 0, 4, -2, 2 ], [ -7, 8, 0, 4, -2, 2 ] ], 0 ], - [ [ [ -9, 8, 0, 4, -2, 2 ], [ -8, 8, 0, 4, -2, 2 ], [ -9, 9, 0, 4, -2, 2 ], [ -7, 8, 0, 4, -2, 2 ] ], 0.25 ] - ], - [ - [ [ [ -9, 8, 0, 4, -2, 2 ], [ -8, 8, 0, 4, -2, 2 ], [ -8, 8, -1, 4, -2, 2 ], [ -7, 8, 0, 4, -2, 2 ] ], 0.25 ], - [ [ [ -9, 8, 0, 4, -2, 2 ], [ -7, 8, -1, 4, -2, 2 ], [ -8, 8, -1, 4, -2, 2 ], [ -7, 8, 0, 4, -2, 2 ] ], 0 ], - [ [ [ -9, 8, -1, 4, -2, 2 ], [ -7, 8, -1, 4, -2, 2 ], [ -8, 8, -1, 4, -2, 2 ], [ -7, 8, 0, 4, -2, 2 ] ], 0.25 ] - ], - [ - [ [ [ -9, 8, -1, 4, -2, 2 ], [ -7, 8, -1, 4, -2, 2 ], [ -9, 9, -1, 4, -2, 2 ], [ -7, 8, 0, 4, -2, 2 ] ], 0 ], - [ [ [ -7, 8, 0, 4, -3, 2 ], [ -7, 8, -1, 4, -2, 2 ], [ -9, 9, -1, 4, -2, 2 ], [ -7, 8, 0, 4, -2, 2 ] ], 0.25 ], - [ [ [ -7, 8, 0, 4, -3, 2 ], [ -7, 8, -1, 4, -2, 2 ], [ -8, 7, 0, 4, -2, 2 ], [ -7, 8, 0, 4, -2, 2 ] ], 0.25 ], - [ [ [ -7, 8, 0, 4, -3, 2 ], [ -7, 8, -1, 4, -2, 2 ], [ -8, 8, 0, 4, -3, 2 ], [ -7, 8, 0, 4, -2, 2 ] ], 0.25 ] - ], - [ - [ [ [ -7, 8, 0, 4, -3, 2 ], [ -7, 7, 0, 4, -3, 2 ], [ -8, 8, 0, 4, -3, 2 ], [ -7, 8, 0, 4, -2, 2 ] ], 0.25 ], - [ [ [ -7, 8, 0, 4, -3, 2 ], [ -7, 7, 0, 4, -3, 2 ], [ -7, 8, -1, 4, -3, 2 ], [ -7, 8, 0, 4, -2, 2 ] ], 0.25 ] - ], - [ - [ [ [ -7, 8, 0, 4, -3, 2 ], [ -7, 7, 0, 4, -3, 2 ], [ -6, 6, 0, 4, -3, 2 ], [ -7, 8, 0, 4, -2, 2 ] ], 0 ], - [ [ [ -7, 8, 0, 4, -3, 2 ], [ -7, 7, 0, 4, -3, 2 ], [ -6, 6, 0, 4, -3, 2 ], [ -7, 6, 0, 4, -3, 2 ] ], 0.25 ], - [ [ [ -8, 6, 0, 4, -3, 2 ], [ -7, 7, 0, 4, -3, 2 ], [ -6, 6, 0, 4, -3, 2 ], [ -7, 6, 0, 4, -3, 2 ] ], 0.25 ] - ], - [ - [ [ [ -8, 7, 0, 4, -3, 2 ], [ -7, 7, 0, 4, -3, 2 ], [ -6, 6, 0, 4, -3, 2 ], [ -7, 6, 0, 4, -3, 2 ] ], 0 ], - [ [ [ -8, 7, 0, 4, -3, 2 ], [ -7, 7, 0, 4, -3, 2 ], [ -7, 8, 0, 4, -3, 2 ], [ -7, 6, 0, 4, -3, 2 ] ], 0 ], - [ [ [ -8, 7, 0, 4, -3, 2 ], [ -7, 7, 0, 4, -3, 2 ], [ -7, 8, 0, 4, -3, 2 ], [ -8, 8, 0, 4, -3, 2 ] ], 0.25 ], - [ [ [ -8, 7, 0, 4, -3, 2 ], [ -7, 7, 0, 4, -3, 2 ], [ -6, 7, -1, 4, -3, 2 ], [ -8, 8, 0, 4, -3, 2 ] ], 0 ], - [ [ [ -8, 7, 0, 4, -3, 2 ], [ -7, 7, 0, 4, -3, 2 ], [ -6, 7, -1, 4, -3, 2 ], [ -7, 7, -1, 4, -3, 2 ] ], 0 ], - [ [ [ -8, 7, -1, 4, -3, 2 ], [ -7, 7, 0, 4, -3, 2 ], [ -6, 7, -1, 4, -3, 2 ], [ -7, 7, -1, 4, -3, 2 ] ], 0.25 ], - [ [ [ -8, 7, -1, 4, -3, 2 ], [ -7, 7, 0, 4, -3, 2 ], [ -6, 7, -1, 4, -3, 2 ], [ -6, 7, 0, 3, -3, 2 ] ], 0.25 ] - ], - [ - [ [ [ -8, 7, -1, 4, -3, 2 ], [ -7, 7, 0, 4, -3, 2 ], [ -7, 7, 0, 5, -3, 2 ], [ -6, 7, 0, 3, -3, 2 ] ], 0 ], - [ [ [ -9, 7, 0, 5, -3, 2 ], [ -7, 7, 0, 4, -3, 2 ], [ -7, 7, 0, 5, -3, 2 ], [ -6, 7, 0, 3, -3, 2 ] ], 0.25 ], - [ [ [ -9, 7, 0, 5, -3, 2 ], [ -7, 7, 0, 4, -3, 2 ], [ -7, 7, 0, 5, -3, 2 ], [ -6, 7, -1, 4, -3, 2 ] ], 0.25 ], - [ [ [ -9, 7, 0, 5, -3, 2 ], [ -7, 7, 0, 4, -3, 2 ], [ -7, 7, 0, 5, -3, 2 ], [ -8, 7, 0, 5, -3, 2 ] ], 0 ], - [ [ [ -9, 7, 0, 5, -3, 2 ], [ -7, 7, 0, 4, -3, 2 ], [ -6, 7, 0, 4, -3, 2 ], [ -8, 7, 0, 5, -3, 2 ] ], 0.25 ], - [ [ [ -9, 7, 0, 5, -3, 2 ], [ -7, 7, 0, 4, -3, 2 ], [ -7, 8, 0, 4, -3, 2 ], [ -8, 7, 0, 5, -3, 2 ] ], 0 ], - [ [ [ -8, 7, 0, 4, -3, 2 ], [ -7, 7, 0, 4, -3, 2 ], [ -7, 8, 0, 4, -3, 2 ], [ -8, 7, 0, 5, -3, 2 ] ], 0.25 ] - ], - [ - [ [ [ -8, 7, 0, 4, -3, 2 ], [ -8, 9, 0, 4, -3, 2 ], [ -7, 8, 0, 4, -3, 2 ], [ -8, 7, 0, 5, -3, 2 ] ], 0 ], - [ [ [ -9, 9, 0, 4, -3, 2 ], [ -8, 9, 0, 4, -3, 2 ], [ -7, 8, 0, 4, -3, 2 ], [ -8, 7, 0, 5, -3, 2 ] ], 0 ], - [ [ [ -9, 9, 0, 4, -3, 2 ], [ -8, 9, 0, 4, -3, 2 ], [ -7, 8, 0, 4, -3, 2 ], [ -8, 8, 1, 4, -3, 2 ] ], 0.25 ], - [ [ [ -9, 9, 0, 4, -3, 2 ], [ -7, 8, -1, 4, -3, 2 ], [ -7, 8, 0, 4, -3, 2 ], [ -8, 8, 1, 4, -3, 2 ] ], 0.25 ], - [ [ [ -9, 8, 0, 4, -3, 2 ], [ -7, 8, -1, 4, -3, 2 ], [ -7, 8, 0, 4, -3, 2 ], [ -8, 8, 1, 4, -3, 2 ] ], 0 ], - [ [ [ -9, 8, 0, 4, -3, 2 ], [ -8, 8, 0, 4, -3, 2 ], [ -7, 8, 0, 4, -3, 2 ], [ -8, 8, 1, 4, -3, 2 ] ], 0.25 ], - [ [ [ -9, 8, 0, 4, -3, 2 ], [ -9, 8, 1, 4, -3, 2 ], [ -7, 8, 0, 4, -3, 2 ], [ -8, 8, 1, 4, -3, 2 ] ], 0.25 ], - [ [ [ -10, 8, 1, 4, -3, 2 ], [ -9, 8, 1, 4, -3, 2 ], [ -7, 8, 0, 4, -3, 2 ], [ -8, 8, 1, 4, -3, 2 ] ], 0.25 ] - ], - [ - [ [ [ -10, 8, 1, 4, -3, 2 ], [ -9, 8, 1, 4, -3, 2 ], [ -7, 8, 0, 4, -3, 2 ], [ -7, 7, 1, 4, -3, 2 ] ], 0.25 ], - [ [ [ -10, 8, 1, 4, -3, 2 ], [ -8, 8, 1, 3, -3, 2 ], [ -7, 8, 0, 4, -3, 2 ], [ -7, 7, 1, 4, -3, 2 ] ], 0.25 ], - [ [ [ -10, 8, 1, 4, -3, 2 ], [ -8, 8, 1, 3, -3, 2 ], [ -8, 9, 1, 4, -3, 2 ], [ -7, 7, 1, 4, -3, 2 ] ], 0.25 ], - [ [ [ -10, 8, 1, 4, -3, 2 ], [ -8, 8, 1, 3, -3, 2 ], [ -8, 8, 1, 4, -3, 2 ], [ -7, 7, 1, 4, -3, 2 ] ], 0 ], - [ [ [ -10, 8, 1, 4, -3, 2 ], [ -9, 9, 1, 4, -3, 2 ], [ -8, 8, 1, 4, -3, 2 ], [ -7, 7, 1, 4, -3, 2 ] ], 0.25 ] - ], - [ - [ [ [ -9, 8, 1, 4, -3, 2 ], [ -9, 9, 1, 4, -3, 2 ], [ -8, 8, 1, 4, -3, 2 ], [ -7, 7, 1, 4, -3, 2 ] ], 0 ], - [ [ [ -9, 8, 1, 4, -3, 2 ], [ -9, 9, 1, 4, -3, 2 ], [ -8, 7, 1, 4, -3, 2 ], [ -7, 7, 1, 4, -3, 2 ] ], 0.25 ], - [ [ [ -8, 7, 0, 4, -3, 2 ], [ -9, 9, 1, 4, -3, 2 ], [ -8, 7, 1, 4, -3, 2 ], [ -7, 7, 1, 4, -3, 2 ] ], 0.25 ] - ], - [ - [ [ [ -8, 7, 0, 4, -3, 2 ], [ -8, 7, 2, 4, -3, 2 ], [ -8, 7, 1, 4, -3, 2 ], [ -7, 7, 1, 4, -3, 2 ] ], 0.25 ], - [ [ [ -8, 7, 0, 4, -3, 2 ], [ -8, 7, 2, 4, -3, 2 ], [ -8, 7, 1, 4, -3, 2 ], [ -7, 8, 1, 4, -3, 2 ] ], 0 ], - [ [ [ -9, 7, 1, 4, -3, 2 ], [ -8, 7, 2, 4, -3, 2 ], [ -8, 7, 1, 4, -3, 2 ], [ -7, 8, 1, 4, -3, 2 ] ], 0.25 ] - ], - [ - [ [ [ -8, 6, 1, 4, -3, 2 ], [ -8, 7, 2, 4, -3, 2 ], [ -8, 7, 1, 4, -3, 2 ], [ -7, 8, 1, 4, -3, 2 ] ], 0 ], - [ [ [ -8, 6, 1, 4, -3, 2 ], [ -8, 7, 2, 4, -3, 2 ], [ -8, 7, 1, 4, -3, 2 ], [ -6, 6, 1, 4, -3, 2 ] ], 0 ], - [ [ [ -8, 6, 1, 4, -3, 2 ], [ -7, 6, 1, 4, -3, 2 ], [ -8, 7, 1, 4, -3, 2 ], [ -6, 6, 1, 4, -3, 2 ] ], 0.25 ], - [ [ [ -9, 8, 1, 4, -3, 2 ], [ -7, 6, 1, 4, -3, 2 ], [ -8, 7, 1, 4, -3, 2 ], [ -6, 6, 1, 4, -3, 2 ] ], 0.25 ], - [ [ [ -7, 7, 1, 4, -3, 2 ], [ -7, 6, 1, 4, -3, 2 ], [ -8, 7, 1, 4, -3, 2 ], [ -6, 6, 1, 4, -3, 2 ] ], 0 ], - [ [ [ -7, 7, 1, 4, -3, 2 ], [ -7, 6, 1, 4, -3, 2 ], [ -8, 7, 1, 4, -3, 2 ], [ -7, 8, 1, 4, -3, 2 ] ], 0 ], - [ [ [ -7, 7, 1, 4, -3, 2 ], [ -8, 8, 1, 4, -3, 2 ], [ -8, 7, 1, 4, -3, 2 ], [ -7, 8, 1, 4, -3, 2 ] ], 0.25 ], - [ [ [ -7, 7, 1, 4, -3, 2 ], [ -8, 8, 1, 4, -3, 2 ], [ -8, 7, 1, 4, -3, 2 ], [ -7, 7, 1, 4, -2, 2 ] ], 0.25 ] - ], - [ - [ [ [ -7, 7, 1, 4, -3, 2 ], [ -8, 8, 1, 4, -3, 2 ], [ -8, 7, 1, 4, -3, 2 ], [ -7, 8, 1, 4, -3, 2 ] ], 0 ], - [ [ [ -9, 7, 1, 4, -3, 2 ], [ -8, 8, 1, 4, -3, 2 ], [ -8, 7, 1, 4, -3, 2 ], [ -7, 8, 1, 4, -3, 2 ] ], 0 ], - [ [ [ -9, 7, 1, 4, -3, 2 ], [ -7, 7, 1, 4, -3, 2 ], [ -8, 7, 1, 4, -3, 2 ], [ -7, 8, 1, 4, -3, 2 ] ], 0.25 ], - [ [ [ -9, 8, 1, 4, -3, 2 ], [ -7, 7, 1, 4, -3, 2 ], [ -8, 7, 1, 4, -3, 2 ], [ -7, 8, 1, 4, -3, 2 ] ], 0 ], - [ [ [ -9, 8, 1, 4, -3, 2 ], [ -8, 8, 1, 4, -3, 2 ], [ -8, 7, 1, 4, -3, 2 ], [ -7, 8, 1, 4, -3, 2 ] ], 0 ], - [ [ [ -9, 8, 1, 4, -3, 2 ], [ -8, 8, 1, 4, -3, 2 ], [ -8, 7, 1, 4, -3, 2 ], [ -7, 7, 1, 4, -3, 2 ] ], 0.25 ] - ], - [ - [ [ [ -9, 8, 1, 4, -3, 2 ], [ -7, 8, 1, 3, -3, 2 ], [ -8, 7, 1, 4, -3, 2 ], [ -7, 7, 1, 4, -3, 2 ] ], 0 ], - [ [ [ -9, 8, 1, 4, -3, 2 ], [ -7, 8, 1, 3, -3, 2 ], [ -8, 7, 1, 4, -3, 2 ], [ -8, 9, 1, 4, -3, 2 ] ], 0 ], - [ [ [ -9, 8, 1, 4, -3, 2 ], [ -7, 8, 1, 3, -3, 2 ], [ -9, 9, 1, 4, -3, 2 ], [ -8, 9, 1, 4, -3, 2 ] ], 0.25 ], - [ [ [ -9, 8, 1, 4, -3, 2 ], [ -8, 8, 2, 4, -3, 2 ], [ -9, 9, 1, 4, -3, 2 ], [ -8, 9, 1, 4, -3, 2 ] ], 0.25 ], - [ [ [ -9, 8, 1, 4, -3, 2 ], [ -7, 7, 1, 4, -3, 2 ], [ -9, 9, 1, 4, -3, 2 ], [ -8, 9, 1, 4, -3, 2 ] ], 0.25 ], - [ [ [ -9, 8, 1, 4, -3, 2 ], [ -7, 7, 1, 4, -3, 2 ], [ -9, 9, 1, 4, -3, 2 ], [ -8, 8, 1, 4, -3, 2 ] ], 0.25 ], - [ [ [ -9, 8, 1, 4, -3, 2 ], [ -7, 7, 1, 4, -3, 2 ], [ -9, 9, 1, 4, -3, 2 ], [ -8, 7, 1, 4, -3, 2 ] ], 0.25 ] - ], - [ - [ [ [ -9, 8, 1, 4, -3, 2 ], [ -7, 7, 1, 4, -3, 2 ], [ -8, 7, 2, 4, -3, 2 ], [ -8, 7, 1, 4, -3, 2 ] ], 0 ], - [ [ [ -9, 8, 1, 4, -3, 2 ], [ -8, 8, 1, 4, -3, 2 ], [ -8, 7, 2, 4, -3, 2 ], [ -8, 7, 1, 4, -3, 2 ] ], 0 ], - [ [ [ -9, 7, 1, 4, -3, 2 ], [ -8, 8, 1, 4, -3, 2 ], [ -8, 7, 2, 4, -3, 2 ], [ -8, 7, 1, 4, -3, 2 ] ], 0.25 ], - [ [ [ -9, 7, 1, 4, -3, 2 ], [ -8, 8, 1, 4, -3, 2 ], [ -7, 7, 1, 4, -3, 2 ], [ -8, 7, 1, 4, -3, 2 ] ], 0.25 ], - [ [ [ -9, 7, 1, 4, -3, 2 ], [ -8, 8, 1, 4, -3, 2 ], [ -7, 8, 1, 4, -3, 2 ], [ -8, 7, 1, 4, -3, 2 ] ], 0.25 ], - [ [ [ -10, 8, 1, 4, -3, 2 ], [ -8, 8, 1, 4, -3, 2 ], [ -7, 8, 1, 4, -3, 2 ], [ -8, 7, 1, 4, -3, 2 ] ], 0 ], - [ [ [ -10, 8, 1, 4, -3, 2 ], [ -8, 8, 1, 4, -3, 2 ], [ -6, 7, 0, 4, -3, 2 ], [ -8, 7, 1, 4, -3, 2 ] ], 0.25 ] - ], - [ - [ [ [ -9, 7, 0, 4, -3, 2 ], [ -8, 8, 1, 4, -3, 2 ], [ -6, 7, 0, 4, -3, 2 ], [ -8, 7, 1, 4, -3, 2 ] ], 0 ], - [ [ [ -9, 7, 0, 4, -3, 2 ], [ -8, 7, 0, 4, -3, 2 ], [ -6, 7, 0, 4, -3, 2 ], [ -8, 7, 1, 4, -3, 2 ] ], 0 ], - [ [ [ -9, 7, 0, 4, -3, 2 ], [ -8, 7, 0, 4, -3, 2 ], [ -6, 7, 0, 4, -3, 2 ], [ -7, 7, 0, 4, -3, 2 ] ], 0.25 ], - [ [ [ -9, 8, 0, 4, -3, 2 ], [ -8, 7, 0, 4, -3, 2 ], [ -6, 7, 0, 4, -3, 2 ], [ -7, 7, 0, 4, -3, 2 ] ], 0.25 ] - ], - [ - [ [ [ -9, 8, 0, 4, -3, 2 ], [ -8, 7, 0, 4, -3, 2 ], [ -6, 7, 0, 4, -3, 2 ], [ -7, 8, 0, 4, -3, 2 ] ], 0.25 ], - [ [ [ -9, 8, 0, 4, -3, 2 ], [ -8, 7, 0, 4, -3, 2 ], [ -8, 8, 0, 4, -3, 2 ], [ -7, 8, 0, 4, -3, 2 ] ], 0 ], - [ [ [ -9, 8, 0, 4, -3, 2 ], [ -9, 9, 0, 4, -3, 2 ], [ -8, 8, 0, 4, -3, 2 ], [ -7, 8, 0, 4, -3, 2 ] ], 0.25 ], - [ [ [ -9, 8, 0, 4, -3, 2 ], [ -9, 9, 0, 4, -3, 2 ], [ -8, 9, 0, 4, -3, 2 ], [ -7, 8, 0, 4, -3, 2 ] ], 0 ], - [ [ [ -9, 8, 0, 4, -3, 2 ], [ -9, 9, 0, 4, -3, 2 ], [ -8, 9, 0, 4, -3, 2 ], [ -7, 9, 0, 4, -3, 2 ] ], 0.25 ], - [ [ [ -9, 8, 0, 4, -3, 2 ], [ -9, 9, 0, 4, -3, 2 ], [ -8, 9, 0, 4, -3, 2 ], [ -8, 8, 0, 4, -3, 2 ] ], 0.25 ] - ] - ] -], -"last_changes": -[ - [ [ -9, 8, 0, 4, -3, 2 ], [ -8, 7, 0, 4, -3, 2 ], [ -8, 8, 0, 4, -3, 2 ], [ -7, 8, 0, 4, -3, 2 ] ], - [ [ -9, 8, 0, 4, -3, 2 ], [ -9, 9, 0, 4, -3, 2 ], [ -8, 8, 0, 4, -3, 2 ], [ -7, 8, 0, 4, -3, 2 ] ], - [ [ -9, 8, 0, 4, -3, 2 ], [ -9, 9, 0, 4, -3, 2 ], [ -8, 9, 0, 4, -3, 2 ], [ -7, 8, 0, 4, -3, 2 ] ], - [ [ -9, 8, 0, 4, -3, 2 ], [ -9, 9, 0, 4, -3, 2 ], [ -8, 9, 0, 4, -3, 2 ], [ -7, 9, 0, 4, -3, 2 ] ], - [ [ -9, 8, 0, 4, -3, 2 ], [ -9, 9, 0, 4, -3, 2 ], [ -8, 9, 0, 4, -3, 2 ], [ -8, 8, 0, 4, -3, 2 ] ] -], -"cur_uid": "615c4008", -"ref_uid": "7276dc78", -"order_seed": 913894, -"dur_seed": 642726, -"motifs_seed": 376961, -"entrances_probs_vals": [ 0.66, 0, 0, 0, 1, 0.019607843137255, 0, 0.2156862745098, 0, 0.2516339869281, 0.76351351351351, 0.31045751633987, 0, 0.46732026143791, 0, 0.50326797385621, 0, 0.5359477124183, 0, 1, 0 ], -"passages_probs_vals": [ 0.66, 0, 0, 0, 1, 0.019607843137255, 0, 0.2156862745098, 0, 0.2516339869281, 0.76351351351351, 0.31045751633987, 0, 0.46732026143791, 0, 0.50326797385621, 0, 0.5359477124183, 0, 1, 0 ], -"exits_probs_vals": [ 0.66, 0, 0, 0, 1, 0.019607843137255, 0, 0.2156862745098, 0, 0.2516339869281, 0.76351351351351, 0.31045751633987, 0, 0.46732026143791, 0, 0.50326797385621, 0, 0.5359477124183, 0, 1, 0 ], -"ranges": [ [ -2400, 1200 ], [ -1200, 1452.6315789474 ], [ -702, 1694.1176470588 ], [ -702, 1972.7554179567 ] ], -"step_probs_vals": [ -1200, 1200, 0.0041152263374486, 0.0056818181818179, 0.080246913580247, 0.02840909090909, 0.20781893004115, 0.028409090909091, 0.41152263374486, 0, 0.44650205761317, 0.16477272727273, 0.47736625514403, 0, 0.53086419753086, 0, 0.54320987654321, 0.92045454545455, 0.58641975308642, 0.92613636363636, 0.61111111111111, 0, 0.7880658436214, 0.034090909090909, 1, 0.034090909090909 ], -"passages_weights": [ 0.58, 1, 0.43, 1, 0.82 ], -"hd_exp": 10, -"hd_invert": 0, -"order": -[ - [ [ 3 ], [ 1, 0, 2, 1, 1, 1 ], [ ] ], - [ [ 2 ], [ 1, 3, 0, 1 ], [ ] ], - [ [ 1 ], [ 2, 3, 0 ], [ ] ], - [ [ 2 ], [ 1, 0, 3, 0, 1, 3, 1 ], [ ] ], - [ [ 0, 2 ], [ 3, 1, 1, 3, 3, 3 ], [ ] ], - [ [ 0 ], [ 3, 1, 2, 1, 3, 3 ], [ ] ], - [ [ 1 ], [ 2, 3, 0 ], [ ] ], - [ [ 3, 0 ], [ 2, 1, 2, 2, 1 ], [ ] ], - [ [ 2, 0 ], [ 3, 1, 3, 1, 1 ], [ ] ], - [ [ 2 ], [ 1, 3, 0, 1, 0, 0 ], [ ] ], - [ [ 3 ], [ 2, 0, 1, 0, 1, 1, 2 ], [ ] ], - [ [ 3 ], [ 0, 2, 1, 1, 1, 0 ], [ ] ], - [ [ 3 ], [ 2, 1, 0 ], [ ] ], - [ [ 1, 3 ], [ 2, 0, 2, 2 ], [ ] ], - [ [ 0, 3 ], [ 1, 2 ], [ ] ], - [ [ 1 ], [ 2, 3, 0 ], [ ] ], - [ [ 1 ], [ 0, 2, 3, 2, 3, 0, 3 ], [ ] ], - [ [ 1 ], [ 2, 0, 3, 3, 2, 2, 0 ], [ ] ], - [ [ 2 ], [ 1, 0, 3, 1, 0, 1, 1, 0 ], [ ] ], - [ [ 0 ], [ 3, 1, 2, 2, 1 ], [ ] ], - [ [ 1, 3 ], [ 0, 2, 0 ], [ ] ], - [ [ 2 ], [ 1, 3, 0 ], [ ] ], - [ [ 2 ], [ 0, 3, 1, 0, 0, 3, 1, 3 ], [ ] ], - [ [ 2 ], [ 3, 0, 1, 0, 1, 3 ], [ ] ], - [ [ 0 ], [ 1, 3, 2, 1, 1, 3, 3 ], [ ] ], - [ [ 3 ], [ 2, 1, 0, 2, 2, 0, 2 ], [ ] ], - [ [ 2 ], [ 0, 1, 3, 0 ], [ ] ], - [ [ 0 ], [ 3, 2, 1, 2, 3, 3 ], [ ] ] -], -"sus_weights": [ 0.69, 0.17, 0 ], -"order_size": [ 28.275510204082, 28.275510204082 ], -"passages_size": [ 0, 6 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/6522664c/6522664c_code.scd b/resources/resources_bak_2024_01_03/string_quartet_3_rise/6522664c/6522664c_code.scd deleted file mode 100644 index 42b64ff..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/6522664c/6522664c_code.scd +++ /dev/null @@ -1,981 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array2) - hsArrayToCents.value(array1); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -/* -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance) -}; -*/ - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = true; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - //if(pDistance >= 0, {stepFunc.value(abs(pDistance))}, {0.01}); - stepFunc.value(pDistance) -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - //tuples = dims.collect({[0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum == 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength.asInteger - minMotifLength.asInteger).rand + minMotifLength.asInteger).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - //noProgIns = (popSize - noSusIns).rand + 1; - noProgIns = (popSize - noSusIns); - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength.asInteger - minProgLength.asInteger).rand + minProgLength.asInteger).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0.01); - - - - /* - if(rangeScore.value(candidate.collect({0}), voices[ins], ranges[ins][1] - 500, ranges[ins][1], 0, true) == 1, { - isInRangeScore = 1 - rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0] + 500, ranges[ins][1] - 500, 0, true); - isInRangeScore = isInRangeScore * rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true) - }, { - isInRangeScore = rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true); - }); - */ - - - isInRangeScore = rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true); - //old way - worked but actually by accident (I think) - //isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - - - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - /* - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - */ - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - //lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - lastState = if(o == 0, {lastXChanges.last.deepCopy}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - /* - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - */ - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - //# voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - # voices, durs = seq.flatten2(if(oneShot, {2}, {3})).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(2).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/6522664c/6522664c_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_3_rise/6522664c/6522664c_mus_model.json deleted file mode 100644 index e6c59fc..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/6522664c/6522664c_mus_model.json +++ /dev/null @@ -1,85 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ -4, 2, 2, 2, 1, 0 ], [ -4, 2, 1, 2, 1, 0 ], [ -2, 1, 1, 2, 1, 0 ], [ -3, 2, 1, 2, 1, 0 ] ], 1 ], - [ [ [ -4, 2, 2, 2, 1, 0 ], [ -3, 1, 2, 2, 1, 0 ], [ -2, 1, 1, 2, 1, 0 ], [ -3, 2, 1, 2, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -4, 2, 2, 2, 1, 0 ], [ -3, 1, 1, 3, 1, 0 ], [ -2, 1, 1, 2, 1, 0 ], [ -3, 2, 1, 2, 1, 0 ] ], 1 ], - [ [ [ -3, 1, 1, 2, 1, 0 ], [ -3, 1, 1, 3, 1, 0 ], [ -2, 1, 1, 2, 1, 0 ], [ -3, 2, 1, 2, 1, 0 ] ], 1 ], - [ [ [ -3, 1, 1, 2, 1, 0 ], [ -3, 1, 1, 3, 1, 0 ], [ -2, 1, 1, 2, 1, 0 ], [ -3, 1, 1, 2, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -3, 2, 1, 2, 1, 0 ], [ -3, 1, 1, 3, 1, 0 ], [ -2, 1, 1, 2, 1, 0 ], [ -3, 1, 1, 2, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -3, 2, 1, 2, 1, 0 ], [ -3, 1, 1, 3, 1, 0 ], [ -2, 1, 1, 2, 1, 0 ], [ -3, 1, 1, 2, 1, 0 ] ], 1 ], - [ [ [ -3, 2, 1, 2, 1, 0 ], [ -3, 2, 2, 2, 1, 0 ], [ -2, 1, 1, 2, 1, 0 ], [ -3, 1, 1, 2, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -3, 2, 1, 2, 1, 0 ], [ -3, 2, 2, 2, 1, 0 ], [ -2, 1, 1, 2, 1, 0 ], [ -3, 1, 2, 2, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -3, 2, 1, 2, 1, 0 ], [ -3, 1, 3, 2, 1, 0 ], [ -2, 1, 1, 2, 1, 0 ], [ -3, 1, 2, 2, 1, 0 ] ], 1 ], - [ [ [ -2, 0, 2, 2, 1, 0 ], [ -3, 1, 3, 2, 1, 0 ], [ -2, 1, 1, 2, 1, 0 ], [ -3, 1, 2, 2, 1, 0 ] ], 1 ], - [ [ [ -2, 0, 2, 2, 1, 0 ], [ -3, 1, 3, 2, 1, 0 ], [ -4, 2, 2, 2, 1, 0 ], [ -3, 1, 2, 2, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -3, 2, 2, 2, 1, 0 ], [ -3, 1, 3, 2, 1, 0 ], [ -4, 2, 2, 2, 1, 0 ], [ -3, 1, 2, 2, 1, 0 ] ], 1 ], - [ [ [ -3, 2, 2, 2, 1, 0 ], [ -3, 1, 3, 2, 1, 0 ], [ -4, 2, 2, 2, 1, 0 ], [ -4, 3, 2, 2, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -3, 2, 2, 2, 1, 0 ], [ -5, 3, 1, 2, 1, 0 ], [ -4, 2, 2, 2, 1, 0 ], [ -4, 3, 2, 2, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -3, 2, 2, 2, 1, 0 ], [ -5, 3, 2, 2, 1, 0 ], [ -4, 2, 2, 2, 1, 0 ], [ -4, 3, 2, 2, 1, 0 ] ], 1 ], - [ [ [ -3, 2, 2, 2, 1, 0 ], [ -5, 3, 2, 2, 1, 0 ], [ -4, 2, 2, 2, 1, 0 ], [ -3, 2, 1, 2, 1, 0 ] ], 1 ], - [ [ [ -4, 2, 1, 2, 1, 0 ], [ -5, 3, 2, 2, 1, 0 ], [ -4, 2, 2, 2, 1, 0 ], [ -3, 2, 1, 2, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -4, 3, 1, 2, 1, 0 ], [ -5, 3, 2, 2, 1, 0 ], [ -4, 2, 2, 2, 1, 0 ], [ -3, 2, 1, 2, 1, 0 ] ], 1 ] - ] - ] -], -"last_changes": -[ - [ [ -3, 2, 2, 2, 1, 0 ], [ -5, 3, 1, 2, 1, 0 ], [ -4, 2, 2, 2, 1, 0 ], [ -4, 3, 2, 2, 1, 0 ] ], - [ [ -3, 2, 2, 2, 1, 0 ], [ -5, 3, 2, 2, 1, 0 ], [ -4, 2, 2, 2, 1, 0 ], [ -4, 3, 2, 2, 1, 0 ] ], - [ [ -3, 2, 2, 2, 1, 0 ], [ -5, 3, 2, 2, 1, 0 ], [ -4, 2, 2, 2, 1, 0 ], [ -3, 2, 1, 2, 1, 0 ] ], - [ [ -4, 2, 1, 2, 1, 0 ], [ -5, 3, 2, 2, 1, 0 ], [ -4, 2, 2, 2, 1, 0 ], [ -3, 2, 1, 2, 1, 0 ] ], - [ [ -4, 3, 1, 2, 1, 0 ], [ -5, 3, 2, 2, 1, 0 ], [ -4, 2, 2, 2, 1, 0 ], [ -3, 2, 1, 2, 1, 0 ] ] -], -"cur_uid": "6522664c", -"ref_uid": "4bf1af12", -"order_seed": 347999, -"dur_seed": 441379, -"motifs_seed": 667646, -"entrances_probs_vals": [ 0, 0, 0, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 0, 0, 0, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 0, 0, 0, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -2400, 1200 ], [ -1200, 1200 ], [ -702, 1200 ], [ -702, 1200 ] ], -"step_probs_vals": [ 0, 1200, 0.0061728395061728, 0.10227272727273, 0.074074074074074, 0.10227272727273, 0.2037037037037, 0.090909090909091, 0.45679012345679, 0.011363636363636, 0.53086419753086, 0, 0.54320987654321, 0.92045454545455, 0.58641975308642, 0.92613636363636, 0.61111111111111, 0, 0.7880658436214, 0.034090909090909, 1, 0.034090909090909 ], -"passages_weights": [ 1, 0.47, 0.43, 1, 0.8 ], -"hd_exp": 8, -"hd_invert": 0, -"order": -[ - [ [ 2, 0 ], [ 3, 1 ], [ ] ], - [ [ 2 ], [ 1, 0, 3 ], [ ] ], - [ [ 2, 3, 1 ], [ 0 ], [ ] ], - [ [ 2, 0 ], [ 3, 1 ], [ ] ], - [ [ 1, 0, 2 ], [ 3 ], [ ] ], - [ [ 3 ], [ 1, 0, 2 ], [ ] ], - [ [ 2, 1 ], [ 0, 3 ], [ ] ], - [ [ 0, 2, 3 ], [ 1 ], [ ] ], - [ [ 2 ], [ 1, 3, 0 ], [ ] ], - [ [ 3, 2, 1 ], [ 0 ], [ ] ] -], -"sus_weights": [ 0.35, 0.37, 0.38 ], -"order_size": [ 10.091836734694, 10.091836734694 ], -"passages_size": [ 0, 0 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/6522664c/lilypond/part_I.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/6522664c/lilypond/part_I.ly deleted file mode 100644 index aa8c464..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/6522664c/lilypond/part_I.ly +++ /dev/null @@ -1,20 +0,0 @@ -{ - { g'1^\markup { \pad-markup #0.2 "-21"} ~ } - \bar "|" - { g'1 } - \bar "|" - { fis1^\markup { \pad-markup #0.2 "+26"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 11↓" }} } - \bar "|" - { c'1^\markup { \pad-markup #0.2 "-23"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 1↑" }} } - \bar "|" - { e'1^\markup { \pad-markup #0.2 "-36"} ~ } - \bar "|" - { e'1 ~ } - \bar "|" - { e'2 fis'2^\markup { \pad-markup #0.2 "-33"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }} ~ } - \bar "|" - { fis'1 } - \bar "|" - { g'1^\markup { \pad-markup #0.2 "-21"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↓" }}} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/6522664c/lilypond/part_II.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/6522664c/lilypond/part_II.ly deleted file mode 100644 index 9007135..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/6522664c/lilypond/part_II.ly +++ /dev/null @@ -1,20 +0,0 @@ -{ - { c''1^\markup { \pad-markup #0.2 "-23"} ~ } - \bar "|" - { c''1 ~ } - \bar "|" - { c''1 ~ } - \bar "|" - { c''1 ~ } - \bar "|" - { c''1 ~ } - \bar "|" - { c''2 b2^\markup { \pad-markup #0.2 "-34"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↑" }} ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/6522664c/lilypond/part_III.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/6522664c/lilypond/part_III.ly deleted file mode 100644 index 77f3a11..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/6522664c/lilypond/part_III.ly +++ /dev/null @@ -1,20 +0,0 @@ -{ - { g2^\markup { \pad-markup #0.2 "-21"} e'2^\markup { \pad-markup #0.2 "-36"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }} } - \bar "|" - { a'1^\markup { \pad-markup #0.2 "+46"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 7↑" }} ~ } - \bar "|" - { a'1 ~ } - \bar "|" - { a'2 b'2^\markup { \pad-markup #0.2 "-34"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }} ~ } - \bar "|" - { b'2 g'2^\markup { \pad-markup #0.2 "+50"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 5↑" }} ~ } - \bar "|" - { g'1 ~ } - \bar "|" - { g'1 } - \bar "|" - { d2^\markup { \pad-markup #0.2 "-19"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 5↓" }} fis2^\markup { \pad-markup #0.2 "-33"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }} ~ } - \bar "|" - { fis1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/6522664c/lilypond/part_IV.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/6522664c/lilypond/part_IV.ly deleted file mode 100644 index 49e5ac8..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/6522664c/lilypond/part_IV.ly +++ /dev/null @@ -1,20 +0,0 @@ -{ - { b1^\markup { \pad-markup #0.2 "-34"} ~ } - \bar "|" - { b2 c'2^\markup { \pad-markup #0.2 "-23"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 1↑" }} ~ } - \bar "|" - { c'2 g'2^\markup { \pad-markup #0.2 "-21"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↑" }} ~ } - \bar "|" - { g'1 ~ } - \bar "|" - { g'1 } - \bar "|" - { a'1^\markup { \pad-markup #0.2 "-38"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↓" }} } - \bar "|" - { b'1^\markup { \pad-markup #0.2 "-34"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 1↑" }} ~ } - \bar "|" - { b'1 ~ } - \bar "|" - { b'2 g2^\markup { \pad-markup #0.2 "-21"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }}} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/6db2efcc/6db2efcc_code.scd b/resources/resources_bak_2024_01_03/string_quartet_3_rise/6db2efcc/6db2efcc_code.scd deleted file mode 100644 index 42b64ff..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/6db2efcc/6db2efcc_code.scd +++ /dev/null @@ -1,981 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array2) - hsArrayToCents.value(array1); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -/* -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance) -}; -*/ - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = true; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - //if(pDistance >= 0, {stepFunc.value(abs(pDistance))}, {0.01}); - stepFunc.value(pDistance) -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - //tuples = dims.collect({[0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum == 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength.asInteger - minMotifLength.asInteger).rand + minMotifLength.asInteger).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - //noProgIns = (popSize - noSusIns).rand + 1; - noProgIns = (popSize - noSusIns); - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength.asInteger - minProgLength.asInteger).rand + minProgLength.asInteger).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0.01); - - - - /* - if(rangeScore.value(candidate.collect({0}), voices[ins], ranges[ins][1] - 500, ranges[ins][1], 0, true) == 1, { - isInRangeScore = 1 - rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0] + 500, ranges[ins][1] - 500, 0, true); - isInRangeScore = isInRangeScore * rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true) - }, { - isInRangeScore = rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true); - }); - */ - - - isInRangeScore = rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true); - //old way - worked but actually by accident (I think) - //isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - - - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - /* - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - */ - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - //lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - lastState = if(o == 0, {lastXChanges.last.deepCopy}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - /* - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - */ - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - //# voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - # voices, durs = seq.flatten2(if(oneShot, {2}, {3})).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(2).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/6db2efcc/6db2efcc_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_3_rise/6db2efcc/6db2efcc_mus_model.json deleted file mode 100644 index d66bfdd..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/6db2efcc/6db2efcc_mus_model.json +++ /dev/null @@ -1,86 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ -5, 2, 3, 3, 1, 0 ], [ -6, 2, 4, 3, 1, 0 ], [ -6, 3, 3, 4, 1, 0 ], [ -6, 2, 3, 4, 1, 0 ] ], 1 ], - [ [ [ -5, 2, 3, 3, 1, 0 ], [ -6, 2, 3, 3, 2, 0 ], [ -6, 3, 3, 4, 1, 0 ], [ -6, 2, 3, 4, 1, 0 ] ], 1 ], - [ [ [ -5, 2, 3, 3, 1, 0 ], [ -6, 2, 3, 3, 2, 0 ], [ -4, 1, 3, 3, 1, 0 ], [ -6, 2, 3, 4, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -5, 2, 3, 3, 1, 0 ], [ -6, 2, 3, 3, 2, 0 ], [ -4, 1, 3, 3, 1, 0 ], [ -4, 2, 3, 3, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -5, 2, 3, 3, 1, 0 ], [ -6, 2, 3, 3, 2, 0 ], [ -4, 1, 3, 3, 1, 0 ], [ -4, 2, 3, 2, 2, 0 ] ], 1 ], - [ [ [ -6, 2, 3, 4, 2, 0 ], [ -6, 2, 3, 3, 2, 0 ], [ -4, 1, 3, 3, 1, 0 ], [ -4, 2, 3, 2, 2, 0 ] ], 1 ], - [ [ [ -6, 2, 3, 4, 2, 0 ], [ -6, 2, 3, 3, 2, 0 ], [ -5, 2, 3, 3, 2, 0 ], [ -4, 2, 3, 2, 2, 0 ] ], 1 ] - ], - [ - [ [ [ -6, 2, 3, 4, 2, 0 ], [ -6, 2, 3, 3, 2, 0 ], [ -4, 1, 3, 2, 2, 0 ], [ -4, 2, 3, 2, 2, 0 ] ], 1 ], - [ [ [ -4, 2, 2, 2, 2, 0 ], [ -6, 2, 3, 3, 2, 0 ], [ -4, 1, 3, 2, 2, 0 ], [ -4, 2, 3, 2, 2, 0 ] ], 1 ], - [ [ [ -4, 2, 2, 2, 2, 0 ], [ -5, 2, 3, 2, 2, 0 ], [ -4, 1, 3, 2, 2, 0 ], [ -4, 2, 3, 2, 2, 0 ] ], 1 ] - ], - [ - [ [ [ -5, 2, 3, 2, 2, 1 ], [ -5, 2, 3, 2, 2, 0 ], [ -4, 1, 3, 2, 2, 0 ], [ -4, 2, 3, 2, 2, 0 ] ], 1 ], - [ [ [ -5, 2, 3, 2, 2, 1 ], [ -5, 2, 3, 2, 2, 0 ], [ -3, 2, 3, 1, 2, 0 ], [ -4, 2, 3, 2, 2, 0 ] ], 1 ] - ], - [ - [ [ [ -3, 2, 3, 1, 1, 0 ], [ -5, 2, 3, 2, 2, 0 ], [ -3, 2, 3, 1, 2, 0 ], [ -4, 2, 3, 2, 2, 0 ] ], 1 ] - ], - [ - [ [ [ -3, 2, 3, 1, 1, 0 ], [ -5, 2, 3, 2, 2, 0 ], [ -3, 2, 3, 2, 2, -1 ], [ -4, 2, 3, 2, 2, 0 ] ], 1 ], - [ [ [ -3, 2, 3, 1, 1, 0 ], [ -5, 2, 3, 2, 2, 0 ], [ -3, 2, 3, 2, 2, -1 ], [ -3, 2, 4, 1, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -3, 2, 3, 1, 1, 0 ], [ -5, 2, 3, 2, 2, 0 ], [ -5, 2, 4, 2, 1, 0 ], [ -3, 2, 4, 1, 1, 0 ] ], 1 ], - [ [ [ -3, 2, 3, 1, 1, 0 ], [ -3, 2, 4, 0, 1, 0 ], [ -5, 2, 4, 2, 1, 0 ], [ -3, 2, 4, 1, 1, 0 ] ], 1 ], - [ [ [ -4, 2, 4, 2, 1, 0 ], [ -3, 2, 4, 0, 1, 0 ], [ -5, 2, 4, 2, 1, 0 ], [ -3, 2, 4, 1, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -4, 2, 4, 2, 1, 0 ], [ -3, 2, 4, 0, 1, 0 ], [ -4, 2, 3, 2, 1, 0 ], [ -3, 2, 4, 1, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -4, 2, 4, 2, 1, 0 ], [ -3, 2, 3, 2, 1, -1 ], [ -4, 2, 3, 2, 1, 0 ], [ -3, 2, 4, 1, 1, 0 ] ], 1 ] - ] - ] -], -"last_changes": -[ - [ [ -3, 2, 3, 1, 1, 0 ], [ -5, 2, 3, 2, 2, 0 ], [ -5, 2, 4, 2, 1, 0 ], [ -3, 2, 4, 1, 1, 0 ] ], - [ [ -3, 2, 3, 1, 1, 0 ], [ -3, 2, 4, 0, 1, 0 ], [ -5, 2, 4, 2, 1, 0 ], [ -3, 2, 4, 1, 1, 0 ] ], - [ [ -4, 2, 4, 2, 1, 0 ], [ -3, 2, 4, 0, 1, 0 ], [ -5, 2, 4, 2, 1, 0 ], [ -3, 2, 4, 1, 1, 0 ] ], - [ [ -4, 2, 4, 2, 1, 0 ], [ -3, 2, 4, 0, 1, 0 ], [ -4, 2, 3, 2, 1, 0 ], [ -3, 2, 4, 1, 1, 0 ] ], - [ [ -4, 2, 4, 2, 1, 0 ], [ -3, 2, 3, 2, 1, -1 ], [ -4, 2, 3, 2, 1, 0 ], [ -3, 2, 4, 1, 1, 0 ] ] -], -"cur_uid": "6db2efcc", -"ref_uid": "521654f8", -"order_seed": 213803, -"dur_seed": 264333, -"motifs_seed": 980711, -"entrances_probs_vals": [ 0, 0, 0, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 0, 0, 0, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 0, 0, 0, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -2400, 1200 ], [ -1200, 1200 ], [ -702, 1200 ], [ -702, 1200 ] ], -"step_probs_vals": [ 0, 1200, 0.0061728395061728, 0.10227272727273, 0.074074074074074, 0.10227272727273, 0.2037037037037, 0.090909090909091, 0.45679012345679, 0.011363636363636, 0.53086419753086, 0, 0.54320987654321, 0.92045454545455, 0.58641975308642, 0.92613636363636, 0.61111111111111, 0, 0.7880658436214, 0.034090909090909, 1, 0.034090909090909 ], -"passages_weights": [ 1, 0.47, 0.43, 1, 0.5 ], -"hd_exp": 5, -"hd_invert": 0, -"order": -[ - [ [ 0 ], [ 3, 1, 2 ], [ ] ], - [ [ 0, 1, 2 ], [ 3 ], [ ] ], - [ [ 1 ], [ 3, 0, 2 ], [ ] ], - [ [ 3 ], [ 2, 0, 1 ], [ ] ], - [ [ 3, 1 ], [ 0, 2 ], [ ] ], - [ [ 1, 2, 3 ], [ 0 ], [ ] ], - [ [ 1, 0 ], [ 2, 3 ], [ ] ], - [ [ 3 ], [ 2, 1, 0 ], [ ] ], - [ [ 0, 1, 3 ], [ 2 ], [ ] ], - [ [ 3, 2, 0 ], [ 1 ], [ ] ] -], -"sus_weights": [ 0.35, 0.37, 0.38 ], -"order_size": [ 10.091836734694, 10.091836734694 ], -"passages_size": [ 0, 0 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/6db2efcc/lilypond/part_I.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/6db2efcc/lilypond/part_I.ly deleted file mode 100644 index 90f111c..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/6db2efcc/lilypond/part_I.ly +++ /dev/null @@ -1,22 +0,0 @@ -{ - { ais1^\markup { \pad-markup #0.2 "-11"} ~ } - \bar "|" - { ais2 g'2^\markup { \pad-markup #0.2 "-31"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 11↓" }} } - \bar "|" - { gis'1^\markup { \pad-markup #0.2 "+3"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 7↓" }} ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 } - \bar "|" - { a'1^\markup { \pad-markup #0.2 "-31"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }} ~ } - \bar "|" - { a'1 ~ } - \bar "|" - { a'1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/6db2efcc/lilypond/part_II.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/6db2efcc/lilypond/part_II.ly deleted file mode 100644 index 88a941a..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/6db2efcc/lilypond/part_II.ly +++ /dev/null @@ -1,22 +0,0 @@ -{ - { f'1^\markup { \pad-markup #0.2 "-9"} } - \bar "|" - { f'1^\markup { \pad-markup #0.2 "+19"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }} ~ } - \bar "|" - { f'1 } - \bar "|" - { fis'2^\markup { \pad-markup #0.2 "-28"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }} cis'2^\markup { \pad-markup #0.2 "+1"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↓" }} ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'2 ais'2^\markup { \pad-markup #0.2 "+34"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 7↓" }} ~ } - \bar "|" - { ais'2 c''2^\markup { \pad-markup #0.2 "-37"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 13↓" }} ~ } - \bar "|" - { c''2 fis2^\markup { \pad-markup #0.2 "+38"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 7↑" }} ~ } - \bar "|" - { fis1 } - \bar "|" - { dis'1^\markup { \pad-markup #0.2 "-48"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↓" }}} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/6db2efcc/lilypond/part_III.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/6db2efcc/lilypond/part_III.ly deleted file mode 100644 index 898501b..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/6db2efcc/lilypond/part_III.ly +++ /dev/null @@ -1,22 +0,0 @@ -{ - { e2^\markup { \pad-markup #0.2 "+7"} fis2^\markup { \pad-markup #0.2 "-28"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 11↑" }} ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis2 gis2^\markup { \pad-markup #0.2 "+3"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }} ~ } - \bar "|" - { gis1 ~ } - \bar "|" - { gis1 ~ } - \bar "|" - { gis1 } - \bar "|" - { b1^\markup { \pad-markup #0.2 "+0"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 7↓" }} ~ } - \bar "|" - { b2 fis'2^\markup { \pad-markup #0.2 "+11"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 13↓" }}} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/6db2efcc/lilypond/part_IV.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/6db2efcc/lilypond/part_IV.ly deleted file mode 100644 index 6098652..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/6db2efcc/lilypond/part_IV.ly +++ /dev/null @@ -1,22 +0,0 @@ -{ - { c'1^\markup { \pad-markup #0.2 "+21"} ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'2 dis'2^\markup { \pad-markup #0.2 "+41"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 7↑" }} ~ } - \bar "|" - { dis'1 } - \bar "|" - { e'1^\markup { \pad-markup #0.2 "+17"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 5↓" }} } - \bar "|" - { e'1^\markup { \pad-markup #0.2 "+44"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 13↑" }} } - \bar "|" - { f'1^\markup { \pad-markup #0.2 "-17"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 11↓" }} ~ } - \bar "|" - { f'1 ~ } - \bar "|" - { f'2 fis'2^\markup { \pad-markup #0.2 "+38"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 1↑" }} ~ } - \bar "|" - { fis'1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/7276dc78/7276dc78_code.scd b/resources/resources_bak_2024_01_03/string_quartet_3_rise/7276dc78/7276dc78_code.scd deleted file mode 100644 index 42b64ff..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/7276dc78/7276dc78_code.scd +++ /dev/null @@ -1,981 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array2) - hsArrayToCents.value(array1); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -/* -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance) -}; -*/ - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = true; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - //if(pDistance >= 0, {stepFunc.value(abs(pDistance))}, {0.01}); - stepFunc.value(pDistance) -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - //tuples = dims.collect({[0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum == 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength.asInteger - minMotifLength.asInteger).rand + minMotifLength.asInteger).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - //noProgIns = (popSize - noSusIns).rand + 1; - noProgIns = (popSize - noSusIns); - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength.asInteger - minProgLength.asInteger).rand + minProgLength.asInteger).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0.01); - - - - /* - if(rangeScore.value(candidate.collect({0}), voices[ins], ranges[ins][1] - 500, ranges[ins][1], 0, true) == 1, { - isInRangeScore = 1 - rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0] + 500, ranges[ins][1] - 500, 0, true); - isInRangeScore = isInRangeScore * rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true) - }, { - isInRangeScore = rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true); - }); - */ - - - isInRangeScore = rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true); - //old way - worked but actually by accident (I think) - //isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - - - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - /* - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - */ - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - //lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - lastState = if(o == 0, {lastXChanges.last.deepCopy}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - /* - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - */ - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - //# voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - # voices, durs = seq.flatten2(if(oneShot, {2}, {3})).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(2).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/7276dc78/7276dc78_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_3_rise/7276dc78/7276dc78_mus_model.json deleted file mode 100644 index 6d0340b..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/7276dc78/7276dc78_mus_model.json +++ /dev/null @@ -1,158 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ -7, 6, 4, -1, 1, 2 ], [ -5, 5, 4, 0, 0, 2 ], [ -6, 6, 4, 0, 0, 2 ], [ -6, 6, 4, 0, 1, 2 ] ], 1 ], - [ [ [ -6, 6, 4, -1, 0, 2 ], [ -5, 5, 4, 0, 0, 2 ], [ -6, 6, 4, 0, 0, 2 ], [ -6, 6, 4, 0, 1, 2 ] ], 1 ], - [ [ [ -6, 6, 4, -1, 0, 2 ], [ -5, 5, 4, 0, 0, 2 ], [ -6, 6, 4, 0, 0, 2 ], [ -7, 6, 5, 0, 0, 2 ] ], 1 ] - ], - [ - [ [ [ -6, 6, 4, -1, 0, 2 ], [ -5, 6, 3, 0, 0, 2 ], [ -6, 6, 4, 0, 0, 2 ], [ -7, 6, 5, 0, 0, 2 ] ], 1 ], - [ [ [ -6, 6, 4, -1, 0, 2 ], [ -5, 6, 3, 0, 0, 2 ], [ -6, 6, 4, 0, 0, 2 ], [ -7, 6, 4, 1, 0, 2 ] ], 1 ], - [ [ [ -6, 6, 3, 0, 0, 2 ], [ -5, 6, 3, 0, 0, 2 ], [ -6, 6, 4, 0, 0, 2 ], [ -7, 6, 4, 1, 0, 2 ] ], 1 ] - ], - [ - [ [ [ -6, 6, 3, 0, 0, 2 ], [ -5, 6, 3, 0, 0, 2 ], [ -5, 6, 2, 0, 0, 2 ], [ -7, 6, 4, 1, 0, 2 ] ], 1 ], - [ [ [ -6, 6, 3, 0, 0, 2 ], [ -5, 6, 3, 0, 0, 2 ], [ -5, 6, 2, 0, 0, 2 ], [ -6, 7, 3, 0, 0, 2 ] ], 1 ] - ], - [ - [ [ [ -6, 6, 3, 0, 0, 2 ], [ -5, 6, 2, -1, 0, 2 ], [ -5, 6, 2, 0, 0, 2 ], [ -6, 7, 3, 0, 0, 2 ] ], 1 ], - [ [ [ -6, 6, 2, 1, 0, 2 ], [ -5, 6, 2, -1, 0, 2 ], [ -5, 6, 2, 0, 0, 2 ], [ -6, 7, 3, 0, 0, 2 ] ], 1 ] - ], - [ - [ [ [ -6, 6, 2, 1, 0, 2 ], [ -5, 6, 2, -1, 0, 2 ], [ -6, 7, 2, 1, 0, 2 ], [ -6, 7, 3, 0, 0, 2 ] ], 1 ], - [ [ [ -6, 6, 2, 1, 0, 2 ], [ -7, 6, 2, 2, 0, 2 ], [ -6, 7, 2, 1, 0, 2 ], [ -6, 7, 3, 0, 0, 2 ] ], 1 ], - [ [ [ -6, 6, 2, 1, 0, 2 ], [ -7, 6, 2, 2, 0, 2 ], [ -6, 7, 2, 1, 0, 2 ], [ -5, 6, 2, 1, -1, 2 ] ], 1 ] - ], - [ - [ [ [ -6, 6, 2, 1, 0, 2 ], [ -7, 6, 2, 2, 0, 2 ], [ -5, 6, 2, 1, -1, 1 ], [ -5, 6, 2, 1, -1, 2 ] ], 1 ] - ], - [ - [ [ [ -6, 6, 2, 1, 0, 2 ], [ -7, 6, 2, 2, 0, 2 ], [ -6, 6, 2, 2, -1, 2 ], [ -5, 6, 2, 1, -1, 2 ] ], 1 ], - [ [ [ -6, 6, 2, 1, 0, 2 ], [ -7, 6, 2, 2, 0, 2 ], [ -6, 6, 2, 2, -1, 2 ], [ -7, 5, 2, 2, 0, 2 ] ], 1 ] - ], - [ - [ [ [ -6, 6, 2, 1, 0, 2 ], [ -7, 6, 2, 2, 0, 2 ], [ -7, 5, 2, 3, 0, 2 ], [ -7, 5, 2, 2, 0, 2 ] ], 1 ], - [ [ [ -8, 6, 2, 2, 0, 2 ], [ -7, 6, 2, 2, 0, 2 ], [ -7, 5, 2, 3, 0, 2 ], [ -7, 5, 2, 2, 0, 2 ] ], 1 ], - [ [ [ -8, 6, 2, 2, 0, 2 ], [ -7, 5, 2, 2, -1, 2 ], [ -7, 5, 2, 3, 0, 2 ], [ -7, 5, 2, 2, 0, 2 ] ], 1 ] - ], - [ - [ [ [ -7, 6, 2, 2, -1, 2 ], [ -7, 5, 2, 2, -1, 2 ], [ -7, 5, 2, 3, 0, 2 ], [ -7, 5, 2, 2, 0, 2 ] ], 1 ] - ], - [ - [ [ [ -7, 6, 2, 2, -1, 2 ], [ -7, 5, 2, 2, -1, 2 ], [ -6, 6, 1, 2, -1, 2 ], [ -7, 5, 2, 2, 0, 2 ] ], 1 ], - [ [ [ -7, 6, 2, 2, -1, 2 ], [ -6, 6, 2, 2, -2, 2 ], [ -6, 6, 1, 2, -1, 2 ], [ -7, 5, 2, 2, 0, 2 ] ], 1 ] - ], - [ - [ [ [ -7, 6, 2, 2, -1, 2 ], [ -5, 5, 1, 2, -1, 2 ], [ -6, 6, 1, 2, -1, 2 ], [ -7, 5, 2, 2, 0, 2 ] ], 1 ] - ], - [ - [ [ [ -7, 6, 2, 2, -1, 2 ], [ -5, 5, 1, 2, -1, 2 ], [ -6, 6, 1, 2, -1, 2 ], [ -6, 5, 2, 2, -1, 2 ] ], 1 ] - ], - [ - [ [ [ -7, 6, 2, 2, -1, 2 ], [ -5, 5, 1, 2, -1, 2 ], [ -6, 6, 1, 2, -1, 2 ], [ -6, 6, 2, 2, -1, 2 ] ], 1 ], - [ [ [ -6, 5, 1, 2, 0, 2 ], [ -5, 5, 1, 2, -1, 2 ], [ -6, 6, 1, 2, -1, 2 ], [ -6, 6, 2, 2, -1, 2 ] ], 1 ] - ], - [ - [ [ [ -6, 5, 1, 2, 0, 2 ], [ -5, 5, 1, 2, -1, 2 ], [ -5, 5, 0, 2, 0, 2 ], [ -6, 6, 2, 2, -1, 2 ] ], 1 ], - [ [ [ -6, 5, 1, 2, 0, 2 ], [ -5, 5, 1, 2, -1, 2 ], [ -5, 5, 0, 2, 0, 2 ], [ -6, 6, 1, 2, 0, 2 ] ], 1 ] - ], - [ - [ [ [ -6, 5, 1, 2, 0, 2 ], [ -5, 5, 1, 2, -1, 2 ], [ -7, 6, 2, 2, 0, 2 ], [ -6, 6, 1, 2, 0, 2 ] ], 1 ] - ], - [ - [ [ [ -6, 5, 1, 3, -1, 2 ], [ -5, 5, 1, 2, -1, 2 ], [ -7, 6, 2, 2, 0, 2 ], [ -6, 6, 1, 2, 0, 2 ] ], 1 ], - [ [ [ -6, 5, 1, 3, -1, 2 ], [ -5, 5, 1, 2, -1, 2 ], [ -7, 5, 1, 3, -1, 2 ], [ -6, 6, 1, 2, 0, 2 ] ], 1 ] - ], - [ - [ [ [ -7, 5, 1, 2, -2, 2 ], [ -5, 5, 1, 2, -1, 2 ], [ -7, 5, 1, 3, -1, 2 ], [ -6, 6, 1, 2, 0, 2 ] ], 1 ] - ], - [ - [ [ [ -7, 5, 1, 2, -2, 2 ], [ -5, 5, 1, 2, -1, 2 ], [ -7, 5, 1, 3, -1, 2 ], [ -6, 5, 1, 2, -1, 2 ] ], 1 ], - [ [ [ -7, 5, 1, 2, -2, 2 ], [ -7, 5, 1, 3, -2, 2 ], [ -7, 5, 1, 3, -1, 2 ], [ -6, 5, 1, 2, -1, 2 ] ], 1 ], - [ [ [ -7, 5, 1, 2, -1, 2 ], [ -7, 5, 1, 3, -2, 2 ], [ -7, 5, 1, 3, -1, 2 ], [ -6, 5, 1, 2, -1, 2 ] ], 1 ] - ], - [ - [ [ [ -7, 5, 1, 2, -1, 2 ], [ -7, 5, 1, 3, -2, 2 ], [ -5, 5, 1, 1, -1, 2 ], [ -6, 5, 1, 2, -1, 2 ] ], 1 ], - [ [ [ -6, 5, 1, 2, -2, 2 ], [ -7, 5, 1, 3, -2, 2 ], [ -5, 5, 1, 1, -1, 2 ], [ -6, 5, 1, 2, -1, 2 ] ], 1 ], - [ [ [ -6, 5, 1, 2, -2, 2 ], [ -7, 5, 1, 3, -1, 2 ], [ -5, 5, 1, 1, -1, 2 ], [ -6, 5, 1, 2, -1, 2 ] ], 1 ] - ], - [ - [ [ [ -8, 5, 0, 3, -1, 2 ], [ -7, 5, 1, 3, -1, 2 ], [ -5, 5, 1, 1, -1, 2 ], [ -6, 5, 1, 2, -1, 2 ] ], 1 ], - [ [ [ -8, 5, 0, 3, -1, 2 ], [ -7, 5, 1, 3, -1, 2 ], [ -6, 6, 1, 2, -1, 2 ], [ -6, 5, 1, 2, -1, 2 ] ], 1 ] - ], - [ - [ [ [ -7, 6, 1, 2, -2, 2 ], [ -7, 5, 1, 3, -1, 2 ], [ -6, 6, 1, 2, -1, 2 ], [ -6, 5, 1, 2, -1, 2 ] ], 1 ] - ], - [ - [ [ [ -7, 6, 1, 2, -2, 2 ], [ -7, 5, 1, 3, -1, 2 ], [ -6, 6, 1, 2, -1, 2 ], [ -7, 6, 1, 3, -1, 2 ] ], 1 ] - ], - [ - [ [ [ -8, 4, 1, 3, -1, 2 ], [ -7, 5, 1, 3, -1, 2 ], [ -6, 6, 1, 2, -1, 2 ], [ -7, 6, 1, 3, -1, 2 ] ], 1 ], - [ [ [ -8, 4, 1, 3, -1, 2 ], [ -7, 5, 1, 3, -1, 2 ], [ -6, 6, 1, 2, -1, 2 ], [ -6, 5, 1, 3, -1, 2 ] ], 1 ] - ], - [ - [ [ [ -9, 5, 1, 4, -1, 2 ], [ -7, 5, 1, 3, -1, 2 ], [ -6, 6, 1, 2, -1, 2 ], [ -6, 5, 1, 3, -1, 2 ] ], 1 ] - ], - [ - [ [ [ -9, 5, 1, 4, -1, 2 ], [ -7, 5, 1, 3, -1, 2 ], [ -6, 6, 1, 2, -1, 2 ], [ -6, 5, 1, 4, -2, 2 ] ], 1 ], - [ [ [ -9, 5, 1, 4, -1, 2 ], [ -7, 5, 1, 4, -2, 2 ], [ -6, 6, 1, 2, -1, 2 ], [ -6, 5, 1, 4, -2, 2 ] ], 1 ] - ] - ] -], -"last_changes": -[ - [ [ -8, 4, 1, 3, -1, 2 ], [ -7, 5, 1, 3, -1, 2 ], [ -6, 6, 1, 2, -1, 2 ], [ -7, 6, 1, 3, -1, 2 ] ], - [ [ -8, 4, 1, 3, -1, 2 ], [ -7, 5, 1, 3, -1, 2 ], [ -6, 6, 1, 2, -1, 2 ], [ -6, 5, 1, 3, -1, 2 ] ], - [ [ -9, 5, 1, 4, -1, 2 ], [ -7, 5, 1, 3, -1, 2 ], [ -6, 6, 1, 2, -1, 2 ], [ -6, 5, 1, 3, -1, 2 ] ], - [ [ -9, 5, 1, 4, -1, 2 ], [ -7, 5, 1, 3, -1, 2 ], [ -6, 6, 1, 2, -1, 2 ], [ -6, 5, 1, 4, -2, 2 ] ], - [ [ -9, 5, 1, 4, -1, 2 ], [ -7, 5, 1, 4, -2, 2 ], [ -6, 6, 1, 2, -1, 2 ], [ -6, 5, 1, 4, -2, 2 ] ] -], -"cur_uid": "7276dc78", -"ref_uid": "531df78c", -"order_seed": 350501, -"dur_seed": 664373, -"motifs_seed": 429600, -"entrances_probs_vals": [ 0, 0, 0, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 0, 0, 0, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 0, 0, 0, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -2400, 1200 ], [ -1200, 1200 ], [ -702, 1200 ], [ -702, 1200 ] ], -"step_probs_vals": [ 0, 1200, 0, 0, 0.069958847736626, 0, 0.31481481481481, 0, 0.38271604938272, 0.13068181818182, 0.45884773662551, 0.14772727272727, 0.53086419753086, 0, 0.54320987654321, 0.92045454545455, 0.58641975308642, 0.92613636363636, 0.61111111111111, 0, 0.79218106995885, 0, 1, 0 ], -"passages_weights": [ 1, 0.47, 0.43, 1, 0.45 ], -"hd_exp": 3.87, -"hd_invert": 0, -"order": -[ - [ [ 2 ], [ 1, 0, 3 ], [ ] ], - [ [ 2 ], [ 1, 3, 0 ], [ ] ], - [ [ 0, 1 ], [ 2, 3 ], [ ] ], - [ [ 2, 3 ], [ 1, 0 ], [ ] ], - [ [ 0 ], [ 2, 1, 3 ], [ ] ], - [ [ 3, 1, 0 ], [ 2 ], [ ] ], - [ [ 0, 1 ], [ 2, 3 ], [ ] ], - [ [ 3 ], [ 2, 0, 1 ], [ ] ], - [ [ 1, 3, 2 ], [ 0 ], [ ] ], - [ [ 3, 0 ], [ 2, 1 ], [ ] ], - [ [ 0, 2, 3 ], [ 1 ], [ ] ], - [ [ 0, 2, 1 ], [ 3 ], [ ] ], - [ [ 1, 2 ], [ 3, 0 ], [ ] ], - [ [ 1, 0 ], [ 2, 3 ], [ ] ], - [ [ 1, 3, 0 ], [ 2 ], [ ] ], - [ [ 1, 3 ], [ 0, 2 ], [ ] ], - [ [ 2, 1, 3 ], [ 0 ], [ ] ], - [ [ 2 ], [ 3, 1, 0 ], [ ] ], - [ [ 3 ], [ 2, 0, 1 ], [ ] ], - [ [ 1, 3 ], [ 0, 2 ], [ ] ], - [ [ 3, 1, 2 ], [ 0 ], [ ] ], - [ [ 2, 0, 1 ], [ 3 ], [ ] ], - [ [ 1, 2 ], [ 0, 3 ], [ ] ], - [ [ 3, 2, 1 ], [ 0 ], [ ] ], - [ [ 2, 0 ], [ 3, 1 ], [ ] ] -], -"sus_weights": [ 0.35, 0.37, 0.38 ], -"order_size": [ 25.244897959184, 25.244897959184 ], -"passages_size": [ 0, 0 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/7276dc78/lilypond/part_I.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/7276dc78/lilypond/part_I.ly deleted file mode 100644 index af7f26d..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/7276dc78/lilypond/part_I.ly +++ /dev/null @@ -1,48 +0,0 @@ -{ - { gis'1^\markup { \pad-markup #0.2 "-11"} } - \bar "|" - { fis1^\markup { \pad-markup #0.2 "+24"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 5↑" }} } - \bar "|" - { c'1^\markup { \pad-markup #0.2 "+7"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 7↑" }} ~ } - \bar "|" - { c'2 fis'2^\markup { \pad-markup #0.2 "-46"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }} ~ } - \bar "|" - { fis'1 ~ } - \bar "|" - { fis'1 } - \bar "|" - { b'1^\markup { \pad-markup #0.2 "-17"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 11↓" }} ~ } - \bar "|" - { b'2 g2^\markup { \pad-markup #0.2 "+1"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↓" }} ~ } - \bar "|" - { g1 ~ } - \bar "|" - { g1 ~ } - \bar "|" - { g1 ~ } - \bar "|" - { g2 cis'2^\markup { \pad-markup #0.2 "+50"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }} } - \bar "|" - { a'1^\markup { \pad-markup #0.2 "-48"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }} ~ } - \bar "|" - { a'2 ais'2^\markup { \pad-markup #0.2 "+17"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }} ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 } - \bar "|" - { ais1^\markup { \pad-markup #0.2 "-37"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }} ~ } - \bar "|" - { ais1 ~ } - \bar "|" - { ais1 ~ } - \bar "|" - { ais1 ~ } - \bar "|" - { ais2 d'2^\markup { \pad-markup #0.2 "+34"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↑" }} ~ } - \bar "|" - { d'2 g'2^\markup { \pad-markup #0.2 "+32"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }} ~ } - \bar "|" - { g'2 b'2^\markup { \pad-markup #0.2 "+50"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 11↓" }}} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/7276dc78/lilypond/part_II.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/7276dc78/lilypond/part_II.ly deleted file mode 100644 index b3e65e4..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/7276dc78/lilypond/part_II.ly +++ /dev/null @@ -1,48 +0,0 @@ -{ - { d'1^\markup { \pad-markup #0.2 "+38"} ~ } - \bar "|" - { d'1 ~ } - \bar "|" - { d'1 } - \bar "|" - { g'1^\markup { \pad-markup #0.2 "-35"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↓" }} ~ } - \bar "|" - { g'1 } - \bar "|" - { b'1^\markup { \pad-markup #0.2 "+36"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }} ~ } - \bar "|" - { b'2 d'2^\markup { \pad-markup #0.2 "+42"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 13↓" }} } - \bar "|" - { a'1^\markup { \pad-markup #0.2 "-48"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 11↓" }} } - \bar "|" - { f'1^\markup { \pad-markup #0.2 "-30"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 7↑" }} ~ } - \bar "|" - { f'1 } - \bar "|" - { f'1^\markup { \pad-markup #0.2 "-35"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↓" }} ~ } - \bar "|" - { f'1 ~ } - \bar "|" - { f'1 } - \bar "|" - { b'1^\markup { \pad-markup #0.2 "+28"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↓" }} } - \bar "|" - { d'1^\markup { \pad-markup #0.2 "+3"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 5↑" }} } - \bar "|" - { g1^\markup { \pad-markup #0.2 "+32"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }} ~ } - \bar "|" - { g1 ~ } - \bar "|" - { g2 c'2^\markup { \pad-markup #0.2 "-5"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↓" }} ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'2 f'2^\markup { \pad-markup #0.2 "-35"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↑" }} ~ } - \bar "|" - { f'1 ~ } - \bar "|" - { f'1 ~ } - \bar "|" - { f'1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/7276dc78/lilypond/part_III.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/7276dc78/lilypond/part_III.ly deleted file mode 100644 index 192a5db..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/7276dc78/lilypond/part_III.ly +++ /dev/null @@ -1,48 +0,0 @@ -{ - { g'1^\markup { \pad-markup #0.2 "+36"} ~ } - \bar "|" - { g'2 b'2^\markup { \pad-markup #0.2 "-48"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 5↓" }} ~ } - \bar "|" - { b'1 ~ } - \bar "|" - { b'1 } - \bar "|" - { a1^\markup { \pad-markup #0.2 "-3"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 7↓" }} ~ } - \bar "|" - { a2 d'2^\markup { \pad-markup #0.2 "+3"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↑" }} ~ } - \bar "|" - { d'1 ~ } - \bar "|" - { d'1 ~ } - \bar "|" - { d'1 } - \bar "|" - { cis1^\markup { \pad-markup #0.2 "+50"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 11↓" }} ~ } - \bar "|" - { cis2 dis'2^\markup { \pad-markup #0.2 "+0"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 11↓" }} } - \bar "|" - { ais'1^\markup { \pad-markup #0.2 "-37"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↓" }} ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'2 d2^\markup { \pad-markup #0.2 "-19"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↑" }} ~ } - \bar "|" - { d1 ~ } - \bar "|" - { d2 g2^\markup { \pad-markup #0.2 "+32"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 7↑" }} ~ } - \bar "|" - { g1 ~ } - \bar "|" - { g1 ~ } - \bar "|" - { g1 ~ } - \bar "|" - { g1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/7276dc78/lilypond/part_IV.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/7276dc78/lilypond/part_IV.ly deleted file mode 100644 index 5fd805f..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/7276dc78/lilypond/part_IV.ly +++ /dev/null @@ -1,48 +0,0 @@ -{ - { ais,2^\markup { \pad-markup #0.2 "+21"} f2^\markup { \pad-markup #0.2 "-31"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 7↓" }} ~ } - \bar "|" - { f1 ~ } - \bar "|" - { f2 b2^\markup { \pad-markup #0.2 "-48"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }} ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b2 e'2^\markup { \pad-markup #0.2 "+34"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 7↑" }} ~ } - \bar "|" - { e'1 ~ } - \bar "|" - { e'1 ~ } - \bar "|" - { e'1 ~ } - \bar "|" - { e'2 d2^\markup { \pad-markup #0.2 "+3"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }} ~ } - \bar "|" - { d2 a2^\markup { \pad-markup #0.2 "-48"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↑" }} ~ } - \bar "|" - { a1 ~ } - \bar "|" - { a1 ~ } - \bar "|" - { a2 dis'2^\markup { \pad-markup #0.2 "+15"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 11↑" }} ~ } - \bar "|" - { dis'1 ~ } - \bar "|" - { dis'2 g'2^\markup { \pad-markup #0.2 "+32"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 7↑" }} ~ } - \bar "|" - { g'2 e,2^\markup { \pad-markup #0.2 "+12"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 11↓" }} ~ } - \bar "|" - { e,1 } - \bar "|" - { ais,1^\markup { \pad-markup #0.2 "-37"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }} } - \bar "|" - { e1^\markup { \pad-markup #0.2 "+12"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 7↓" }} } - \bar "|" - { dis,1^\markup { \pad-markup #0.2 "+46"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 5↓" }} } - \bar "|" - { b,1^\markup { \pad-markup #0.2 "+14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 11↓" }} } - \bar "|" - { c,1^\markup { \pad-markup #0.2 "+30"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↓" }} } - \bar "|" - { f,1^\markup { \pad-markup #0.2 "+1"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 7↑" }}} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/78a94ed1/78a94ed1_code.scd b/resources/resources_bak_2024_01_03/string_quartet_3_rise/78a94ed1/78a94ed1_code.scd deleted file mode 100644 index 42b64ff..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/78a94ed1/78a94ed1_code.scd +++ /dev/null @@ -1,981 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array2) - hsArrayToCents.value(array1); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -/* -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance) -}; -*/ - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = true; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - //if(pDistance >= 0, {stepFunc.value(abs(pDistance))}, {0.01}); - stepFunc.value(pDistance) -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - //tuples = dims.collect({[0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum == 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength.asInteger - minMotifLength.asInteger).rand + minMotifLength.asInteger).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - //noProgIns = (popSize - noSusIns).rand + 1; - noProgIns = (popSize - noSusIns); - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength.asInteger - minProgLength.asInteger).rand + minProgLength.asInteger).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0.01); - - - - /* - if(rangeScore.value(candidate.collect({0}), voices[ins], ranges[ins][1] - 500, ranges[ins][1], 0, true) == 1, { - isInRangeScore = 1 - rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0] + 500, ranges[ins][1] - 500, 0, true); - isInRangeScore = isInRangeScore * rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true) - }, { - isInRangeScore = rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true); - }); - */ - - - isInRangeScore = rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true); - //old way - worked but actually by accident (I think) - //isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - - - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - /* - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - */ - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - //lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - lastState = if(o == 0, {lastXChanges.last.deepCopy}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - /* - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - */ - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - //# voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - # voices, durs = seq.flatten2(if(oneShot, {2}, {3})).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(2).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/78a94ed1/78a94ed1_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_3_rise/78a94ed1/78a94ed1_mus_model.json deleted file mode 100644 index 078670e..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/78a94ed1/78a94ed1_mus_model.json +++ /dev/null @@ -1,90 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ -6, 1, 5, 1, 0, 2 ], [ -5, 1, 4, 2, 0, 2 ], [ -5, 1, 5, 2, 0, 2 ], [ -4, 2, 5, 1, 0, 2 ] ], 1 ], - [ [ [ -6, 1, 5, 1, 0, 2 ], [ -5, 1, 4, 2, 0, 2 ], [ -3, 0, 5, 1, 0, 2 ], [ -4, 2, 5, 1, 0, 2 ] ], 1 ] - ], - [ - [ [ [ -6, 1, 5, 1, 0, 2 ], [ -5, 1, 4, 2, 0, 2 ], [ -3, 0, 5, 1, 0, 2 ], [ -4, 1, 5, 1, 0, 2 ] ], 1 ], - [ [ [ -6, 1, 5, 1, 0, 2 ], [ -5, 1, 4, 2, 0, 2 ], [ -4, 2, 5, 1, 0, 2 ], [ -4, 1, 5, 1, 0, 2 ] ], 1 ], - [ [ [ -6, 1, 5, 1, 0, 2 ], [ -5, 2, 5, 1, 0, 2 ], [ -4, 2, 5, 1, 0, 2 ], [ -4, 1, 5, 1, 0, 2 ] ], 1 ] - ], - [ - [ [ [ -6, 1, 5, 1, 0, 2 ], [ -5, 2, 5, 1, 0, 2 ], [ -5, 1, 6, 1, 0, 2 ], [ -4, 1, 5, 1, 0, 2 ] ], 1 ], - [ [ [ -6, 1, 5, 1, 0, 2 ], [ -4, 1, 4, 1, 0, 2 ], [ -5, 1, 6, 1, 0, 2 ], [ -4, 1, 5, 1, 0, 2 ] ], 1 ], - [ [ [ -6, 1, 5, 1, 0, 2 ], [ -4, 1, 4, 1, 0, 2 ], [ -5, 1, 6, 1, 0, 2 ], [ -4, 2, 5, 1, 0, 2 ] ], 1 ] - ], - [ - [ [ [ -6, 1, 5, 1, 0, 2 ], [ -4, 1, 4, 1, 0, 2 ], [ -5, 2, 5, 1, 0, 2 ], [ -4, 2, 5, 1, 0, 2 ] ], 1 ], - [ [ [ -6, 1, 5, 1, 0, 2 ], [ -4, 2, 4, 1, 0, 2 ], [ -5, 2, 5, 1, 0, 2 ], [ -4, 2, 5, 1, 0, 2 ] ], 1 ], - [ [ [ -7, 2, 5, 1, 1, 2 ], [ -4, 2, 4, 1, 0, 2 ], [ -5, 2, 5, 1, 0, 2 ], [ -4, 2, 5, 1, 0, 2 ] ], 1 ] - ], - [ - [ [ [ -7, 2, 5, 1, 1, 2 ], [ -4, 2, 4, 1, 0, 2 ], [ -5, 2, 5, 1, 0, 2 ], [ -5, 1, 5, 1, 1, 2 ] ], 1 ], - [ [ [ -7, 2, 5, 1, 1, 2 ], [ -4, 2, 4, 1, 0, 2 ], [ -4, 1, 4, 1, 0, 2 ], [ -5, 1, 5, 1, 1, 2 ] ], 1 ] - ], - [ - [ [ [ -7, 2, 5, 1, 1, 2 ], [ -4, 2, 4, 1, 0, 2 ], [ -4, 1, 4, 1, 0, 2 ], [ -3, 1, 4, 0, 0, 2 ] ], 1 ], - [ [ [ -6, 2, 5, 1, 0, 2 ], [ -4, 2, 4, 1, 0, 2 ], [ -4, 1, 4, 1, 0, 2 ], [ -3, 1, 4, 0, 0, 2 ] ], 1 ] - ], - [ - [ [ [ -6, 2, 4, 1, 1, 2 ], [ -4, 2, 4, 1, 0, 2 ], [ -4, 1, 4, 1, 0, 2 ], [ -3, 1, 4, 0, 0, 2 ] ], 1 ], - [ [ [ -6, 2, 4, 1, 1, 2 ], [ -4, 2, 4, 1, 0, 2 ], [ -4, 1, 4, 1, 0, 2 ], [ -3, 2, 4, 0, 0, 2 ] ], 1 ], - [ [ [ -6, 2, 4, 1, 1, 2 ], [ -4, 2, 4, 1, 0, 2 ], [ -5, 3, 4, 1, 0, 2 ], [ -3, 2, 4, 0, 0, 2 ] ], 1 ] - ], - [ - [ [ [ -6, 2, 4, 1, 1, 2 ], [ -4, 2, 4, 1, 0, 2 ], [ -5, 3, 4, 1, 0, 2 ], [ -5, 2, 4, 2, 1, 2 ] ], 1 ] - ], - [ - [ [ [ -6, 2, 4, 1, 1, 2 ], [ -4, 2, 4, 1, 0, 2 ], [ -5, 3, 4, 1, 0, 2 ], [ -6, 2, 4, 2, 1, 2 ] ], 1 ], - [ [ [ -6, 2, 4, 1, 1, 2 ], [ -5, 3, 4, 1, 1, 2 ], [ -5, 3, 4, 1, 0, 2 ], [ -6, 2, 4, 2, 1, 2 ] ], 1 ], - [ [ [ -6, 2, 4, 1, 1, 2 ], [ -5, 3, 4, 1, 1, 2 ], [ -5, 2, 4, 1, 1, 3 ], [ -6, 2, 4, 2, 1, 2 ] ], 1 ] - ], - [ - [ [ [ -6, 2, 4, 1, 1, 2 ], [ -5, 3, 4, 1, 1, 2 ], [ -5, 2, 4, 2, 1, 2 ], [ -6, 2, 4, 2, 1, 2 ] ], 1 ], - [ [ [ -6, 2, 4, 1, 1, 2 ], [ -5, 3, 4, 1, 1, 2 ], [ -5, 2, 4, 2, 1, 2 ], [ -6, 3, 4, 2, 1, 2 ] ], 1 ] - ] - ] -], -"last_changes": -[ - [ [ -6, 2, 4, 1, 1, 2 ], [ -4, 2, 4, 1, 0, 2 ], [ -5, 3, 4, 1, 0, 2 ], [ -6, 2, 4, 2, 1, 2 ] ], - [ [ -6, 2, 4, 1, 1, 2 ], [ -5, 3, 4, 1, 1, 2 ], [ -5, 3, 4, 1, 0, 2 ], [ -6, 2, 4, 2, 1, 2 ] ], - [ [ -6, 2, 4, 1, 1, 2 ], [ -5, 3, 4, 1, 1, 2 ], [ -5, 2, 4, 1, 1, 3 ], [ -6, 2, 4, 2, 1, 2 ] ], - [ [ -6, 2, 4, 1, 1, 2 ], [ -5, 3, 4, 1, 1, 2 ], [ -5, 2, 4, 2, 1, 2 ], [ -6, 2, 4, 2, 1, 2 ] ], - [ [ -6, 2, 4, 1, 1, 2 ], [ -5, 3, 4, 1, 1, 2 ], [ -5, 2, 4, 2, 1, 2 ], [ -6, 3, 4, 2, 1, 2 ] ] -], -"cur_uid": "78a94ed1", -"ref_uid": "4e9f1dcc", -"order_seed": 418736, -"dur_seed": 167372, -"motifs_seed": 741164, -"entrances_probs_vals": [ 0, 0, 0, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 0, 0, 0, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 0, 0, 0, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -2400, 1200 ], [ -1200, 1200 ], [ -702, 1200 ], [ -702, 1200 ] ], -"step_probs_vals": [ 0, 1200, 0.0061728395061728, 0.10227272727273, 0.074074074074074, 0.10227272727273, 0.2037037037037, 0.090909090909091, 0.45679012345679, 0.011363636363636, 0.53086419753086, 0, 0.54320987654321, 0.92045454545455, 0.58641975308642, 0.92613636363636, 0.61111111111111, 0, 0.7880658436214, 0.034090909090909, 1, 0.034090909090909 ], -"passages_weights": [ 1, 0.47, 0.43, 1, 0.2 ], -"hd_exp": 2, -"hd_invert": 0, -"order": -[ - [ [ 1, 0 ], [ 3, 2 ], [ ] ], - [ [ 0 ], [ 3, 2, 1 ], [ ] ], - [ [ 0 ], [ 2, 1, 3 ], [ ] ], - [ [ 3 ], [ 2, 1, 0 ], [ ] ], - [ [ 0, 1 ], [ 3, 2 ], [ ] ], - [ [ 1, 2 ], [ 3, 0 ], [ ] ], - [ [ 1 ], [ 0, 3, 2 ], [ ] ], - [ [ 2, 1, 0 ], [ 3 ], [ ] ], - [ [ 0 ], [ 3, 1, 2 ], [ ] ], - [ [ 0, 1 ], [ 2, 3 ], [ ] ] -], -"sus_weights": [ 0.35, 0.37, 0.38 ], -"order_size": [ 10.091836734694, 10.091836734694 ], -"passages_size": [ 0, 0 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/78a94ed1/lilypond/part_I.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/78a94ed1/lilypond/part_I.ly deleted file mode 100644 index cf060ff..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/78a94ed1/lilypond/part_I.ly +++ /dev/null @@ -1,26 +0,0 @@ -{ - { c''1^\markup { \pad-markup #0.2 "-15"} } - \bar "|" - { f'1^\markup { \pad-markup #0.2 "-17"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }} ~ } - \bar "|" - { f'1 ~ } - \bar "|" - { f'2 c''2^\markup { \pad-markup #0.2 "-15"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }} ~ } - \bar "|" - { c''1 ~ } - \bar "|" - { c''2 ais2^\markup { \pad-markup #0.2 "+35"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }} ~ } - \bar "|" - { ais2 dis'2^\markup { \pad-markup #0.2 "+28"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 7↓" }} ~ } - \bar "|" - { dis'1 } - \bar "|" - { ais'1^\markup { \pad-markup #0.2 "+30"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 7↓" }} } - \bar "|" - { b'2^\markup { \pad-markup #0.2 "+19"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↑" }} b2^\markup { \pad-markup #0.2 "+19"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↑" }} ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b2 fis'2^\markup { \pad-markup #0.2 "+21"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 7↑" }}} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/78a94ed1/lilypond/part_II.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/78a94ed1/lilypond/part_II.ly deleted file mode 100644 index 9712ce1..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/78a94ed1/lilypond/part_II.ly +++ /dev/null @@ -1,26 +0,0 @@ -{ - { dis'2^\markup { \pad-markup #0.2 "-48"} ais'2^\markup { \pad-markup #0.2 "-19"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }} ~ } - \bar "|" - { ais'2 c''2^\markup { \pad-markup #0.2 "-15"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }} ~ } - \bar "|" - { c''2 a2^\markup { \pad-markup #0.2 "-30"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }} ~ } - \bar "|" - { a1 } - \bar "|" - { c'1^\markup { \pad-markup #0.2 "-15"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }} ~ } - \bar "|" - { c'1 } - \bar "|" - { cis'1^\markup { \pad-markup #0.2 "-3"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↓" }} ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'2 dis'2^\markup { \pad-markup #0.2 "+1"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↑" }} ~ } - \bar "|" - { dis'1 ~ } - \bar "|" - { dis'2 ais'2^\markup { \pad-markup #0.2 "-9"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↑" }} } - \bar "|" - { b'1^\markup { \pad-markup #0.2 "+19"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }}} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/78a94ed1/lilypond/part_III.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/78a94ed1/lilypond/part_III.ly deleted file mode 100644 index 4950731..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/78a94ed1/lilypond/part_III.ly +++ /dev/null @@ -1,26 +0,0 @@ -{ - { b1^\markup { \pad-markup #0.2 "-34"} ~ } - \bar "|" - { b1 } - \bar "|" - { c'1^\markup { \pad-markup #0.2 "-15"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 1↑" }} } - \bar "|" - { cis'1^\markup { \pad-markup #0.2 "-3"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↓" }} ~ } - \bar "|" - { cis'2 gis'2^\markup { \pad-markup #0.2 "-1"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 5↓" }} ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 } - \bar "|" - { a'1^\markup { \pad-markup #0.2 "-48"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }} ~ } - \bar "|" - { a'1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/78a94ed1/lilypond/part_IV.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/78a94ed1/lilypond/part_IV.ly deleted file mode 100644 index f5a6564..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/78a94ed1/lilypond/part_IV.ly +++ /dev/null @@ -1,26 +0,0 @@ -{ - { f,1^\markup { \pad-markup #0.2 "-17"} ~ } - \bar "|" - { f,1 ~ } - \bar "|" - { f,1 ~ } - \bar "|" - { f,1 ~ } - \bar "|" - { f,1 } - \bar "|" - { f,1^\markup { \pad-markup #0.2 "+37"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 11↑" }} ~ } - \bar "|" - { f,1 } - \bar "|" - { c2^\markup { \pad-markup #0.2 "-15"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 5↑" }} d2^\markup { \pad-markup #0.2 "-50"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 11↑" }} ~ } - \bar "|" - { d1 ~ } - \bar "|" - { d1 ~ } - \bar "|" - { d1 ~ } - \bar "|" - { d1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/7c30c182/7c30c182_code.scd b/resources/resources_bak_2024_01_03/string_quartet_3_rise/7c30c182/7c30c182_code.scd deleted file mode 100644 index 42b64ff..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/7c30c182/7c30c182_code.scd +++ /dev/null @@ -1,981 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array2) - hsArrayToCents.value(array1); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -/* -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance) -}; -*/ - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = true; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - //if(pDistance >= 0, {stepFunc.value(abs(pDistance))}, {0.01}); - stepFunc.value(pDistance) -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - //tuples = dims.collect({[0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum == 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength.asInteger - minMotifLength.asInteger).rand + minMotifLength.asInteger).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - //noProgIns = (popSize - noSusIns).rand + 1; - noProgIns = (popSize - noSusIns); - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength.asInteger - minProgLength.asInteger).rand + minProgLength.asInteger).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0.01); - - - - /* - if(rangeScore.value(candidate.collect({0}), voices[ins], ranges[ins][1] - 500, ranges[ins][1], 0, true) == 1, { - isInRangeScore = 1 - rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0] + 500, ranges[ins][1] - 500, 0, true); - isInRangeScore = isInRangeScore * rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true) - }, { - isInRangeScore = rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true); - }); - */ - - - isInRangeScore = rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true); - //old way - worked but actually by accident (I think) - //isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - - - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - /* - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - */ - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - //lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - lastState = if(o == 0, {lastXChanges.last.deepCopy}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - /* - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - */ - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - //# voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - # voices, durs = seq.flatten2(if(oneShot, {2}, {3})).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(2).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/7c30c182/7c30c182_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_3_rise/7c30c182/7c30c182_mus_model.json deleted file mode 100644 index f796261..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/7c30c182/7c30c182_mus_model.json +++ /dev/null @@ -1,271 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ -1, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 1 ], - [ [ [ -1, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -1, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ] ], 1 ], - [ [ [ -1, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 1, 0, -1, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ] ], 1 ], - [ [ [ -1, 0, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ], [ 1, 0, -1, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ -1, 0, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ], [ 1, 0, -1, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ] ], 1 ], - [ [ [ 0, -1, -1, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0 ], [ 1, 0, -1, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ 0, -1, -1, 0, 0, 0 ], [ 1, -1, -1, 0, 0, 0 ], [ 1, 0, -1, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ] ], 1 ], - [ [ [ 0, 0, -1, 0, -1, 0 ], [ 1, -1, -1, 0, 0, 0 ], [ 1, 0, -1, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ] ], 1 ], - [ [ [ 0, 0, -1, 0, -1, 0 ], [ 1, -1, -1, 0, 0, 0 ], [ 1, 0, -1, 0, 0, 0 ], [ 0, 0, -1, 1, 0, 0 ] ], 1 ] - ], - [ - [ [ [ 0, 0, -1, 0, -1, 0 ], [ 1, -1, -1, 0, 0, 0 ], [ 2, 0, -1, 0, -2, 0 ], [ 0, 0, -1, 1, 0, 0 ] ], 1 ], - [ [ [ 0, 0, -1, 0, -1, 0 ], [ 1, 0, -1, 0, -1, 0 ], [ 2, 0, -1, 0, -2, 0 ], [ 0, 0, -1, 1, 0, 0 ] ], 1 ], - [ [ [ 0, 0, -1, 0, -1, 0 ], [ 1, 0, -1, 0, -1, 0 ], [ 2, 0, -1, 0, -2, 0 ], [ 2, -1, -1, 0, -1, 0 ] ], 1 ] - ], - [ - [ [ [ 0, 0, -1, 0, -1, 0 ], [ 1, 0, -1, 0, -1, 0 ], [ 2, 0, -2, 0, -1, 0 ], [ 2, -1, -1, 0, -1, 0 ] ], 1 ] - ], - [ - [ [ [ 0, 0, -2, 0, 0, 0 ], [ 1, 0, -1, 0, -1, 0 ], [ 2, 0, -2, 0, -1, 0 ], [ 2, -1, -1, 0, -1, 0 ] ], 1 ], - [ [ [ 0, 0, -2, 0, 0, 0 ], [ 2, -1, -2, 0, -1, 0 ], [ 2, 0, -2, 0, -1, 0 ], [ 2, -1, -1, 0, -1, 0 ] ], 1 ] - ], - [ - [ [ [ 0, 0, -2, 0, 0, 0 ], [ 2, -1, -2, 0, -1, 0 ], [ 3, -1, -3, 0, -1, 0 ], [ 2, -1, -1, 0, -1, 0 ] ], 1 ] - ], - [ - [ [ [ 0, 0, -2, 0, 0, 0 ], [ 1, 0, -2, 0, 1, 0 ], [ 3, -1, -3, 0, -1, 0 ], [ 2, -1, -1, 0, -1, 0 ] ], 1 ], - [ [ [ 0, 0, -2, 0, 0, 0 ], [ 1, 0, -2, 0, 1, 0 ], [ 3, -1, -3, 0, -1, 0 ], [ 2, -1, -2, 0, 0, 0 ] ], 1 ], - [ [ [ 0, 0, -2, 0, 0, 0 ], [ 1, 0, -2, 0, 1, 0 ], [ 0, 0, -2, 1, 0, 0 ], [ 2, -1, -2, 0, 0, 0 ] ], 1 ] - ], - [ - [ [ [ 0, 0, -2, 0, 0, 0 ], [ 1, 0, -2, 0, 1, 0 ], [ 0, 0, -2, 1, 0, 0 ], [ 1, 0, -3, 1, 0, 0 ] ], 1 ], - [ [ [ 0, 0, -3, 0, 1, 0 ], [ 1, 0, -2, 0, 1, 0 ], [ 0, 0, -2, 1, 0, 0 ], [ 1, 0, -3, 1, 0, 0 ] ], 1 ] - ], - [ - [ [ [ 0, 0, -3, 0, 1, 0 ], [ 2, -1, -3, 0, 1, 0 ], [ 0, 0, -2, 1, 0, 0 ], [ 1, 0, -3, 1, 0, 0 ] ], 1 ] - ], - [ - [ [ [ 0, 0, -3, 0, 1, 0 ], [ 2, -1, -3, 0, 1, 0 ], [ 0, 0, -3, 1, 1, 0 ], [ 1, 0, -3, 1, 0, 0 ] ], 1 ], - [ [ [ 0, 0, -3, 0, 1, 0 ], [ 2, -1, -3, 0, 1, 0 ], [ 0, 0, -3, 1, 1, 0 ], [ 1, 0, -3, 0, 2, 0 ] ], 1 ], - [ [ [ 0, 0, -3, 0, 1, 0 ], [ 0, 0, -2, 0, 1, 0 ], [ 0, 0, -3, 1, 1, 0 ], [ 1, 0, -3, 0, 2, 0 ] ], 1 ] - ], - [ - [ [ [ 0, 0, -3, 0, 1, 0 ], [ 0, 0, -2, 0, 1, 0 ], [ 0, 0, -3, 1, 1, 0 ], [ 1, 0, -3, 0, 1, 0 ] ], 1 ], - [ [ [ 0, 0, -3, 0, 1, 0 ], [ 0, 0, -2, 0, 1, 0 ], [ 1, 0, -3, 0, 2, 0 ], [ 1, 0, -3, 0, 1, 0 ] ], 1 ], - [ [ [ 0, 0, -3, 0, 1, 0 ], [ 1, -1, -3, 0, 1, 0 ], [ 1, 0, -3, 0, 2, 0 ], [ 1, 0, -3, 0, 1, 0 ] ], 1 ] - ], - [ - [ [ [ 0, 0, -3, 0, 1, 0 ], [ 1, -1, -3, 0, 1, 0 ], [ 2, -1, -3, 0, 1, 0 ], [ 1, 0, -3, 0, 1, 0 ] ], 1 ] - ], - [ - [ [ [ 0, 0, -3, 0, 1, 0 ], [ 1, -1, -3, 0, 1, 0 ], [ 2, -1, -3, 0, 1, 0 ], [ 2, -1, -4, 0, 1, 0 ] ], 1 ], - [ [ [ 0, 0, -3, 0, 1, 0 ], [ 1, -1, -3, 0, 1, 0 ], [ 1, -1, -3, 1, 1, 0 ], [ 2, -1, -4, 0, 1, 0 ] ], 1 ] - ], - [ - [ [ [ 0, 0, -3, 0, 1, 0 ], [ 2, -2, -4, 0, 1, 0 ], [ 1, -1, -3, 1, 1, 0 ], [ 2, -1, -4, 0, 1, 0 ] ], 1 ] - ], - [ - [ [ [ 1, -1, -4, 0, 1, 0 ], [ 2, -2, -4, 0, 1, 0 ], [ 1, -1, -3, 1, 1, 0 ], [ 2, -1, -4, 0, 1, 0 ] ], 1 ], - [ [ [ 1, -1, -4, 0, 1, 0 ], [ 1, -2, -3, 1, 1, 0 ], [ 1, -1, -3, 1, 1, 0 ], [ 2, -1, -4, 0, 1, 0 ] ], 1 ] - ], - [ - [ [ [ 1, -1, -4, 0, 1, 0 ], [ 2, -1, -5, 0, 1, 0 ], [ 1, -1, -3, 1, 1, 0 ], [ 2, -1, -4, 0, 1, 0 ] ], 1 ] - ], - [ - [ [ [ 1, -1, -4, 0, 1, 0 ], [ 2, -1, -5, 0, 1, 0 ], [ 1, -1, -3, 1, 1, 0 ], [ 2, -1, -5, 0, 2, 0 ] ], 1 ], - [ [ [ 1, -1, -4, 0, 1, 0 ], [ 2, -1, -5, 0, 1, 0 ], [ 3, -1, -5, 0, 0, 0 ], [ 2, -1, -5, 0, 2, 0 ] ], 1 ] - ], - [ - [ [ [ 2, -2, -5, 0, 1, 0 ], [ 2, -1, -5, 0, 1, 0 ], [ 3, -1, -5, 0, 0, 0 ], [ 2, -1, -5, 0, 2, 0 ] ], 1 ] - ], - [ - [ [ [ 2, -2, -5, 0, 1, 0 ], [ 2, -1, -5, 0, 1, 0 ], [ 3, -1, -5, -1, 2, 0 ], [ 2, -1, -5, 0, 2, 0 ] ], 1 ], - [ [ [ 2, -2, -5, 0, 1, 0 ], [ 2, -1, -6, 0, 2, 0 ], [ 3, -1, -5, -1, 2, 0 ], [ 2, -1, -5, 0, 2, 0 ] ], 1 ], - [ [ [ -1, -1, -5, 0, 3, 0 ], [ 2, -1, -6, 0, 2, 0 ], [ 3, -1, -5, -1, 2, 0 ], [ 2, -1, -5, 0, 2, 0 ] ], 1 ] - ], - [ - [ [ [ -1, -1, -5, 0, 3, 0 ], [ 2, -1, -6, 0, 2, 0 ], [ 3, -1, -5, -1, 2, 0 ], [ 1, 0, -5, -1, 2, 0 ] ], 1 ], - [ [ [ 1, -2, -5, -1, 2, 0 ], [ 2, -1, -6, 0, 2, 0 ], [ 3, -1, -5, -1, 2, 0 ], [ 1, 0, -5, -1, 2, 0 ] ], 1 ], - [ [ [ 1, -2, -5, -1, 2, 0 ], [ 2, 0, -5, -1, 2, 0 ], [ 3, -1, -5, -1, 2, 0 ], [ 1, 0, -5, -1, 2, 0 ] ], 1 ] - ], - [ - [ [ [ 1, -1, -5, -1, 1, 0 ], [ 2, 0, -5, -1, 2, 0 ], [ 3, -1, -5, -1, 2, 0 ], [ 1, 0, -5, -1, 2, 0 ] ], 1 ] - ], - [ - [ [ [ 1, -1, -5, -1, 1, 0 ], [ 2, 0, -5, -1, 2, 0 ], [ 3, -1, -5, -1, 2, 0 ], [ 1, -1, -5, -1, 2, 1 ] ], 1 ] - ], - [ - [ [ [ 1, -1, -5, -1, 1, 0 ], [ 3, -1, -6, -1, 2, 0 ], [ 3, -1, -5, -1, 2, 0 ], [ 1, -1, -5, -1, 2, 1 ] ], 1 ], - [ [ [ 1, -1, -6, -1, 2, 0 ], [ 3, -1, -6, -1, 2, 0 ], [ 3, -1, -5, -1, 2, 0 ], [ 1, -1, -5, -1, 2, 1 ] ], 1 ] - ], - [ - [ [ [ 0, -1, -5, 0, 2, 0 ], [ 3, -1, -6, -1, 2, 0 ], [ 3, -1, -5, -1, 2, 0 ], [ 1, -1, -5, -1, 2, 1 ] ], 1 ], - [ [ [ 0, -1, -5, 0, 2, 0 ], [ 2, -1, -5, 0, 2, 0 ], [ 3, -1, -5, -1, 2, 0 ], [ 1, -1, -5, -1, 2, 1 ] ], 1 ] - ], - [ - [ [ [ 0, -1, -5, 0, 2, 0 ], [ 2, -1, -5, 0, 2, 0 ], [ 2, -2, -5, -1, 2, 1 ], [ 1, -1, -5, -1, 2, 1 ] ], 1 ], - [ [ [ 0, -1, -5, 0, 2, 0 ], [ 3, -1, -5, -2, 2, 1 ], [ 2, -2, -5, -1, 2, 1 ], [ 1, -1, -5, -1, 2, 1 ] ], 1 ] - ], - [ - [ [ [ 0, -1, -5, 0, 2, 0 ], [ 3, -1, -5, -2, 2, 1 ], [ 2, -1, -5, -1, 1, 1 ], [ 1, -1, -5, -1, 2, 1 ] ], 1 ], - [ [ [ 0, -1, -5, 0, 2, 0 ], [ 3, -1, -5, -1, 2, 0 ], [ 2, -1, -5, -1, 1, 1 ], [ 1, -1, -5, -1, 2, 1 ] ], 1 ] - ], - [ - [ [ [ 0, -1, -5, 0, 2, 0 ], [ 2, -1, -5, 0, 1, 1 ], [ 2, -1, -5, -1, 1, 1 ], [ 1, -1, -5, -1, 2, 1 ] ], 1 ], - [ [ [ 0, -1, -5, 0, 2, 0 ], [ 2, -1, -5, 0, 1, 1 ], [ 2, -1, -5, -1, 1, 1 ], [ 2, -1, -5, -1, 0, 1 ] ], 1 ] - ], - [ - [ [ [ 0, -1, -5, 0, 2, 0 ], [ 3, -1, -6, -1, 1, 1 ], [ 2, -1, -5, -1, 1, 1 ], [ 2, -1, -5, -1, 0, 1 ] ], 1 ] - ], - [ - [ [ [ 0, -1, -5, 0, 2, 0 ], [ 3, -1, -6, -1, 1, 1 ], [ 2, -1, -5, -1, 1, 1 ], [ 2, -1, -6, -1, 1, 1 ] ], 1 ] - ], - [ - [ [ [ 0, -1, -5, 0, 2, 0 ], [ 3, -1, -6, -1, 1, 1 ], [ 3, -2, -6, -1, 1, 1 ], [ 2, -1, -6, -1, 1, 1 ] ], 1 ], - [ [ [ 0, -1, -5, 0, 2, 0 ], [ 3, -1, -5, -1, 2, 0 ], [ 3, -2, -6, -1, 1, 1 ], [ 2, -1, -6, -1, 1, 1 ] ], 1 ] - ], - [ - [ [ [ 0, -1, -5, 0, 2, 0 ], [ 3, -1, -5, -1, 2, 0 ], [ 3, -2, -6, -1, 1, 1 ], [ 2, -2, -6, -1, 1, 2 ] ], 1 ] - ], - [ - [ [ [ 1, 0, -5, -1, 2, 0 ], [ 3, -1, -5, -1, 2, 0 ], [ 3, -2, -6, -1, 1, 1 ], [ 2, -2, -6, -1, 1, 2 ] ], 1 ], - [ [ [ 1, 0, -5, -1, 2, 0 ], [ 3, -1, -5, -1, 2, 0 ], [ 3, -2, -6, -1, 1, 1 ], [ 3, -2, -5, -1, 2, 0 ] ], 1 ], - [ [ [ 1, 0, -5, -1, 2, 0 ], [ 3, -1, -5, -1, 2, 0 ], [ 2, -1, -5, -1, 3, 0 ], [ 3, -2, -5, -1, 2, 0 ] ], 1 ] - ], - [ - [ [ [ 1, 0, -5, -1, 2, 0 ], [ 3, -1, -5, -1, 2, 0 ], [ 2, 0, -5, -1, 2, 0 ], [ 3, -2, -5, -1, 2, 0 ] ], 1 ] - ], - [ - [ [ [ 2, -1, -6, -1, 2, 0 ], [ 3, -1, -5, -1, 2, 0 ], [ 2, 0, -5, -1, 2, 0 ], [ 3, -2, -5, -1, 2, 0 ] ], 1 ], - [ [ [ 2, -1, -6, -1, 2, 0 ], [ 3, -1, -5, -1, 2, 0 ], [ 2, 0, -5, -1, 2, 0 ], [ 3, -1, -5, -1, 1, 0 ] ], 1 ], - [ [ [ 2, -1, -6, -1, 2, 0 ], [ 3, -1, -5, -1, 2, 0 ], [ 3, -1, -6, -1, 2, 0 ], [ 3, -1, -5, -1, 1, 0 ] ], 1 ] - ], - [ - [ [ [ 2, -1, -6, -1, 2, 0 ], [ 3, -1, -5, -1, 2, 0 ], [ 2, -1, -5, 0, 2, 0 ], [ 3, -1, -5, -1, 1, 0 ] ], 1 ], - [ [ [ 1, -1, -5, 0, 2, 0 ], [ 3, -1, -5, -1, 2, 0 ], [ 2, -1, -5, 0, 2, 0 ], [ 3, -1, -5, -1, 1, 0 ] ], 1 ], - [ [ [ 1, -1, -5, 0, 2, 0 ], [ 3, -1, -5, -1, 2, 0 ], [ 2, -1, -5, 0, 2, 0 ], [ 3, -1, -6, -1, 2, 0 ] ], 1 ] - ], - [ - [ [ [ 3, -1, -6, -2, 2, 0 ], [ 3, -1, -5, -1, 2, 0 ], [ 2, -1, -5, 0, 2, 0 ], [ 3, -1, -6, -1, 2, 0 ] ], 1 ] - ], - [ - [ [ [ 3, -1, -6, -2, 2, 0 ], [ 3, -1, -5, -1, 2, 0 ], [ 2, -1, -5, 0, 2, 0 ], [ 4, -1, -6, -2, 2, -1 ] ], 1 ], - [ [ [ 3, -1, -6, -2, 2, 0 ], [ 3, -1, -5, -1, 2, 0 ], [ 4, -1, -6, -2, 2, 0 ], [ 4, -1, -6, -2, 2, -1 ] ], 1 ] - ], - [ - [ [ [ 3, -1, -6, -2, 2, 0 ], [ 3, -1, -5, -1, 2, 0 ], [ 4, -1, -6, -2, 2, 0 ], [ 4, -2, -6, -2, 2, 0 ] ], 1 ] - ], - [ - [ [ [ 3, -1, -6, -2, 2, 0 ], [ 5, -1, -6, -3, 2, 0 ], [ 4, -1, -6, -2, 2, 0 ], [ 4, -2, -6, -2, 2, 0 ] ], 1 ], - [ [ [ 3, -1, -6, -2, 2, 0 ], [ 5, -1, -6, -3, 2, 0 ], [ 5, -2, -7, -2, 2, 0 ], [ 4, -2, -6, -2, 2, 0 ] ], 1 ] - ], - [ - [ [ [ 4, -2, -7, -2, 2, 0 ], [ 5, -1, -6, -3, 2, 0 ], [ 5, -2, -7, -2, 2, 0 ], [ 4, -2, -6, -2, 2, 0 ] ], 1 ] - ], - [ - [ [ [ 4, -2, -7, -2, 2, 0 ], [ 5, -1, -6, -3, 2, 0 ], [ 5, -2, -7, -2, 2, 0 ], [ 5, -3, -7, -2, 2, 0 ] ], 1 ], - [ [ [ 4, -1, -6, -3, 2, 0 ], [ 5, -1, -6, -3, 2, 0 ], [ 5, -2, -7, -2, 2, 0 ], [ 5, -3, -7, -2, 2, 0 ] ], 1 ] - ], - [ - [ [ [ 4, -3, -7, -1, 2, 0 ], [ 5, -1, -6, -3, 2, 0 ], [ 5, -2, -7, -2, 2, 0 ], [ 5, -3, -7, -2, 2, 0 ] ], 1 ], - [ [ [ 4, -3, -7, -1, 2, 0 ], [ 5, -1, -6, -3, 2, 0 ], [ 5, -3, -7, -2, 2, 1 ], [ 5, -3, -7, -2, 2, 0 ] ], 1 ] - ], - [ - [ [ [ 4, -3, -7, -1, 2, 0 ], [ 5, -1, -6, -3, 2, 0 ], [ 4, -1, -6, -2, 2, 0 ], [ 5, -3, -7, -2, 2, 0 ] ], 1 ] - ], - [ - [ [ [ 4, -2, -6, -2, 2, 0 ], [ 5, -1, -6, -3, 2, 0 ], [ 4, -1, -6, -2, 2, 0 ], [ 5, -3, -7, -2, 2, 0 ] ], 1 ], - [ [ [ 4, -2, -6, -2, 2, 0 ], [ 5, -1, -6, -3, 2, 0 ], [ 4, -1, -6, -2, 2, 0 ], [ 3, 0, -6, -2, 2, 0 ] ], 1 ], - [ [ [ 4, -2, -6, -2, 2, 0 ], [ 3, -2, -6, -2, 2, 0 ], [ 4, -1, -6, -2, 2, 0 ], [ 3, 0, -6, -2, 2, 0 ] ], 1 ] - ], - [ - [ [ [ 4, -2, -6, -2, 2, 0 ], [ 3, -2, -6, -2, 2, 0 ], [ 4, -1, -6, -2, 2, 0 ], [ 3, -1, -6, -2, 2, 1 ] ], 1 ], - [ [ [ 4, -2, -6, -2, 2, 0 ], [ 3, -1, -6, -2, 1, 0 ], [ 4, -1, -6, -2, 2, 0 ], [ 3, -1, -6, -2, 2, 1 ] ], 1 ], - [ [ [ 4, -1, -6, -2, 1, 0 ], [ 3, -1, -6, -2, 1, 0 ], [ 4, -1, -6, -2, 2, 0 ], [ 3, -1, -6, -2, 2, 1 ] ], 1 ] - ], - [ - [ [ [ 4, -1, -7, -2, 2, 0 ], [ 3, -1, -6, -2, 1, 0 ], [ 4, -1, -6, -2, 2, 0 ], [ 3, -1, -6, -2, 2, 1 ] ], 1 ] - ] - ] -], -"last_changes": -[ - [ [ 4, -2, -6, -2, 2, 0 ], [ 3, -2, -6, -2, 2, 0 ], [ 4, -1, -6, -2, 2, 0 ], [ 3, 0, -6, -2, 2, 0 ] ], - [ [ 4, -2, -6, -2, 2, 0 ], [ 3, -2, -6, -2, 2, 0 ], [ 4, -1, -6, -2, 2, 0 ], [ 3, -1, -6, -2, 2, 1 ] ], - [ [ 4, -2, -6, -2, 2, 0 ], [ 3, -1, -6, -2, 1, 0 ], [ 4, -1, -6, -2, 2, 0 ], [ 3, -1, -6, -2, 2, 1 ] ], - [ [ 4, -1, -6, -2, 1, 0 ], [ 3, -1, -6, -2, 1, 0 ], [ 4, -1, -6, -2, 2, 0 ], [ 3, -1, -6, -2, 2, 1 ] ], - [ [ 4, -1, -7, -2, 2, 0 ], [ 3, -1, -6, -2, 1, 0 ], [ 4, -1, -6, -2, 2, 0 ], [ 3, -1, -6, -2, 2, 1 ] ] -], -"cur_uid": "7c30c182", -"ref_uid": "nil", -"order_seed": 993548, -"dur_seed": 828564, -"motifs_seed": 174746, -"entrances_probs_vals": [ 0, 0, 0, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 0, 0, 0, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 0, 0, 0, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -2400, 1200 ], [ -1200, 1200 ], [ -702, 1200 ], [ -702, 1200 ] ], -"step_probs_vals": [ -1200, 1200, 0, 0, 0.037037037037037, 0, 0.18518518518519, 0, 0.45679012345679, 0, 0.53086419753086, 0, 0.54320987654321, 0.92045454545455, 0.58230452674897, 0, 0.61111111111111, 0, 0.7798353909465, 0, 1, 0 ], -"passages_weights": [ 1, 0.47, 0.43, 1, 1 ], -"hd_exp": 3.22, -"hd_invert": 0, -"order": -[ - [ [ 1, 3 ], [ 0, 2 ], [ ] ], - [ [ 0 ], [ 3, 2, 1 ], [ ] ], - [ [ 2, 1 ], [ 3, 0 ], [ ] ], - [ [ 2 ], [ 1, 0, 3 ], [ ] ], - [ [ 0 ], [ 2, 1, 3 ], [ ] ], - [ [ 3, 1, 0 ], [ 2 ], [ ] ], - [ [ 2, 3 ], [ 0, 1 ], [ ] ], - [ [ 3, 1, 0 ], [ 2 ], [ ] ], - [ [ 0 ], [ 1, 3, 2 ], [ ] ], - [ [ 2, 1 ], [ 3, 0 ], [ ] ], - [ [ 2, 3, 0 ], [ 1 ], [ ] ], - [ [ 0 ], [ 2, 3, 1 ], [ ] ], - [ [ 0 ], [ 3, 2, 1 ], [ ] ], - [ [ 1, 3, 0 ], [ 2 ], [ ] ], - [ [ 1, 0 ], [ 3, 2 ], [ ] ], - [ [ 0, 2, 3 ], [ 1 ], [ ] ], - [ [ 3, 2 ], [ 0, 1 ], [ ] ], - [ [ 2, 3, 0 ], [ 1 ], [ ] ], - [ [ 1, 0 ], [ 3, 2 ], [ ] ], - [ [ 2, 1, 3 ], [ 0 ], [ ] ], - [ [ 3 ], [ 2, 1, 0 ], [ ] ], - [ [ 2 ], [ 3, 0, 1 ], [ ] ], - [ [ 3, 1, 2 ], [ 0 ], [ ] ], - [ [ 1, 0, 2 ], [ 3 ], [ ] ], - [ [ 2, 3 ], [ 1, 0 ], [ ] ], - [ [ 2, 3 ], [ 0, 1 ], [ ] ], - [ [ 3, 0 ], [ 2, 1 ], [ ] ], - [ [ 3, 0 ], [ 2, 1 ], [ ] ], - [ [ 0, 2 ], [ 1, 3 ], [ ] ], - [ [ 3, 0, 2 ], [ 1 ], [ ] ], - [ [ 1, 0, 2 ], [ 3 ], [ ] ], - [ [ 0, 3 ], [ 2, 1 ], [ ] ], - [ [ 1, 2, 0 ], [ 3 ], [ ] ], - [ [ 1 ], [ 0, 3, 2 ], [ ] ], - [ [ 3, 0, 1 ], [ 2 ], [ ] ], - [ [ 1 ], [ 0, 3, 2 ], [ ] ], - [ [ 1 ], [ 2, 0, 3 ], [ ] ], - [ [ 2, 1, 3 ], [ 0 ], [ ] ], - [ [ 0, 1 ], [ 3, 2 ], [ ] ], - [ [ 0, 2, 1 ], [ 3 ], [ ] ], - [ [ 3, 0 ], [ 1, 2 ], [ ] ], - [ [ 3, 1, 2 ], [ 0 ], [ ] ], - [ [ 2, 1 ], [ 3, 0 ], [ ] ], - [ [ 1, 3 ], [ 0, 2 ], [ ] ], - [ [ 1, 0, 3 ], [ 2 ], [ ] ], - [ [ 2 ], [ 0, 3, 1 ], [ ] ], - [ [ 2 ], [ 3, 1, 0 ], [ ] ], - [ [ 2, 3, 1 ], [ 0 ], [ ] ] -], -"sus_weights": [ 0.35, 0.37, 0.38 ], -"order_size": [ 48.479591836735, 48.479591836735 ], -"passages_size": [ 0, 0 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/7c30c182/lilypond/part_I.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/7c30c182/lilypond/part_I.ly deleted file mode 100644 index 533c6b9..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/7c30c182/lilypond/part_I.ly +++ /dev/null @@ -1,92 +0,0 @@ -{ - { c'1^\markup { \pad-markup #0.2 "+0"} } - \bar "|" - { e'1^\markup { \pad-markup #0.2 "-14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }} ~ } - \bar "|" - { e'2 f'2^\markup { \pad-markup #0.2 "-2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }} ~ } - \bar "|" - { f'1 ~ } - \bar "|" - { f'2 fis'2^\markup { \pad-markup #0.2 "-17"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 7↑" }} ~ } - \bar "|" - { fis'1 } - \bar "|" - { gis'1^\markup { \pad-markup #0.2 "-40"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }} ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 } - \bar "|" - { a'1^\markup { \pad-markup #0.2 "+25"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }} } - \bar "|" - { ais'1^\markup { \pad-markup #0.2 "+10"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 5↓" }} ~ } - \bar "|" - { ais'1 } - \bar "|" - { b'1^\markup { \pad-markup #0.2 "+44"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 11↑" }} } - \bar "|" - { fis'1^\markup { \pad-markup #0.2 "-8"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }} ~ } - \bar "|" - { fis'1 } - \bar "|" - { g'1^\markup { \pad-markup #0.2 "+4"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 5↓" }} ~ } - \bar "|" - { g'1 ~ } - \bar "|" - { g'1 } - \bar "|" - { a'1^\markup { \pad-markup #0.2 "-31"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 11↑" }} ~ } - \bar "|" - { a'1 ~ } - \bar "|" - { a'1 } - \bar "|" - { fis1^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↑" }} ~ } - \bar "|" - { fis1 } - \bar "|" - { g1^\markup { \pad-markup #0.2 "+41"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 13↑" }} ~ } - \bar "|" - { g1 ~ } - \bar "|" - { g1 ~ } - \bar "|" - { g1 ~ } - \bar "|" - { g1 } - \bar "|" - { gis1^\markup { \pad-markup #0.2 "+38"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 11↓" }} } - \bar "|" - { ais1^\markup { \pad-markup #0.2 "+3"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }} ~ } - \bar "|" - { ais2 b2^\markup { \pad-markup #0.2 "+42"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 13↑" }} ~ } - \bar "|" - { b2 e'2^\markup { \pad-markup #0.2 "-2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↓" }} ~ } - \bar "|" - { e'1 ~ } - \bar "|" - { e'2 f'2^\markup { \pad-markup #0.2 "+49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 11↓" }} ~ } - \bar "|" - { f'1 ~ } - \bar "|" - { f'2 g'2^\markup { \pad-markup #0.2 "+14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 5↓" }} ~ } - \bar "|" - { g'2 cis'2^\markup { \pad-markup #0.2 "+5"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↓" }} ~ } - \bar "|" - { cis'2 d'2^\markup { \pad-markup #0.2 "+43"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }} ~ } - \bar "|" - { d'1 ~ } - \bar "|" - { d'2 e'2^\markup { \pad-markup #0.2 "-45"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }} ~ } - \bar "|" - { e'1 ~ } - \bar "|" - { e'1 ~ } - \bar "|" - { e'2 e'2^\markup { \pad-markup #0.2 "+47"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↑" }} ~ } - \bar "|" - { e'2 fis'2^\markup { \pad-markup #0.2 "-14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 13↑" }} ~ } - \bar "|" - { fis'1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/7c30c182/lilypond/part_II.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/7c30c182/lilypond/part_II.ly deleted file mode 100644 index c4d9581..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/7c30c182/lilypond/part_II.ly +++ /dev/null @@ -1,92 +0,0 @@ -{ - { c'2^\markup { \pad-markup #0.2 "+0"} g'2^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }} ~ } - \bar "|" - { g'2 gis'2^\markup { \pad-markup #0.2 "+14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↓" }} ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 ~ } - \bar "|" - { gis'1 } - \bar "|" - { a'1^\markup { \pad-markup #0.2 "+11"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 11↓" }} ~ } - \bar "|" - { a'2 b'2^\markup { \pad-markup #0.2 "-24"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↓" }} ~ } - \bar "|" - { b'1 } - \bar "|" - { c''1^\markup { \pad-markup #0.2 "-12"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 5↓" }} ~ } - \bar "|" - { c''2 d'2^\markup { \pad-markup #0.2 "-4"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↑" }} ~ } - \bar "|" - { d'1 ~ } - \bar "|" - { d'2 e'2^\markup { \pad-markup #0.2 "-39"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↑" }} ~ } - \bar "|" - { e'1 ~ } - \bar "|" - { e'2 b'2^\markup { \pad-markup #0.2 "+44"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 11↑" }} ~ } - \bar "|" - { b'2 b'2^\markup { \pad-markup #0.2 "-10"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }} ~ } - \bar "|" - { b'2 a'2^\markup { \pad-markup #0.2 "-41"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 7↑" }} ~ } - \bar "|" - { a'1 ~ } - \bar "|" - { a'1 ~ } - \bar "|" - { a'2 ais'2^\markup { \pad-markup #0.2 "-34"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 11↓" }} ~ } - \bar "|" - { ais'2 b'2^\markup { \pad-markup #0.2 "+0"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 7↓" }} ~ } - \bar "|" - { b'1 ~ } - \bar "|" - { b'1 ~ } - \bar "|" - { b'1 ~ } - \bar "|" - { b'1 ~ } - \bar "|" - { b'1 ~ } - \bar "|" - { b'2 c'2^\markup { \pad-markup #0.2 "+39"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↓" }} ~ } - \bar "|" - { c'2 d'2^\markup { \pad-markup #0.2 "-11"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 11↓" }} ~ } - \bar "|" - { d'1 ~ } - \bar "|" - { d'1 ~ } - \bar "|" - { d'2 dis'2^\markup { \pad-markup #0.2 "+1"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↓" }} ~ } - \bar "|" - { dis'1 ~ } - \bar "|" - { dis'1 } - \bar "|" - { f'2^\markup { \pad-markup #0.2 "-48"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 11↑" }} fis'2^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }} ~ } - \bar "|" - { fis'1 } - \bar "|" - { g'2^\markup { \pad-markup #0.2 "+14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }} a'2^\markup { \pad-markup #0.2 "-31"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 7↑" }} ~ } - \bar "|" - { a'1 ~ } - \bar "|" - { a'1 } - \bar "|" - { a'1^\markup { \pad-markup #0.2 "+45"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }} ~ } - \bar "|" - { a'2 b'2^\markup { \pad-markup #0.2 "-43"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 5↓" }} ~ } - \bar "|" - { b'1 ~ } - \bar "|" - { b'1 } - \bar "|" - { c''2^\markup { \pad-markup #0.2 "-5"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 13↑" }} a'2^\markup { \pad-markup #0.2 "+45"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 7↑" }} ~ } - \bar "|" - { a'1 ~ } - \bar "|" - { a'1 ~ } - \bar "|" - { a'1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/7c30c182/lilypond/part_III.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/7c30c182/lilypond/part_III.ly deleted file mode 100644 index 2a0ff52..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/7c30c182/lilypond/part_III.ly +++ /dev/null @@ -1,92 +0,0 @@ -{ - { c'1^\markup { \pad-markup #0.2 "+0"} ~ } - \bar "|" - { c'1 } - \bar "|" - { c''1^\markup { \pad-markup #0.2 "+0"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }} ~ } - \bar "|" - { c''2 cis'2^\markup { \pad-markup #0.2 "+12"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }} ~ } - \bar "|" - { cis'1 ~ } - \bar "|" - { cis'2 dis'2^\markup { \pad-markup #0.2 "-38"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }} ~ } - \bar "|" - { dis'1 ~ } - \bar "|" - { dis'2 e'2^\markup { \pad-markup #0.2 "-26"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↓" }} ~ } - \bar "|" - { e'2 ais'2^\markup { \pad-markup #0.2 "-21"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 11↑" }} ~ } - \bar "|" - { ais'1 ~ } - \bar "|" - { ais'1 } - \bar "|" - { b'1^\markup { \pad-markup #0.2 "-10"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }} ~ } - \bar "|" - { b'2 ais2^\markup { \pad-markup #0.2 "-21"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }} ~ } - \bar "|" - { ais1 } - \bar "|" - { b1^\markup { \pad-markup #0.2 "-10"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }} ~ } - \bar "|" - { b1 } - \bar "|" - { c'1^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↓" }} } - \bar "|" - { d'2^\markup { \pad-markup #0.2 "-43"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↓" }} dis'2^\markup { \pad-markup #0.2 "+18"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↓" }} ~ } - \bar "|" - { dis'1 ~ } - \bar "|" - { dis'1 } - \bar "|" - { f'1^\markup { \pad-markup #0.2 "-17"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 5↓" }} ~ } - \bar "|" - { f'1 } - \bar "|" - { fis'1^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }} ~ } - \bar "|" - { fis'2 g'2^\markup { \pad-markup #0.2 "+14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 5↓" }} ~ } - \bar "|" - { g'1 } - \bar "|" - { a'1^\markup { \pad-markup #0.2 "-31"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }} } - \bar "|" - { ais'1^\markup { \pad-markup #0.2 "-28"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 7↓" }} } - \bar "|" - { b'2^\markup { \pad-markup #0.2 "+0"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↓" }} c''2^\markup { \pad-markup #0.2 "-42"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 7↑" }} ~ } - \bar "|" - { c''2 ais'2^\markup { \pad-markup #0.2 "+3"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 5↓" }} ~ } - \bar "|" - { ais'1 } - \bar "|" - { b'1^\markup { \pad-markup #0.2 "+0"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↓" }} ~ } - \bar "|" - { b'1 ~ } - \bar "|" - { b'1 ~ } - \bar "|" - { b'1 ~ } - \bar "|" - { b'1 ~ } - \bar "|" - { b'1 ~ } - \bar "|" - { b'1 ~ } - \bar "|" - { b'1 } - \bar "|" - { c''1^\markup { \pad-markup #0.2 "-24"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↓" }} ~ } - \bar "|" - { c''1 ~ } - \bar "|" - { c''1 ~ } - \bar "|" - { c''1 ~ } - \bar "|" - { c''1 } - \bar "|" - { d1^\markup { \pad-markup #0.2 "+43"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }} } - \bar "|" - { e1^\markup { \pad-markup #0.2 "-6"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 11↓" }}} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/7c30c182/lilypond/part_IV.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/7c30c182/lilypond/part_IV.ly deleted file mode 100644 index 3a4f61a..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/7c30c182/lilypond/part_IV.ly +++ /dev/null @@ -1,92 +0,0 @@ -{ - { c1^\markup { \pad-markup #0.2 "+0"} ~ } - \bar "|" - { c1 ~ } - \bar "|" - { c1 } - \bar "|" - { cis1^\markup { \pad-markup #0.2 "+12"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↓" }} } - \bar "|" - { dis1^\markup { \pad-markup #0.2 "-38"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 11↓" }} ~ } - \bar "|" - { dis1 ~ } - \bar "|" - { dis1 } - \bar "|" - { e1^\markup { \pad-markup #0.2 "+27"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 11↑" }} ~ } - \bar "|" - { e1 ~ } - \bar "|" - { e1 ~ } - \bar "|" - { e2 fis2^\markup { \pad-markup #0.2 "-8"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 5↓" }} ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis1 ~ } - \bar "|" - { fis2 g2^\markup { \pad-markup #0.2 "+4"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }} ~ } - \bar "|" - { g1 ~ } - \bar "|" - { g1 } - \bar "|" - { gis1^\markup { \pad-markup #0.2 "+16"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↓" }} ~ } - \bar "|" - { gis2 d,2^\markup { \pad-markup #0.2 "+20"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 11↑" }} ~ } - \bar "|" - { d,2 e,2^\markup { \pad-markup #0.2 "-2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↓" }} ~ } - \bar "|" - { e,2 f,2^\markup { \pad-markup #0.2 "+49"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 11↓" }} ~ } - \bar "|" - { f,1 } - \bar "|" - { g,2^\markup { \pad-markup #0.2 "+14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }} a,2^\markup { \pad-markup #0.2 "-31"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 7↑" }} ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 ~ } - \bar "|" - { a,1 } - \bar "|" - { fis1^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↑" }} ~ } - \bar "|" - { fis1 } - \bar "|" - { g1^\markup { \pad-markup #0.2 "+14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 5↓" }} ~ } - \bar "|" - { g1 } - \bar "|" - { a1^\markup { \pad-markup #0.2 "-31"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 1↑" }} } - \bar "|" - { a1^\markup { \pad-markup #0.2 "+45"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 7↓" }} ~ } - \bar "|" - { a1 ~ } - \bar "|" - { a1 } - \bar "|" - { b1^\markup { \pad-markup #0.2 "-43"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 1↑" }} } - \bar "|" - { c'2^\markup { \pad-markup #0.2 "-24"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }} cis'2^\markup { \pad-markup #0.2 "+24"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 7↑" }} ~ } - \bar "|" - { cis'1 } - \bar "|" - { d'1^\markup { \pad-markup #0.2 "+43"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↓" }} ~ } - \bar "|" - { d'1 ~ } - \bar "|" - { d'2 e'2^\markup { \pad-markup #0.2 "-6"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }}} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/7ede7adb/7ede7adb_code.scd b/resources/resources_bak_2024_01_03/string_quartet_3_rise/7ede7adb/7ede7adb_code.scd deleted file mode 100644 index 42b64ff..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/7ede7adb/7ede7adb_code.scd +++ /dev/null @@ -1,981 +0,0 @@ -( -// helper funcs -var hsArrayToCents, pDist, hdSum, hsChordalDistance, hsArrayToFreq; - -// score funcs -var isInRange, spacingScore, rangeScore, intervalScore, inclusionScore; - -// subroutines -var genTuples, initVoices, genOrders, genSubMotif, updateVoices, genDurFunc, genStepFunc; - -// primary routines -var genMotif, genSecondarySeq; - -// audition funcs -var genPatterns, genMidiPatterns; - -// resource management funcs -var seedFunc, genUID, writeResources, stringifyToDepth, setSeeds, sanityCheck, -msgInterpret, loadLedgerFile, loadLedgerJSON, loadModelFile, loadModelJSON, -setGlobalVars, globalVarsToDict, saveLedger; - -// model vars -//(model and global vars mostly set by OSC funcs -var seq, lastXChanges, -curUID, refUID, orderSeed, durSeed, motifSeed, -entrancesProbVals, passagesProbVals, exitsProbVals, -ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, -orders, susWeights, orderSize, passagesSize, -motifEdited, orderEdited; - -// model aux vars -var entrancesDurFunc, passagesDurFunc, exitsDurFunc, stepFunc; - -// other global vars -var popSize, exPath, dir, primes, dims, tuples, -group, player, resourceDir, ledgerPath, ledger, currentlyPlayingUID, -nameSpaces; - -// install JSON quark (not used) -/* -if(Quarks.isInstalled("JSONlib").not, { - Quarks.install("https://github.com/musikinformatik/JSONlib.git"); - thisProcess.recompile; - //HelpBrowser.openHelpFor("Classes/JSONlib"); -}); -*/ - - -//------helper funcs - -hsArrayToCents = { - arg hsArray; - hsArray.collect({arg dist, p; dist * 1200 * log2(primes[p][0]/primes[p][1])}).sum -}; - -pDist = { - arg array1, array2, signed = false; - var pDistance; - pDistance = hsArrayToCents.value(array2) - hsArrayToCents.value(array1); - if(signed, {pDistance}, {abs(pDistance)}) -}; - -hdSum = { - arg hsArrays; - var size, distances, mean; - size = hsArrays.size; - distances = (size - 1).collect({arg i; - ((i + 1)..(size - 1)).collect({arg j; - abs(hsArrays[i] - hsArrays[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsChordalDistance = { - arg hsArrays1, hsArrays2; - var size, distances, mean; - size = hsArrays1.size; - distances = hsArrays1.size.collect({arg i; - hsArrays2.size.collect({arg j; - abs(hsArrays1[i] - hsArrays2[j]).collect({arg dist, p; dist * log2(primes[p].product)}).sum - }); - }).flat; - mean = distances.sum / distances.size; - distances.sum - //mean + ((1 / sqrt((pow(distances - mean, 2)).sum / distances.size)) * mean) -}; - -hsArrayToFreq = { - arg array; - array.collect({arg dim, d; pow(primes[d][0]/primes[d][1], dim)}).product -}; - -//------score funcs - -/* -isInRange = { - arg hsArray, min, max; - var cents; - cents = hsArrayToCents.value(hsArray); - (cents >= min) && (cents <= max) -}; -*/ - -spacingScore = { - arg hsArrays, min; - var centsArray; - centsArray = hsArrays.collect({arg hsArray; hsArrayToCents.value(hsArray)}).sort({arg a, b; a < b}); - centsArray.differentiate.drop(1).collect({arg pDistance; if(pDistance >= min, {1}, {0.01})}).sum; -}; - -rangeScore = { - arg hsArray1, hsArray2, min, max, low, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - if((pDistance >= min) && (pDistance <= max), {1}, {low}); -}; - -/* -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = false; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - stepFunc.value(pDistance) -}; -*/ - -intervalScore = { - arg hsArray1, hsArray2, mean, sd, signed = true; - var pDistance; - pDistance = pDist.value(hsArray1, hsArray2, signed); - //pDistance.gaussCurve(1, mean, sd) - //if(pDistance >= 0, {stepFunc.value(abs(pDistance))}, {0.01}); - stepFunc.value(pDistance) -}; - -inclusionScore = { - arg array, test, min = 0.01; - if(array.collect({arg v; v.hash}).includes(test.hash), {min}, {1}); -}; - - -//------subroutines - -genTuples = { - var tuples; - tuples = dims.collect({[-1, 0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum <= 1) && (tuple[0] == 0)}); - //tuples = dims.collect({[0, 1]}).allTuples.select({arg tuple; (abs(tuple.drop(1)).sum == 1) && (tuple[0] == 0)}); - tuples = tuples ++ tuples.collect({arg tuple; [-3, -2, -1, 1, 2, 3].collect({arg octTrans; tuple.deepCopy.put(0, octTrans)})}).flatten; -}; - -initVoices = { - var init, voicesInit; - voicesInit = popSize.collect({dims.collect({0})}); - /* - voicesInit = [dims.collect({0})]; - (popSize - 1).do({ - arg rep, new; - rep = dims.rand; - new = voicesInit.last.deepCopy; - new[rep] = new[rep] + [-1, 1].choose(); - voicesInit = voicesInit.add(new); - }); - */ - voicesInit.deepCopy; -}; - -genDurFunc = {arg chordProb, minPad, maxPad, minDur, maxDur, envData, seed; - var env, pTable, durFunc; - env = Env.pairs([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).asSignal(256).asList.asArray; - pTable = env.asRandomTable; - [chordProb, minPad, maxPad, minDur, maxDur, envData].postln; - durFunc = {arg allowChord, pad = false; - var res; - res = if(allowChord.not, { - pTable.tableRand * (maxDur - minDur) + minDur - }, { - if(1.0.rand < chordProb, {0}, {pTable.tableRand * (maxDur - minDur) + minDur}); - }).round(0.125); - if(pad, {res = res + rrand(minPad.asFloat, maxPad.asFloat).round(0.125)}); - if(res.asInteger == res, {res = res.asInteger}); - res - }; - seedFunc.value(durFunc, seed); -}; - -genStepFunc = {arg minStep, maxStep, envData, seed; - var envDataNorm, env, pTable, stepFunc; - [minStep, maxStep, envData].postln; - envDataNorm = ([[0, 0]] ++ envData.clump(2) ++ [[1, 0]]).flop; - envDataNorm = [envDataNorm[0].normalize(minStep, maxStep), envDataNorm[1]].flop; - env = Env.pairs(envDataNorm); - stepFunc = {arg pDist; - env.at(pDist).clip(0.001, 1); - }; - seedFunc.value(stepFunc, seed); -}; - -genOrders = {arg minMotifLength = 1, maxMotifLength = 5, minProgLength = 0, maxProgLength = 5; - ((maxMotifLength.asInteger - minMotifLength.asInteger).rand + minMotifLength.asInteger).collect({ - var noProgIns, noSusIns, noSilentIns, prog, sus, silent, order; - noSusIns = [1, 2, 3].wchoose(susWeights.normalizeSum); - //noProgIns = (popSize - noSusIns).rand + 1; - noProgIns = (popSize - noSusIns); - noSilentIns = popSize - noSusIns - noProgIns; - - # prog, sus, silent = (0..(popSize-1)).scramble.clumps([noProgIns, noSusIns, noSilentIns]); - - prog = (prog.scramble ++ ((maxProgLength.asInteger - minProgLength.asInteger).rand + minProgLength.asInteger).collect({prog.choose}).scramble); - if(silent == nil, {silent = []}); - [sus.scramble, prog, silent.scramble] - }); -}; - -updateVoices = {arg ins, sus; - var voices, candidates, nWeights, nProbs, sel; - - voices = lastXChanges.deepCopy.last; - - candidates = sus.collect({arg v; tuples.collect({arg t; voices[v] + t})}).flatten; - candidates = difference(candidates.asSet, voices.asSet).asList; - nProbs = candidates.collect({arg candidate; - var stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore; - - //stepScore = intervalScore.value(voices[ins], candidate, 30, 400, 0.1); - stepScore = intervalScore.value(voices[ins], candidate, 100, 100); - recentlySoundedScore = inclusionScore.value(lastXChanges.flop[ins], candidate, 0.01); - - - - /* - if(rangeScore.value(candidate.collect({0}), voices[ins], ranges[ins][1] - 500, ranges[ins][1], 0, true) == 1, { - isInRangeScore = 1 - rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0] + 500, ranges[ins][1] - 500, 0, true); - isInRangeScore = isInRangeScore * rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true) - }, { - isInRangeScore = rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true); - }); - */ - - - isInRangeScore = rangeScore.value(candidate.collect({0}), candidate, ranges[ins][0], ranges[ins][1], 0, true); - //old way - worked but actually by accident (I think) - //isInRangeScore = rangeScore.value(candidate, candidate.collect({0}), ranges[ins][0], ranges[ins][1], 0, true); - - - regScore = spacingScore.value(voices.deepCopy.put(ins, candidate), 300); - hdScore = pow(hdSum.value(voices.deepCopy.put(ins, candidate)), hdExp); - if(hdInvert == 0, {hdScore = 1/hdScore}); - //maybe what you want here is a vector to another root and then favoring movement towards it. - //distScore = pow(hsChordalDistance.value(voices, voices.put(ins, candidate)), 2); - - [stepScore, recentlySoundedScore, isInRangeScore, regScore, hdScore] - }); - - nWeights = passagesWeights; - - //this handles nWeights of 0; mainly for testing - nProbs = nProbs.flop.select({arg scores, s; nWeights[s] != 0}).flop; - nWeights = nWeights.select({arg weight; weight != 0}); - nProbs = nProbs.flop.collect({arg scores, s; - if(scores.sum == 0, {scores}, {scores.normalizeSum * nWeights[s]}) - }); - nProbs = nProbs.flop.collect({arg scores, s; scores.product}).normalizeSum; - - sel = candidates.wchoose(nProbs); - - voices[ins] = sel; - lastXChanges = lastXChanges.add(voices).keep(-5); -}; - -genSubMotif = {arg order, orderIndex, lastState, repeatLast = false, startFromLast = false, isLastOrder = false; - var sus, prog, silent, flatOrder, res, isInChord, allowChord, pad, lastXChangesHold, voices, adder; - # sus, prog, silent = order; - flatOrder = silent ++ sus ++ prog; - lastXChangesHold = lastXChanges.deepCopy; - voices = lastState.deepCopy; - isInChord = popSize.collect({false}); - allowChord = false; - pad = false; - res = []; - "------generating motif".postln; - //need to figure out here if voices move between motifs - flatOrder.do({arg ins, i; - - if(prog.includes(ins) && repeatLast.not, {updateVoices.value(ins, sus)}); - adder = if(silent.includes(ins), {["Rest"]}, {lastXChanges.last.deepCopy[ins]}); - - if(voices[ins] != adder, { - var dur; - - if((sus ++ silent).includes(ins), { - allowChord = (ins != sus.last); - pad = (ins == sus.last); - }, { - if(i < (flatOrder.size - 1), { - allowChord = (isInChord[flatOrder[i + 1]] || (ins == flatOrder[i + 1])).not; - pad = false; - }, { - allowChord = false; - pad = true - }); - }); - if((orderIndex == 0) && sus.includes(ins), { - dur = entrancesDurFunc.value(allowChord, pad); - }, { - dur = passagesDurFunc.value(allowChord, pad); - }); - if(dur == 0, {isInChord[ins] = true}, {isInChord = popSize.collect({false})}); - - voices[ins] = adder; - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - - // pad ending - /* - if(orderIndex == (orders.size - 1), { - (0..(popSize-1)).scramble.do({arg ins; - if(res.last.first[ins] != ["Rest"], { - var dur; - voices[ins] = ["Rest"]; - allowChord = (voices != popSize.collect({["Rest"]})); - pad = allowChord.not; - dur = exitsDurFunc.value(allowChord, pad); - res = res.add([voices.deepCopy.postln, dur]); - }); - }); - }); - */ - - //format and return - if(startFromLast, {lastXChanges = lastXChangesHold.deepCopy}); - res; -}; - - -//------primary routines - -genMotif = { - var repeats, fSeq, fDur, durAdd; - - repeats = 1; - fSeq = []; - - repeats.do({arg index; - var motif; - - motif = []; - - orders.do({arg order, o; - var lastState, subMotif; - //lastState = if(o == 0, {popSize.collect({["Rest"]})}, {motif.last.last.first}); - lastState = if(o == 0, {lastXChanges.last.deepCopy}, {motif.last.last.first}); - subMotif = genSubMotif.value(order, o, lastState, isLastOrder: o == (orders.size - 1)); - motif = motif.add(subMotif); - - }); - - sanityCheck.value(motif, index); - - fSeq = fSeq.add(motif); - }); - - //round last duration to measure - /* - fDur = fSeq.flatten.flatten.slice(nil, 1).sum; - durAdd = fDur.round(4) - fDur; - if(durAdd < 0, {durAdd = 4 - durAdd}); - fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] = fSeq[0][orders.size - 1][fSeq[0][orders.size - 1].size - 1][1] + durAdd; - */ - - fSeq -}; - -genSecondarySeq = {arg seq; - var curdles, fSeq; - curdles = []; - while({curdles.sum < seq.size}, {curdles = curdles ++ [3.rand + 1]}); - - fSeq = seq.clumps(curdles).collect({arg clump, m; - var repeats, paddedSeq; - - //add rest - paddedSeq = clump.add([[[popSize.collect({["Rest"]}), 0.5.rand]]]); - - //implement repeats - repeats = [0.rand + 1, 1].wchoose([1, 0].normalizeSum); - repeats.collect({paddedSeq}); - }); - fSeq -}; - - -//------audition funcs - -/* -Event.addEventType(\osc, { - if (~addr.postln.notNil) { - ~addr.sendMsg(~indexPath, ~indexMsg); - ~addr.sendMsg(~seqPath, stringifyToDepth.value(~seqMsg, 3)); - //~addr.sendMsg("/STATE/OPEN", (dir.replace("supercollider", "resources") +/+ ~idMsg +/+ ~idMsg ++ "_gui_state" ++ ".state").standardizePath.postln); - }; -}); -*/ - -Event.addEventType(\osc, { - if (~addr.notNil) { - ~msg; - ~addr.sendMsg(~path, *~msg); - }; -}); - -genPatterns = {arg inSeq, addr, oneShot = false; - var voices, durs, pbinds, res, indices, sectionDurs, msg, ids, seq; - seq = inSeq.collect({arg mSeq; mSeq[0]}); - //# voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - # voices, durs = seq.flatten2(if(oneShot, {2}, {3})).flop; - pbinds = voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs, attacks, rels, amps; - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - //attacks = 2.collect({rrand(1, 3)}) ++ freqs.drop(2).collect({rrand(0.3, 0.5)}); - attacks = fDurs.collect({arg dur; dur * rrand(0.2, 0.4)}); - //rels = freqs.drop(2).collect({rrand(0.3, 0.5)}) ++ 2.collect({rrand(1, 3)}); - rels = (clumps.size - 1).collect({arg c; - if(clumps[c + 1][0] == ["Rest"], {rrand(1.0, 3.0)}, {rrand(0.3, 0.5)}); - }); - rels = rels.add(rrand(1.0, 3.0)); - amps = freqs.collect({rrand(0.6, 0.99)}); - - [ - Pbind( - \instrument, \string_model, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \attack, Pseq(attacks, 1), - \sustain, Pseq(fDurs, 1), - \release, Pseq(rels, 1), - //\amp, Pseq(amps, 1), - \amp, Pbrown(0.5, 1, 0.5), - \busIndex, v - ), - Pbind( - \instrument, \sine, - \group, group, - \freq, Pseq(freqs, 1), - \dur, Pseq(fDurs, 1), - \sustain, Pseq(fDurs, 1), - \busIndex, v - ) - ] - }).flatten; - if(oneShot.not, { - msg = inSeq.collect({arg mSeq, m; mSeq[1..]}); - //ids = inSeq.collect({arg mSeq, m; mSeq[2]}); - sectionDurs = seq.collect({arg mSeq; mSeq.flatten2(2).flop[1].sum}); - pbinds = pbinds ++ - [ - Pbind( - \type, \osc, - \addr, addr, - \path, "/playing", - \msg, Pseq(msg, 1), - \dur, Pseq(sectionDurs, 1) - ); - ] - }); - res = Ppar(pbinds); - res -}; - -/* -genMidiPatterns = {arg seq; - var voices, durs, patterns, res, mOut, pbRange; - pbRange = 1; //semitones - change this as needed for your situation - mOut = MIDIOut.newByName("TiMidity", "TiMidity port 0").latency_(Server.default.latency); - # voices, durs = seq.flatten2(seq.maxDepth - 5).flop; - res = Ppar( - voices.flop.collect({arg voice, v; - var clumps, hdScores, freqs, fDurs; - - mOut.program(v, 70); - - clumps = voice.separate({arg a, b; a != b }); - freqs = clumps.collect({arg clump; if(clump[0] != ["Rest"], {(60.midicps * hsArrayToFreq.value(clump[0]))}, {Rest(0)})}); - fDurs = durs.clumps(clumps.collect({arg clump; clump.size})).collect({arg clump; clump.sum}); - - Pbind( - \type, \midi, - \chan, v, - \noteval, Pseq(freqs.cpsmidi - 24, 1), - \note, Pfunc({ | event | event[\noteval].floor }), - \dur, Pseq(fDurs, 1), - \midiout, mOut, - \amp, 1, - \bend, Pfunc({ - | event | - if (event[\note].isRest.not) { - var pitchbendvalue = event[\noteval].frac.linlin(0, pbRange, 8192, 8192*2).asInteger; - m.bend(v, pitchbendvalue); - }; - 0; // return something other than nil to avoid stopping the pattern - }), - ); - }); - ); - res -}; -*/ - - -//------resource management funcs - -genUID = {Date.seed.asHexString.toLower}; - -seedFunc = {arg func, seed; - var funcArgs, next; - next = Routine({loop{func.valueArray(funcArgs).yield }}); - next.randSeed_(seed); - {arg ...args; funcArgs = args; next.value} -}; - -stringifyToDepth = {arg data, maxDepth = 1; - var prettyString = "", rCount = 0, writeArray, indent; - - if(maxDepth == 0, { - data.asCompileString - }, { - indent = {arg size; size.collect({" "}).join("")}; - writeArray = {arg array; - prettyString = prettyString ++ indent.value(rCount) ++ "[\n"; - rCount = rCount + 1; - if(rCount < maxDepth, { - array.do({arg subArray; writeArray.value(subArray)}); - }, { - prettyString = prettyString ++ array.collect({arg subArray; - indent.value(rCount + 1) ++ subArray.asCompileString - }).join(",\n"); - }); - rCount = rCount - 1; - prettyString = prettyString ++ "\n" ++ indent.value(rCount) ++ "],\n"; - }; - - writeArray.value(data); - prettyString.replace(",\n\n", "\n").drop(-2); - }) -}; - -sanityCheck = {arg motif, index; - //print functions = very helpful - ("----------" + index + "------------").postln; - - motif.flatten.do({arg val, v; - if(v > 0, { - if(motif.flatten[v-1][0].hammingDistance(val[0]) > 1, {"problem 1".postln}); - if(motif.flatten[v-1][0].hammingDistance(val[0]) == 0, {"problem 2".postln}); - }); - val.postln - }); - "***********".postln; -}; - -msgInterpret = {arg in, escapeDoubleQuotes = true, escapeSingleQuotes = true; - var res; - - res = in; - if(res.isNil.not, { - if((res.isArray && res.isString.not), { - res = res.asCompileString; - res = res.replace(" ", "").replace("\n", "").replace("\t", ""); - if(escapeSingleQuotes, {res = res.replace("\'", "")}); - if(escapeDoubleQuotes, {res = res.replace("\"", "")}); - res = res.replace("Rest", "\"Rest\""); - res = res.interpret; - }, { - var tmpRes; - if(res.every({arg char; char.isDecDigit}), {tmpRes = res.asInteger}); - if(res.contains("."), {tmpRes = res.asFloat}); - if(tmpRes != nil, {res = tmpRes}); - }); - }); - res -}; - -writeResources = {arg path, dict; - var file, modelItems, resString; - file = File(path,"w"); - - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - - resString = nameSpaces.collect({arg nameSpace; - var depth = 0, insert = " "; - if(nameSpace == "music_data", {depth = 3; insert = "\n"}); - if(nameSpace == "last_changes", {depth = 1; insert = "\n"}); - if(nameSpace == "order", {depth = 1; insert = "\n"}); - if((nameSpace == "ref_uid") && (dict[nameSpace] == nil), {dict[nameSpace] = "nil"}); - "\"" ++ nameSpace ++ "\":" ++ insert ++ stringifyToDepth.value(dict[nameSpace], depth) - }).join(",\n"); - - resString = "{\n" ++ resString ++ "\n}"; - - file.write(resString); - file.close; - resString -}; - -loadModelFile = {arg path; loadModelJSON.value(File(path, "r").readAllString.parseJSON)}; - -loadModelJSON = {arg jsonObject; - var dict; - dict = Dictionary.with(*nameSpaces.collect({arg nS; nS->msgInterpret.value(jsonObject[nS])})); - dict -}; - -setGlobalVars = {arg dict, skipLastXChanges = false; - var tmpLastXChanges; - tmpLastXChanges = lastXChanges.deepCopy; - // order really matters!!!! - # seq, lastXChanges, curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited = nameSpaces.collect({arg nS; dict[nS]}); - if(skipLastXChanges, {lastXChanges = tmpLastXChanges}); - dict -}; - -globalVarsToDict = { - var modelItems, dict; - // order really matters!!!! - modelItems = [ - seq, lastXChanges, - curUID, refUID, orderSeed, durSeed, motifSeed, - entrancesProbVals, passagesProbVals, exitsProbVals, - ranges, stepProbsVals, passagesWeights, hdExp, hdInvert, - orders, susWeights, orderSize, passagesSize, - motifEdited, orderEdited - ]; - dict = Dictionary.with(*nameSpaces.collect({arg nS, n; nS->modelItems[n]})); -}; - -loadLedgerFile = {arg path; - ledgerPath = path; - resourceDir = path.splitext(".").drop(-1).join; - loadLedgerJSON.value(File(ledgerPath, "r").readAllString.parseJSON) -}; - -loadLedgerJSON = {arg jsonObject; ledger = jsonObject["ledger"]}; - -saveLedger = {arg ledger, path; - var file, curResourceDir; - file = File(path, "w"); - curResourceDir = resourceDir; - resourceDir = path.splitext(".").drop(-1).join; - if(curResourceDir != resourceDir, { - File.mkdir(resourceDir); - ledger.do({arg id; - File.copy(curResourceDir +/+ id, resourceDir +/+ id); - }); - }); - file.write("{\n\"ledger\":\n" ++ stringifyToDepth.value(ledger, 1) ++ "\n}"); - file.close; -}; - -//------global vars - -primes = [[2, 1], [3, 2], [5, 4], [7, 4], [11, 8], [13, 8]]; -//ranges = [[-2400, 0], [-1200, 1200], [0, 2400], [0, 2400]]; -exPath = thisProcess.nowExecutingPath; -dir = exPath.dirname; -//popSize = 4; -dims = primes.size; -tuples = genTuples.value(); -//refUID = nil; -group = Group.new; -~group = group; -loadLedgerFile.value(dir +/+ ".." +/+ "resources" +/+ "piece_ledger.json"); -resourceDir = (dir +/+ ".." +/+ "resources" +/+ "piece_ledger"); -//passagesWeights = [1, 1, 1, 1, 1]; -//susWeights = [1, 1, 1]; -// order really matters!!!! -nameSpaces = [ - "music_data", "last_changes", "cur_uid", "ref_uid", "order_seed", "dur_seed", "motifs_seed", - "entrances_probs_vals","passages_probs_vals", "exits_probs_vals", - "ranges", "step_probs_vals", "passages_weights", "hd_exp", "hd_invert", - "order", "sus_weights", "order_size", "passages_size", - "motif_edited", "order_edited" -]; - - -//------OSC funcs - -OSCdef(\load_ledger, {arg msg, time, addr, port; - loadLedgerFile.value(msg[1].asString); -}, \load_ledger); - -OSCdef(\load_model, {arg msg, time, addr, port; - var dict; - dict = loadModelFile.value(msg[1].asString); - setGlobalVars.value(dict); -}, \load_model); - -OSCdef(\save_ledger, {arg msg, time, addr, port; - msg.postln; - ledger = msgInterpret.value(msg[1].asString.parseJSON["ledger"], false).postln; - //loadLedgerJSON.value(msg[0]) - saveLedger.value(ledger, msg[2].asString); - //loadLedgerFile.value(msg[1].asString); -}, \save_ledger); - -OSCdef(\generate, {arg msg, time, addr, port; - var path, dict, durSeeds, musPath, modelString; - msg.postln; - - path = msg[1].asString; - - dict = loadModelFile.value(path); - setGlobalVars.value(dict, true); - - popSize = ranges.size; - - //refUID.postln; - - loadLedgerFile.value(ledgerPath); - if(ledger == nil, {ledger = ["tmp"]}); - if(ledger.last != "tmp", {ledger = ledger.add("tmp")}); - - if(refUID == nil, {lastXChanges = [initVoices.value().deepCopy]}); - if((refUID != nil) && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - lastXChanges = msgInterpret.value(file.readAllString.parseJSON["last_changes"]); - }); - - refUID.postln; - lastXChanges.collect({arg item; item.postln}); - - durSeeds = seedFunc.value({3.collect({rrand(100000, 999999)})}, durSeed).value.postln; - entrancesDurFunc = genDurFunc.valueArray(entrancesProbVals[..4] ++ [entrancesProbVals[5..]] ++ [durSeeds[0]]); - passagesDurFunc = genDurFunc.valueArray(passagesProbVals[..4] ++ [passagesProbVals[5..]] ++ [durSeeds[1]]); - exitsDurFunc = genDurFunc.valueArray(exitsProbVals[..4] ++ [exitsProbVals[5..]] ++ [durSeeds[2]]); - - if(orders == nil, { - orders = seedFunc.value(genOrders, orderSeed).valueArray(orderSize ++ passagesSize); - //addr.sendMsg("/order", stringifyToDepth.value(orders, 1)); - }); - - stepFunc = genStepFunc.valueArray(stepProbsVals[..1] ++ [stepProbsVals[2..]] ++ [motifSeed]); - seq = seedFunc.value(genMotif, motifSeed).value; - - lastXChanges.collect({arg item; item.postln}); - - dict = globalVarsToDict.value; - modelString = writeResources.value(path, dict); - - //addr.sendMsg("/generated", musPath, stringifyToDepth.value(seq, 3)); - //~seq = seq; - - addr.sendMsg("/generated", path, modelString, ledgerPath); -}, \generate); - - -OSCdef(\commit, {arg msg, time, addr, port; - var musicData, musicChanged, dict, newLedger, modelPath, musString, musFile, test1, test2, lastCurUID, commitType, commitPos, equalityLedger; - //msg.postln; - - /* - test1 = msg[1].asString.parseJSON; - test2 = (dir +/+ ".." +/+ "resources/tmp/tmp_music" ++ ".json").standardizePath.parseJSONFile; - msgInterpret.value(test1["music"])[0][0][0][1].class.postln; - msgInterpret.value(test2["music_data"])[0][0][0][1].class.postln; - (test1["music"] == test2["music_data"]).postln; - */ - - musicData = loadModelJSON.value(msg[1].asString.parseJSON)["music_data"].postln; - musicChanged = (musicData != seq).postln; - commitType = msg[2].asString; - commitPos = msg[3].postln.asInteger; - - lastCurUID = curUID.deepCopy; - curUID = genUID.value; - - File.mkdir((resourceDir +/+ curUID).standardizePath); - File.copy(exPath, (resourceDir +/+ curUID +/+ curUID ++ "_code" ++ ".scd").standardizePath); - - modelPath = (resourceDir +/+ curUID +/+ curUID ++ "_mus_model" ++ ".json").standardizePath; - dict = globalVarsToDict.value; - if(musicChanged, { - seq = musicData; - dict["music_data"] = seq; - dict["motif_edited"] = "true" - }); - dict["cur_uid"] = curUID; - - writeResources.value(modelPath, dict); - - File.delete(ledgerPath ++ "_bak"); - File.copy(ledgerPath, ledgerPath ++ "_bak"); - File.delete(ledgerPath); - - /* - if(commitType == "add", { - if(lastCurUID == "tmp", { - ledger = ledger.drop(-1).add(curUID); - }, { - ledger = ledger.add(curUID); - }) - }); - */ - - ledger.postln; - - if(commitType == "add", {ledger = ledger.add(curUID)}); - - if(commitType == "insert", {ledger = ledger.insert(commitPos + 1, curUID)}); - - if(commitType == "replace", {ledger = ledger.put(commitPos, curUID)}); - - equalityLedger = ledger.collect({arg item; item.asSymbol}); - if(equalityLedger.includes(\tmp).postln, {ledger.removeAt(equalityLedger.indexOf(\tmp).postln)}); - - ledger.postln; - - saveLedger.value(ledger, ledgerPath); - - addr.sendMsg("/committed", curUID, ledgerPath); - //refUID = curUID; - -}, \commit); - -OSCdef(\transport, {arg msg, time, addr, port; - msg.postln; - if(msg[1] == 0, { - group.set(\release, 2); - group.set(\gate, 0); - player.stop; - }, { - // the cued sequence can now be read from file, so this can be cleaned up - var cSize, patterns, pSeq, cuedSeek, indexStart, indexEnd, tmpLedger; - if(msg[1] == 1, { - pSeq = []; - cuedSeek = (seq != nil); - indexStart = msg[2].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.postln.parseJSON["music_data"]), path, indexStart + index, uid]); - file.close; - }); - }); - if(cuedSeek, { - var path, file; - path = (resourceDir +/+ "tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - patterns = genPatterns.value(pSeq, addr); - }, { - pSeq = [loadModelJSON.value(msg[2].asString.parseJSON)["music_data"].postln]; - patterns = genPatterns.value(pSeq, addr, true); - }); - player = Pfset(pattern: patterns, cleanupFunc: { - addr.sendMsg("/transport", 0); - addr.sendMsg("/one_shot", 0); - }); - player = player.play - }); -}, \transport); - - -OSCdef(\transcribe_motif, {arg msg, time, addr, port; - var tSeq, refChord, refUID; - - msg.postln; - - tSeq = [loadModelJSON.value(msg[1].asString.parseJSON)["music_data"]]; - refUID = msg[2].asString.postln; - - if((refUID != "nil") && (refUID != "tmp"), { - var file; - file = File((resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }, { - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - }); - - ~transcribe.value(tSeq, refChord, (dir +/+ ".." +/+ "lilypond" +/+ "includes").standardizePath, addr, "/transcribe_motif"); -}, \transcribe_motif); - - -OSCdef(\transcribe_all, {arg msg, time, addr, port; - var cSize, patterns, cuedSeek, indexStart, indexEnd, tmpLedger; - if(true, { - cuedSeek = (seq != nil); - indexStart = msg[1].asInteger; - indexEnd = ledger.size - if(cuedSeek, {2}, {1}); - - //tmp for testing transcription - //indexEnd = (indexStart+5); - - //ledger.postln; - if(((indexStart == (ledger.size - 1)) && cuedSeek).not, { - var lilyPartLedgerFiles; - - lilyPartLedgerFiles = 4.collect({arg p; - File((dir +/+ ".." +/+ "lilypond" +/+ "includes" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly").standardizePath, "w"); - }); - - ledger[indexStart..indexEnd].do({arg uid, index; - var path, file, fileString, tSeq, refUID, refChord; - path = (resourceDir +/+ uid +/+ uid ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - fileString = file.readAllString; - tSeq = msgInterpret.value(fileString.parseJSON["music_data"]); - refUID = msgInterpret.value(fileString.parseJSON["ref_uid"]); - file.close; - - //uid.postln; - //(refUID == "nil").postln; - - refChord = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; - - if(refUID != "nil", { - path = (resourceDir +/+ refUID +/+ refUID ++ "_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - refChord = msgInterpret.value(file.readAllString.parseJSON["last_changes"]).last; - file.close; - }); - - if(index != indexEnd, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath); - }, { - ~transcribe.value(tSeq, refChord, (resourceDir +/+ uid +/+ "lilypond").standardizePath, addr, "/transcribe_all"); - }); - - lilyPartLedgerFiles.do({arg f, p; - f.write("\\include \"" ++ resourceDir +/+ uid +/+ "lilypond" +/+ "part_" ++ ["IV", "III", "II", "I"][p] ++ ".ly\"\n"); - }); - - }); - - lilyPartLedgerFiles.do({arg f; - f.close - }); - }); - /* - if(cuedSeek, { - var path, file; - path = (dir +/+ ".." +/+ "resources/tmp/tmp_mus_model" ++ ".json").standardizePath; - file = File(path, "r"); - pSeq = pSeq.add([msgInterpret.value(file.readAllString.parseJSON["music_data"]), path, ledger.size - 1, "tmp"]); - file.close; - }); - */ - }, { - - }); - -}, \transcribe_all); - -) - - diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/7ede7adb/7ede7adb_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_3_rise/7ede7adb/7ede7adb_mus_model.json deleted file mode 100644 index b5aa312..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/7ede7adb/7ede7adb_mus_model.json +++ /dev/null @@ -1,83 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ -4, 2, 2, 3, 1, 0 ], [ -5, 3, 2, 2, 1, 0 ], [ -4, 2, 2, 2, 1, 0 ], [ -3, 2, 1, 2, 1, 0 ] ], 1 ], - [ [ [ -4, 2, 2, 3, 1, 0 ], [ -3, 1, 1, 2, 1, 0 ], [ -4, 2, 2, 2, 1, 0 ], [ -3, 2, 1, 2, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 1, 1, 2, 1, 0 ], [ -3, 1, 1, 2, 1, 0 ], [ -4, 2, 2, 2, 1, 0 ], [ -3, 2, 1, 2, 1, 0 ] ], 1 ], - [ [ [ -2, 1, 1, 2, 1, 0 ], [ -3, 1, 1, 2, 1, 0 ], [ -4, 2, 2, 2, 1, 0 ], [ -3, 2, 2, 2, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -2, 1, 1, 2, 1, 0 ], [ -3, 1, 1, 2, 1, 0 ], [ -4, 2, 2, 2, 1, 0 ], [ -4, 2, 1, 2, 1, 0 ] ], 1 ], - [ [ [ -5, 2, 1, 2, 1, 0 ], [ -3, 1, 1, 2, 1, 0 ], [ -4, 2, 2, 2, 1, 0 ], [ -4, 2, 1, 2, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -5, 2, 1, 2, 1, 0 ], [ -3, 1, 1, 2, 1, 0 ], [ -4, 2, 2, 2, 1, 0 ], [ -4, 3, 1, 2, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -5, 2, 1, 2, 1, 0 ], [ -3, 2, 1, 2, 1, 0 ], [ -4, 2, 2, 2, 1, 0 ], [ -4, 3, 1, 2, 1, 0 ] ], 1 ], - [ [ [ -5, 3, 1, 2, 1, 0 ], [ -3, 2, 1, 2, 1, 0 ], [ -4, 2, 2, 2, 1, 0 ], [ -4, 3, 1, 2, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -5, 3, 1, 2, 1, 0 ], [ -3, 2, 1, 2, 1, 0 ], [ -4, 2, 2, 2, 1, 0 ], [ -3, 1, 2, 2, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -5, 3, 1, 2, 1, 0 ], [ -3, 2, 1, 2, 1, 0 ], [ -4, 2, 2, 2, 1, 0 ], [ -4, 3, 2, 2, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -5, 3, 1, 2, 1, 0 ], [ -3, 2, 1, 2, 1, 0 ], [ -4, 2, 2, 2, 1, 0 ], [ -2, 2, 1, 1, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -5, 3, 1, 2, 1, 0 ], [ -3, 2, 1, 2, 1, 0 ], [ -4, 3, 2, 2, 1, 0 ], [ -2, 2, 1, 1, 1, 0 ] ], 1 ], - [ [ [ -5, 3, 1, 2, 1, 0 ], [ -3, 2, 1, 2, 1, 0 ], [ -4, 3, 2, 2, 1, 0 ], [ -2, 1, 1, 2, 1, 0 ] ], 1 ] - ], - [ - [ [ [ -5, 3, 1, 2, 1, 0 ], [ -3, 2, 1, 2, 1, 0 ], [ -2, 1, 0, 2, 1, 0 ], [ -2, 1, 1, 2, 1, 0 ] ], 1 ], - [ [ [ -5, 3, 1, 2, 1, 0 ], [ -3, 1, 1, 3, 1, 0 ], [ -2, 1, 0, 2, 1, 0 ], [ -2, 1, 1, 2, 1, 0 ] ], 1 ], - [ [ [ -3, 0, 1, 2, 1, 0 ], [ -3, 1, 1, 3, 1, 0 ], [ -2, 1, 0, 2, 1, 0 ], [ -2, 1, 1, 2, 1, 0 ] ], 1 ] - ] - ] -], -"last_changes": -[ - [ [ -5, 3, 1, 2, 1, 0 ], [ -3, 2, 1, 2, 1, 0 ], [ -4, 3, 2, 2, 1, 0 ], [ -2, 2, 1, 1, 1, 0 ] ], - [ [ -5, 3, 1, 2, 1, 0 ], [ -3, 2, 1, 2, 1, 0 ], [ -4, 3, 2, 2, 1, 0 ], [ -2, 1, 1, 2, 1, 0 ] ], - [ [ -5, 3, 1, 2, 1, 0 ], [ -3, 2, 1, 2, 1, 0 ], [ -2, 1, 0, 2, 1, 0 ], [ -2, 1, 1, 2, 1, 0 ] ], - [ [ -5, 3, 1, 2, 1, 0 ], [ -3, 1, 1, 3, 1, 0 ], [ -2, 1, 0, 2, 1, 0 ], [ -2, 1, 1, 2, 1, 0 ] ], - [ [ -3, 0, 1, 2, 1, 0 ], [ -3, 1, 1, 3, 1, 0 ], [ -2, 1, 0, 2, 1, 0 ], [ -2, 1, 1, 2, 1, 0 ] ] -], -"cur_uid": "7ede7adb", -"ref_uid": "6522664c", -"order_seed": 455950, -"dur_seed": 308053, -"motifs_seed": 206233, -"entrances_probs_vals": [ 0, 0, 0, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"passages_probs_vals": [ 0, 0, 0, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"exits_probs_vals": [ 0, 0, 0, 1, 1, 0, 0.5, 0.5, 0.5, 1, 0.5 ], -"ranges": [ [ -2400, 1200 ], [ -1200, 1200 ], [ -702, 1200 ], [ -702, 1200 ] ], -"step_probs_vals": [ 0, 1200, 0.0061728395061728, 0.10227272727273, 0.074074074074074, 0.10227272727273, 0.2037037037037, 0.090909090909091, 0.45679012345679, 0.011363636363636, 0.53086419753086, 0, 0.54320987654321, 0.92045454545455, 0.58641975308642, 0.92613636363636, 0.61111111111111, 0, 0.7880658436214, 0.034090909090909, 1, 0.034090909090909 ], -"passages_weights": [ 1, 0.47, 0.43, 1, 0.7 ], -"hd_exp": 7, -"hd_invert": 0, -"order": -[ - [ [ 2, 3 ], [ 0, 1 ], [ ] ], - [ [ 1, 2 ], [ 0, 3 ], [ ] ], - [ [ 2, 1 ], [ 3, 0 ], [ ] ], - [ [ 0, 1, 2 ], [ 3 ], [ ] ], - [ [ 2, 3 ], [ 1, 0 ], [ ] ], - [ [ 2, 1, 0 ], [ 3 ], [ ] ], - [ [ 1, 0, 2 ], [ 3 ], [ ] ], - [ [ 2, 0, 1 ], [ 3 ], [ ] ], - [ [ 0, 1 ], [ 2, 3 ], [ ] ], - [ [ 3 ], [ 2, 1, 0 ], [ ] ] -], -"sus_weights": [ 0.35, 0.37, 0.38 ], -"order_size": [ 10.091836734694, 10.091836734694 ], -"passages_size": [ 0, 0 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/7ede7adb/lilypond/part_I.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/7ede7adb/lilypond/part_I.ly deleted file mode 100644 index 41fe1e5..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/7ede7adb/lilypond/part_I.ly +++ /dev/null @@ -1,18 +0,0 @@ -{ - { g'1^\markup { \pad-markup #0.2 "-21"} ~ } - \bar "|" - { g'2 b'2^\markup { \pad-markup #0.2 "-34"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 1↑" }} } - \bar "|" - { g1^\markup { \pad-markup #0.2 "-21"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }} } - \bar "|" - { d'1^\markup { \pad-markup #0.2 "-19"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }} ~ } - \bar "|" - { d'2 e'2^\markup { \pad-markup #0.2 "-36"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↓" }} } - \bar "|" - { fis'2^\markup { \pad-markup #0.2 "-33"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }} a'2^\markup { \pad-markup #0.2 "+10"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 7↓" }} ~ } - \bar "|" - { a'2 c''2^\markup { \pad-markup #0.2 "-23"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↓" }} ~ } - \bar "|" - { c''1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/7ede7adb/lilypond/part_II.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/7ede7adb/lilypond/part_II.ly deleted file mode 100644 index ce1994b..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/7ede7adb/lilypond/part_II.ly +++ /dev/null @@ -1,18 +0,0 @@ -{ - { b1^\markup { \pad-markup #0.2 "-34"} ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 ~ } - \bar "|" - { b1 } - \bar "|" - { fis'1^\markup { \pad-markup #0.2 "-33"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }} } - \bar "|" - { gis'1^\markup { \pad-markup #0.2 "-9"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 5↓" }}} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/7ede7adb/lilypond/part_III.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/7ede7adb/lilypond/part_III.ly deleted file mode 100644 index e5a072c..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/7ede7adb/lilypond/part_III.ly +++ /dev/null @@ -1,18 +0,0 @@ -{ - { fis2^\markup { \pad-markup #0.2 "-33"} c'2^\markup { \pad-markup #0.2 "-23"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↓" }} ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'1 ~ } - \bar "|" - { c'2 g'2^\markup { \pad-markup #0.2 "-21"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }} ~ } - \bar "|" - { g'1 ~ } - \bar "|" - { g'1 ~ } - \bar "|" - { g'1 ~ } - \bar "|" - { g'2 a'2^\markup { \pad-markup #0.2 "+46"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 7↑" }}} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/7ede7adb/lilypond/part_IV.ly b/resources/resources_bak_2024_01_03/string_quartet_3_rise/7ede7adb/lilypond/part_IV.ly deleted file mode 100644 index bf1c7e0..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/7ede7adb/lilypond/part_IV.ly +++ /dev/null @@ -1,18 +0,0 @@ -{ - { gis'1^\markup { \pad-markup #0.2 "+34"} } - \bar "|" - { c''1^\markup { \pad-markup #0.2 "-23"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }} ~ } - \bar "|" - { c''2 g,2^\markup { \pad-markup #0.2 "-21"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }} ~ } - \bar "|" - { g,1 } - \bar "|" - { d1^\markup { \pad-markup #0.2 "-19"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }} ~ } - \bar "|" - { d1 ~ } - \bar "|" - { d1 ~ } - \bar "|" - { d1} -\bar "||" -} \ No newline at end of file diff --git a/resources/resources_bak_2024_01_03/string_quartet_3_rise/tmp/tmp_mus_model.json b/resources/resources_bak_2024_01_03/string_quartet_3_rise/tmp/tmp_mus_model.json deleted file mode 100644 index 1a3fb49..0000000 --- a/resources/resources_bak_2024_01_03/string_quartet_3_rise/tmp/tmp_mus_model.json +++ /dev/null @@ -1,274 +0,0 @@ -{ -"music_data": -[ - [ - [ - [ [ [ 1, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 0 ], - [ [ [ 1, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ], [ 0, -1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 0 ], - [ [ [ 1, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0 ], [ 0, -1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 0.25 ], - [ [ [ 1, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 0, -1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0 ] ], 0.25 ] - ], - [ - [ [ [ 1, 0, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 0, -1, 0, 0, 0, 0 ], [ 1, -1, -1, 0, 0, 0 ] ], 0 ], - [ [ [ 0, -1, 0, 1, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 0, -1, 0, 0, 0, 0 ], [ 1, -1, -1, 0, 0, 0 ] ], 0 ], - [ [ [ 0, -1, 0, 1, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, -1, 0, -1, 0, 0 ], [ 1, -1, -1, 0, 0, 0 ] ], 0.25 ], - [ [ [ 0, -1, 0, 0, 0, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, -1, 0, -1, 0, 0 ], [ 1, -1, -1, 0, 0, 0 ] ], 0.25 ], - [ [ [ 1, -1, 0, 0, -1, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, -1, 0, -1, 0, 0 ], [ 1, -1, -1, 0, 0, 0 ] ], 0 ], - [ [ [ 1, -1, 0, 0, -1, 0 ], [ 1, -1, 0, 0, 0, 0 ], [ 1, -1, 0, -1, 0, 0 ], [ 0, -1, 0, 1, 0, 0 ] ], 0.25 ] - ], - [ - [ [ [ 1, -1, 0, 0, -1, 0 ], [ 2, -1, 0, -1, 0, 0 ], [ 1, -1, 0, -1, 0, 0 ], [ 0, -1, 0, 1, 0, 0 ] ], 0.25 ], - [ [ [ 1, -2, 0, -1, 0, 0 ], [ 2, -1, 0, -1, 0, 0 ], [ 1, -1, 0, -1, 0, 0 ], [ 0, -1, 0, 1, 0, 0 ] ], 0 ], - [ [ [ 1, -2, 0, -1, 0, 0 ], [ 2, -1, 0, -1, 0, 0 ], [ 1, -1, 0, -1, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ] ], 0 ], - [ [ [ 1, -2, 0, -1, 0, 0 ], [ 2, -2, 0, -1, 0, 0 ], [ 1, -1, 0, -1, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ] ], 0.25 ] - ], - [ - [ [ [ 1, -2, 0, -1, 0, 0 ], [ 2, -2, 0, -1, 0, 0 ], [ 2, -1, 0, -1, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ] ], 0 ], - [ [ [ 1, -2, 0, -1, 0, 0 ], [ 1, -1, 0, -1, 0, 0 ], [ 2, -1, 0, -1, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ] ], 0.5 ], - [ [ [ 0, 0, 0, -1, 0, 0 ], [ 1, -1, 0, -1, 0, 0 ], [ 2, -1, 0, -1, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, -1, 0, 0 ], [ 0, 1, 0, -1, 0, 0 ], [ 2, -1, 0, -1, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ] ], 0.25 ] - ], - [ - [ [ [ 0, 0, 0, -1, 0, 0 ], [ 1, -1, 1, -1, 0, 0 ], [ 2, -1, 0, -1, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ] ], 0.5 ], - [ [ [ 1, -1, -1, -1, 0, 0 ], [ 1, -1, 1, -1, 0, 0 ], [ 2, -1, 0, -1, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ] ], 0 ], - [ [ [ 1, -1, -1, -1, 0, 0 ], [ 1, -1, 1, -1, 0, 0 ], [ 2, -1, 0, -1, 0, 0 ], [ 2, -1, -1, -1, 0, 0 ] ], 0.5 ] - ], - [ - [ [ [ 2, -1, -1, -2, 0, 0 ], [ 1, -1, 1, -1, 0, 0 ], [ 2, -1, 0, -1, 0, 0 ], [ 2, -1, -1, -1, 0, 0 ] ], 0 ], - [ [ [ 2, -1, -1, -2, 0, 0 ], [ 1, -1, 1, -1, 0, 0 ], [ 3, -1, -1, -2, 0, 0 ], [ 2, -1, -1, -1, 0, 0 ] ], 0 ], - [ [ [ 2, -1, -1, -2, 0, 0 ], [ 1, -1, -1, 0, 0, 0 ], [ 3, -1, -1, -2, 0, 0 ], [ 2, -1, -1, -1, 0, 0 ] ], 0.5 ], - [ [ [ 0, -1, -1, 0, 0, 0 ], [ 1, -1, -1, 0, 0, 0 ], [ 3, -1, -1, -2, 0, 0 ], [ 2, -1, -1, -1, 0, 0 ] ], 0.25 ] - ], - [ - [ [ [ 0, -1, -1, 0, 0, 0 ], [ 1, -1, -1, 0, 0, 0 ], [ 3, -1, -1, -2, 0, 0 ], [ 2, -1, -1, -2, 0, 0 ] ], 0 ], - [ [ [ 0, -1, -1, 0, 0, 0 ], [ 2, -1, -1, -1, 0, 0 ], [ 3, -1, -1, -2, 0, 0 ], [ 2, -1, -1, -2, 0, 0 ] ], 0 ], - [ [ [ 1, -1, -1, -1, 0, 0 ], [ 2, -1, -1, -1, 0, 0 ], [ 3, -1, -1, -2, 0, 0 ], [ 2, -1, -1, -2, 0, 0 ] ], 0.25 ], - [ [ [ 1, -1, -1, -2, 0, 0 ], [ 2, -1, -1, -1, 0, 0 ], [ 3, -1, -1, -2, 0, 0 ], [ 2, -1, -1, -2, 0, 0 ] ], 0 ], - [ [ [ 1, -1, -1, -2, 0, 0 ], [ 2, -1, -1, -1, 0, 0 ], [ 3, -1, -1, -2, 0, 0 ], [ 3, -1, -1, -3, 0, 0 ] ], 0.25 ], - [ [ [ 2, -1, -1, -3, 0, 0 ], [ 2, -1, -1, -1, 0, 0 ], [ 3, -1, -1, -2, 0, 0 ], [ 3, -1, -1, -3, 0, 0 ] ], 0.25 ], - [ [ [ 2, -1, -1, -2, 0, 0 ], [ 2, -1, -1, -1, 0, 0 ], [ 3, -1, -1, -2, 0, 0 ], [ 3, -1, -1, -3, 0, 0 ] ], 0.25 ], - [ [ [ 2, -1, -1, -2, 0, 0 ], [ 2, -1, -1, -1, 0, 0 ], [ 3, -1, -1, -2, 0, 0 ], [ 2, -1, 0, -2, 0, 0 ] ], 0.25 ] - ], - [ - [ [ [ 2, -1, -1, -2, 0, 0 ], [ 2, -1, -1, -1, 0, 0 ], [ 3, -1, -1, -2, 0, 0 ], [ 1, 0, -1, -1, 0, 0 ] ], 0 ], - [ [ [ 1, -1, -1, -1, 0, 1 ], [ 2, -1, -1, -1, 0, 0 ], [ 3, -1, -1, -2, 0, 0 ], [ 1, 0, -1, -1, 0, 0 ] ], 0 ], - [ [ [ 1, -1, -1, -1, 0, 1 ], [ 2, -1, -1, -1, 0, 0 ], [ 3, -1, -1, -1, 0, 0 ], [ 1, 0, -1, -1, 0, 0 ] ], 0.5 ], - [ [ [ 1, -1, -1, -1, 0, 0 ], [ 2, -1, -1, -1, 0, 0 ], [ 3, -1, -1, -1, 0, 0 ], [ 1, 0, -1, -1, 0, 0 ] ], 0.25 ] - ], - [ - [ [ [ 1, -1, -1, -1, 0, 0 ], [ 2, -1, -1, -1, 0, 0 ], [ 3, -1, -1, -1, 0, 0 ], [ 2, -1, -2, -1, 0, 0 ] ], 0 ], - [ [ [ 1, -1, -1, -1, 0, 0 ], [ 3, -1, -2, -1, 0, 0 ], [ 3, -1, -1, -1, 0, 0 ], [ 2, -1, -2, -1, 0, 0 ] ], 0 ], - [ [ [ 1, -1, -1, -1, 0, 0 ], [ 3, -1, -2, -1, 0, 0 ], [ 2, -1, -1, -1, 0, 0 ], [ 2, -1, -2, -1, 0, 0 ] ], 0.25 ], - [ [ [ 1, -1, -1, -1, 0, 0 ], [ 2, 0, -1, -1, 0, 0 ], [ 2, -1, -1, -1, 0, 0 ], [ 2, -1, -2, -1, 0, 0 ] ], 0.25 ] - ], - [ - [ [ [ 1, -1, -1, -1, 0, 0 ], [ 2, -1, -1, -1, 0, 1 ], [ 2, -1, -1, -1, 0, 0 ], [ 2, -1, -2, -1, 0, 0 ] ], 0.25 ], - [ [ [ 1, -1, -1, -1, 0, 0 ], [ 2, -1, -1, -1, 0, 1 ], [ 2, -1, -1, -1, 0, 0 ], [ 3, -2, -1, -1, 0, 0 ] ], 0 ], - [ [ [ 1, -1, -1, -1, 0, 0 ], [ 2, -1, -1, -1, 0, 1 ], [ 2, -1, -1, -2, 0, 0 ], [ 3, -2, -1, -1, 0, 0 ] ], 0.25 ] - ], - [ - [ [ [ 1, -1, -1, -1, 0, 0 ], [ 2, -1, -1, -1, 0, 1 ], [ 1, -1, 0, -1, 0, 0 ], [ 3, -2, -1, -1, 0, 0 ] ], 0 ], - [ [ [ 1, -1, -1, -1, 0, 0 ], [ 2, -1, -1, -1, 0, 1 ], [ 1, -1, 0, -1, 0, 0 ], [ 2, -1, 0, -1, 0, 0 ] ], 0.5 ], - [ [ [ 1, -1, -1, -1, 0, 0 ], [ 2, -1, -1, -1, 0, 0 ], [ 1, -1, 0, -1, 0, 0 ], [ 2, -1, 0, -1, 0, 0 ] ], 0.25 ], - [ [ [ 1, -1, -1, -1, 0, 0 ], [ 2, 0, -1, -1, 0, 0 ], [ 1, -1, 0, -1, 0, 0 ], [ 2, -1, 0, -1, 0, 0 ] ], 0.5 ], - [ [ [ 1, -1, -1, -1, 0, 0 ], [ 2, 0, -1, -1, 0, 0 ], [ 1, -1, 0, -1, 0, 0 ], [ 2, -2, -1, -1, 0, 0 ] ], 0.25 ], - [ [ [ 1, -1, -1, -1, 0, 0 ], [ 2, 0, -1, -1, 0, 0 ], [ 2, -1, -1, -1, 0, 0 ], [ 2, -2, -1, -1, 0, 0 ] ], 0 ], - [ [ [ 1, -1, -1, -1, 0, 0 ], [ 2, 0, -1, -1, 0, 0 ], [ 2, -1, -1, -1, 0, 0 ], [ 1, 0, -1, -1, 0, 0 ] ], 0.25 ], - [ [ [ 1, -1, -1, -1, 0, 0 ], [ 2, 0, -1, -1, 0, 0 ], [ 2, -1, 0, -1, 0, 0 ], [ 1, 0, -1, -1, 0, 0 ] ], 0.25 ] - ], - [ - [ [ [ 1, -1, -1, -1, 0, 0 ], [ 2, 0, -1, -1, 0, 0 ], [ 3, -1, -1, -1, 0, 0 ], [ 1, 0, -1, -1, 0, 0 ] ], 0.5 ], - [ [ [ 0, 1, -1, -1, 0, 0 ], [ 2, 0, -1, -1, 0, 0 ], [ 3, -1, -1, -1, 0, 0 ], [ 1, 0, -1, -1, 0, 0 ] ], 0 ], - [ [ [ 0, 1, -1, -1, 0, 0 ], [ 1, 1, -1, -1, 0, 0 ], [ 3, -1, -1, -1, 0, 0 ], [ 1, 0, -1, -1, 0, 0 ] ], 0 ], - [ [ [ 0, 1, -1, -1, 0, 0 ], [ 1, 1, -1, -1, 0, 0 ], [ 2, 0, -1, -1, 0, 0 ], [ 1, 0, -1, -1, 0, 0 ] ], 0.5 ], - [ [ [ 0, 1, -1, -1, 0, 0 ], [ 1, 1, -1, -1, 0, 0 ], [ 1, 0, 0, -1, 0, 0 ], [ 1, 0, -1, -1, 0, 0 ] ], 0.25 ], - [ [ [ 0, 1, -1, -1, 0, 0 ], [ 1, 1, -1, -1, 0, 0 ], [ 2, -1, -1, -1, 0, 0 ], [ 1, 0, -1, -1, 0, 0 ] ], 0 ], - [ [ [ 0, 0, -1, -1, 0, 0 ], [ 1, 1, -1, -1, 0, 0 ], [ 2, -1, -1, -1, 0, 0 ], [ 1, 0, -1, -1, 0, 0 ] ], 0.25 ], - [ [ [ 0, 0, -1, -1, 0, 0 ], [ 1, 1, -1, -1, 0, 0 ], [ 0, 1, -1, -1, 0, 0 ], [ 1, 0, -1, -1, 0, 0 ] ], 0.5 ] - ], - [ - [ [ [ 1, 0, -1, -2, 0, 0 ], [ 1, 1, -1, -1, 0, 0 ], [ 0, 1, -1, -1, 0, 0 ], [ 1, 0, -1, -1, 0, 0 ] ], 0.25 ], - [ [ [ 1, 0, -1, -2, 0, 0 ], [ 1, 1, -1, -1, 0, 0 ], [ 2, 0, -1, -2, 0, 0 ], [ 1, 0, -1, -1, 0, 0 ] ], 0 ], - [ [ [ 1, 0, -1, -2, 0, 0 ], [ 2, 0, -2, -1, 0, 0 ], [ 2, 0, -1, -2, 0, 0 ], [ 1, 0, -1, -1, 0, 0 ] ], 0.25 ], - [ [ [ 1, 0, -1, -2, 0, 0 ], [ 2, 0, -2, -1, 0, 0 ], [ 2, 0, -1, -1, 0, 0 ], [ 1, 0, -1, -1, 0, 0 ] ], 0.5 ], - [ [ [ 1, 0, -1, -2, 0, 0 ], [ 1, 0, -1, 0, 0, 0 ], [ 2, 0, -1, -1, 0, 0 ], [ 1, 0, -1, -1, 0, 0 ] ], 0.5 ], - [ [ [ 1, 0, -1, -2, 0, 0 ], [ 2, 0, -1, -2, 0, 0 ], [ 2, 0, -1, -1, 0, 0 ], [ 1, 0, -1, -1, 0, 0 ] ], 0 ], - [ [ [ 0, 0, 0, -1, 0, 0 ], [ 2, 0, -1, -2, 0, 0 ], [ 2, 0, -1, -1, 0, 0 ], [ 1, 0, -1, -1, 0, 0 ] ], 0.25 ] - ], - [ - [ [ [ 0, 0, 0, -1, 0, 0 ], [ 2, 0, -1, -2, 0, 0 ], [ 3, 0, -1, -2, 0, 0 ], [ 1, 0, -1, -1, 0, 0 ] ], 0 ], - [ [ [ 1, -1, -1, -1, 0, 0 ], [ 2, 0, -1, -2, 0, 0 ], [ 3, 0, -1, -2, 0, 0 ], [ 1, 0, -1, -1, 0, 0 ] ], 0.25 ], - [ [ [ 1, -1, -1, -1, 0, 0 ], [ 2, 0, -1, -1, 0, 0 ], [ 3, 0, -1, -2, 0, 0 ], [ 1, 0, -1, -1, 0, 0 ] ], 0.25 ] - ], - [ - [ [ [ 0, 0, -1, -1, 0, 0 ], [ 2, 0, -1, -1, 0, 0 ], [ 3, 0, -1, -2, 0, 0 ], [ 1, 0, -1, -1, 0, 0 ] ], 0 ], - [ [ [ 0, 0, -1, -1, 0, 0 ], [ 2, 0, -1, -1, 0, 0 ], [ 3, 0, -1, -2, 0, 0 ], [ 2, 0, -1, -2, 0, 0 ] ], 0 ], - [ [ [ 0, 0, -1, -1, 0, 0 ], [ 3, 0, -2, -2, 0, 0 ], [ 3, 0, -1, -2, 0, 0 ], [ 2, 0, -1, -2, 0, 0 ] ], 0.5 ], - [ [ [ 0, 0, -1, -1, 0, 0 ], [ 3, 0, -2, -2, 0, 0 ], [ 3, 0, -1, -2, 0, 0 ], [ 3, 0, -1, -3, 0, 0 ] ], 0 ], - [ [ [ 1, 0, -1, -2, 0, 0 ], [ 3, 0, -2, -2, 0, 0 ], [ 3, 0, -1, -2, 0, 0 ], [ 3, 0, -1, -3, 0, 0 ] ], 0.25 ], - [ [ [ 2, 0, -2, -2, 0, 0 ], [ 3, 0, -2, -2, 0, 0 ], [ 3, 0, -1, -2, 0, 0 ], [ 3, 0, -1, -3, 0, 0 ] ], 0 ], - [ [ [ 2, 0, -2, -2, 0, 0 ], [ 2, 1, -1, -2, 0, 0 ], [ 3, 0, -1, -2, 0, 0 ], [ 3, 0, -1, -3, 0, 0 ] ], 0.25 ] - ], - [ - [ [ [ 1, 1, -1, -2, 0, 0 ], [ 2, 1, -1, -2, 0, 0 ], [ 3, 0, -1, -2, 0, 0 ], [ 3, 0, -1, -3, 0, 0 ] ], 0.25 ], - [ [ [ 1, 1, -1, -2, 0, 0 ], [ 2, 1, -1, -2, 0, 0 ], [ 3, 0, -1, -2, 0, 0 ], [ 2, 1, -2, -2, 0, 0 ] ], 0.25 ], - [ [ [ 1, 1, -1, -2, 0, 0 ], [ 2, 1, -1, -2, 0, 0 ], [ 2, 2, -1, -2, 0, 0 ], [ 2, 1, -2, -2, 0, 0 ] ], 0.5 ] - ], - [ - [ [ [ 1, 1, -1, -2, 0, 0 ], [ 2, 1, -1, -2, 0, 0 ], [ 3, 1, -2, -2, 0, 0 ], [ 2, 1, -2, -2, 0, 0 ] ], 0 ], - [ [ [ 1, 1, -1, -2, 0, 0 ], [ 2, 1, -1, -2, 0, 0 ], [ 3, 1, -2, -2, 0, 0 ], [ 1, 1, -1, -1, 0, 0 ] ], 0 ], - [ [ [ 1, 1, -1, -2, 0, 0 ], [ 3, 1, -1, -3, 0, 0 ], [ 3, 1, -2, -2, 0, 0 ], [ 1, 1, -1, -1, 0, 0 ] ], 0.25 ], - [ [ [ 1, 1, -1, -2, 0, 0 ], [ 3, 1, -1, -3, 0, 0 ], [ 3, 1, -2, -2, 0, 0 ], [ 2, 1, -1, -2, 0, 0 ] ], 0 ], - [ [ [ 1, 1, -1, -2, 0, 0 ], [ 1, 2, -1, -2, 0, 0 ], [ 3, 1, -2, -2, 0, 0 ], [ 2, 1, -1, -2, 0, 0 ] ], 0.25 ] - ], - [ - [ [ [ 1, 1, -1, -2, 0, 0 ], [ 2, 1, -2, -2, 0, 0 ], [ 3, 1, -2, -2, 0, 0 ], [ 2, 1, -1, -2, 0, 0 ] ], 0 ], - [ [ [ 1, 1, -1, -2, 0, 0 ], [ 2, 1, -2, -2, 0, 0 ], [ 3, 1, -2, -2, 0, 0 ], [ 3, 1, -1, -3, 0, 0 ] ], 0 ], - [ [ [ 1, 1, -1, -2, 0, 0 ], [ 2, 1, -2, -2, 0, 0 ], [ 2, 2, -1, -2, 0, 0 ], [ 3, 1, -1, -3, 0, 0 ] ], 0.5 ], - [ [ [ 1, 1, -1, -2, 0, 0 ], [ 2, 1, -2, -2, 0, 0 ], [ 2, 1, -1, -2, 1, 0 ], [ 3, 1, -1, -3, 0, 0 ] ], 0 ], - [ [ [ 1, 1, -1, -2, 0, 0 ], [ 1, 1, -1, -1, 0, 0 ], [ 2, 1, -1, -2, 1, 0 ], [ 3, 1, -1, -3, 0, 0 ] ], 0.375 ], - [ [ [ 1, 1, -1, -2, 0, 0 ], [ 2, 1, -1, -2, 0, 0 ], [ 2, 1, -1, -2, 1, 0 ], [ 3, 1, -1, -3, 0, 0 ] ], 0 ], - [ [ [ 1, 1, -1, -2, 0, 0 ], [ 2, 1, -1, -2, 0, 0 ], [ 2, 0, -1, -2, 0, 0 ], [ 3, 1, -1, -3, 0, 0 ] ], 0.25 ] - ], - [ - [ [ [ 1, 1, -1, -2, 0, 0 ], [ 1, 1, -1, -2, -1, 0 ], [ 2, 0, -1, -2, 0, 0 ], [ 3, 1, -1, -3, 0, 0 ] ], 0.25 ], - [ [ [ 1, 1, -1, -2, 0, 0 ], [ 1, 1, -1, -2, -1, 0 ], [ 2, 0, -1, -2, 0, 0 ], [ 2, 1, 0, -2, 0, 0 ] ], 0 ], - [ [ [ 1, 1, -1, -2, 0, 0 ], [ 1, 1, -1, -2, -1, 0 ], [ 1, 2, -1, -2, 0, 0 ], [ 2, 1, 0, -2, 0, 0 ] ], 0.5 ], - [ [ [ 1, 1, -1, -2, 0, 0 ], [ 1, 1, -1, -2, -1, 0 ], [ 2, 1, -1, -2, 0, 0 ], [ 2, 1, 0, -2, 0, 0 ] ], 0 ], - [ [ [ 1, 1, -1, -2, 0, 0 ], [ 1, 1, -1, -2, -1, 0 ], [ 2, 1, -1, -2, 0, 0 ], [ 3, 0, -1, -2, 0, 0 ] ], 0.5 ], - [ [ [ 1, 1, -1, -2, 0, 0 ], [ 1, 1, -1, -2, -1, 0 ], [ 2, 1, -1, -2, 0, 0 ], [ 3, 1, -1, -2, -1, 0 ] ], 0.25 ], - [ [ [ 1, 1, -1, -2, 0, 0 ], [ 1, 1, -1, -2, -1, 0 ], [ 2, 1, -1, -2, -1, 0 ], [ 3, 1, -1, -2, -1, 0 ] ], 0.25 ] - ], - [ - [ [ [ 1, 2, -1, -2, -1, 0 ], [ 1, 1, -1, -2, -1, 0 ], [ 2, 1, -1, -2, -1, 0 ], [ 3, 1, -1, -2, -1, 0 ] ], 0.25 ], - [ [ [ 1, 2, -1, -2, -1, 0 ], [ 1, 1, -1, -2, -1, 0 ], [ 2, 1, -1, -2, -1, 0 ], [ 2, 2, -1, -2, -1, 0 ] ], 0.25 ], - [ [ [ 1, 2, -1, -2, -1, 0 ], [ 1, 1, -1, -2, -1, 0 ], [ 3, 1, -1, -3, -1, 0 ], [ 2, 2, -1, -2, -1, 0 ] ], 0.25 ], - [ [ [ 1, 1, -1, -2, -1, 1 ], [ 1, 1, -1, -2, -1, 0 ], [ 3, 1, -1, -3, -1, 0 ], [ 2, 2, -1, -2, -1, 0 ] ], 0 ], - [ [ [ 1, 1, -1, -2, -1, 1 ], [ 1, 1, -1, -2, -1, 0 ], [ 2, 1, 0, -2, -1, 0 ], [ 2, 2, -1, -2, -1, 0 ] ], 0.5 ], - [ [ [ 1, 1, -1, -1, -1, 0 ], [ 1, 1, -1, -2, -1, 0 ], [ 2, 1, 0, -2, -1, 0 ], [ 2, 2, -1, -2, -1, 0 ] ], 0.25 ], - [ [ [ 2, 1, -1, -2, -1, 0 ], [ 1, 1, -1, -2, -1, 0 ], [ 2, 1, 0, -2, -1, 0 ], [ 2, 2, -1, -2, -1, 0 ] ], 0.5 ], - [ [ [ 2, 1, -1, -2, -1, 0 ], [ 1, 1, -1, -2, -1, 0 ], [ 2, 1, 0, -2, -1, 0 ], [ 3, 1, -1, -2, -1, 0 ] ], 0.5 ] - ], - [ - [ [ [ 2, 1, -1, -2, -1, 0 ], [ 1, 1, 0, -2, -1, 0 ], [ 2, 1, 0, -2, -1, 0 ], [ 3, 1, -1, -2, -1, 0 ] ], 0.5 ], - [ [ [ 1, 2, 0, -2, -1, 0 ], [ 1, 1, 0, -2, -1, 0 ], [ 2, 1, 0, -2, -1, 0 ], [ 3, 1, -1, -2, -1, 0 ] ], 0.5 ], - [ [ [ 1, 2, 0, -2, -1, 0 ], [ 1, 1, 0, -2, -1, 0 ], [ 2, 1, 0, -2, -1, 0 ], [ 2, 2, 0, -2, -1, 0 ] ], 0.25 ] - ], - [ - [ [ [ 0, 1, 0, -2, -1, 0 ], [ 1, 1, 0, -2, -1, 0 ], [ 2, 1, 0, -2, -1, 0 ], [ 2, 2, 0, -2, -1, 0 ] ], 0 ], - [ [ [ 0, 1, 0, -2, -1, 0 ], [ 1, 1, 0, -2, -1, 0 ], [ 1, 3, 0, -2, -1, 0 ], [ 2, 2, 0, -2, -1, 0 ] ], 0.5 ], - [ [ [ 0, 1, 0, -2, -1, 0 ], [ 1, 2, 0, -2, -1, 0 ], [ 1, 3, 0, -2, -1, 0 ], [ 2, 2, 0, -2, -1, 0 ] ], 0.25 ], - [ [ [ 0, 1, 0, -2, -1, 0 ], [ 0, 2, 0, -2, -1, 0 ], [ 1, 3, 0, -2, -1, 0 ], [ 2, 2, 0, -2, -1, 0 ] ], 0 ], - [ [ [ -1, 3, 0, -2, -1, 0 ], [ 0, 2, 0, -2, -1, 0 ], [ 1, 3, 0, -2, -1, 0 ], [ 2, 2, 0, -2, -1, 0 ] ], 0.625 ] - ], - [ - [ [ [ -1, 3, 0, -2, -1, 0 ], [ 0, 2, 0, -2, -1, 0 ], [ 1, 2, 0, -2, -1, 0 ], [ 2, 2, 0, -2, -1, 0 ] ], 0.25 ], - [ [ [ -1, 2, 0, -2, -1, 0 ], [ 0, 2, 0, -2, -1, 0 ], [ 1, 2, 0, -2, -1, 0 ], [ 2, 2, 0, -2, -1, 0 ] ], 0 ], - [ [ [ -1, 2, 0, -2, -1, 0 ], [ 0, 2, 0, -2, -1, 0 ], [ 1, 2, 0, -2, -1, 0 ], [ 1, 3, 0, -2, -1, 0 ] ], 0.5 ], - [ [ [ 0, 3, 0, -2, -1, 0 ], [ 0, 2, 0, -2, -1, 0 ], [ 1, 2, 0, -2, -1, 0 ], [ 1, 3, 0, -2, -1, 0 ] ], 0 ], - [ [ [ 0, 3, 0, -2, -1, 0 ], [ 0, 2, 0, -2, -1, 0 ], [ 1, 1, 0, -2, -1, 0 ], [ 1, 3, 0, -2, -1, 0 ] ], 0.25 ], - [ [ [ 0, 3, 0, -2, -1, 0 ], [ 0, 2, 0, -2, -1, 0 ], [ 1, 1, 0, -2, -1, 0 ], [ 1, 2, 0, -2, -1, 0 ] ], 0.5 ], - [ [ [ 0, 3, 0, -2, -1, 0 ], [ 0, 2, 0, -2, -1, 0 ], [ 1, 1, 0, -2, -1, 0 ], [ 2, 1, 0, -2, -1, 0 ] ], 0.5 ] - ], - [ - [ [ [ 0, 3, 0, -2, -1, 0 ], [ 0, 2, 0, -2, -1, 0 ], [ 1, 1, 0, -2, -1, 0 ], [ 2, 2, 0, -2, -1, 0 ] ], 0.25 ], - [ [ [ 2, 1, 0, -2, -1, 0 ], [ 0, 2, 0, -2, -1, 0 ], [ 1, 1, 0, -2, -1, 0 ], [ 2, 2, 0, -2, -1, 0 ] ], 0 ], - [ [ [ 2, 1, 0, -2, -1, 0 ], [ 0, 2, 0, -2, -1, 0 ], [ 1, 2, 0, -2, -1, 0 ], [ 2, 2, 0, -2, -1, 0 ] ], 0.25 ], - [ [ [ 1, 3, 0, -2, -1, 0 ], [ 0, 2, 0, -2, -1, 0 ], [ 1, 2, 0, -2, -1, 0 ], [ 2, 2, 0, -2, -1, 0 ] ], 0 ], - [ [ [ 1, 3, 0, -2, -1, 0 ], [ 0, 2, 0, -2, -1, 0 ], [ 1, 2, 0, -2, -1, 0 ], [ 1, 1, 0, -2, -1, 0 ] ], 0.5 ] - ], - [ - [ [ [ 1, 3, 0, -2, -1, 0 ], [ 0, 2, 0, -2, -1, 0 ], [ 1, 2, 0, -2, -1, 0 ], [ 0, 3, 0, -2, -1, 0 ] ], 0.25 ], - [ [ [ 1, 3, 0, -2, -1, 0 ], [ 1, 2, 0, -3, -1, 0 ], [ 1, 2, 0, -2, -1, 0 ], [ 0, 3, 0, -2, -1, 0 ] ], 0.25 ], - [ [ [ 2, 2, -1, -2, -1, 0 ], [ 1, 2, 0, -3, -1, 0 ], [ 1, 2, 0, -2, -1, 0 ], [ 0, 3, 0, -2, -1, 0 ] ], 0.25 ], - [ [ [ 2, 2, -1, -2, -1, 0 ], [ 1, 2, 0, -3, -1, 0 ], [ 1, 2, 0, -2, -1, 0 ], [ 1, 2, 1, -2, -1, 0 ] ], 0 ], - [ [ [ 2, 2, -1, -2, -1, 0 ], [ 0, 2, 1, -2, -1, 0 ], [ 1, 2, 0, -2, -1, 0 ], [ 1, 2, 1, -2, -1, 0 ] ], 0.25 ], - [ [ [ 2, 2, -1, -2, -1, 0 ], [ 0, 2, 1, -2, -1, 0 ], [ 1, 2, 0, -2, -1, 0 ], [ 1, 3, 0, -2, -1, 0 ] ], 0 ], - [ [ [ 2, 2, -1, -2, -1, 0 ], [ 1, 2, -1, -2, -1, 0 ], [ 1, 2, 0, -2, -1, 0 ], [ 1, 3, 0, -2, -1, 0 ] ], 0.25 ], - [ [ [ 2, 2, -1, -2, -1, 0 ], [ 1, 2, -1, -2, -1, 0 ], [ 1, 2, 0, -2, -1, 0 ], [ 2, 2, 0, -2, -1, 0 ] ], 0.25 ] - ], - [ - [ [ [ 1, 3, 0, -2, -1, 0 ], [ 1, 2, -1, -2, -1, 0 ], [ 1, 2, 0, -2, -1, 0 ], [ 2, 2, 0, -2, -1, 0 ] ], 0 ], - [ [ [ 1, 3, 0, -2, -1, 0 ], [ 1, 2, -1, -2, -1, 0 ], [ 2, 2, 0, -3, -1, 0 ], [ 2, 2, 0, -2, -1, 0 ] ], 0.25 ], - [ [ [ 1, 3, 0, -2, -1, 0 ], [ 0, 2, 0, -2, -1, 0 ], [ 2, 2, 0, -3, -1, 0 ], [ 2, 2, 0, -2, -1, 0 ] ], 0 ], - [ [ [ 1, 3, 0, -2, -1, 0 ], [ 0, 2, 0, -2, -1, 0 ], [ 0, 3, 0, -2, -1, 0 ], [ 2, 2, 0, -2, -1, 0 ] ], 0.25 ], - [ [ [ 1, 3, 0, -2, -1, 0 ], [ 0, 2, 0, -2, -1, 0 ], [ 1, 2, -1, -2, -1, 0 ], [ 2, 2, 0, -2, -1, 0 ] ], 0 ], - [ [ [ 1, 3, 0, -2, -1, 0 ], [ 0, 3, 0, -2, -1, 0 ], [ 1, 2, -1, -2, -1, 0 ], [ 2, 2, 0, -2, -1, 0 ] ], 0 ], - [ [ [ 2, 2, -1, -2, -1, 0 ], [ 0, 3, 0, -2, -1, 0 ], [ 1, 2, -1, -2, -1, 0 ], [ 2, 2, 0, -2, -1, 0 ] ], 0.25 ] - ], - [ - [ [ [ 1, 2, 0, -2, -1, 0 ], [ 0, 3, 0, -2, -1, 0 ], [ 1, 2, -1, -2, -1, 0 ], [ 2, 2, 0, -2, -1, 0 ] ], 0 ], - [ [ [ 1, 2, 0, -2, -1, 0 ], [ 0, 3, 0, -2, -1, 0 ], [ 1, 2, -1, -2, -1, 0 ], [ 1, 2, -1, -1, -1, 0 ] ], 0 ], - [ [ [ 1, 2, 0, -2, -1, 0 ], [ 1, 2, -1, -2, -1, -1 ], [ 1, 2, -1, -2, -1, 0 ], [ 1, 2, -1, -1, -1, 0 ] ], 0.25 ], - [ [ [ 1, 2, 0, -2, -1, 0 ], [ 1, 2, -1, -2, -1, -1 ], [ 1, 2, -1, -2, -1, 0 ], [ 2, 2, -1, -2, -1, 0 ] ], 0 ], - [ [ [ 2, 1, -1, -2, -1, 0 ], [ 1, 2, -1, -2, -1, -1 ], [ 1, 2, -1, -2, -1, 0 ], [ 2, 2, -1, -2, -1, 0 ] ], 0.5 ], - [ [ [ 2, 2, -1, -2, -1, -1 ], [ 1, 2, -1, -2, -1, -1 ], [ 1, 2, -1, -2, -1, 0 ], [ 2, 2, -1, -2, -1, 0 ] ], 0 ], - [ [ [ 2, 2, -1, -2, -1, -1 ], [ 1, 2, -1, -2, -1, -1 ], [ 1, 2, -1, -2, -1, 0 ], [ 2, 3, -1, -2, -1, 0 ] ], 0.5 ] - ], - [ - [ [ [ 2, 2, -1, -2, -1, -1 ], [ 1, 2, -1, -2, -1, -1 ], [ 1, 3, -1, -2, -1, -1 ], [ 2, 3, -1, -2, -1, 0 ] ], 0 ], - [ [ [ 2, 2, -1, -2, -1, -1 ], [ -1, 3, -1, -1, -1, 0 ], [ 1, 3, -1, -2, -1, -1 ], [ 2, 3, -1, -2, -1, 0 ] ], 0 ], - [ [ [ 0, 3, -1, -1, -1, 0 ], [ -1, 3, -1, -1, -1, 0 ], [ 1, 3, -1, -2, -1, -1 ], [ 2, 3, -1, -2, -1, 0 ] ], 0.25 ], - [ [ [ 1, 3, -1, -2, -1, 0 ], [ -1, 3, -1, -1, -1, 0 ], [ 1, 3, -1, -2, -1, -1 ], [ 2, 3, -1, -2, -1, 0 ] ], 0 ], - [ [ [ 1, 3, -1, -2, -1, 0 ], [ 0, 3, -1, -2, -1, 0 ], [ 1, 3, -1, -2, -1, -1 ], [ 2, 3, -1, -2, -1, 0 ] ], 0.25 ] - ] - ] -], -"last_changes": -[ - [ [ 2, 2, -1, -2, -1, -1 ], [ 1, 2, -1, -2, -1, -1 ], [ 1, 3, -1, -2, -1, -1 ], [ 2, 3, -1, -2, -1, 0 ] ], - [ [ 2, 2, -1, -2, -1, -1 ], [ -1, 3, -1, -1, -1, 0 ], [ 1, 3, -1, -2, -1, -1 ], [ 2, 3, -1, -2, -1, 0 ] ], - [ [ 0, 3, -1, -1, -1, 0 ], [ -1, 3, -1, -1, -1, 0 ], [ 1, 3, -1, -2, -1, -1 ], [ 2, 3, -1, -2, -1, 0 ] ], - [ [ 1, 3, -1, -2, -1, 0 ], [ -1, 3, -1, -1, -1, 0 ], [ 1, 3, -1, -2, -1, -1 ], [ 2, 3, -1, -2, -1, 0 ] ], - [ [ 1, 3, -1, -2, -1, 0 ], [ 0, 3, -1, -2, -1, 0 ], [ 1, 3, -1, -2, -1, -1 ], [ 2, 3, -1, -2, -1, 0 ] ] -], -"cur_uid": "tmp", -"ref_uid": "nil", -"order_seed": 482760, -"dur_seed": 662444, -"motifs_seed": 696864, -"entrances_probs_vals": [ 0.63, 0, 0, 0, 1, 0.019607843137255, 0, 0.2156862745098, 0, 0.2516339869281, 0.76351351351351, 0.31045751633987, 0, 0.44771241830065, 0, 0.50653594771242, 0.41216216216216, 0.5359477124183, 0, 1, 0 ], -"passages_probs_vals": [ 0.63, 0, 0, 0, 1, 0.019607843137255, 0, 0.2156862745098, 0, 0.2516339869281, 0.76351351351351, 0.31045751633987, 0, 0.44771241830065, 0, 0.50653594771242, 0.41216216216216, 0.5359477124183, 0, 1, 0 ], -"exits_probs_vals": [ 0.63, 0, 0, 0, 1, 0.019607843137255, 0, 0.2156862745098, 0, 0.2516339869281, 0.76351351351351, 0.31045751633987, 0, 0.44771241830065, 0, 0.50653594771242, 0.41216216216216, 0.5359477124183, 0, 1, 0 ], -"ranges": [ [ -2400, 1200 ], [ -1200, 1453 ], [ -702, 1694 ], [ -702, 1973 ] ], -"step_probs_vals": [ -1200, 1200, 0.0041152263374486, 0.0056818181818179, 0.080246913580247, 0.02840909090909, 0.20781893004115, 0.028409090909091, 0.41152263374486, 0, 0.44650205761317, 0.16477272727273, 0.47736625514403, 0, 0.53086419753086, 0, 0.54320987654321, 0.92045454545455, 0.58641975308642, 0.92613636363636, 0.61111111111111, 0, 0.7880658436214, 0.034090909090909, 1, 0.034090909090909 ], -"passages_weights": [ 0.58, 1, 0.43, 1, 0.82 ], -"hd_exp": 10, -"hd_invert": 0, -"order": -[ - [ [ 3 ], [ 0, 2, 1, 1 ], [ ] ], - [ [ 1 ], [ 3, 0, 2, 0, 0, 3 ], [ ] ], - [ [ 2 ], [ 1, 0, 3, 1 ], [ ] ], - [ [ 3 ], [ 2, 1, 0, 1 ], [ ] ], - [ [ 2 ], [ 1, 0, 3 ], [ ] ], - [ [ 3 ], [ 0, 2, 1, 0 ], [ ] ], - [ [ 2 ], [ 3, 1, 0, 0, 3, 0, 0, 3 ], [ ] ], - [ [ 1 ], [ 3, 0, 2, 0 ], [ ] ], - [ [ 0 ], [ 3, 1, 2, 1 ], [ ] ], - [ [ 0 ], [ 1, 3, 2 ], [ ] ], - [ [ 0 ], [ 2, 3, 1, 1, 3, 2, 3, 2 ], [ ] ], - [ [ 3 ], [ 2, 0, 1, 2, 2, 2, 0, 2 ], [ ] ], - [ [ 3 ], [ 0, 2, 1, 2, 1, 1, 0 ], [ ] ], - [ [ 3 ], [ 2, 0, 1 ], [ ] ], - [ [ 2 ], [ 0, 3, 1, 3, 0, 0, 1 ], [ ] ], - [ [ 1 ], [ 0, 3, 2 ], [ ] ], - [ [ 0 ], [ 2, 3, 1, 3, 1 ], [ ] ], - [ [ 0 ], [ 1, 3, 2, 2, 1, 1, 2 ], [ ] ], - [ [ 0 ], [ 1, 3, 2, 2, 3, 3, 2 ], [ ] ], - [ [ 1 ], [ 0, 3, 2, 0, 2, 0, 0, 3 ], [ ] ], - [ [ 2 ], [ 1, 0, 3 ], [ ] ], - [ [ 3 ], [ 0, 2, 1, 1, 0 ], [ ] ], - [ [ 1 ], [ 2, 0, 3, 0, 2, 3, 3 ], [ ] ], - [ [ 1 ], [ 3, 0, 2, 0, 3 ], [ ] ], - [ [ 2 ], [ 3, 1, 0, 3, 1, 3, 1, 3 ], [ ] ], - [ [ 3 ], [ 0, 2, 1, 2, 2, 1, 0 ], [ ] ], - [ [ 2 ], [ 0, 3, 1, 3, 0, 0, 3 ], [ ] ], - [ [ 3 ], [ 2, 1, 0, 0, 1 ], [ ] ] -], -"sus_weights": [ 0.69, 0, 0 ], -"order_size": [ 28, 28.275510204082 ], -"passages_size": [ 0, 6 ], -"motif_edited": "false", -"order_edited": "false" -} \ No newline at end of file diff --git a/resources/string_quartet_2/60adbbef/lilypond/part_I.ly b/resources/string_quartet_2/60adbbef/lilypond/part_I.ly index 745ebef..91557ba 100644 --- a/resources/string_quartet_2/60adbbef/lilypond/part_I.ly +++ b/resources/string_quartet_2/60adbbef/lilypond/part_I.ly @@ -19,12 +19,6 @@ \bar "|" { a'2 r2 } \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } + { r1 \fermata^8 } \bar "||" } \ No newline at end of file diff --git a/resources/string_quartet_2/60adbbef/lilypond/part_II.ly b/resources/string_quartet_2/60adbbef/lilypond/part_II.ly index e2312d8..cfe133c 100644 --- a/resources/string_quartet_2/60adbbef/lilypond/part_II.ly +++ b/resources/string_quartet_2/60adbbef/lilypond/part_II.ly @@ -20,11 +20,5 @@ { e'2 r2 } \bar "|" { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } \bar "||" } \ No newline at end of file diff --git a/resources/string_quartet_2/60adbbef/lilypond/part_III.ly b/resources/string_quartet_2/60adbbef/lilypond/part_III.ly index e27bd19..73127e7 100644 --- a/resources/string_quartet_2/60adbbef/lilypond/part_III.ly +++ b/resources/string_quartet_2/60adbbef/lilypond/part_III.ly @@ -20,11 +20,5 @@ { cis'2 r2 } \bar "|" { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } \bar "||" } \ No newline at end of file diff --git a/resources/string_quartet_2/60adbbef/lilypond/part_IV.ly b/resources/string_quartet_2/60adbbef/lilypond/part_IV.ly index c144b19..3eb2077 100644 --- a/resources/string_quartet_2/60adbbef/lilypond/part_IV.ly +++ b/resources/string_quartet_2/60adbbef/lilypond/part_IV.ly @@ -20,11 +20,5 @@ { a,2 r2 } \bar "|" { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } \bar "||" } \ No newline at end of file diff --git a/resources/string_quartet_2/74b8f8d9/lilypond/part_I.ly b/resources/string_quartet_2/74b8f8d9/lilypond/part_I.ly index 607f119..6b1515c 100644 --- a/resources/string_quartet_2/74b8f8d9/lilypond/part_I.ly +++ b/resources/string_quartet_2/74b8f8d9/lilypond/part_I.ly @@ -27,12 +27,6 @@ \bar "|" { d'8.[ r16] r2. } \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } + { r1\fermata^8 } \bar "||" } \ No newline at end of file diff --git a/resources/string_quartet_2/74b8f8d9/lilypond/part_II.ly b/resources/string_quartet_2/74b8f8d9/lilypond/part_II.ly index 16c2d82..ea84dfa 100644 --- a/resources/string_quartet_2/74b8f8d9/lilypond/part_II.ly +++ b/resources/string_quartet_2/74b8f8d9/lilypond/part_II.ly @@ -28,11 +28,5 @@ { fis'8.[ r16] r2. } \bar "|" { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } \bar "||" } \ No newline at end of file diff --git a/resources/string_quartet_2/74b8f8d9/lilypond/part_III.ly b/resources/string_quartet_2/74b8f8d9/lilypond/part_III.ly index d5db128..f0bc9d8 100644 --- a/resources/string_quartet_2/74b8f8d9/lilypond/part_III.ly +++ b/resources/string_quartet_2/74b8f8d9/lilypond/part_III.ly @@ -28,11 +28,5 @@ { f8.[ r16] r2. } \bar "|" { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } \bar "||" } \ No newline at end of file diff --git a/resources/string_quartet_2/74b8f8d9/lilypond/part_IV.ly b/resources/string_quartet_2/74b8f8d9/lilypond/part_IV.ly index 1aeccc8..4267347 100644 --- a/resources/string_quartet_2/74b8f8d9/lilypond/part_IV.ly +++ b/resources/string_quartet_2/74b8f8d9/lilypond/part_IV.ly @@ -28,11 +28,5 @@ { a,8.[ r16] r2. } \bar "|" { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } - \bar "|" - { r1 } \bar "||" } \ No newline at end of file diff --git a/resources/string_quartet_3_rise_coda_only.json b/resources/string_quartet_3_rise_coda_only.json index 8dee13f..e73fbfc 100644 --- a/resources/string_quartet_3_rise_coda_only.json +++ b/resources/string_quartet_3_rise_coda_only.json @@ -13,6 +13,7 @@ "5ef20586", "4dd2a130", "767e70f0", - "536cac90" + "536cac90", + "5ededd80" ] } \ No newline at end of file diff --git a/resources/string_quartet_3_rise_coda_only/4dd2a130/4dd2a130_mus_model.json b/resources/string_quartet_3_rise_coda_only/4dd2a130/4dd2a130_mus_model.json index bf4b64e..65401bc 100644 --- a/resources/string_quartet_3_rise_coda_only/4dd2a130/4dd2a130_mus_model.json +++ b/resources/string_quartet_3_rise_coda_only/4dd2a130/4dd2a130_mus_model.json @@ -3,29 +3,29 @@ [ [ [ - [ [ [ -5, 5, 1, 2, -1, 2 ], [ -5, 3, 1, 2, -1, 2 ], [ -4, 4, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0.25 ], - [ [ [ -5, 5, 1, 2, -1, 2 ], [ -5, 3, 1, 2, -1, 2 ], [ -6, 5, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0.25 ], - [ [ [ -4, 4, 0, 2, -1, 2 ], [ -5, 3, 1, 2, -1, 2 ], [ -6, 5, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0 ], - [ [ [ -4, 4, 0, 2, -1, 2 ], [ -5, 3, 1, 2, -1, 2 ], [ -5, 4, 0, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0.25 ], - [ [ [ -4, 4, 0, 2, -1, 2 ], [ -5, 3, 1, 2, -1, 2 ], [ -4, 3, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0.25 ], - [ [ [ -4, 4, 0, 2, -1, 2 ], [ -6, 5, 1, 2, -1, 2 ], [ -4, 3, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0.25 ], - [ [ [ -4, 4, 0, 2, -1, 2 ], [ -6, 5, 1, 2, -1, 2 ], [ -5, 5, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0.25 ] + [ [ [ -6, 5, 1, 2, -1, 2 ], [ -5, 3, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0.25 ], + [ [ [ -6, 5, 1, 2, -1, 2 ], [ -5, 3, 1, 2, -1, 2 ], [ -6, 5, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0.25 ], + [ [ [ -5, 4, 0, 2, -1, 2 ], [ -5, 3, 1, 2, -1, 2 ], [ -6, 5, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0 ], + [ [ [ -5, 4, 0, 2, -1, 2 ], [ -5, 3, 1, 2, -1, 2 ], [ -5, 4, 0, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0.25 ], + [ [ [ -5, 4, 0, 2, -1, 2 ], [ -5, 3, 1, 2, -1, 2 ], [ -4, 3, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0.25 ], + [ [ [ -5, 4, 0, 2, -1, 2 ], [ -6, 5, 1, 2, -1, 2 ], [ -4, 3, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0.25 ], + [ [ [ -5, 4, 0, 2, -1, 2 ], [ -6, 5, 1, 2, -1, 2 ], [ -5, 5, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0.25 ] ], [ - [ [ [ -4, 4, 0, 2, -1, 2 ], [ -5, 4, 0, 2, -1, 2 ], [ -5, 5, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0 ], - [ [ [ -4, 4, 0, 2, -1, 2 ], [ -5, 4, 0, 2, -1, 2 ], [ -4, 4, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0.25 ], - [ [ [ -4, 4, 0, 2, -1, 2 ], [ -6, 4, 1, 2, -1, 2 ], [ -4, 4, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0.25 ] + [ [ [ -5, 4, 0, 2, -1, 2 ], [ -5, 4, 0, 2, -1, 2 ], [ -5, 5, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0 ], + [ [ [ -5, 4, 0, 2, -1, 2 ], [ -5, 4, 0, 2, -1, 2 ], [ -4, 4, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0.25 ], + [ [ [ -5, 4, 0, 2, -1, 2 ], [ -6, 4, 1, 2, -1, 2 ], [ -4, 4, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0.25 ] ], [ - [ [ [ -4, 4, 0, 2, -1, 2 ], [ -6, 4, 1, 2, -1, 2 ], [ -5, 4, 0, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0.25 ], - [ [ [ -4, 4, 0, 2, -1, 2 ], [ -5, 4, 1, 1, -1, 2 ], [ -5, 4, 0, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0 ], - [ [ [ -5, 5, 1, 2, -1, 2 ], [ -5, 4, 1, 1, -1, 2 ], [ -5, 4, 0, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0.25 ] + [ [ [ -5, 4, 0, 2, -1, 2 ], [ -6, 4, 1, 2, -1, 2 ], [ -4, 4, 0, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0.25 ], + [ [ [ -5, 4, 0, 2, -1, 2 ], [ -5, 4, 1, 1, -1, 2 ], [ -4, 4, 0, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0 ], + [ [ [ -6, 5, 1, 2, -1, 2 ], [ -5, 4, 1, 1, -1, 2 ], [ -4, 4, 0, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0.25 ] ], [ - [ [ [ -5, 4, 1, 2, -1, 3 ], [ -5, 4, 1, 1, -1, 2 ], [ -5, 4, 0, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0 ], - [ [ [ -5, 4, 1, 2, -1, 3 ], [ -5, 4, -1, 2, -1, 2 ], [ -5, 4, 0, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0.25 ], - [ [ [ -5, 4, 1, 2, -1, 3 ], [ -5, 3, 1, 2, -1, 2 ], [ -5, 4, 0, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0 ], - [ [ [ -4, 3, 1, 2, -1, 2 ], [ -5, 3, 1, 2, -1, 2 ], [ -5, 4, 0, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0.25 ] + [ [ [ -6, 4, 1, 2, -1, 3 ], [ -5, 4, 1, 1, -1, 2 ], [ -4, 4, 0, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0 ], + [ [ [ -6, 4, 1, 2, -1, 3 ], [ -5, 4, -1, 2, -1, 2 ], [ -4, 4, 0, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0.25 ], + [ [ [ -6, 4, 1, 2, -1, 3 ], [ -5, 3, 1, 2, -1, 2 ], [ -4, 4, 0, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0 ], + [ [ [ -5, 3, 1, 2, -1, 2 ], [ -5, 3, 1, 2, -1, 2 ], [ -4, 4, 0, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0.25 ] ] ] ], diff --git a/resources/string_quartet_3_rise_coda_only/4dd2a130/lilypond/part_II.ly b/resources/string_quartet_3_rise_coda_only/4dd2a130/lilypond/part_II.ly index 702338f..d5acdbf 100644 --- a/resources/string_quartet_3_rise_coda_only/4dd2a130/lilypond/part_II.ly +++ b/resources/string_quartet_3_rise_coda_only/4dd2a130/lilypond/part_II.ly @@ -1,6 +1,6 @@ { - { f''8^\markup { \pad-markup #0.2 "-38"}[ c'8^\markup { \pad-markup #0.2 "-37"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }}] cis'8^\markup { \pad-markup #0.2 "-25"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }}[ ais'8^\markup { \pad-markup #0.2 "-40"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }}] ~ ais'8[ c''8^\markup { \pad-markup #0.2 "-37"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }}] f''4^\markup { \pad-markup #0.2 "-38"} } + { f'8^\markup { \pad-markup #0.2 "-38"}[ c'8^\markup { \pad-markup #0.2 "-37"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }}] cis'8^\markup { \pad-markup #0.2 "-25"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }}[ ais'8^\markup { \pad-markup #0.2 "-40"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }}] ~ ais'8[ c''8^\markup { \pad-markup #0.2 "-37"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }}] f''4^\markup { \pad-markup #0.2 "-38"} } \bar "|" - { cis'1^\markup { \pad-markup #0.2 "-25"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }}} + { cis''1^\markup { \pad-markup #0.2 "-25"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }}} \bar "||" } \ No newline at end of file diff --git a/resources/string_quartet_3_rise_coda_only/4dd2a130/lilypond/part_IV.ly b/resources/string_quartet_3_rise_coda_only/4dd2a130/lilypond/part_IV.ly index 74ec7e4..e73d174 100644 --- a/resources/string_quartet_3_rise_coda_only/4dd2a130/lilypond/part_IV.ly +++ b/resources/string_quartet_3_rise_coda_only/4dd2a130/lilypond/part_IV.ly @@ -1,6 +1,6 @@ { - { c''4^\markup { \pad-markup #0.2 "-37"} cis''2.^\markup { \pad-markup #0.2 "-25"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 5↓" }} ~ } + { c'4^\markup { \pad-markup #0.2 "-37"} cis'2.^\markup { \pad-markup #0.2 "-25"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 5↓" }} ~ } \bar "|" - { cis''8[ c''8^\markup { \pad-markup #0.2 "-37"}] cis''8^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 13↑" }}[ ais'8^\markup { \pad-markup #0.2 "-40"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }}] ~ ais'2} + { cis'8[ c'8^\markup { \pad-markup #0.2 "-37"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↑" }}] cis'8^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 13↑" }}[ ais8^\markup { \pad-markup #0.2 "-40"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }}] ~ ais2} \bar "||" } \ No newline at end of file diff --git a/resources/string_quartet_3_rise_coda_only/50c2b0ad/50c2b0ad_mus_model.json b/resources/string_quartet_3_rise_coda_only/50c2b0ad/50c2b0ad_mus_model.json index 10eff06..e91ef34 100644 --- a/resources/string_quartet_3_rise_coda_only/50c2b0ad/50c2b0ad_mus_model.json +++ b/resources/string_quartet_3_rise_coda_only/50c2b0ad/50c2b0ad_mus_model.json @@ -25,34 +25,34 @@ [ [ [ -4, 4, -1, 1, -2, 2 ], [ -4, 4, 0, 2, -2, 2 ], [ -4, 5, -1, 2, -2, 2 ], [ -4, 4, -1, 2, -2, 2 ] ], 0 ], [ [ [ -5, 4, 0, 2, -2, 2 ], [ -4, 4, 0, 2, -2, 2 ], [ -4, 5, -1, 2, -2, 2 ], [ -4, 4, -1, 2, -2, 2 ] ], 0.25 ], [ [ [ -5, 4, -1, 2, -2, 2 ], [ -4, 4, 0, 2, -2, 2 ], [ -4, 5, -1, 2, -2, 2 ], [ -4, 4, -1, 2, -2, 2 ] ], 0 ], - [ [ [ -5, 4, -1, 2, -2, 2 ], [ -4, 3, -1, 2, -2, 2 ], [ -4, 5, -1, 2, -2, 2 ], [ -4, 4, -1, 2, -2, 2 ] ], 0.25 ], - [ [ [ -5, 4, -1, 2, -2, 2 ], [ -5, 5, -1, 2, -2, 2 ], [ -4, 5, -1, 2, -2, 2 ], [ -4, 4, -1, 2, -2, 2 ] ], 0.25 ], - [ [ [ -5, 4, -1, 2, -2, 2 ], [ -4, 3, -1, 2, -2, 2 ], [ -4, 5, -1, 2, -2, 2 ], [ -4, 4, -1, 2, -2, 2 ] ], 0.25 ] + [ [ [ -5, 4, -1, 2, -2, 2 ], [ -3, 3, -1, 2, -2, 2 ], [ -4, 5, -1, 2, -2, 2 ], [ -4, 4, -1, 2, -2, 2 ] ], 0.25 ], + [ [ [ -5, 4, -1, 2, -2, 2 ], [ -4, 5, -1, 2, -2, 2 ], [ -4, 5, -1, 2, -2, 2 ], [ -4, 4, -1, 2, -2, 2 ] ], 0.25 ], + [ [ [ -5, 4, -1, 2, -2, 2 ], [ -3, 3, -1, 2, -2, 2 ], [ -4, 5, -1, 2, -2, 2 ], [ -4, 4, -1, 2, -2, 2 ] ], 0.25 ] ], [ - [ [ [ -5, 4, -1, 2, -2, 2 ], [ -5, 5, -1, 2, -2, 2 ], [ -4, 5, -1, 2, -2, 2 ], [ -4, 4, -1, 2, -2, 2 ] ], 0.25 ], - [ [ [ -5, 4, -1, 2, -2, 2 ], [ -5, 5, -1, 2, -2, 2 ], [ -3, 4, -1, 2, -2, 2 ], [ -4, 4, -1, 2, -2, 2 ] ], 0 ], - [ [ [ -4, 5, -1, 2, -2, 2 ], [ -5, 5, -1, 2, -2, 2 ], [ -3, 4, -1, 2, -2, 2 ], [ -4, 4, -1, 2, -2, 2 ] ], 0.25 ], - [ [ [ -4, 5, -1, 2, -2, 2 ], [ -5, 5, -1, 2, -2, 2 ], [ -2, 4, -1, 1, -2, 2 ], [ -4, 4, -1, 2, -2, 2 ] ], 0.25 ], - [ [ [ -4, 5, -1, 2, -2, 2 ], [ -5, 5, -1, 2, -2, 2 ], [ -3, 4, -1, 2, -2, 2 ], [ -4, 4, -1, 2, -2, 2 ] ], 0 ], - [ [ [ -4, 5, -1, 2, -2, 2 ], [ -4, 3, -1, 2, -2, 2 ], [ -3, 4, -1, 2, -2, 2 ], [ -4, 4, -1, 2, -2, 2 ] ], 0.25 ], - [ [ [ -4, 5, -1, 2, -2, 2 ], [ -4, 3, -1, 2, -2, 2 ], [ -3, 3, -1, 2, -2, 2 ], [ -4, 4, -1, 2, -2, 2 ] ], 0.25 ] + [ [ [ -5, 4, -1, 2, -2, 2 ], [ -4, 5, -1, 2, -2, 2 ], [ -4, 5, -1, 2, -2, 2 ], [ -4, 4, -1, 2, -2, 2 ] ], 0.25 ], + [ [ [ -5, 4, -1, 2, -2, 2 ], [ -4, 5, -1, 2, -2, 2 ], [ -3, 4, -1, 2, -2, 2 ], [ -4, 4, -1, 2, -2, 2 ] ], 0 ], + [ [ [ -5, 5, -1, 2, -2, 2 ], [ -4, 5, -1, 2, -2, 2 ], [ -3, 4, -1, 2, -2, 2 ], [ -4, 4, -1, 2, -2, 2 ] ], 0.25 ], + [ [ [ -5, 5, -1, 2, -2, 2 ], [ -4, 5, -1, 2, -2, 2 ], [ -2, 4, -1, 1, -2, 2 ], [ -4, 4, -1, 2, -2, 2 ] ], 0.25 ], + [ [ [ -5, 5, -1, 2, -2, 2 ], [ -4, 5, -1, 2, -2, 2 ], [ -3, 4, -1, 2, -2, 2 ], [ -4, 4, -1, 2, -2, 2 ] ], 0 ], + [ [ [ -5, 5, -1, 2, -2, 2 ], [ -3, 3, -1, 2, -2, 2 ], [ -3, 4, -1, 2, -2, 2 ], [ -4, 4, -1, 2, -2, 2 ] ], 0.25 ], + [ [ [ -5, 5, -1, 2, -2, 2 ], [ -3, 3, -1, 2, -2, 2 ], [ -3, 3, -1, 2, -2, 2 ], [ -4, 4, -1, 2, -2, 2 ] ], 0.25 ] ], [ - [ [ [ -4, 5, -1, 2, -2, 2 ], [ -5, 4, 0, 2, -2, 2 ], [ -3, 3, -1, 2, -2, 2 ], [ -4, 4, -1, 2, -2, 2 ] ], 0 ], - [ [ [ -4, 5, -1, 2, -2, 2 ], [ -5, 4, 0, 2, -2, 2 ], [ -4, 4, 0, 2, -2, 2 ], [ -4, 4, -1, 2, -2, 2 ] ], 0.25 ], - [ [ [ -4, 5, -1, 2, -2, 2 ], [ -5, 4, -1, 2, -2, 2 ], [ -4, 4, 0, 2, -2, 2 ], [ -4, 4, -1, 2, -2, 2 ] ], 0.25 ] + [ [ [ -5, 5, -1, 2, -2, 2 ], [ -4, 4, 0, 2, -2, 2 ], [ -3, 3, -1, 2, -2, 2 ], [ -4, 4, -1, 2, -2, 2 ] ], 0 ], + [ [ [ -5, 5, -1, 2, -2, 2 ], [ -4, 4, 0, 2, -2, 2 ], [ -4, 4, 0, 2, -2, 2 ], [ -4, 4, -1, 2, -2, 2 ] ], 0.25 ], + [ [ [ -5, 5, -1, 2, -2, 2 ], [ -3, 4, -1, 2, -2, 2 ], [ -4, 4, 0, 2, -2, 2 ], [ -4, 4, -1, 2, -2, 2 ] ], 0.25 ] ], [ - [ [ [ -4, 5, -1, 2, -2, 2 ], [ -5, 4, -1, 2, -2, 2 ], [ -5, 5, -1, 2, -2, 2 ], [ -4, 4, -1, 2, -2, 2 ] ], 0 ], - [ [ [ -4, 5, -1, 2, -2, 2 ], [ -3, 4, -1, 2, -2, 2 ], [ -5, 5, -1, 2, -2, 2 ], [ -4, 4, -1, 2, -2, 2 ] ], 0 ], - [ [ [ -3, 3, -1, 2, -2, 2 ], [ -3, 4, -1, 2, -2, 2 ], [ -5, 5, -1, 2, -2, 2 ], [ -4, 4, -1, 2, -2, 2 ] ], 0.25 ] + [ [ [ -5, 5, -1, 2, -2, 2 ], [ -3, 4, -1, 2, -2, 2 ], [ -5, 5, -1, 2, -2, 2 ], [ -4, 4, -1, 2, -2, 2 ] ], 0 ], + [ [ [ -5, 5, -1, 2, -2, 2 ], [ -3, 4, -1, 2, -2, 2 ], [ -5, 5, -1, 2, -2, 2 ], [ -4, 4, -1, 2, -2, 2 ] ], 0 ], + [ [ [ -4, 3, -1, 2, -2, 2 ], [ -3, 4, -1, 2, -2, 2 ], [ -5, 5, -1, 2, -2, 2 ], [ -4, 4, -1, 2, -2, 2 ] ], 0.25 ] ], [ - [ [ [ -4, 4, 0, 2, -2, 2 ], [ -3, 4, -1, 2, -2, 2 ], [ -5, 5, -1, 2, -2, 2 ], [ -4, 4, -1, 2, -2, 2 ] ], 0 ], - [ [ [ -4, 4, 0, 2, -2, 2 ], [ -4, 5, 0, 2, -2, 2 ], [ -5, 5, -1, 2, -2, 2 ], [ -4, 4, -1, 2, -2, 2 ] ], 0.25 ], - [ [ [ -4, 4, 0, 2, -2, 2 ], [ -4, 4, -1, 3, -2, 2 ], [ -5, 5, -1, 2, -2, 2 ], [ -4, 4, -1, 2, -2, 2 ] ], 0 ], - [ [ [ -4, 4, -1, 2, -1, 2 ], [ -4, 4, -1, 3, -2, 2 ], [ -5, 5, -1, 2, -2, 2 ], [ -4, 4, -1, 2, -2, 2 ] ], 0.25 ] + [ [ [ -5, 4, 0, 2, -2, 2 ], [ -3, 4, -1, 2, -2, 2 ], [ -5, 5, -1, 2, -2, 2 ], [ -4, 4, -1, 2, -2, 2 ] ], 0 ], + [ [ [ -5, 4, 0, 2, -2, 2 ], [ -4, 5, 0, 2, -2, 2 ], [ -5, 5, -1, 2, -2, 2 ], [ -4, 4, -1, 2, -2, 2 ] ], 0.25 ], + [ [ [ -5, 4, 0, 2, -2, 2 ], [ -4, 4, -1, 3, -2, 2 ], [ -5, 5, -1, 2, -2, 2 ], [ -4, 4, -1, 2, -2, 2 ] ], 0 ], + [ [ [ -5, 4, -1, 2, -1, 2 ], [ -4, 4, -1, 3, -2, 2 ], [ -5, 5, -1, 2, -2, 2 ], [ -4, 4, -1, 2, -2, 2 ] ], 0.25 ] ] ] ], diff --git a/resources/string_quartet_3_rise_coda_only/50c2b0ad/lilypond/part_III.ly b/resources/string_quartet_3_rise_coda_only/50c2b0ad/lilypond/part_III.ly index 2c18edf..33029d2 100644 --- a/resources/string_quartet_3_rise_coda_only/50c2b0ad/lilypond/part_III.ly +++ b/resources/string_quartet_3_rise_coda_only/50c2b0ad/lilypond/part_III.ly @@ -1,8 +1,8 @@ { { d'8^\markup { \pad-markup #0.2 "-18"}[ dis'8^\markup { \pad-markup #0.2 "+38"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }}] e'8^\markup { \pad-markup #0.2 "-14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↑" }}[ fis'8^\markup { \pad-markup #0.2 "-31"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↓" }}] ~ fis'2 ~ } \bar "|" - { fis'8[ g'8^\markup { \pad-markup #0.2 "+24"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 5↑" }}] gis8^\markup { \pad-markup #0.2 "+36"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }}[ ais8^\markup { \pad-markup #0.2 "+40"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 1↑" }}] gis8^\markup { \pad-markup #0.2 "+36"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }}[ ais8^\markup { \pad-markup #0.2 "+40"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 1↑" }}] ~ ais4 } + { fis'8[ g'8^\markup { \pad-markup #0.2 "+24"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 5↑" }}] gis'8^\markup { \pad-markup #0.2 "+36"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }}[ ais'8^\markup { \pad-markup #0.2 "+40"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 1↑" }}] gis'8^\markup { \pad-markup #0.2 "+36"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }}[ ais'8^\markup { \pad-markup #0.2 "+40"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 1↑" }}] ~ ais'4 } \bar "|" - { gis4^\markup { \pad-markup #0.2 "+36"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↓" }} g8^\markup { \pad-markup #0.2 "+24"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 5↑" }}[ dis8^\markup { \pad-markup #0.2 "+38"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }}] dis''8^\markup { \pad-markup #0.2 "+38"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }}[ d''8^\markup { \pad-markup #0.2 "+26"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }}] cis''4^\markup { \pad-markup #0.2 "+6"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 7↑" }}} + { gis'4^\markup { \pad-markup #0.2 "+36"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↓" }} g'8^\markup { \pad-markup #0.2 "+24"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 5↑" }}[ dis''8^\markup { \pad-markup #0.2 "+38"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }}] ~ dis''8[ d''8^\markup { \pad-markup #0.2 "+26"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }}] cis''4^\markup { \pad-markup #0.2 "+6"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 7↑" }}} \bar "||" } \ No newline at end of file diff --git a/resources/string_quartet_3_rise_coda_only/50c2b0ad/lilypond/part_IV.ly b/resources/string_quartet_3_rise_coda_only/50c2b0ad/lilypond/part_IV.ly index 5f683d4..99f1bb0 100644 --- a/resources/string_quartet_3_rise_coda_only/50c2b0ad/lilypond/part_IV.ly +++ b/resources/string_quartet_3_rise_coda_only/50c2b0ad/lilypond/part_IV.ly @@ -1,8 +1,8 @@ { { ais2^\markup { \pad-markup #0.2 "+40"} fis2^\markup { \pad-markup #0.2 "-31"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }} ~ } \bar "|" - { fis8[ g8^\markup { \pad-markup #0.2 "+24"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }}] dis2^\markup { \pad-markup #0.2 "+38"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }} ais'4^\markup { \pad-markup #0.2 "+40"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }} ~ } + { fis8[ g8^\markup { \pad-markup #0.2 "+24"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }}] dis2^\markup { \pad-markup #0.2 "+38"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }} ais4^\markup { \pad-markup #0.2 "+40"} ~ } \bar "|" - { ais'2 gis'8^\markup { \pad-markup #0.2 "+36"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↓" }}[ g'8^\markup { \pad-markup #0.2 "+24"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 5↑" }}] a'4^\markup { \pad-markup #0.2 "-11"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 11↑" }}} + { ais2 gis8^\markup { \pad-markup #0.2 "+36"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↓" }}[ g8^\markup { \pad-markup #0.2 "+24"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 5↑" }}] a4^\markup { \pad-markup #0.2 "-11"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 11↑" }}} \bar "||" } \ No newline at end of file diff --git a/resources/string_quartet_3_rise_coda_only/536cac90/536cac90_mus_model.json b/resources/string_quartet_3_rise_coda_only/536cac90/536cac90_mus_model.json index 1017c6b..4c3d339 100644 --- a/resources/string_quartet_3_rise_coda_only/536cac90/536cac90_mus_model.json +++ b/resources/string_quartet_3_rise_coda_only/536cac90/536cac90_mus_model.json @@ -9,12 +9,12 @@ [ [ [ -6, 4, 1, 2, -1, 2 ], [ -5, 3, 1, 2, -1, 2 ], [ -6, 4, 1, 3, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0.25 ] ], [ - [ [ [ -6, 4, 1, 2, -1, 2 ], [ -5, 3, 1, 2, -1, 2 ], [ -6, 4, 1, 3, -1, 2 ], [ -6, 3, 1, 3, -1, 2 ] ], 0.25 ], - [ [ [ -6, 3, 1, 2, -1, 2 ], [ -5, 3, 1, 2, -1, 2 ], [ -6, 4, 1, 3, -1, 2 ], [ -6, 3, 1, 3, -1, 2 ] ], 0 ], - [ [ [ -6, 3, 1, 2, -1, 2 ], [ -5, 3, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ], [ -6, 3, 1, 3, -1, 2 ] ], 0.25 ], - [ [ [ -6, 3, 1, 2, -1, 2 ], [ -5, 3, 1, 2, -1, 2 ], [ -5, 3, 1, 2, 0, 2 ], [ -6, 3, 1, 3, -1, 2 ] ], 0.25 ], - [ [ [ -6, 3, 1, 2, -1, 2 ], [ -5, 3, 1, 2, -1, 2 ], [ -4, 2, 1, 2, -1, 2 ], [ -6, 3, 1, 3, -1, 2 ] ], 0.25 ], - [ [ [ -6, 3, 1, 2, -1, 2 ], [ -5, 3, 1, 2, -1, 2 ], [ -5, 3, 2, 2, -1, 2 ], [ -6, 3, 1, 3, -1, 2 ] ], 0.25 ] + [ [ [ -6, 4, 1, 2, -1, 2 ], [ -5, 3, 1, 2, -1, 2 ], [ -6, 4, 1, 3, -1, 2 ], [ -5, 3, 1, 3, -1, 2 ] ], 0.25 ], + [ [ [ -6, 3, 1, 2, -1, 2 ], [ -5, 3, 1, 2, -1, 2 ], [ -6, 4, 1, 3, -1, 2 ], [ -5, 3, 1, 3, -1, 2 ] ], 0 ], + [ [ [ -6, 3, 1, 2, -1, 2 ], [ -5, 3, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ], [ -5, 3, 1, 3, -1, 2 ] ], 0.25 ], + [ [ [ -6, 3, 1, 2, -1, 2 ], [ -5, 3, 1, 2, -1, 2 ], [ -5, 3, 1, 2, 0, 2 ], [ -5, 3, 1, 3, -1, 2 ] ], 0.25 ], + [ [ [ -6, 3, 1, 2, -1, 2 ], [ -5, 3, 1, 2, -1, 2 ], [ -4, 2, 1, 2, -1, 2 ], [ -5, 3, 1, 3, -1, 2 ] ], 0.25 ], + [ [ [ -6, 3, 1, 2, -1, 2 ], [ -5, 3, 1, 2, -1, 2 ], [ -5, 3, 2, 2, -1, 2 ], [ -5, 3, 1, 3, -1, 2 ] ], 0.25 ] ], [ [ [ [ -6, 3, 1, 2, -1, 2 ], [ -5, 3, 1, 2, -1, 2 ], [ -5, 3, 2, 2, -1, 2 ], [ -4, 3, 1, 2, -1, 2 ] ], 0.25 ], @@ -44,17 +44,10 @@ [ [ [ -5, 2, 1, 2, -1, 2 ], [ -4, 2, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ], [ -4, 3, 1, 2, -1, 2 ] ], 0.25 ] ], [ - [ [ [ -5, 2, 1, 2, -1, 2 ], [ -4, 2, 1, 2, -1, 2 ], [ -3, 2, 1, 2, -1, 2 ], [ -4, 3, 1, 2, -1, 2 ] ], 0.25 ], - [ [ [ -5, 2, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ], [ -3, 2, 1, 2, -1, 2 ], [ -4, 3, 1, 2, -1, 2 ] ], 0.25 ], - [ [ [ -6, 4, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ], [ -3, 2, 1, 2, -1, 2 ], [ -4, 3, 1, 2, -1, 2 ] ], 0.25 ] + [ [ [ -5, 2, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ], [ -4, 3, 1, 2, -1, 2 ] ], 0.25 ] ], [ - [ [ [ -6, 3, 1, 2, 0, 2 ], [ -5, 4, 1, 2, -1, 2 ], [ -3, 2, 1, 2, -1, 2 ], [ -4, 3, 1, 2, -1, 2 ] ], 0 ], - [ [ [ -6, 3, 1, 2, 0, 2 ], [ -5, 3, 1, 2, 0, 2 ], [ -3, 2, 1, 2, -1, 2 ], [ -4, 3, 1, 2, -1, 2 ] ], 0.25 ], - [ [ [ -6, 3, 1, 2, 0, 2 ], [ -4, 3, 1, 2, -2, 2 ], [ -3, 2, 1, 2, -1, 2 ], [ -4, 3, 1, 2, -1, 2 ] ], 0 ], - [ [ [ -5, 3, 1, 2, -2, 2 ], [ -4, 3, 1, 2, -2, 2 ], [ -3, 2, 1, 2, -1, 2 ], [ -4, 3, 1, 2, -1, 2 ] ], 0.5 ], - [ [ [ -6, 3, 1, 2, -2, 2 ], [ -4, 4, 1, 2, -2, 2 ], [ -3, 3, 2, 2, -2, 2 ], [ -4, 3, 1, 3, -2, 2 ] ], 1.5 ], - [ [ [ -5, 2, 1, 2, -2, 2 ], [ -4, 3, 1, 2, -2, 2 ], [ -3, 3, 1, 2, -2, 2 ], [ -3, 2, 1, 2, -2, 2 ] ], 2.25 ] + [ [ [ -5, 2, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ], [ -4, 3, 1, 2, -1, 2 ]], 0.25 ] ] ] ], diff --git a/resources/string_quartet_3_rise_coda_only/536cac90/lilypond/part_I.ly b/resources/string_quartet_3_rise_coda_only/536cac90/lilypond/part_I.ly index 4aeeb9f..814b1ff 100644 --- a/resources/string_quartet_3_rise_coda_only/536cac90/lilypond/part_I.ly +++ b/resources/string_quartet_3_rise_coda_only/536cac90/lilypond/part_I.ly @@ -1,14 +1,10 @@ { - { f'2^\markup { \pad-markup #0.2 "-38"} g2^\markup { \pad-markup #0.2 "+28"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 7↑" }} ~ } + { f'2^\markup { \pad-markup #0.2 "-38"} g'2^\markup { \pad-markup #0.2 "+28"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 7↑" }} ~ } \bar "|" - { g8[ ais'8^\markup { \pad-markup #0.2 "-40"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }}] ~ ais'2. ~ } + { g'8[ ais'8^\markup { \pad-markup #0.2 "-40"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }}] ~ ais'2. ~ } \bar "|" { ais'1 ~ } \bar "|" - { ais'2 d''2^\markup { \pad-markup #0.2 "-23"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↑" }} ~ } - \bar "|" - { d''4 a'2.^\markup { \pad-markup #0.2 "+6"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }} ~ } - \bar "|" - { a'1} + { ais'1} \bar "||" } \ No newline at end of file diff --git a/resources/string_quartet_3_rise_coda_only/536cac90/lilypond/part_II.ly b/resources/string_quartet_3_rise_coda_only/536cac90/lilypond/part_II.ly index 3e38076..cc4b378 100644 --- a/resources/string_quartet_3_rise_coda_only/536cac90/lilypond/part_II.ly +++ b/resources/string_quartet_3_rise_coda_only/536cac90/lilypond/part_II.ly @@ -3,12 +3,8 @@ \bar "|" { cis'4^\markup { \pad-markup #0.2 "+46"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }} c'8^\markup { \pad-markup #0.2 "-9"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↓" }}[ fis'8^\markup { \pad-markup #0.2 "-27"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↓" }}] ~ fis'2 } \bar "|" - { f'8^\markup { \pad-markup #0.2 "-38"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↑" }}[ dis'8^\markup { \pad-markup #0.2 "-42"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }}] cis'8^\markup { \pad-markup #0.2 "+46"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 5↑" }}[ dis'8^\markup { \pad-markup #0.2 "+11"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 11↑" }}] f'4^\markup { \pad-markup #0.2 "-38"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↑" }} dis''4^\markup { \pad-markup #0.2 "-42"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }} ~ } + { f'8^\markup { \pad-markup #0.2 "-38"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↑" }}[ dis'8^\markup { \pad-markup #0.2 "-42"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }}] cis'8^\markup { \pad-markup #0.2 "+46"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 5↑" }}[ dis'8^\markup { \pad-markup #0.2 "+11"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 11↑" }}] f'2^\markup { \pad-markup #0.2 "-38"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↑" }} ~ } \bar "|" - { dis''2 gis''2^\markup { \pad-markup #0.2 "-5"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }} ~ } - \bar "|" - { gis''4 e''2.^\markup { \pad-markup #0.2 "+8"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }} ~ } - \bar "|" - { e''1} + { f'1} \bar "||" } \ No newline at end of file diff --git a/resources/string_quartet_3_rise_coda_only/536cac90/lilypond/part_III.ly b/resources/string_quartet_3_rise_coda_only/536cac90/lilypond/part_III.ly index 8b4f748..c40e7cc 100644 --- a/resources/string_quartet_3_rise_coda_only/536cac90/lilypond/part_III.ly +++ b/resources/string_quartet_3_rise_coda_only/536cac90/lilypond/part_III.ly @@ -3,12 +3,8 @@ \bar "|" { ais4 ~ ais8[ c'8^\markup { \pad-markup #0.2 "-9"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↓" }}] cis'8^\markup { \pad-markup #0.2 "+46"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 5↑" }}[ dis'8^\markup { \pad-markup #0.2 "-42"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↓" }}] cis'8^\markup { \pad-markup #0.2 "+19"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }}[ ais8^\markup { \pad-markup #0.2 "-40"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }}] ~ } \bar "|" - { ais4 c'4^\markup { \pad-markup #0.2 "-9"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 7↓" }} cis'8^\markup { \pad-markup #0.2 "+46"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 5↑" }}[ dis'8^\markup { \pad-markup #0.2 "-42"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }}] ~ dis'8[ f'8^\markup { \pad-markup #0.2 "-38"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↑" }}] ~ } + { ais4 c'4^\markup { \pad-markup #0.2 "-9"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 7↓" }} cis'8^\markup { \pad-markup #0.2 "+46"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 5↑" }}[ dis'8^\markup { \pad-markup #0.2 "-42"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }}] f'4^\markup { \pad-markup #0.2 "-38"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 1↑" }} ~ } \bar "|" - { f'8[ dis'8^\markup { \pad-markup #0.2 "+11"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }}] e'4^\markup { \pad-markup #0.2 "+8"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 11↓" }} b'2^\markup { \pad-markup #0.2 "+10"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }} ~ } - \bar "|" - { b'4 e'2.^\markup { \pad-markup #0.2 "+8"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 1↑" }} ~ } - \bar "|" - { e'1} + { f'1} \bar "||" } \ No newline at end of file diff --git a/resources/string_quartet_3_rise_coda_only/536cac90/lilypond/part_IV.ly b/resources/string_quartet_3_rise_coda_only/536cac90/lilypond/part_IV.ly index d79bdff..f87a18d 100644 --- a/resources/string_quartet_3_rise_coda_only/536cac90/lilypond/part_IV.ly +++ b/resources/string_quartet_3_rise_coda_only/536cac90/lilypond/part_IV.ly @@ -3,12 +3,8 @@ \bar "|" { ais,4 ~ ais,8[ c8^\markup { \pad-markup #0.2 "-9"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }}] cis2^\markup { \pad-markup #0.2 "+19"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 13↓" }} } \bar "|" - { dis1^\markup { \pad-markup #0.2 "-42"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↓" }} } + { dis1^\markup { \pad-markup #0.2 "-42"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↓" }} ~ } \bar "|" - { f8^\markup { \pad-markup #0.2 "-38"}[ dis8^\markup { \pad-markup #0.2 "+11"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 11↑" }}] e4^\markup { \pad-markup #0.2 "+8"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }} e,2^\markup { \pad-markup #0.2 "+8"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↓" }} ~ } - \bar "|" - { e,4 a,2.^\markup { \pad-markup #0.2 "+6"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }} ~ } - \bar "|" - { a,1} + { dis1} \bar "||" } \ No newline at end of file diff --git a/resources/string_quartet_3_rise_coda_only/5ededd80/5ededd80_mus_model.json b/resources/string_quartet_3_rise_coda_only/5ededd80/5ededd80_mus_model.json index f52e7df..9fc6a16 100644 --- a/resources/string_quartet_3_rise_coda_only/5ededd80/5ededd80_mus_model.json +++ b/resources/string_quartet_3_rise_coda_only/5ededd80/5ededd80_mus_model.json @@ -3,8 +3,20 @@ [ [ [ - [ [ [ -6, 3, 1, 2, -2, 2 ], [ -4, 4, 1, 2, -2, 2 ], [ -3, 3, 2, 2, -2, 2 ], [ -3, 3, 1, 3, -2, 2 ] ], 0.5 ], - [ [ [ -5, 2, 1, 2, -2, 2 ], [ -4, 3, 1, 2, -2, 2 ], [ -3, 3, 1, 2, -2, 2 ], [ -2, 2, 1, 2, -2, 2 ] ], 2.25 ] + [ [ [ -5, 2, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ], [ -5, 3, 1, 3, -1, 2 ], [ -4, 3, 2, 2, -1, 2 ] ], 0.25 ], + [ [ [ -5, 2, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ], [ -5, 3, 1, 2, -1, 3 ], [ -4, 3, 1, 2, 0, 2 ] ], 0.25 ], + + [ [ [ -6, 3, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ], [ -4, 4, 1, 2, -1, 2 ] ], 0.25 ], + [ [ [ -6, 3, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ], [ -5, 3, 1, 2, 0, 2 ], [ -4, 3, 1, 2, -1, 3 ] ], 0.25 ], + [ [ [ -6, 3, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ], [ -5, 3, 2, 2, -1, 2 ], [ -4, 3, 1, 3, -1, 2 ] ], 0.25 ], + [ [ [ -6, 3, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ], [ -6, 5, 1, 2, -1, 2 ], [ -3, 3, 1, 2, -1, 2 ] ], 0.25 ], + [ [ [ -6, 3, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ], [ -5, 3, 1, 2, -1, 2 ], [ -3, 3, 1, 2, -1, 2 ] ], 0.25 ], + [ [ [ -6, 3, 1, 2, -1, 2 ], [ "Rest" ], [ -5, 3, 1, 2, -1, 2 ], [ -3, 3, 1, 2, -1, 2 ] ], 0.25 ], + [ [ [ -6, 3, 1, 2, -1, 2 ], [ "Rest" ], [ -5, 3, 1, 2, -1, 2 ], [ -3, 3, 1, 2, -1, 2 ] ], 0.25 ], + [ [ [ "Rest" ], [ "Rest" ], [ -5, 3, 1, 2, -1, 2 ], [ -3, 3, 1, 2, -1, 2 ] ], 0.25 ], + [ [ [ "Rest" ], [ "Rest" ], [ -5, 3, 1, 2, -1, 2 ], [ -3, 3, 1, 2, -1, 2 ] ], 0.25 ], + [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 1.5 ], + [ [ [ "Rest" ], [ "Rest" ], [ "Rest" ], [ "Rest" ] ], 2.25 ] ] ] ], diff --git a/resources/string_quartet_3_rise_coda_only/5ededd80/lilypond/part_I.ly b/resources/string_quartet_3_rise_coda_only/5ededd80/lilypond/part_I.ly index 136105a..9d22a0a 100644 --- a/resources/string_quartet_3_rise_coda_only/5ededd80/lilypond/part_I.ly +++ b/resources/string_quartet_3_rise_coda_only/5ededd80/lilypond/part_I.ly @@ -1,6 +1,10 @@ { - { d'''4^\markup { \pad-markup #0.2 "-23"} a''2.^\markup { \pad-markup #0.2 "+6"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }} ~ } + { cis''8^\markup { \pad-markup #0.2 "+46"}[ dis''8^\markup { \pad-markup #0.2 "+11"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 6↑" }}] f''8^\markup { \pad-markup #0.2 "-38"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }}[ fis''8^\markup { \pad-markup #0.2 "+0"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↑" }}] g''8^\markup { \pad-markup #0.2 "+28"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↑" }}[ ais''8^\markup { \pad-markup #0.2 "-40"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }}] ~ ais''4 ~ } \bar "|" - { a''1} + { ais''4 ~ ais''8[ r8] r2 } + \bar "|" + { r1 } + \bar "|" + { r1 } \bar "||" } \ No newline at end of file diff --git a/resources/string_quartet_3_rise_coda_only/5ededd80/lilypond/part_II.ly b/resources/string_quartet_3_rise_coda_only/5ededd80/lilypond/part_II.ly index 36fb6c9..34b1835 100644 --- a/resources/string_quartet_3_rise_coda_only/5ededd80/lilypond/part_II.ly +++ b/resources/string_quartet_3_rise_coda_only/5ededd80/lilypond/part_II.ly @@ -1,6 +1,10 @@ { - { gis''4^\markup { \pad-markup #0.2 "-5"} e''2.^\markup { \pad-markup #0.2 "+8"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }} ~ } + { g'8^\markup { \pad-markup #0.2 "+28"}[ fis'8^\markup { \pad-markup #0.2 "+0"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 6↑" }}] f'8^\markup { \pad-markup #0.2 "-38"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }}[ dis'8^\markup { \pad-markup #0.2 "+11"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 11↑" }}] cis'8^\markup { \pad-markup #0.2 "+46"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }}[ c'8^\markup { \pad-markup #0.2 "-37"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↑" }}] ais4^\markup { \pad-markup #0.2 "-40"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }} ~ } \bar "|" - { e''1} + { ais4 ~ ais8[ r8] r2 } + \bar "|" + { r1 } + \bar "|" + { r1 } \bar "||" } \ No newline at end of file diff --git a/resources/string_quartet_3_rise_coda_only/5ededd80/lilypond/part_III.ly b/resources/string_quartet_3_rise_coda_only/5ededd80/lilypond/part_III.ly index bb36c57..7fa68b8 100644 --- a/resources/string_quartet_3_rise_coda_only/5ededd80/lilypond/part_III.ly +++ b/resources/string_quartet_3_rise_coda_only/5ededd80/lilypond/part_III.ly @@ -1,6 +1,10 @@ { - { b'4^\markup { \pad-markup #0.2 "+10"} e'2.^\markup { \pad-markup #0.2 "+8"} ~ } + { f'2.^\markup { \pad-markup #0.2 "-38"} ~ f'8[ r8] } \bar "|" - { e'1} + { r1 } + \bar "|" + { r1 } + \bar "|" + { r1 } \bar "||" } \ No newline at end of file diff --git a/resources/string_quartet_3_rise_coda_only/5ededd80/lilypond/part_IV.ly b/resources/string_quartet_3_rise_coda_only/5ededd80/lilypond/part_IV.ly index ebe7849..fadaa75 100644 --- a/resources/string_quartet_3_rise_coda_only/5ededd80/lilypond/part_IV.ly +++ b/resources/string_quartet_3_rise_coda_only/5ededd80/lilypond/part_IV.ly @@ -1,6 +1,10 @@ { - { e,4^\markup { \pad-markup #0.2 "+8"} a,2.^\markup { \pad-markup #0.2 "+6"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }} ~ } + { dis4^\markup { \pad-markup #0.2 "-42"} ais,2.^\markup { \pad-markup #0.2 "-40"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↓" }} ~ } \bar "|" - { a,1} + { ais,8[ r8] r2. } + \bar "|" + { r1 } + \bar "|" + { r1 } \bar "||" } \ No newline at end of file diff --git a/resources/string_quartet_3_rise_coda_only/5ef20586/5ef20586_mus_model.json b/resources/string_quartet_3_rise_coda_only/5ef20586/5ef20586_mus_model.json index c78bd2a..2e25b90 100644 --- a/resources/string_quartet_3_rise_coda_only/5ef20586/5ef20586_mus_model.json +++ b/resources/string_quartet_3_rise_coda_only/5ef20586/5ef20586_mus_model.json @@ -9,12 +9,12 @@ [ [ [ -5, 4, 1, 2, -1, 2 ], [ -5, 4, 0, 2, -1, 2 ], [ -4, 4, 1, 2, -1, 2 ], [ -4, 3, 1, 2, -1, 2 ] ], 0.25 ], [ [ [ -5, 4, 1, 2, -1, 2 ], [ -5, 4, 0, 2, -1, 2 ], [ -3, 4, 1, 1, -1, 2 ], [ -4, 3, 1, 2, -1, 2 ] ], 0 ], [ [ [ -5, 4, 1, 2, -1, 2 ], [ -6, 4, 1, 3, -1, 2 ], [ -3, 4, 1, 1, -1, 2 ], [ -4, 3, 1, 2, -1, 2 ] ], 0.25 ], - [ [ [ -5, 4, 1, 2, -1, 2 ], [ -6, 4, 1, 3, -1, 2 ], [ -5, 3, 1, 2, -1, 2 ], [ -4, 3, 1, 2, -1, 2 ] ], 0.25 ] + [ [ [ -5, 4, 1, 2, -1, 2 ], [ -6, 4, 1, 3, -1, 2 ], [ -4, 3, 1, 2, -1, 2 ], [ -4, 3, 1, 2, -1, 2 ] ], 0.25 ] ], [ - [ [ [ -5, 4, 1, 2, -1, 2 ], [ -5, 3, 2, 2, -1, 2 ], [ -5, 3, 1, 2, -1, 2 ], [ -4, 3, 1, 2, -1, 2 ] ], 0 ], - [ [ [ -5, 4, 1, 2, -1, 2 ], [ -5, 3, 2, 2, -1, 2 ], [ -6, 4, 2, 2, -1, 2 ], [ -4, 3, 1, 2, -1, 2 ] ], 0.25 ], - [ [ [ -5, 4, 1, 2, -1, 2 ], [ -5, 3, 1, 2, -1, 2 ], [ -6, 4, 2, 2, -1, 2 ], [ -4, 3, 1, 2, -1, 2 ] ], 0.25 ] + [ [ [ -5, 4, 1, 2, -1, 2 ], [ -5, 3, 2, 2, -1, 2 ], [ -4, 3, 1, 2, -1, 2 ], [ -4, 3, 1, 2, -1, 2 ] ], 0 ], + [ [ [ -5, 4, 1, 2, -1, 2 ], [ -5, 3, 2, 2, -1, 2 ], [ -5, 4, 2, 2, -1, 2 ], [ -4, 3, 1, 2, -1, 2 ] ], 0.25 ], + [ [ [ -5, 4, 1, 2, -1, 2 ], [ -5, 3, 1, 2, -1, 2 ], [ -5, 4, 2, 2, -1, 2 ], [ -4, 3, 1, 2, -1, 2 ] ], 0.25 ] ], [ [ [ [ -5, 4, 1, 2, -1, 2 ], [ -5, 3, 1, 2, -1, 2 ], [ -4, 4, 1, 2, -1, 2 ], [ -4, 3, 1, 2, -1, 2 ] ], 0.25 ], diff --git a/resources/string_quartet_3_rise_coda_only/5ef20586/lilypond/part_II.ly b/resources/string_quartet_3_rise_coda_only/5ef20586/lilypond/part_II.ly index 953bcf0..2663740 100644 --- a/resources/string_quartet_3_rise_coda_only/5ef20586/lilypond/part_II.ly +++ b/resources/string_quartet_3_rise_coda_only/5ef20586/lilypond/part_II.ly @@ -1,5 +1,5 @@ { - { d''8^\markup { \pad-markup #0.2 "+30"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↑" }}[ f''8^\markup { \pad-markup #0.2 "-38"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }}] g''8^\markup { \pad-markup #0.2 "-7"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↓" }}[ ais8^\markup { \pad-markup #0.2 "-40"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }}] gis4^\markup { \pad-markup #0.2 "+48"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }} f''4^\markup { \pad-markup #0.2 "-38"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }} ~ } + { d''8^\markup { \pad-markup #0.2 "+30"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↑" }}[ f''8^\markup { \pad-markup #0.2 "-38"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }}] g''8^\markup { \pad-markup #0.2 "-7"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↓" }}[ ais'8^\markup { \pad-markup #0.2 "-40"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }}] gis'4^\markup { \pad-markup #0.2 "+48"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }} f''4^\markup { \pad-markup #0.2 "-38"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }} ~ } \bar "|" { f''1} \bar "||" diff --git a/resources/string_quartet_3_rise_coda_only/5f0075ab/5f0075ab_mus_model.json b/resources/string_quartet_3_rise_coda_only/5f0075ab/5f0075ab_mus_model.json index 11843ff..59ba63a 100644 --- a/resources/string_quartet_3_rise_coda_only/5f0075ab/5f0075ab_mus_model.json +++ b/resources/string_quartet_3_rise_coda_only/5f0075ab/5f0075ab_mus_model.json @@ -19,7 +19,7 @@ [ [ [ [ -6, 4, 1, 1, -1, 2 ], [ -5, 4, 2, 1, -1, 2 ], [ -4, 4, 0, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0 ], [ [ [ -6, 4, 1, 1, -1, 2 ], [ -5, 4, 0, 2, -1, 2 ], [ -4, 4, 0, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0 ], - [ [ [ -7, 4, 1, 2, -1, 2 ], [ -5, 4, 0, 2, -1, 2 ], [ -4, 4, 0, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0.25 ] + [ [ [ -6, 4, 1, 2, -1, 2 ], [ -5, 4, 0, 2, -1, 2 ], [ -4, 4, 0, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0.25 ] ], [ [ [ [ -5, 3, 0, 2, -1, 2 ], [ -5, 4, 0, 2, -1, 2 ], [ -4, 4, 0, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0 ], diff --git a/resources/string_quartet_3_rise_coda_only/5f0075ab/lilypond/part_IV.ly b/resources/string_quartet_3_rise_coda_only/5f0075ab/lilypond/part_IV.ly index a3fcbc8..b67d51d 100644 --- a/resources/string_quartet_3_rise_coda_only/5f0075ab/lilypond/part_IV.ly +++ b/resources/string_quartet_3_rise_coda_only/5f0075ab/lilypond/part_IV.ly @@ -1,5 +1,5 @@ { - { f,4^\markup { \pad-markup #0.2 "-38"} g,2^\markup { \pad-markup #0.2 "-7"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }} ~ g,8[ f,8^\markup { \pad-markup #0.2 "-38"}] } + { f,4^\markup { \pad-markup #0.2 "-38"} g,2^\markup { \pad-markup #0.2 "-7"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }} ~ g,8[ f8^\markup { \pad-markup #0.2 "-38"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }}] } \bar "|" { fis8^\markup { \pad-markup #0.2 "-27"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↓" }}[ f8^\markup { \pad-markup #0.2 "-38"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }}] ~ f2.} \bar "||" diff --git a/resources/string_quartet_3_rise_coda_only/61207e49/61207e49_mus_model.json b/resources/string_quartet_3_rise_coda_only/61207e49/61207e49_mus_model.json index cdac35c..f28e746 100644 --- a/resources/string_quartet_3_rise_coda_only/61207e49/61207e49_mus_model.json +++ b/resources/string_quartet_3_rise_coda_only/61207e49/61207e49_mus_model.json @@ -3,17 +3,17 @@ [ [ [ - [ [ [ -6, 6, -1, 1, -2, 2 ], [ -5, 6, -1, 1, -2, 2 ], [ -5, 7, -1, 1, -2, 2 ], [ -4, 5, -1, 1, -2, 2 ] ], 0.25 ], - [ [ [ -6, 6, -1, 1, -2, 2 ], [ -5, 6, -1, 1, -2, 2 ], [ -4, 6, -2, 1, -2, 2 ], [ -4, 5, -1, 1, -2, 2 ] ], 0.25 ], - [ [ [ -6, 6, -1, 1, -2, 2 ], [ -5, 6, -1, 1, -2, 2 ], [ -5, 6, -1, 2, -2, 2 ], [ -4, 5, -1, 1, -2, 2 ] ], 0.25 ], - [ [ [ -6, 6, -1, 1, -2, 2 ], [ -5, 6, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ], [ -4, 5, -1, 1, -2, 2 ] ], 0.25 ] + [ [ [ -6, 6, -1, 1, -2, 2 ], [ -5, 6, -1, 1, -2, 2 ], [ -5, 7, -1, 1, -2, 2 ], [ -3, 5, -1, 1, -2, 2 ] ], 0.25 ], + [ [ [ -6, 6, -1, 1, -2, 2 ], [ -5, 6, -1, 1, -2, 2 ], [ -4, 6, -2, 1, -2, 2 ], [ -3, 5, -1, 1, -2, 2 ] ], 0.25 ], + [ [ [ -6, 6, -1, 1, -2, 2 ], [ -5, 6, -1, 1, -2, 2 ], [ -5, 6, -1, 2, -2, 2 ], [ -3, 5, -1, 1, -2, 2 ] ], 0.25 ], + [ [ [ -6, 6, -1, 1, -2, 2 ], [ -5, 6, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ], [ -3, 5, -1, 1, -2, 2 ] ], 0.25 ] ], [ - [ [ [ -6, 6, -1, 1, -2, 2 ], [ -3, 6, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ], [ -4, 5, -1, 1, -2, 2 ] ], 0 ], - [ [ [ -5, 6, -1, 1, -2, 2 ], [ -3, 6, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ], [ -4, 5, -1, 1, -2, 2 ] ], 0 ], - [ [ [ -5, 6, -1, 1, -2, 2 ], [ -3, 6, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ], [ -5, 7, -1, 1, -2, 2 ] ], 0.25 ], - [ [ [ -5, 6, -1, 1, -2, 2 ], [ -3, 6, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ], [ -4, 6, -2, 1, -2, 2 ] ], 0.25 ], - [ [ [ -5, 6, -1, 1, -2, 2 ], [ -3, 6, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ], [ -5, 6, -1, 2, -2, 2 ] ], 0.25 ], + [ [ [ -6, 6, -1, 1, -2, 2 ], [ -3, 6, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ], [ -3, 5, -1, 1, -2, 2 ] ], 0 ], + [ [ [ -5, 6, -1, 1, -2, 2 ], [ -3, 6, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ], [ -3, 5, -1, 1, -2, 2 ] ], 0 ], + [ [ [ -5, 6, -1, 1, -2, 2 ], [ -3, 6, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ], [ -4, 7, -1, 1, -2, 2 ] ], 0.25 ], + [ [ [ -5, 6, -1, 1, -2, 2 ], [ -3, 6, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ], [ -3, 6, -2, 1, -2, 2 ] ], 0.25 ], + [ [ [ -5, 6, -1, 1, -2, 2 ], [ -3, 6, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ], [ -4, 6, -1, 2, -2, 2 ] ], 0.25 ], [ [ [ -5, 6, -1, 1, -2, 2 ], [ -3, 6, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ], [ -4, 7, -1, 1, -2, 2 ] ], 0.25 ] ], [ @@ -31,9 +31,9 @@ ], [ [ [ [ -5, 7, -2, 1, -2, 2 ], [ -5, 7, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ], [ -4, 7, -1, 1, -2, 2 ] ], 0.25 ], - [ [ [ -5, 7, -2, 1, -2, 2 ], [ -5, 7, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ], [ -3, 7, -1, 0, -2, 2 ] ], 0 ], - [ [ [ -6, 8, -1, 1, -2, 2 ], [ -5, 7, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ], [ -3, 7, -1, 0, -2, 2 ] ], 0.25 ], - [ [ [ -6, 8, -1, 1, -2, 2 ], [ -5, 7, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ], [ -4, 7, 0, 1, -2, 2 ] ], 0.25 ], + [ [ [ -5, 7, -2, 1, -2, 2 ], [ -5, 7, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ], [ -4, 7, -1, 0, -2, 2 ] ], 0 ], + [ [ [ -6, 8, -1, 1, -2, 2 ], [ -5, 7, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ], [ -4, 7, -1, 0, -2, 2 ] ], 0.25 ], + [ [ [ -6, 8, -1, 1, -2, 2 ], [ -5, 7, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ], [ -5, 7, 0, 1, -2, 2 ] ], 0.25 ], [ [ [ -6, 8, -1, 1, -2, 2 ], [ -5, 7, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ], [ -5, 8, -1, 1, -2, 2 ] ], 0 ], [ [ [ -6, 8, -1, 1, -2, 2 ], [ -5, 7, -1, 1, -2, 2 ], [ -5, 7, 0, 1, -2, 2 ], [ -5, 8, -1, 1, -2, 2 ] ], 0.25 ], [ [ [ -6, 8, -1, 1, -2, 2 ], [ -5, 7, -1, 1, -2, 2 ], [ -5, 7, 0, 1, -2, 2 ], [ -5, 7, -1, 1, -2, 3 ] ], 0.25 ] @@ -71,27 +71,27 @@ [ [ [ -5, 6, -1, 1, -2, 2 ], [ -4, 6, -2, 1, -3, 2 ], [ -4, 6, 0, 1, -2, 2 ], [ -3, 6, -1, 1, -3, 2 ] ], 0.25 ], [ [ [ -5, 6, -1, 1, -2, 2 ], [ -5, 7, -1, 1, -3, 2 ], [ -4, 6, 0, 1, -2, 2 ], [ -3, 6, -1, 1, -3, 2 ] ], 0.25 ], [ [ [ -5, 6, -1, 1, -2, 2 ], [ -5, 7, -1, 1, -3, 2 ], [ -4, 7, -1, 1, -2, 2 ], [ -3, 6, -1, 1, -3, 2 ] ], 0.25 ], - [ [ [ -5, 6, -1, 1, -2, 2 ], [ -5, 7, -1, 1, -3, 2 ], [ -4, 5, -1, 1, -2, 2 ], [ -3, 6, -1, 1, -3, 2 ] ], 0.25 ] + [ [ [ -5, 6, -1, 1, -2, 2 ], [ -5, 7, -1, 1, -3, 2 ], [ -3, 5, -1, 1, -2, 2 ], [ -3, 6, -1, 1, -3, 2 ] ], 0.25 ] ], [ - [ [ [ -4, 5, -1, 1, -3, 2 ], [ -5, 7, -1, 1, -3, 2 ], [ -4, 5, -1, 1, -2, 2 ], [ -3, 6, -1, 1, -3, 2 ] ], 0 ], - [ [ [ -4, 5, -1, 1, -3, 2 ], [ -5, 7, -1, 1, -3, 2 ], [ -4, 5, -1, 1, -2, 2 ], [ -3, 5, -1, 1, -3, 2 ] ], 0 ], - [ [ [ -4, 5, -1, 1, -3, 2 ], [ -5, 6, -1, 1, -2, 2 ], [ -4, 5, -1, 1, -2, 2 ], [ -3, 5, -1, 1, -3, 2 ] ], 0.25 ], - [ [ [ -4, 5, -1, 1, -3, 2 ], [ -5, 6, -1, 1, -2, 2 ], [ -4, 5, -1, 1, -2, 2 ], [ -3, 4, -1, 1, -2, 2 ] ], 0 ], - [ [ [ -4, 4, -1, 1, -2, 2 ], [ -5, 6, -1, 1, -2, 2 ], [ -4, 5, -1, 1, -2, 2 ], [ -3, 4, -1, 1, -2, 2 ] ], 0 ], - [ [ [ -4, 4, -1, 1, -2, 2 ], [ -3, 5, -1, 1, -2, 2 ], [ -4, 5, -1, 1, -2, 2 ], [ -3, 4, -1, 1, -2, 2 ] ], 0.25 ] + [ [ [ -4, 5, -1, 1, -3, 2 ], [ -5, 7, -1, 1, -3, 2 ], [ -3, 5, -1, 1, -2, 2 ], [ -3, 6, -1, 1, -3, 2 ] ], 0 ], + [ [ [ -4, 5, -1, 1, -3, 2 ], [ -5, 7, -1, 1, -3, 2 ], [ -3, 5, -1, 1, -2, 2 ], [ -3, 5, -1, 1, -3, 2 ] ], 0 ], + [ [ [ -4, 5, -1, 1, -3, 2 ], [ -5, 6, -1, 1, -2, 2 ], [ -3, 5, -1, 1, -2, 2 ], [ -3, 5, -1, 1, -3, 2 ] ], 0.25 ], + [ [ [ -4, 5, -1, 1, -3, 2 ], [ -5, 6, -1, 1, -2, 2 ], [ -3, 5, -1, 1, -2, 2 ], [ -3, 4, -1, 1, -2, 2 ] ], 0 ], + [ [ [ -4, 4, -1, 1, -2, 2 ], [ -5, 6, -1, 1, -2, 2 ], [ -3, 5, -1, 1, -2, 2 ], [ -3, 4, -1, 1, -2, 2 ] ], 0 ], + [ [ [ -4, 4, -1, 1, -2, 2 ], [ -4, 5, -1, 1, -2, 2 ], [ -3, 5, -1, 1, -2, 2 ], [ -3, 4, -1, 1, -2, 2 ] ], 0.25 ] ], [ - [ [ [ -5, 5, -1, 1, -2, 2 ], [ -3, 5, -1, 1, -2, 2 ], [ -4, 5, -1, 1, -2, 2 ], [ -3, 4, -1, 1, -2, 2 ] ], 0.25 ], - [ [ [ -5, 5, -1, 1, -2, 2 ], [ -3, 5, -1, 1, -2, 2 ], [ -4, 5, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ] ], 0 ], - [ [ [ -4, 5, -1, 0, -2, 2 ], [ -3, 5, -1, 1, -2, 2 ], [ -4, 5, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ] ], 0.25 ], - [ [ [ -5, 5, 0, 1, -2, 2 ], [ -3, 5, -1, 1, -2, 2 ], [ -4, 5, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ] ], 0.25 ], - [ [ [ -5, 6, -1, 1, -2, 2 ], [ -3, 5, -1, 1, -2, 2 ], [ -4, 5, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ] ], 0.25 ], - [ [ [ -4, 5, -2, 1, -2, 2 ], [ -3, 5, -1, 1, -2, 2 ], [ -4, 5, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ] ], 0.25 ] + [ [ [ -5, 5, -1, 1, -2, 2 ], [ -4, 5, -1, 1, -2, 2 ], [ -3, 5, -1, 1, -2, 2 ], [ -3, 4, -1, 1, -2, 2 ] ], 0.25 ], + [ [ [ -5, 5, -1, 1, -2, 2 ], [ -4, 5, -1, 1, -2, 2 ], [ -3, 5, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ] ], 0 ], + [ [ [ -4, 5, -1, 0, -2, 2 ], [ -4, 5, -1, 1, -2, 2 ], [ -3, 5, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ] ], 0.25 ], + [ [ [ -5, 5, 0, 1, -2, 2 ], [ -4, 5, -1, 1, -2, 2 ], [ -3, 5, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ] ], 0.25 ], + [ [ [ -5, 6, -1, 1, -2, 2 ], [ -4, 5, -1, 1, -2, 2 ], [ -3, 5, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ] ], 0.25 ], + [ [ [ -4, 5, -2, 1, -2, 2 ], [ -4, 5, -1, 1, -2, 2 ], [ -3, 5, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ] ], 0.25 ] ], [ - [ [ [ -4, 5, -2, 1, -2, 2 ], [ -3, 5, -1, 1, -2, 2 ], [ -4, 5, -1, 1, -2, 2 ], [ -3, 5, -2, 1, -2, 2 ] ], 0.25 ], - [ [ [ -5, 5, -1, 2, -2, 2 ], [ -3, 5, -1, 1, -2, 2 ], [ -4, 5, -1, 1, -2, 2 ], [ -3, 5, -2, 1, -2, 2 ] ], 0.25 ] + [ [ [ -4, 5, -2, 1, -2, 2 ], [ -4, 5, -1, 1, -2, 2 ], [ -3, 5, -1, 1, -2, 2 ], [ -3, 5, -2, 1, -2, 2 ] ], 0.25 ], + [ [ [ -5, 5, -1, 2, -2, 2 ], [ -4, 5, -1, 1, -2, 2 ], [ -3, 5, -1, 1, -2, 2 ], [ -3, 5, -2, 1, -2, 2 ] ], 0.25 ] ] ] ], diff --git a/resources/string_quartet_3_rise_coda_only/61207e49/lilypond/part_I.ly b/resources/string_quartet_3_rise_coda_only/61207e49/lilypond/part_I.ly index c6af1e7..871d25d 100644 --- a/resources/string_quartet_3_rise_coda_only/61207e49/lilypond/part_I.ly +++ b/resources/string_quartet_3_rise_coda_only/61207e49/lilypond/part_I.ly @@ -1,7 +1,7 @@ { - { cis'2^\markup { \pad-markup #0.2 "-29"} dis'8^\markup { \pad-markup #0.2 "-25"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }}[ e'8^\markup { \pad-markup #0.2 "-14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↓" }}] f'8^\markup { \pad-markup #0.2 "+41"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↑" }}[ dis''8^\markup { \pad-markup #0.2 "-25"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }}] } + { cis''2^\markup { \pad-markup #0.2 "-29"} dis''8^\markup { \pad-markup #0.2 "-25"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }}[ e''8^\markup { \pad-markup #0.2 "-14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↓" }}] f''8^\markup { \pad-markup #0.2 "+41"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 7↑" }}[ dis''8^\markup { \pad-markup #0.2 "-25"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }}] } \bar "|" - { e''8^\markup { \pad-markup #0.2 "+13"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↑" }}[ dis''8^\markup { \pad-markup #0.2 "-25"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }}] ~ dis''2 f''8^\markup { \pad-markup #0.2 "+6"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 7↓" }}[ g''8^\markup { \pad-markup #0.2 "-39"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 5↑" }}] } + { e''8^\markup { \pad-markup #0.2 "+13"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↑" }}[ dis''8^\markup { \pad-markup #0.2 "-25"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }}] ~ dis''2 f'8^\markup { \pad-markup #0.2 "+6"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 7↓" }}[ g'8^\markup { \pad-markup #0.2 "-39"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 5↑" }}] } \bar "|" { ais'8^\markup { \pad-markup #0.2 "-23"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }}[ b'8^\markup { \pad-markup #0.2 "+15"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 13↑" }}] ais'4^\markup { \pad-markup #0.2 "-23"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }} b'4^\markup { \pad-markup #0.2 "-12"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 5↓" }} ~ b'8[ cis''8^\markup { \pad-markup #0.2 "-29"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }}] } \bar "|" diff --git a/resources/string_quartet_3_rise_coda_only/61207e49/lilypond/part_II.ly b/resources/string_quartet_3_rise_coda_only/61207e49/lilypond/part_II.ly index d08b37b..e4af8bd 100644 --- a/resources/string_quartet_3_rise_coda_only/61207e49/lilypond/part_II.ly +++ b/resources/string_quartet_3_rise_coda_only/61207e49/lilypond/part_II.ly @@ -5,10 +5,10 @@ \bar "|" { g'4^\markup { \pad-markup #0.2 "-39"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 5↑" }} fis'8^\markup { \pad-markup #0.2 "+17"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↑" }}[ f'8^\markup { \pad-markup #0.2 "-21"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }}] fis'8^\markup { \pad-markup #0.2 "+34"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 13↓" }}[ gis'8^\markup { \pad-markup #0.2 "+26"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }}] ais'8^\markup { \pad-markup #0.2 "-23"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↑" }}[ b'8^\markup { \pad-markup #0.2 "+32"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↓" }}] ~ } \bar "|" - { b'4 cis''4^\markup { \pad-markup #0.2 "-29"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }} c''4^\markup { \pad-markup #0.2 "-41"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }} dis''8^\markup { \pad-markup #0.2 "-25"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }}[ cis'8^\markup { \pad-markup #0.2 "-29"}] ~ } + { b'4 cis''4^\markup { \pad-markup #0.2 "-29"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }} c''4^\markup { \pad-markup #0.2 "-41"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }} dis''8^\markup { \pad-markup #0.2 "-25"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }}[ cis''8^\markup { \pad-markup #0.2 "-29"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }}] ~ } \bar "|" - { cis'1 ~ } + { cis''1 ~ } \bar "|" - { cis'1} + { cis''1} \bar "||" } \ No newline at end of file diff --git a/resources/string_quartet_3_rise_coda_only/61207e49/lilypond/part_III.ly b/resources/string_quartet_3_rise_coda_only/61207e49/lilypond/part_III.ly index ce3d023..7232caa 100644 --- a/resources/string_quartet_3_rise_coda_only/61207e49/lilypond/part_III.ly +++ b/resources/string_quartet_3_rise_coda_only/61207e49/lilypond/part_III.ly @@ -7,8 +7,8 @@ \bar "|" { c'2^\markup { \pad-markup #0.2 "-41"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↑" }} ais8^\markup { \pad-markup #0.2 "+35"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 5↓" }}[ a8^\markup { \pad-markup #0.2 "+23"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↑" }}] ~ a4 } \bar "|" - { gis8^\markup { \pad-markup #0.2 "-27"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↑" }}[ cis''8^\markup { \pad-markup #0.2 "-29"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 1↑" }}] ~ cis''2. ~ } + { gis8^\markup { \pad-markup #0.2 "-27"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 3↑" }}[ cis'8^\markup { \pad-markup #0.2 "-29"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 1↑" }}] ~ cis'2. ~ } \bar "|" - { cis''1} + { cis'1} \bar "||" } \ No newline at end of file diff --git a/resources/string_quartet_3_rise_coda_only/624f7439/624f7439_mus_model.json b/resources/string_quartet_3_rise_coda_only/624f7439/624f7439_mus_model.json index 835be59..7e36c60 100644 --- a/resources/string_quartet_3_rise_coda_only/624f7439/624f7439_mus_model.json +++ b/resources/string_quartet_3_rise_coda_only/624f7439/624f7439_mus_model.json @@ -10,55 +10,55 @@ ], [ [ [ [ -6, 6, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ], [ -4, 5, -1, 1, -2, 2 ], [ -3, 6, -1, 1, -2, 2 ] ], 0 ], - [ [ [ -3, 5, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ], [ -4, 5, -1, 1, -2, 2 ], [ -3, 6, -1, 1, -2, 2 ] ], 0 ], - [ [ [ -3, 5, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ], [ -5, 6, -1, 1, -2, 2 ], [ -3, 6, -1, 1, -2, 2 ] ], 0.25 ], - [ [ [ -3, 5, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ], [ -4, 6, -1, 0, -2, 2 ], [ -3, 6, -1, 1, -2, 2 ] ], 0.25 ], - [ [ [ -3, 5, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ], [ -5, 6, 0, 1, -2, 2 ], [ -3, 6, -1, 1, -2, 2 ] ], 0.25 ], - [ [ [ -3, 5, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ], [ -4, 5, -1, 1, -2, 2 ], [ -3, 6, -1, 1, -2, 2 ] ], 0.25 ] + [ [ [ -5, 5, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ], [ -4, 5, -1, 1, -2, 2 ], [ -3, 6, -1, 1, -2, 2 ] ], 0 ], + [ [ [ -5, 5, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ], [ -5, 6, -1, 1, -2, 2 ], [ -3, 6, -1, 1, -2, 2 ] ], 0.25 ], + [ [ [ -5, 5, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ], [ -4, 6, -1, 0, -2, 2 ], [ -3, 6, -1, 1, -2, 2 ] ], 0.25 ], + [ [ [ -5, 5, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ], [ -5, 6, 0, 1, -2, 2 ], [ -3, 6, -1, 1, -2, 2 ] ], 0.25 ], + [ [ [ -5, 5, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ], [ -4, 5, -1, 1, -2, 2 ], [ -3, 6, -1, 1, -2, 2 ] ], 0.25 ] ], [ - [ [ [ -3, 5, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ], [ -4, 5, -1, 1, -2, 2 ], [ -5, 6, -1, 1, -2, 2 ] ], 0 ], - [ [ [ -3, 5, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ], [ -5, 7, -1, 1, -2, 2 ], [ -5, 6, -1, 1, -2, 2 ] ], 0.25 ] + [ [ [ -5, 5, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ], [ -4, 5, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ] ], 0 ], + [ [ [ -5, 5, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ], [ -5, 7, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ] ], 0.25 ] ], [ - [ [ [ -3, 5, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ], [ -4, 6, -2, 1, -2, 2 ], [ -5, 6, -1, 1, -2, 2 ] ], 0 ], - [ [ [ -3, 5, -1, 1, -2, 2 ], [ -4, 5, -1, 1, -2, 2 ], [ -4, 6, -2, 1, -2, 2 ], [ -5, 6, -1, 1, -2, 2 ] ], 0 ], - [ [ [ -4, 6, -1, 1, -2, 2 ], [ -4, 5, -1, 1, -2, 2 ], [ -4, 6, -2, 1, -2, 2 ], [ -5, 6, -1, 1, -2, 2 ] ], 0.25 ], - [ [ [ -5, 6, -1, 0, -2, 2 ], [ -4, 5, -1, 1, -2, 2 ], [ -4, 6, -2, 1, -2, 2 ], [ -5, 6, -1, 1, -2, 2 ] ], 0 ], - [ [ [ -5, 6, -1, 0, -2, 2 ], [ -4, 6, -1, 1, -3, 2 ], [ -4, 6, -2, 1, -2, 2 ], [ -5, 6, -1, 1, -2, 2 ] ], 0.25 ], - [ [ [ -5, 6, -1, 0, -2, 2 ], [ -5, 7, -1, 1, -2, 2 ], [ -4, 6, -2, 1, -2, 2 ], [ -5, 6, -1, 1, -2, 2 ] ], 0.25 ], - [ [ [ -5, 6, -1, 0, -2, 2 ], [ -5, 6, -1, 1, -1, 2 ], [ -4, 6, -2, 1, -2, 2 ], [ -5, 6, -1, 1, -2, 2 ] ], 0.25 ] + [ [ [ -5, 5, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ], [ -4, 6, -2, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ] ], 0 ], + [ [ [ -5, 5, -1, 1, -2, 2 ], [ -4, 5, -1, 1, -2, 2 ], [ -4, 6, -2, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ] ], 0 ], + [ [ [ -6, 6, -1, 1, -2, 2 ], [ -4, 5, -1, 1, -2, 2 ], [ -4, 6, -2, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ] ], 0.25 ], + [ [ [ -5, 6, -1, 0, -2, 2 ], [ -4, 5, -1, 1, -2, 2 ], [ -4, 6, -2, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ] ], 0 ], + [ [ [ -5, 6, -1, 0, -2, 2 ], [ -4, 6, -1, 1, -3, 2 ], [ -4, 6, -2, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ] ], 0.25 ], + [ [ [ -5, 6, -1, 0, -2, 2 ], [ -5, 7, -1, 1, -2, 2 ], [ -4, 6, -2, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ] ], 0.25 ], + [ [ [ -5, 6, -1, 0, -2, 2 ], [ -5, 6, -1, 1, -1, 2 ], [ -4, 6, -2, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ] ], 0.25 ] ], [ - [ [ [ -5, 6, -1, 0, -2, 2 ], [ -5, 6, 0, 1, -2, 2 ], [ -4, 6, -2, 1, -2, 2 ], [ -5, 6, -1, 1, -2, 2 ] ], 0.25 ], - [ [ [ -5, 6, -1, 0, -2, 2 ], [ -5, 6, 0, 1, -2, 2 ], [ -5, 7, -1, 1, -2, 2 ], [ -5, 6, -1, 1, -2, 2 ] ], 0 ], - [ [ [ -6, 6, 0, 1, -2, 2 ], [ -5, 6, 0, 1, -2, 2 ], [ -5, 7, -1, 1, -2, 2 ], [ -5, 6, -1, 1, -2, 2 ] ], 0.25 ], - [ [ [ -6, 6, 0, 1, -2, 2 ], [ -5, 6, 0, 1, -2, 2 ], [ -4, 6, 0, 1, -2, 2 ], [ -5, 6, -1, 1, -2, 2 ] ], 0.25 ], - [ [ [ -6, 6, 0, 1, -2, 2 ], [ -5, 6, 0, 1, -2, 2 ], [ -3, 5, -1, 1, -2, 2 ], [ -5, 6, -1, 1, -2, 2 ] ], 0 ], - [ [ [ -6, 6, 0, 1, -2, 2 ], [ -4, 5, -1, 1, -2, 2 ], [ -3, 5, -1, 1, -2, 2 ], [ -5, 6, -1, 1, -2, 2 ] ], 0.25 ], - [ [ [ -6, 6, 0, 1, -2, 2 ], [ -4, 5, -1, 1, -2, 2 ], [ -4, 7, -1, 1, -2, 2 ], [ -5, 6, -1, 1, -2, 2 ] ], 0.25 ] + [ [ [ -5, 6, -1, 0, -2, 2 ], [ -5, 6, 0, 1, -2, 2 ], [ -4, 6, -2, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ] ], 0.25 ], + [ [ [ -5, 6, -1, 0, -2, 2 ], [ -5, 6, 0, 1, -2, 2 ], [ -4, 7, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ] ], 0 ], + [ [ [ -6, 6, 0, 1, -2, 2 ], [ -5, 6, 0, 1, -2, 2 ], [ -4, 7, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ] ], 0.25 ], + [ [ [ -6, 6, 0, 1, -2, 2 ], [ -5, 6, 0, 1, -2, 2 ], [ -4, 6, 0, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ] ], 0.25 ], + [ [ [ -6, 6, 0, 1, -2, 2 ], [ -5, 6, 0, 1, -2, 2 ], [ -3, 5, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ] ], 0 ], + [ [ [ -6, 6, 0, 1, -2, 2 ], [ -4, 5, -1, 1, -2, 2 ], [ -3, 5, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ] ], 0.25 ], + [ [ [ -6, 6, 0, 1, -2, 2 ], [ -4, 5, -1, 1, -2, 2 ], [ -4, 7, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ] ], 0.25 ] ], [ - [ [ [ -6, 6, 0, 1, -2, 2 ], [ -5, 7, -1, 1, -2, 2 ], [ -4, 7, -1, 1, -2, 2 ], [ -5, 6, -1, 1, -2, 2 ] ], 0 ], - [ [ [ -6, 6, 0, 1, -2, 2 ], [ -5, 7, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ], [ -5, 6, -1, 1, -2, 2 ] ], 0.25 ], - [ [ [ -6, 6, 0, 1, -2, 2 ], [ -4, 5, 0, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ], [ -5, 6, -1, 1, -2, 2 ] ], 0.25 ] + [ [ [ -6, 6, 0, 1, -2, 2 ], [ -5, 7, -1, 1, -2, 2 ], [ -4, 7, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ] ], 0 ], + [ [ [ -6, 6, 0, 1, -2, 2 ], [ -5, 7, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ] ], 0.25 ], + [ [ [ -6, 6, 0, 1, -2, 2 ], [ -4, 5, 0, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ] ], 0.25 ] ], [ - [ [ [ -6, 6, 0, 1, -2, 2 ], [ -4, 5, 0, 1, -2, 2 ], [ -5, 6, 0, 1, -2, 2 ], [ -5, 6, -1, 1, -2, 2 ] ], 0 ], - [ [ [ -6, 6, 0, 1, -2, 2 ], [ -5, 6, -1, 2, -2, 2 ], [ -5, 6, 0, 1, -2, 2 ], [ -5, 6, -1, 1, -2, 2 ] ], 0 ], - [ [ [ -6, 6, -1, 1, -1, 2 ], [ -5, 6, -1, 2, -2, 2 ], [ -5, 6, 0, 1, -2, 2 ], [ -5, 6, -1, 1, -2, 2 ] ], 0.25 ] + [ [ [ -6, 6, 0, 1, -2, 2 ], [ -4, 5, 0, 1, -2, 2 ], [ -5, 6, 0, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ] ], 0 ], + [ [ [ -6, 6, 0, 1, -2, 2 ], [ -5, 6, -1, 2, -2, 2 ], [ -5, 6, 0, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ] ], 0 ], + [ [ [ -6, 6, -1, 1, -1, 2 ], [ -5, 6, -1, 2, -2, 2 ], [ -5, 6, 0, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ] ], 0.25 ] ], [ - [ [ [ -6, 7, -1, 1, -2, 2 ], [ -5, 6, -1, 2, -2, 2 ], [ -5, 6, 0, 1, -2, 2 ], [ -5, 6, -1, 1, -2, 2 ] ], 0 ], - [ [ [ -6, 7, -1, 1, -2, 2 ], [ -5, 7, 0, 1, -2, 2 ], [ -5, 6, 0, 1, -2, 2 ], [ -5, 6, -1, 1, -2, 2 ] ], 0.25 ], - [ [ [ -6, 7, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ], [ -5, 6, 0, 1, -2, 2 ], [ -5, 6, -1, 1, -2, 2 ] ], 0 ], - [ [ [ -5, 5, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ], [ -5, 6, 0, 1, -2, 2 ], [ -5, 6, -1, 1, -2, 2 ] ], 0.25 ] + [ [ [ -6, 7, -1, 1, -2, 2 ], [ -5, 6, -1, 2, -2, 2 ], [ -5, 6, 0, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ] ], 0 ], + [ [ [ -6, 7, -1, 1, -2, 2 ], [ -5, 7, 0, 1, -2, 2 ], [ -5, 6, 0, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ] ], 0.25 ], + [ [ [ -6, 7, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ], [ -5, 6, 0, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ] ], 0 ], + [ [ [ -5, 5, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ], [ -5, 6, 0, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ] ], 0.25 ] ], [ - [ [ [ -5, 5, -1, 1, -2, 2 ], [ -3, 5, -2, 1, -2, 2 ], [ -5, 6, 0, 1, -2, 2 ], [ -5, 6, -1, 1, -2, 2 ] ], 0 ], - [ [ [ -5, 5, -1, 1, -2, 2 ], [ -3, 5, -2, 1, -2, 2 ], [ -5, 6, 0, 1, -2, 2 ], [ -4, 5, -2, 1, -2, 2 ] ], 0 ], - [ [ [ -5, 5, -1, 1, -2, 2 ], [ -3, 5, -2, 1, -2, 2 ], [ -4, 5, -1, 1, -2, 2 ], [ -4, 5, -2, 1, -2, 2 ] ], 0.25 ], - [ [ [ -5, 5, -1, 1, -2, 2 ], [ -3, 5, -2, 1, -2, 2 ], [ -4, 5, 0, 1, -2, 2 ], [ -4, 5, -2, 1, -2, 2 ] ], 0 ], + [ [ [ -5, 5, -1, 1, -2, 2 ], [ -3, 5, -2, 1, -2, 2 ], [ -5, 6, 0, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ] ], 0 ], + [ [ [ -5, 5, -1, 1, -2, 2 ], [ -3, 5, -2, 1, -2, 2 ], [ -5, 6, 0, 1, -2, 2 ], [ -3, 5, -2, 1, -2, 2 ] ], 0 ], + [ [ [ -5, 5, -1, 1, -2, 2 ], [ -3, 5, -2, 1, -2, 2 ], [ -4, 5, -1, 1, -2, 2 ], [ -3, 5, -2, 1, -2, 2 ] ], 0.25 ], + [ [ [ -5, 5, -1, 1, -2, 2 ], [ -3, 5, -2, 1, -2, 2 ], [ -4, 5, 0, 1, -2, 2 ], [ -3, 5, -2, 1, -2, 2 ] ], 0 ], [ [ [ -5, 5, -1, 1, -2, 2 ], [ -3, 5, -2, 1, -2, 2 ], [ -4, 5, 0, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ] ], 0.25 ], [ [ [ -5, 5, -1, 1, -2, 2 ], [ -3, 5, -2, 1, -2, 2 ], [ -3, 4, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ] ], 0.25 ], [ [ [ -5, 5, -1, 1, -2, 2 ], [ -4, 5, -1, 2, -2, 2 ], [ -3, 4, -1, 1, -2, 2 ], [ -4, 6, -1, 1, -2, 2 ] ], 0.25 ] diff --git a/resources/string_quartet_3_rise_coda_only/624f7439/lilypond/part_I.ly b/resources/string_quartet_3_rise_coda_only/624f7439/lilypond/part_I.ly index 7901a68..571d606 100644 --- a/resources/string_quartet_3_rise_coda_only/624f7439/lilypond/part_I.ly +++ b/resources/string_quartet_3_rise_coda_only/624f7439/lilypond/part_I.ly @@ -1,9 +1,9 @@ { { gis2^\markup { \pad-markup #0.2 "-27"} gis''2^\markup { \pad-markup #0.2 "-27"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }} } \bar "|" - { gis1^\markup { \pad-markup #0.2 "-27"} ~ } + { gis'1^\markup { \pad-markup #0.2 "-27"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }} ~ } \bar "|" - { gis2. ~ gis8[ a8^\markup { \pad-markup #0.2 "-16"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }}] } + { gis'2. ~ gis'8[ a'8^\markup { \pad-markup #0.2 "-16"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }}] } \bar "|" { gis'2^\markup { \pad-markup #0.2 "-27"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↑" }} a'8^\markup { \pad-markup #0.2 "-16"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 5↓" }}[ g'8^\markup { \pad-markup #0.2 "+19"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 11↓" }}] ~ g'4 } \bar "|" diff --git a/resources/string_quartet_3_rise_coda_only/624f7439/lilypond/part_II.ly b/resources/string_quartet_3_rise_coda_only/624f7439/lilypond/part_II.ly index 79346aa..4effe9d 100644 --- a/resources/string_quartet_3_rise_coda_only/624f7439/lilypond/part_II.ly +++ b/resources/string_quartet_3_rise_coda_only/624f7439/lilypond/part_II.ly @@ -1,7 +1,7 @@ { { cis'2^\markup { \pad-markup #0.2 "-29"} gis8^\markup { \pad-markup #0.2 "-27"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }}[ ais8^\markup { \pad-markup #0.2 "+4"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 7↓" }}] c'8^\markup { \pad-markup #0.2 "-41"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 5↑" }}[ cis'8^\markup { \pad-markup #0.2 "-29"}] } \bar "|" - { dis'8^\markup { \pad-markup #0.2 "-25"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↑" }}[ e'8^\markup { \pad-markup #0.2 "-14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 5↓" }}] ~ e'2 dis'8^\markup { \pad-markup #0.2 "-25"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↑" }}[ c''8^\markup { \pad-markup #0.2 "-41"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }}] } + { dis'8^\markup { \pad-markup #0.2 "-25"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↑" }}[ e'8^\markup { \pad-markup #0.2 "-14"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 5↓" }}] ~ e'2 dis''8^\markup { \pad-markup #0.2 "-25"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↑" }}[ c''8^\markup { \pad-markup #0.2 "-41"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }}] } \bar "|" { cis''8^\markup { \pad-markup #0.2 "-29"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↓" }}[ dis''8^\markup { \pad-markup #0.2 "-25"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↑" }}] gis'4^\markup { \pad-markup #0.2 "-27"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }} c'4^\markup { \pad-markup #0.2 "-41"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }} ~ c'8[ cis'8^\markup { \pad-markup #0.2 "-29"}] } \bar "|" diff --git a/resources/string_quartet_3_rise_coda_only/624f7439/lilypond/part_IV.ly b/resources/string_quartet_3_rise_coda_only/624f7439/lilypond/part_IV.ly index dc2b6a7..ee8b179 100644 --- a/resources/string_quartet_3_rise_coda_only/624f7439/lilypond/part_IV.ly +++ b/resources/string_quartet_3_rise_coda_only/624f7439/lilypond/part_IV.ly @@ -1,7 +1,7 @@ { - { gis,2^\markup { \pad-markup #0.2 "-27"} cis''2^\markup { \pad-markup #0.2 "-29"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 1↑" }} ~ } + { gis,2^\markup { \pad-markup #0.2 "-27"} cis2^\markup { \pad-markup #0.2 "-29"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 1↑" }} ~ } \bar "|" - { cis''8[ gis'8^\markup { \pad-markup #0.2 "-27"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }}] ais,2^\markup { \pad-markup #0.2 "+4"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 7↓" }} c4^\markup { \pad-markup #0.2 "-41"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }} ~ } + { cis8[ gis,8^\markup { \pad-markup #0.2 "-27"}] ais,2^\markup { \pad-markup #0.2 "+4"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 7↓" }} c4^\markup { \pad-markup #0.2 "-41"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }} ~ } \bar "|" { c2 cis8^\markup { \pad-markup #0.2 "+24"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 11↑" }}[ dis8^\markup { \pad-markup #0.2 "-25"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↑" }}] cis4^\markup { \pad-markup #0.2 "-29"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 3↓" }} ~ } \bar "|" diff --git a/resources/string_quartet_3_rise_coda_only/65120e88/65120e88_mus_model.json b/resources/string_quartet_3_rise_coda_only/65120e88/65120e88_mus_model.json index f07d71f..c76bc8b 100644 --- a/resources/string_quartet_3_rise_coda_only/65120e88/65120e88_mus_model.json +++ b/resources/string_quartet_3_rise_coda_only/65120e88/65120e88_mus_model.json @@ -18,14 +18,14 @@ ], [ [ [ [ -7, 5, 1, 2, -1, 2 ], [ -5, 4, 1, 3, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ], [ -6, 4, 1, 3, -1, 2 ] ], 0 ], - [ [ [ -7, 5, 1, 2, -1, 2 ], [ -6, 4, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ], [ -6, 4, 1, 3, -1, 2 ] ], 0 ], - [ [ [ -6, 4, 0, 2, -1, 2 ], [ -6, 4, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ], [ -6, 4, 1, 3, -1, 2 ] ], 0.25 ] + [ [ [ -7, 5, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ], [ -6, 4, 1, 3, -1, 2 ] ], 0 ], + [ [ [ -6, 4, 0, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ], [ -6, 4, 1, 3, -1, 2 ] ], 0.25 ] ], [ - [ [ [ -7, 4, 1, 3, -1, 2 ], [ -6, 4, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ], [ -6, 4, 1, 3, -1, 2 ] ], 0 ], - [ [ [ -7, 4, 1, 3, -1, 2 ], [ -6, 4, 1, 3, -1, 1 ], [ -5, 4, 1, 2, -1, 2 ], [ -6, 4, 1, 3, -1, 2 ] ], 0.25 ], - [ [ [ -7, 4, 1, 3, -1, 2 ], [ -6, 3, 1, 3, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ], [ -6, 4, 1, 3, -1, 2 ] ], 0 ], - [ [ [ -7, 4, 0, 3, -1, 2 ], [ -6, 3, 1, 3, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ], [ -6, 4, 1, 3, -1, 2 ] ], 0.25 ] + [ [ [ -7, 4, 1, 3, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ], [ -6, 4, 1, 3, -1, 2 ] ], 0 ], + [ [ [ -7, 4, 1, 3, -1, 2 ], [ -5, 4, 1, 3, -1, 1 ], [ -5, 4, 1, 2, -1, 2 ], [ -6, 4, 1, 3, -1, 2 ] ], 0.25 ], + [ [ [ -7, 4, 1, 3, -1, 2 ], [ -5, 3, 1, 3, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ], [ -6, 4, 1, 3, -1, 2 ] ], 0 ], + [ [ [ -7, 4, 0, 3, -1, 2 ], [ -5, 3, 1, 3, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ], [ -6, 4, 1, 3, -1, 2 ] ], 0.25 ] ] ] ], diff --git a/resources/string_quartet_3_rise_coda_only/65120e88/lilypond/part_III.ly b/resources/string_quartet_3_rise_coda_only/65120e88/lilypond/part_III.ly index 03337bd..972b1a3 100644 --- a/resources/string_quartet_3_rise_coda_only/65120e88/lilypond/part_III.ly +++ b/resources/string_quartet_3_rise_coda_only/65120e88/lilypond/part_III.ly @@ -1,6 +1,6 @@ { - { cis''4^\markup { \pad-markup #0.2 "-25"} c''4^\markup { \pad-markup #0.2 "-37"} cis''8^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 13↑" }}[ d''8^\markup { \pad-markup #0.2 "+30"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 7↑" }}] f8^\markup { \pad-markup #0.2 "-38"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 1↑" }}[ fis8^\markup { \pad-markup #0.2 "-10"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↓" }}] } + { cis''4^\markup { \pad-markup #0.2 "-25"} c''4^\markup { \pad-markup #0.2 "-37"} cis''8^\markup { \pad-markup #0.2 "+2"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 13↑" }}[ d''8^\markup { \pad-markup #0.2 "+30"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 7↑" }}] f'8^\markup { \pad-markup #0.2 "-38"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 1↑" }}[ fis'8^\markup { \pad-markup #0.2 "-10"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 13↓" }}] } \bar "|" - { g1^\markup { \pad-markup #0.2 "+28"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }}} + { g'1^\markup { \pad-markup #0.2 "+28"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 3↓" }}} \bar "||" } \ No newline at end of file diff --git a/resources/string_quartet_3_rise_coda_only/66b20499/66b20499_mus_model.json b/resources/string_quartet_3_rise_coda_only/66b20499/66b20499_mus_model.json index 2a8636b..8e02a12 100644 --- a/resources/string_quartet_3_rise_coda_only/66b20499/66b20499_mus_model.json +++ b/resources/string_quartet_3_rise_coda_only/66b20499/66b20499_mus_model.json @@ -3,27 +3,27 @@ [ [ [ - [ [ [ -4, 4, -1, 2, -1, 2 ], [ -4, 4, -1, 2, -2, 3 ], [ -5, 5, -1, 2, -2, 2 ], [ -4, 4, -1, 2, -2, 2 ] ], 0.25 ], - [ [ [ -4, 4, -1, 2, -1, 2 ], [ -4, 5, -1, 2, -2, 2 ], [ -5, 5, -1, 2, -2, 2 ], [ -4, 4, -1, 2, -2, 2 ] ], 0.25 ], - [ [ [ -4, 4, -1, 2, -1, 2 ], [ -3, 4, -2, 2, -2, 2 ], [ -5, 5, -1, 2, -2, 2 ], [ -4, 4, -1, 2, -2, 2 ] ], 0.25 ], - [ [ [ -4, 4, -1, 2, -1, 2 ], [ -4, 4, 0, 2, -1, 2 ], [ -5, 5, -1, 2, -2, 2 ], [ -4, 4, -1, 2, -2, 2 ] ], 0.25 ] + [ [ [ -5, 4, -1, 2, -1, 2 ], [ -4, 4, -1, 2, -2, 3 ], [ -5, 5, -1, 2, -2, 2 ], [ -4, 4, -1, 2, -2, 2 ] ], 0.25 ], + [ [ [ -5, 4, -1, 2, -1, 2 ], [ -4, 5, -1, 2, -2, 2 ], [ -5, 5, -1, 2, -2, 2 ], [ -4, 4, -1, 2, -2, 2 ] ], 0.25 ], + [ [ [ -5, 4, -1, 2, -1, 2 ], [ -3, 4, -2, 2, -2, 2 ], [ -5, 5, -1, 2, -2, 2 ], [ -4, 4, -1, 2, -2, 2 ] ], 0.25 ], + [ [ [ -5, 4, -1, 2, -1, 2 ], [ -4, 4, 0, 2, -1, 2 ], [ -5, 5, -1, 2, -2, 2 ], [ -4, 4, -1, 2, -2, 2 ] ], 0.25 ] ], [ - [ [ [ -4, 4, -1, 2, -1, 2 ], [ -4, 4, 0, 2, -1, 2 ], [ -5, 5, -1, 2, -2, 2 ], [ -4, 4, 0, 1, -1, 2 ] ], 0 ], - [ [ [ -4, 4, 0, 2, -2, 2 ], [ -4, 4, 0, 2, -1, 2 ], [ -5, 5, -1, 2, -2, 2 ], [ -4, 4, 0, 1, -1, 2 ] ], 0.25 ], - [ [ [ -4, 4, 0, 2, -2, 2 ], [ -4, 4, 0, 2, -1, 2 ], [ -5, 4, 0, 2, -1, 2 ], [ -4, 4, 0, 1, -1, 2 ] ], 0.25 ], - [ [ [ -4, 4, 0, 2, -2, 2 ], [ -4, 4, 0, 2, -1, 2 ], [ -5, 4, -1, 2, -1, 2 ], [ -4, 4, 0, 1, -1, 2 ] ], 0.25 ], - [ [ [ -4, 4, 0, 2, -2, 2 ], [ -4, 4, 0, 2, -1, 2 ], [ -5, 4, 0, 2, -2, 2 ], [ -4, 4, 0, 1, -1, 2 ] ], 0.25 ], - [ [ [ -4, 4, 0, 2, -2, 2 ], [ -4, 4, 0, 2, -1, 2 ], [ -6, 5, 0, 2, -1, 2 ], [ -4, 4, 0, 1, -1, 2 ] ], 0.25 ] + [ [ [ -5, 4, -1, 2, -1, 2 ], [ -4, 4, 0, 2, -1, 2 ], [ -5, 5, -1, 2, -2, 2 ], [ -4, 4, 0, 1, -1, 2 ] ], 0 ], + [ [ [ -5, 4, 0, 2, -2, 2 ], [ -4, 4, 0, 2, -1, 2 ], [ -5, 5, -1, 2, -2, 2 ], [ -4, 4, 0, 1, -1, 2 ] ], 0.25 ], + [ [ [ -5, 4, 0, 2, -2, 2 ], [ -4, 4, 0, 2, -1, 2 ], [ -5, 4, 0, 2, -1, 2 ], [ -4, 4, 0, 1, -1, 2 ] ], 0.25 ], + [ [ [ -5, 4, 0, 2, -2, 2 ], [ -4, 4, 0, 2, -1, 2 ], [ -5, 4, -1, 2, -1, 2 ], [ -4, 4, 0, 1, -1, 2 ] ], 0.25 ], + [ [ [ -5, 4, 0, 2, -2, 2 ], [ -4, 4, 0, 2, -1, 2 ], [ -5, 4, 0, 2, -2, 2 ], [ -4, 4, 0, 1, -1, 2 ] ], 0.25 ], + [ [ [ -5, 4, 0, 2, -2, 2 ], [ -4, 4, 0, 2, -1, 2 ], [ -6, 5, 0, 2, -1, 2 ], [ -4, 4, 0, 1, -1, 2 ] ], 0.25 ] ], [ - [ [ [ -4, 4, 0, 2, -2, 2 ], [ -4, 4, 0, 2, -1, 2 ], [ -6, 5, 0, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0 ], - [ [ [ -4, 4, 0, 2, -2, 2 ], [ -4, 4, 0, 2, -1, 2 ], [ -4, 4, 0, 1, -2, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0.25 ] + [ [ [ -5, 4, 0, 2, -2, 2 ], [ -4, 4, 0, 2, -1, 2 ], [ -6, 5, 0, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0 ], + [ [ [ -5, 4, 0, 2, -2, 2 ], [ -4, 4, 0, 2, -1, 2 ], [ -4, 4, 0, 1, -2, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0.25 ] ], [ - [ [ [ -4, 4, 0, 2, -2, 2 ], [ -4, 4, 0, 2, -1, 2 ], [ -6, 5, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0 ], - [ [ [ -4, 4, 0, 2, -2, 2 ], [ -5, 5, 1, 2, -1, 2 ], [ -6, 5, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0 ], - [ [ [ -5, 4, 2, 2, -1, 2 ], [ -5, 5, 1, 2, -1, 2 ], [ -6, 5, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0.25 ], + [ [ [ -5, 4, 0, 2, -2, 2 ], [ -4, 4, 0, 2, -1, 2 ], [ -6, 5, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0 ], + [ [ [ -5, 4, 0, 2, -2, 2 ], [ -5, 5, 1, 2, -1, 2 ], [ -6, 5, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0 ], + [ [ [ -6, 4, 2, 2, -1, 2 ], [ -5, 5, 1, 2, -1, 2 ], [ -6, 5, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0.25 ], [ [ [ -6, 4, 1, 2, -1, 2 ], [ -5, 5, 1, 2, -1, 2 ], [ -6, 5, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0 ], [ [ [ -6, 4, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 3 ], [ -6, 5, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0.25 ], [ [ [ -6, 4, 1, 2, -1, 2 ], [ -5, 5, 1, 2, -1, 2 ], [ -6, 5, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0.25 ], diff --git a/resources/string_quartet_3_rise_coda_only/66b20499/lilypond/part_IV.ly b/resources/string_quartet_3_rise_coda_only/66b20499/lilypond/part_IV.ly index 845aaae..5aa7572 100644 --- a/resources/string_quartet_3_rise_coda_only/66b20499/lilypond/part_IV.ly +++ b/resources/string_quartet_3_rise_coda_only/66b20499/lilypond/part_IV.ly @@ -1,7 +1,7 @@ { - { a'2^\markup { \pad-markup #0.2 "-11"} g'2^\markup { \pad-markup #0.2 "+24"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 11↓" }} ~ } + { a2^\markup { \pad-markup #0.2 "-11"} g2^\markup { \pad-markup #0.2 "+24"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 11↓" }} ~ } \bar "|" - { g'4 gis'8^\markup { \pad-markup #0.2 "+48"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 5↑" }}[ f8^\markup { \pad-markup #0.2 "-38"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }}] ~ f4 ais,4^\markup { \pad-markup #0.2 "-40"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↓" }} ~ } + { g4 gis8^\markup { \pad-markup #0.2 "+48"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 5↑" }}[ f8^\markup { \pad-markup #0.2 "-38"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }}] ~ f4 ais,4^\markup { \pad-markup #0.2 "-40"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 3↓" }} ~ } \bar "|" { ais,2 b,8^\markup { \pad-markup #0.2 "+10"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 11↓" }}[ d8^\markup { \pad-markup #0.2 "+30"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }}] ~ d4 } \bar "|" diff --git a/resources/string_quartet_3_rise_coda_only/736745da/736745da_mus_model.json b/resources/string_quartet_3_rise_coda_only/736745da/736745da_mus_model.json index bf97af4..6a53117 100644 --- a/resources/string_quartet_3_rise_coda_only/736745da/736745da_mus_model.json +++ b/resources/string_quartet_3_rise_coda_only/736745da/736745da_mus_model.json @@ -24,8 +24,8 @@ [ [ [ [ -6, 3, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ], [ -5, 4, 0, 2, -1, 2 ], [ -5, 5, 1, 2, -1, 2 ] ], 0 ], [ [ [ -6, 3, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ], [ -6, 5, 1, 2, -1, 2 ], [ -5, 5, 1, 2, -1, 2 ] ], 0.25 ], - [ [ [ -6, 3, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ], [ -6, 4, 1, 2, -1, 2 ], [ -5, 5, 1, 2, -1, 2 ] ], 0.25 ], - [ [ [ -7, 4, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ], [ -6, 4, 1, 2, -1, 2 ], [ -5, 5, 1, 2, -1, 2 ] ], 0.25 ] + [ [ [ -6, 3, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ], [ -5, 5, 1, 2, -1, 2 ] ], 0.25 ], + [ [ [ -7, 4, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ], [ -5, 5, 1, 2, -1, 2 ] ], 0.25 ] ] ] ], diff --git a/resources/string_quartet_3_rise_coda_only/736745da/lilypond/part_II.ly b/resources/string_quartet_3_rise_coda_only/736745da/lilypond/part_II.ly index 75b08b0..3e4a791 100644 --- a/resources/string_quartet_3_rise_coda_only/736745da/lilypond/part_II.ly +++ b/resources/string_quartet_3_rise_coda_only/736745da/lilypond/part_II.ly @@ -1,6 +1,6 @@ { { ais4^\markup { \pad-markup #0.2 "-40"} gis4^\markup { \pad-markup #0.2 "+48"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 5↑" }} ais8^\markup { \pad-markup #0.2 "+13"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "IV"\normal-size-super " 1↑" }}[ c'8^\markup { \pad-markup #0.2 "-37"}] cis'8^\markup { \pad-markup #0.2 "-25"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 5↓" }}[ c'8^\markup { \pad-markup #0.2 "-37"}] } \bar "|" - { f1^\markup { \pad-markup #0.2 "-38"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }}} + { f'1^\markup { \pad-markup #0.2 "-38"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }}} \bar "||" } \ No newline at end of file diff --git a/resources/string_quartet_3_rise_coda_only/767e70f0/767e70f0_mus_model.json b/resources/string_quartet_3_rise_coda_only/767e70f0/767e70f0_mus_model.json index 8421367..1c5521c 100644 --- a/resources/string_quartet_3_rise_coda_only/767e70f0/767e70f0_mus_model.json +++ b/resources/string_quartet_3_rise_coda_only/767e70f0/767e70f0_mus_model.json @@ -3,28 +3,28 @@ [ [ [ - [ [ [ -4, 3, 1, 2, -1, 2 ], [ -6, 5, 1, 2, -1, 2 ], [ -5, 4, 0, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0 ], - [ [ [ -4, 3, 1, 2, -1, 2 ], [ -6, 5, 1, 2, -1, 2 ], [ -5, 3, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0 ], - [ [ [ -5, 5, 1, 2, -1, 2 ], [ -6, 5, 1, 2, -1, 2 ], [ -5, 3, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0.25 ], - [ [ [ -5, 5, 1, 2, -1, 2 ], [ -6, 5, 1, 2, -1, 2 ], [ -6, 4, 2, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0.25 ], - [ [ [ -5, 5, 1, 2, -1, 2 ], [ -6, 5, 1, 2, -1, 2 ], [ -6, 4, 1, 2, 0, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0 ], - [ [ [ -5, 5, 1, 2, -1, 2 ], [ -5, 4, 0, 2, -1, 2 ], [ -6, 4, 1, 2, 0, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0.25 ], - [ [ [ -5, 5, 1, 2, -1, 2 ], [ -5, 4, 0, 2, -1, 2 ], [ -6, 5, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0.25 ] + [ [ [ -5, 3, 1, 2, -1, 2 ], [ -6, 5, 1, 2, -1, 2 ], [ -5, 4, 0, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0 ], + [ [ [ -5, 3, 1, 2, -1, 2 ], [ -6, 5, 1, 2, -1, 2 ], [ -5, 3, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0 ], + [ [ [ -6, 5, 1, 2, -1, 2 ], [ -6, 5, 1, 2, -1, 2 ], [ -5, 3, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0.25 ], + [ [ [ -6, 5, 1, 2, -1, 2 ], [ -6, 5, 1, 2, -1, 2 ], [ -6, 4, 2, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0.25 ], + [ [ [ -6, 5, 1, 2, -1, 2 ], [ -6, 5, 1, 2, -1, 2 ], [ -6, 4, 1, 2, 0, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0 ], + [ [ [ -6, 5, 1, 2, -1, 2 ], [ -5, 4, 0, 2, -1, 2 ], [ -6, 4, 1, 2, 0, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0.25 ], + [ [ [ -6, 5, 1, 2, -1, 2 ], [ -5, 4, 0, 2, -1, 2 ], [ -6, 5, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0.25 ] ], [ - [ [ [ -5, 5, 1, 2, -1, 2 ], [ -6, 4, 1, 2, -1, 2 ], [ -6, 5, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0 ], - [ [ [ -5, 5, 1, 2, -1, 2 ], [ -6, 4, 1, 2, -1, 2 ], [ -5, 4, 0, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0.25 ], - [ [ [ -5, 5, 1, 2, -1, 2 ], [ -7, 6, 1, 2, -1, 2 ], [ -5, 4, 0, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0.25 ] + [ [ [ -6, 5, 1, 2, -1, 2 ], [ -6, 4, 1, 2, -1, 2 ], [ -6, 5, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0 ], + [ [ [ -6, 5, 1, 2, -1, 2 ], [ -6, 4, 1, 2, -1, 2 ], [ -5, 4, 0, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0.25 ], + [ [ [ -6, 5, 1, 2, -1, 2 ], [ -7, 6, 1, 2, -1, 2 ], [ -5, 4, 0, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0.25 ] ], [ - [ [ [ -5, 5, 1, 2, -1, 2 ], [ -7, 6, 1, 2, -1, 2 ], [ -6, 4, 1, 3, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0 ], - [ [ [ -5, 5, 1, 2, -1, 2 ], [ -6, 4, 2, 2, -1, 2 ], [ -6, 4, 1, 3, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0.25 ], - [ [ [ -4, 4, 0, 2, -1, 2 ], [ -6, 4, 2, 2, -1, 2 ], [ -6, 4, 1, 3, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0.25 ] + [ [ [ -6, 5, 1, 2, -1, 2 ], [ -7, 6, 1, 2, -1, 2 ], [ -6, 4, 1, 3, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0 ], + [ [ [ -6, 5, 1, 2, -1, 2 ], [ -6, 4, 2, 2, -1, 2 ], [ -6, 4, 1, 3, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0.25 ], + [ [ [ -5, 4, 0, 2, -1, 2 ], [ -6, 4, 2, 2, -1, 2 ], [ -6, 4, 1, 3, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0.25 ] ], [ - [ [ [ -6, 4, 1, 4, -1, 2 ], [ -6, 4, 2, 2, -1, 2 ], [ -6, 4, 1, 3, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0 ], - [ [ [ -6, 4, 1, 4, -1, 2 ], [ -5, 3, 1, 2, -1, 2 ], [ -6, 4, 1, 3, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0.25 ], - [ [ [ -6, 4, 1, 4, -1, 2 ], [ -5, 4, 1, 2, -1, 1 ], [ -6, 4, 1, 3, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0 ], + [ [ [ -7, 4, 1, 4, -1, 2 ], [ -6, 4, 2, 2, -1, 2 ], [ -6, 4, 1, 3, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0 ], + [ [ [ -7, 4, 1, 4, -1, 2 ], [ -5, 3, 1, 2, -1, 2 ], [ -6, 4, 1, 3, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0.25 ], + [ [ [ -7, 4, 1, 4, -1, 2 ], [ -5, 4, 1, 2, -1, 1 ], [ -6, 4, 1, 3, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0 ], [ [ [ -6, 4, 1, 2, -1, 2 ], [ -5, 4, 1, 2, -1, 1 ], [ -6, 4, 1, 3, -1, 2 ], [ -5, 4, 1, 2, -1, 2 ] ], 0.25 ] ] ] diff --git a/resources/string_quartet_3_rise_coda_only/767e70f0/lilypond/part_IV.ly b/resources/string_quartet_3_rise_coda_only/767e70f0/lilypond/part_IV.ly index 85ee8f1..28f6045 100644 --- a/resources/string_quartet_3_rise_coda_only/767e70f0/lilypond/part_IV.ly +++ b/resources/string_quartet_3_rise_coda_only/767e70f0/lilypond/part_IV.ly @@ -1,6 +1,6 @@ { - { c''2.^\markup { \pad-markup #0.2 "-37"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }} ~ c''8[ cis''8^\markup { \pad-markup #0.2 "-25"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 5↓" }}] } + { c'2.^\markup { \pad-markup #0.2 "-37"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "III"\normal-size-super " 1↑" }} ~ c'8[ cis'8^\markup { \pad-markup #0.2 "-25"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 5↓" }}] } \bar "|" - { c''8^\markup { \pad-markup #0.2 "-1"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 7↑" }}[ f8^\markup { \pad-markup #0.2 "-38"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }}] ~ f2.} + { c'8^\markup { \pad-markup #0.2 "-1"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "II"\normal-size-super " 7↑" }}[ f8^\markup { \pad-markup #0.2 "-38"}_\markup { \lower #3 \pad-markup #0.2 \concat{ "I"\normal-size-super " 1↑" }}] ~ f2.} \bar "||" } \ No newline at end of file