|
|
@@ -1,4 +1,4 @@
|
|
|
-// Module 5: OSC Communication Setup with ROBUST Synth Pool
|
|
|
+// Module 5: OSC Communication Setup with Fixed Synth Pool (No s.sync)
|
|
|
// Save as "5_osc_communication.scd" (REPLACE PREVIOUS VERSION)
|
|
|
|
|
|
(
|
|
|
@@ -34,12 +34,12 @@ OSCdef.freeAll;
|
|
|
blueAmt: 0.5
|
|
|
);
|
|
|
|
|
|
-// ========== ROBUST SYNTH POOL SYSTEM ==========
|
|
|
+// ========== SIMPLE SYNTH POOL SYSTEM ==========
|
|
|
// Synth Pool Configuration
|
|
|
~poolSize = 16; // Number of pre-allocated synths
|
|
|
-~synthPool = Array.newClear(~poolSize); // Array instead of dictionary
|
|
|
+~synthPool = Array.newClear(~poolSize); // Array of synths
|
|
|
~activeSynths = IdentityDictionary.new; // Track which synths are in use
|
|
|
-~freeIndices = Array.series(~poolSize); // Available synth indices
|
|
|
+~freeIndices = Array.series(~poolSize); // Available synth indices (0,1,2...15)
|
|
|
~synthPoolGroup = nil;
|
|
|
~poolInitialized = false;
|
|
|
|
|
|
@@ -50,20 +50,22 @@ OSCdef.freeAll;
|
|
|
// Set flag
|
|
|
~poolInitialized = false;
|
|
|
|
|
|
- // Return all active synths
|
|
|
- ~activeSynths.keys.do({ |key|
|
|
|
- try {
|
|
|
- ~returnSynthToPool.value(key);
|
|
|
- } { |error|
|
|
|
- // Silent cleanup - don't print errors during cleanup
|
|
|
- };
|
|
|
+ // Return all active synths to pool (without errors)
|
|
|
+ if(~activeSynths.notNil, {
|
|
|
+ ~activeSynths.keys.do({ |key|
|
|
|
+ try {
|
|
|
+ ~returnSynthToPool.value(key);
|
|
|
+ } {
|
|
|
+ // Silent cleanup
|
|
|
+ };
|
|
|
+ });
|
|
|
});
|
|
|
|
|
|
// Free the group (this frees all synths)
|
|
|
if(~synthPoolGroup.notNil, {
|
|
|
try {
|
|
|
~synthPoolGroup.free;
|
|
|
- } { |error|
|
|
|
+ } {
|
|
|
// Silent cleanup
|
|
|
};
|
|
|
~synthPoolGroup = nil;
|
|
|
@@ -72,7 +74,7 @@ OSCdef.freeAll;
|
|
|
// Clear data structures
|
|
|
~synthPool = Array.newClear(~poolSize);
|
|
|
~activeSynths.clear;
|
|
|
- ~freeIndices = Array.series(~poolSize);
|
|
|
+ ~freeIndices = Array.series(~poolSize); // Reset to [0,1,2,3...15]
|
|
|
|
|
|
// Reset touch state
|
|
|
~touchState.isActive = false;
|
|
|
@@ -81,28 +83,33 @@ OSCdef.freeAll;
|
|
|
"Synth pool cleaned up".postln;
|
|
|
};
|
|
|
|
|
|
-// Initialize the synth pool
|
|
|
+// Initialize the synth pool - FIXED VERSION (no s.sync)
|
|
|
~initializeSynthPool = {
|
|
|
// Clean up first
|
|
|
~cleanupSynthPool.value;
|
|
|
|
|
|
- // Wait for server
|
|
|
- s.sync;
|
|
|
+ "Creating synth pool with % synths...".format(~poolSize).postln;
|
|
|
|
|
|
// Create a group to hold all pool synths
|
|
|
~synthPoolGroup = Group.new;
|
|
|
- s.sync;
|
|
|
-
|
|
|
- "Creating synth pool with % synths...".format(~poolSize).postln;
|
|
|
|
|
|
- // Create all synths at once
|
|
|
+ // Create all synths at once without s.sync
|
|
|
~poolSize.do({ |i|
|
|
|
try {
|
|
|
var synth = Synth(\rgbSynth, [
|
|
|
\out, ~sourceBus ? 0,
|
|
|
\gate, 0, // Start with gate closed (silent)
|
|
|
\amp, 0,
|
|
|
- \freq, 440
|
|
|
+ \freq, 440,
|
|
|
+ \ampAttack, 0.01,
|
|
|
+ \ampRelease, 1,
|
|
|
+ \filterAttack, 0,
|
|
|
+ \filterRelease, 0,
|
|
|
+ \pitchAttack, 0,
|
|
|
+ \pitchRelease, 0,
|
|
|
+ \redAmt, 0.5,
|
|
|
+ \greenAmt, 0.5,
|
|
|
+ \blueAmt, 0.5
|
|
|
], ~synthPoolGroup);
|
|
|
|
|
|
// Store in array
|
|
|
@@ -113,21 +120,19 @@ OSCdef.freeAll;
|
|
|
};
|
|
|
});
|
|
|
|
|
|
- // Wait for all synths to be created
|
|
|
- s.sync;
|
|
|
-
|
|
|
// Mark as initialized
|
|
|
~poolInitialized = true;
|
|
|
|
|
|
"Synth pool initialized with % synths".format(~poolSize).postln;
|
|
|
"Free synths: %".format(~freeIndices.size).postln;
|
|
|
+ "Pool status: %".format(~poolInitialized).postln;
|
|
|
};
|
|
|
|
|
|
// Get a free synth from the pool
|
|
|
~getSynthFromPool = { |key|
|
|
|
var synthIndex, synth = nil;
|
|
|
|
|
|
- if(~poolInitialized.not, {
|
|
|
+ if(~poolInitialized != true, {
|
|
|
"Error: Synth pool not initialized!".postln;
|
|
|
nil;
|
|
|
}, {
|
|
|
@@ -136,8 +141,8 @@ OSCdef.freeAll;
|
|
|
synthIndex = ~freeIndices.removeAt(0);
|
|
|
synth = ~synthPool[synthIndex];
|
|
|
|
|
|
- // Check if synth is valid
|
|
|
- if(synth.notNil and: { synth.isPlaying }, {
|
|
|
+ // Check if synth exists
|
|
|
+ if(synth.notNil, {
|
|
|
// Mark it as active
|
|
|
~activeSynths[key] = (synth: synth, index: synthIndex);
|
|
|
|
|
|
@@ -160,9 +165,9 @@ OSCdef.freeAll;
|
|
|
|
|
|
synth;
|
|
|
}, {
|
|
|
- // Synth is invalid, put index back and return nil
|
|
|
+ // Synth is nil, put index back and return nil
|
|
|
~freeIndices.add(synthIndex);
|
|
|
- "Warning: Synth % is invalid".format(synthIndex).postln;
|
|
|
+ "Warning: Synth % is nil".format(synthIndex).postln;
|
|
|
nil;
|
|
|
});
|
|
|
}, {
|
|
|
@@ -649,7 +654,7 @@ CmdPeriod.add({
|
|
|
thisProcess.openUDPPort(57120);
|
|
|
|
|
|
"========================================".postln;
|
|
|
-"OSC Communication with ROBUST Synth Pool loaded".postln;
|
|
|
+"OSC Communication with FIXED Synth Pool loaded".postln;
|
|
|
"========================================".postln;
|
|
|
"Available functions:".postln;
|
|
|
" ~initializeSynthPool.value - Initialize 16 synths".postln;
|
|
|
@@ -658,5 +663,6 @@ thisProcess.openUDPPort(57120);
|
|
|
" ~cleanupOSCSystem.value - Clean up OSC".postln;
|
|
|
"".postln;
|
|
|
"IMPORTANT: Run ~initializeSynthPool.value after effects chain is ready!".postln;
|
|
|
+"NO MORE S.SYNC CALLS - Should work without Routine errors!".postln;
|
|
|
"========================================".postln;
|
|
|
)
|