Example #1
0
    // Use this for initialization
    void Start()
    {
        myChuck = GetComponent <ChuckSubInstance>();
        myChuck.RunCode(@"
			global float dacLoudness;

			dac=> FFT fft =^ RMS rms => blackhole;
			1024 => fft.size;
			Windowing.hann(fft.size() ) => fft.window;

			while(true)
			{
				//upchuck: take fft then rms
				rms.upchuck() @=> UAnaBlob data;

				//store value in global
				data.fval(0) => dacLoudness; //where is this data var coming from?

				//advance time
				fft.size()::samp=>now;
			}
		"        );

        myGetLoudnessSyncer = gameObject.AddComponent <ChuckFloatSyncer>();
        myGetLoudnessSyncer.SyncFloat(myChuck, "dacLoudness");
    }
Example #2
0
 void SetUpChuck()
 {
     myChuckPitchTrack = GetComponent <ChuckSubInstance>();
     myPitchSyncer     = gameObject.AddComponent <ChuckFloatSyncer>();
     myPitchSyncer.SyncFloat(myChuckPitchTrack, "midiPos"); //current instance of chuck is determining pos value
     myAdcSyncer = gameObject.AddComponent <ChuckFloatSyncer>();
     myAdcSyncer.SyncFloat(myChuckPitchTrack, "adcOnFlag");
     //StartChuckPitchTrack(myChuckPitchTrack);
 }
Example #3
0
    // initialize audio
    void InitAudio()
    {
        // run the sequencer
        GetComponent <ChuckSubInstance>().RunFile("chickencer.ck", true);

        // add the float sync
        m_ckPlayheadPos = gameObject.AddComponent <ChuckFloatSyncer>();
        m_ckPlayheadPos.SyncFloat(GetComponent <ChuckSubInstance>(), "playheadPos");
        // add the int sync
        m_ckCurrentChicken = gameObject.AddComponent <ChuckIntSyncer>();
        m_ckCurrentChicken.SyncInt(GetComponent <ChuckSubInstance>(), "currentChicken");
    }
Example #4
0
    private void Start()
    {
        chuckSubInstance   = gameObject.GetComponent <ChuckSubInstance>();
        myFloatSyncer      = gameObject.AddComponent <ChuckFloatSyncer>();
        myAdvancerListener = gameObject.AddComponent <ChuckEventListener>();

        roomsInScene = new List <RoomController>(FindObjectsOfType <RoomController>());
        for (int i = 0; i < roomsInScene.Count; i++)
        {
            roomsInScene[i].beatFileName = "dum" + i.ToString();
        }
        StartChuckTimer();
    }
Example #5
0
 void SetChuckVars()
 {
     //metronome
     myChuckTempo      = GetComponent <ChuckSubInstance>();
     myMetronomeSyncer = gameObject.AddComponent <ChuckFloatSyncer>();
     myMetronomeSyncer.SyncFloat(myChuckTempo, "BEATS_PER_MIN"); //current instance of chuck is determining pos value
     //instruments
     myTempoSyncer = gameObject.AddComponent <ChuckFloatSyncer>();
     myTempoSyncer.SyncFloat(myChuck, "BEATS_PER_MIN");  //current instance of chuck is determining pos value
     myMeterSyncer = gameObject.AddComponent <ChuckFloatSyncer>();
     myMeterSyncer.SyncFloat(myChuck, "BEATS_PER_MEAS"); //current instance of chuck is determining pos value
     myInstrumentSyncer = gameObject.AddComponent <ChuckIntSyncer>();
     myInstrumentSyncer.SyncInt(myChuck, "instrument");
 }
    // Use this for initialization
    void Start()
    {
        myChuck = GetComponent <ChuckSubInstance>();
        myPos   = 0;

        myChuck.RunCode(@"
			1 => global float timeStep;
			global float pos;
			global Event notifier;

			fun void updatePos() {
				timeStep::second => dur currentTimeStep;
				currentTimeStep / 1000 => dur deltaTime;
				now => time startTime;
				
				pos => float originalPos;
								
				while( now < startTime + currentTimeStep )
				{
					deltaTime / currentTimeStep +=> pos;
					deltaTime => now;
				}
			}
			

			fun void playNote() {
				SinOsc foo => dac;
				0.2::second => now;
				foo =< dac;
			}

			while( true )
			{
				spork ~ playNote();
				spork ~ updatePos();
				notifier.broadcast();
				timeStep::second => now;
			}
		"        );

        myAdvancerSyncer = gameObject.AddComponent <ChuckFloatSyncer>();
        myAdvancerSyncer.SyncFloat(myChuck, "pos");           //current instance of chuck is determining pos value

        myAdvancerListener = gameObject.AddComponent <ChuckEventListener>();
        myAdvancerListener.ListenForEvent(myChuck, "notifier", RotateMyCube);
    }
Example #7
0
    float yPos; //syncer variable

    void Start()
    {
        // set display variables
        count      = 0;
        countBonus = 0;
        SetCountText();
        winText.text = "";

        // set chuck position tracking variables
        yPos     = midiStartNote;
        yPosPrev = yPos;

        // set up chuck
        myChuckPitchTrack = GetComponent <ChuckSubInstance>();
        StartChuckPitchTrack(myChuckPitchTrack);
        myPitchSyncer = gameObject.AddComponent <ChuckFloatSyncer>();
        myPitchSyncer.SyncFloat(myChuckPitchTrack, "midiPos"); //current instance of chuck is determining pos value
        myTimeSyncer = gameObject.AddComponent <ChuckFloatSyncer>();
        myTimeSyncer.SyncFloat(myChuckPitchTrack, "timePos");  //current instance of chuck is determining pos value
    }
    void RunChuckClock()
    {
        myChuck = GetComponent <ChuckSubInstance>();

        myChuck.RunCode(@"
			80.0 => global float bpm;
			//global float beatPos;
			global Event beatNotifier;
			
			while( true )
			{
				(15.0/bpm)::second => now; //increment by 16th note interval
				beatNotifier.broadcast();
			}
		"        );

        myTempoSyncer = gameObject.AddComponent <ChuckFloatSyncer>();
        myTempoSyncer.SyncFloat(myChuck, "bpm");
        myNextBeatListener = gameObject.AddComponent <ChuckEventListener>();
        myNextBeatListener.ListenForEvent(myChuck, "beatNotifier", ProcessBeat);
    }
Example #9
0
    // Use this for initialization
    void Start()
    {
        myChuck = GetComponent <ChuckSubInstance>();
        myChuck.RunCode(@"
            global float midiPlayed;
            global float midiValue;
            global float intensity;

            // Midi Set-up
            //---------------------------------------------------------------------
            // number of the device to open (see: chuck --probe)
            0 => int deviceNumber;
            if (me.args()) me.arg(0) => Std.atoi => deviceNumber;
            MidiIn min;
            MidiMsg msg;
            // open the device
            if (!min.open(deviceNumber)) me.exit();
            // print out device that was opened
            <<< ""MIDI device: "", min.num(), ""-> "", min.name() >>>;
            //--------------------------------------------------------------------- 

            // make our own event
                class NoteEvent extends Event
                {
                int note;
                int velocity;
            }

            // the event
            NoteEvent on;
            // array of ugen's handling each note
            Event @ us[128];

            // the base patch
            //Gain g => JCRev r => dac;
            Gain g => JCRev r => LPF lpf => HPF hpf => Pan2 p => dac;
            1.0 => g.gain;
            .6 => r.mix;
            10000 => lpf.freq;
            100 => hpf.freq;

            // handler for a single voice
            fun void handler()
            {
                // don't connect to dac until we need it
                FMVoices m;
                Event off;
                int note;

                while (true)
                {
                    on => now;
                    on.note => note;
                    // dynamically repatch
                    m => g;
                    Std.mtof(note) => m.freq;
                    //Math.random2f( .6, .8 ) => m.pluckPos;
                    on.velocity / 128.0 => m.noteOn;
                    off @=> us[note];

                    off => now;
                    null @=> us[note];
                    m =< g;
                }
            }

            // spork handlers, one for each voice
            for( 0 => int i; i< 20; i++ ) spork ~handler();

            fun void filterTracker() {
                while (true) {
                    // daytime
                    1.0 => g.gain;
                    .6 => r.mix;
                    for ( 0 => int i; i < 11979; i++ ) {
                        8000 - i/3 => lpf.freq;
                        7000 - i/3 => hpf.freq;
                        -.9 => p.pan;
                        1::ms => now;
                    }
                    0 => g.gain;
                    0 => r.mix;
                    20::ms => now;
                    // nighttime
                    1.0 => g.gain;
                    .6 => r.mix;
                    for ( 0 => int i; i < 11979; i++ ) {
                        100 + i/12 => lpf.freq;
                        100 => hpf.freq;
                        .9 => p.pan;
                        1::ms => now;
                    }
                    0 => g.gain;
                    0 => r.mix;
                    20::ms => now;
                }
            }

            3::second => now;

            spork ~filterTracker();

            // infinite time-loop
            while( true )
            {
                // wait on midi event
                min => now;
                
                // get the midimsg
                while(min.recv(msg ) )
                {
                    // catch only noteon
                    if(msg.data1 != 144 )
                        continue;
                    
                    1.0 => midiPlayed;
                    msg.data3 => intensity;
                    <<< ""keyNum down: "", msg.data2 >>>;
                    msg.data2 => int midiDataInt;
                    midiDataInt => float midiDataFloat;
                    midiDataFloat - 60 => midiValue;
                    25::ms => now;

                    // check velocity
                    if(msg.data3 > 0 )
                    {
                        // store midi note number
                        msg.data2 => on.note;
                        // store velocity
                        msg.data3 => on.velocity;
                        // signal the event
                        on.signal();
                        // yield without advancing time to allow shred to run
                        me.yield();
                    }
                    else
                    {
                        if(us[msg.data2] != null ) us[msg.data2].signal();
                    }
                }
                0.0 => midiPlayed;
            }
        ");

        midiPlayedSyncer = gameObject.AddComponent <ChuckFloatSyncer>();
        midiPlayedSyncer.SyncFloat(myChuck, "midiPlayed");
        midiValueSyncer = gameObject.AddComponent <ChuckFloatSyncer>();
        midiValueSyncer.SyncFloat(myChuck, "midiValue");
        intensitySyncer = gameObject.AddComponent <ChuckFloatSyncer>();
        intensitySyncer.SyncFloat(myChuck, "intensity");
    }