AJ | Pact | logo
PACT
Supercollider a day

Supercollider a day

1 September 2009

Hackpact (30 posts)

For Hackpact I will attempt to learn the Supercollider audio programming language, updating this page with a new block of code each day.

Speaking patch (for the farewell)

30/09/09

To say goodbye to Hackpact, here's a speaking patch.

/* ==========================================================================
   Supercollider a day - for HackPact 2009
   -------------------
   by Adam Jansch
  
   30 September 2009
   
   Speaking patch (for the farewell)
   ========================================================================== */


 
(
  // Declare UI controls -------------------------------------

  var speak_window, speak_text, speak_button;
  
  // Define UI controls --------------------------------------

  speak_window = SCWindow("Speaking patch", Rect(100, 100, 370, 60)).front;
  speak_text = SCTextField(speak_window, Rect(10, 10, 280, 40))
    .font_(Font.new("Helvetica", 16)).focus(true).string_("Goodbye world!");
  speak_button = SCButton(speak_window, Rect(300, 10, 60, 40))
    .states_([["Speak", Color.black, Color.green]]);
  
  // UI control actions --------------------------------------

  speak_text.action_({
    |speak_text_val|
    
    speak_text_val.value.speak;
  });
  
  speak_button.action_({
    speak_text.value.speak;
  });
)