diff --git a/sound_algo/data_only/matrix.scd b/sound_algo/data_only/matrix.scd index 6a8f773..674145f 100644 --- a/sound_algo/data_only/matrix.scd +++ b/sound_algo/data_only/matrix.scd @@ -513,6 +513,35 @@ File.exists(~matDir).not.if({ ("mkdir -p " ++ ~matDir.quote).systemCmd }); File.exists(up).if({ ~matLoadFile.(up) }, { ~matLoadFile.(pp) }) }; +// -- ~matAudition : preview a voice's 6 colors as a 1-beat-per-step loop -- +// on=true starts a Routine cycling color 1..6 (re-sources the voice's Pdef each +// step); on=false stops the routine and silences the voice. Preview only — does +// not move the grid playhead. +~matAudition = { |vi, on| + (vi >= 0 and: { vi < ~matVoices.size }).if({ + var name = ~matVoices[vi]; + var key = ("lp_" ++ name).asSymbol; + ~matAudRoutine = ~matAudRoutine ? IdentityDictionary.new; + ~matAudRoutine[vi] !? { ~matAudRoutine[vi].stop }; + on.if({ + var clock = ~lp[\clock] ? TempoClock.default; + ~matAudRoutine[vi] = Routine({ + var c = 1; + loop { + var pat = ~matVariation.(name, c, vi); + pat.notNil.if({ Pdef(key, pat); Pdef(key).play(clock, quant: 1) }); + 1.wait; + c = (c % 6) + 1; + } + }).play(clock, quant: 1); + }, { + ~matAudRoutine[vi] = nil; + Pdef.all.includesKey(key).if({ Pdef(key).stop }); + ~matLastColor[vi] = -1; // force normal re-source on next grid bar + }) + }) +}; + // -- OSCdefs (unique \mat_* keys; register sender for TouchOSC feedback) -- OSCdef(\mat_cell, { |msg, time, addr| ~toscTouch !? { ~toscTouch.(addr) }; @@ -586,6 +615,11 @@ OSCdef(\mat_colordef_get, { |msg, time, addr| ~matColorDefPush.((msg[1] ? 0).asInteger) }, '/matrix/colordefs/get'); +OSCdef(\mat_audition, { |msg, time, addr| + ~toscTouch !? { ~toscTouch.(addr) }; + ~matAudition.((msg[1] ? 0).asInteger, (msg[2] ? 0) > 0) +}, '/matrix/audition'); + // -- Capture mod source cache (nil-guarded; idempotent reload) -- ~matModCache = ~matModCache ? IdentityDictionary.new; ~matModSources = ~matModSources ? diff --git a/sound_algo/data_only/test/test_matrix.scd b/sound_algo/data_only/test/test_matrix.scd index 1cb07c3..0d61b4c 100644 --- a/sound_algo/data_only/test/test_matrix.scd +++ b/sound_algo/data_only/test/test_matrix.scd @@ -333,6 +333,12 @@ pass = pass and: { (~matColorDefs[5][3][\bogus]).isNil }; pass = pass and: { ~matColorDefs[0][1][\inst].isNil }; ~matSetColorDef.(5, 3, \octave, 0); // restore +// --- Color editor: audition (Task 3) --- +pass = pass and: { ~matAudition.notNil }; +// off when not running must not raise +try { ~matAudition.(0, false) } { |e| pass = false; + ("EXCEPTION matAudition off: " ++ e.class.name).postln }; + pass.if( { "TEST PASS".postln }, { "TEST FAIL".postln }