lambdaway
::
musical_scales
6
|
list
|
login
|
load
|
|
_img data/8BCDB20E-D0D4-4FD7-A3F0-35BB74535D03.jpeg _h1 musical scales _p See also [[dodecaphony|http://lambdaway.free.fr/workshop/index.php?view=dodecaphony]] and [[fantasia|https://imslp.org/wiki/Fantasia_in_D_minor,_K.397/385g_(Mozart,_Wolfgang_Amadeus)]]. _p Using the {b musicalScale()} javascript function found in [[rosettacode.org|https://rosettacode.org/wiki/Musical_scale#JavaScript]], we build a lambdatalk interface to output the 8 notes of the C major diatonic scale, and more. _h2 functions {pre '{def note {lambda {:i} {floor {* 262 {pow 2 {/ :i 12}}}}}} // do = 262Hz, la = 440Hz -> {def note {lambda {:i} {floor {* 262 {pow 2 {/ :i 12}}}}}} '{S.map note {S.serie 0 12}} -> {S.map note {S.serie 0 12}} '{def scale {lambda {:notes} [{S.map {lambda {:i} {note :i},} :notes}]}} -> {def scale {lambda {:notes} [{S.map {lambda {:i} {note :i},} :notes}]}} '{def play {lambda {:n} {input {@ type="button" value="Play :n" onclick="musicalScale({scale :n})"}}}} -> {def play {lambda {:n} {input {@ type="button" value="Play" onclick="musicalScale({scale :n})"}}}} '{def display {lambda {:n} {span {@ style="vertical-align:{* 5 :n}px; letter-spacing:0.05em;"}:n}}} -> {def display {lambda {:n} {span {@ style="vertical-align:{* 5 :n}px; letter-spacing:0.05em; ;; border:1px solid #444; border-radius:10px; "}:n}}} '{def foo {lambda {:n} {div {@ style="background:#ddd; padding:5px;"} {S.map display :n}} {play :n}}} -> {def foo {lambda {:n} {div {@ style="background-color:#ddd; padding:5px;"} {S.map display :n}} {play :n}}} } ;; {div {@ class="solf"}} _h2 playing {pre 1) diatonic up '{foo 0 2 4 5 7 9 11 12} // do ré mi fa sol la si do -> {foo 0 2 4 5 7 9 11 12 12 12} 2) diatonic down '{foo 12 11 9 7 5 4 2 0} // do si la sol fa mi ré do -> {foo 12 11 9 7 5 4 2 0 0 0} 3) twelve intervals of the octave '{foo {S.serie 0 12}} -> {foo {S.serie 0 12}} 4) starting xxx '{foo 0 2 3 5 7 3 7 7 6 2 6 6 7 3 7 7 0 2 3 5 7 3 7 12 10 7 3 7 10 10 10 10} -> {foo 0 2 3 5 7 3 7 7 6 2 6 6 7 3 7 7 0 2 3 5 7 3 7 12 10 7 3 7 10 10 10 10} 5) the same reversed '{foo 10 7 3 7 10 12 7 3 7 5 3 2 0 7 7 3 7 6 6 2 6 7 7 3 7 5 3 2 0 0 0} -> {foo 10 7 3 7 10 12 7 3 7 5 3 2 0 7 7 3 7 6 6 2 6 7 7 3 7 5 3 2 0 0 0} 6) random walk '{foo {S.map {lambda {} {round {* 20 {random}}}} {S.serie 0 30}}} -> {foo {S.map {lambda {} {round {* 20 {random}}}} {S.serie 0 30}}} 7) en route vers "A la claire fontaine..." '{foo 0 0 0 4 4 2 4 0 0 0 4 4 2 4 4 4 4 4 4 2 0 4 7 4 7 7 7 4 0 4 2 2 2} -> {foo 0 0 0 4 4 2 4 0 0 0 4 4 2 4 4 4 4 4 4 2 0 4 7 4 7 7 7 4 0 4 2 2 2} il y a long temps que je t'ai me ja mais je ne t'ou blie rai. '{foo 0 0 0 0 0 0 4 4 4 4 2 0 4 4 0 0 4 4 4 4 4 2 0 4 4 2 2 0 0} -> {foo 0 0 0 0 0 0 4 4 4 4 2 0 4 4 0 0 4 4 4 4 4 4 2 0 4 4 2 2 0 0} } _img https://musescore.com/static/musescore/scoredata/gen/4/7/8/5057874/bd9f25e2845bff6d17bb5a610d46334244658fb8/score_0.png {script function musicalScale(freqArr){ var AudioContext = window.AudioContext || window.webkitAudioContext; var audioCtx = new AudioContext(); var oscillator = audioCtx.createOscillator(); var gainNode = audioCtx.createGain(); oscillator.connect(gainNode); gainNode.connect(audioCtx.destination); duration = 0.25 // seconds freqArr.forEach(function (freq, i){ oscillator.frequency.setValueAtTime( freq, audioCtx.currentTime + i * duration); }); oscillator.start(); oscillator.stop(audioCtx.currentTime + freqArr.length * duration); } } {style .solf { background-image: url("https://www.tabs4acoustic.com/images/uploads/images/Exemples_introduction_au_solfege_0015-600x70.png") 50% 50% ; background-color: #888; box-shadow:0 0 8px #000; } }
lambdaway v.20211111