コード例 #1
0
 void Start()
 {
     // get chuck subinstance
     myChuck = GetComponent <ChuckSubInstance>();
     // start music
     Play();
 }
コード例 #2
0
 // Use this for initialization
 void Start()
 {
     myChuck = GetComponent <ChuckSubInstance>();
     SetChuckVars();
     RunChuckInstrument();
     StartCoroutine(DestroyChuckSound(SetChuckAliveTime()));
 }
コード例 #3
0
    // Use this for initialization
    void Start()
    {
        myChuck = GetComponent <ChuckSubInstance>();
        myChuck.RunCode(@"
			TriOsc myOsc;
			[60.0] @=> global float myFloatNotes[];
			global Event playMyNotes;
			
			while( true )
			{
				playMyNotes => now;
				myOsc => dac;
				for( 0 => int i; i < myFloatNotes.size(); i++ )
				{
                    <<< ""myFloatNotes["", i, ""] ="", myFloatNotes[i] >>>;
					myFloatNotes[i] => Math.mtof => myOsc.freq;
					100::ms => now;
				}
				<<< myFloatNotes[""numPlayed""], ""played so far"" >>>;
				myOsc =< dac;
			}
		"        );

        myFloatArrayCallback = myChuck.CreateGetFloatArrayCallback(GetInitialArrayCallback);
        myFloatCallback      = myChuck.CreateGetFloatCallback(GetANumberCallback);
    }
コード例 #4
0
 // Use this for initialization
 void Start()
 {
     myChuck = GetComponent <ChuckSubInstance>();
     SetChuckVars();
     StartChuckMetronome(myChuckTempo);
     RunChuckInstrument();
 }
コード例 #5
0
    // Use this for initialization
    void Start()
    {
        myChuck = GetComponent <ChuckSubInstance>();

        // for no logs: you will probably use this setting 99% of the time.
        Debug.Log("no chuck logs:");
        Chuck.SetLogLevel(Chuck.LogLevel.None);
        RunAChuckProgram();


        // for warnings

        /*
         * Debug.Log( "warning chuck logs:" );
         * Chuck.SetLogLevel( Chuck.LogLevel.Warning );
         * RunAChuckProgram();
         */

        // for all possible logs.

        /*
         * Debug.Log( "'crazy' chuck logs:" );
         * Chuck.SetLogLevel( Chuck.LogLevel.Crazy );
         * RunAChuckProgram();
         */

        // see other levels between the above in Chuck.cs
    }
コード例 #6
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");
    }
コード例 #7
0
 void Awake()
 {
     Assert.IsNotNull(textureClip);
     sc            = GetComponent <SphereController>();
     chuck         = GetComponent <ChuckSubInstance>();
     source        = GetComponent <AudioSource>();
     collideSource = transform.Find("CollisionAudioSource").GetComponent <AudioSource>();
 }
コード例 #8
0
 //MainScript TheScript;
 // Start is called before the first frame update
 void Start()
 {
     TheGameController = GameObject.Find("Button");
     myChuck           = GetComponent <ChuckSubInstance>();
     counter           = 1;
     paused            = false;
     started           = false;
 }
コード例 #9
0
 // Use this for initialization
 void Start()
 {
     // If bpm not set, set it to 120
     chuck = GetComponent <ChuckSubInstance>();
     bpm   = bpm == 0 ? 120 : bpm;
     SetBPM(bpm);
     t = eventDelta;
 }
コード例 #10
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);
 }
コード例 #11
0
    private void Start()
    {
        chuckSubInstance = GetComponent <ChuckSubInstance>();
        Debug.Assert(chuckSubInstance != null);

        poisInRoom = new List <PoiController>();

        partyLight.intensity = 0;
        partyLight.color     = roomColor;
    }
コード例 #12
0
    // ================= PUBLIC FACING ================== //


    // ----------------------------------------------------
    // name: SyncString
    // desc: start checking chuck for stringToSync so that
    //       later, you can get it whenever you want
    // ----------------------------------------------------
    public void SyncString(ChuckSubInstance chuck, string stringToSync)
    {
        // cancel existing if it's happening
        StopSyncing();

        // start up again
        myChuck          = chuck;
        myStringName     = stringToSync;
        myStringCallback = Chuck.CreateGetStringCallback(MyCallback);
    }
コード例 #13
0
    // ================= PUBLIC FACING ================== //


    // ----------------------------------------------------
    // name: SyncInt
    // desc: start checking chuck for intToSync so that
    //       later, you can get it whenever you want
    // ----------------------------------------------------
    public void SyncInt(ChuckSubInstance chuck, string intToSync)
    {
        // cancel existing if it's happening
        StopSyncing();

        // start up again
        myChuck       = chuck;
        myIntName     = intToSync;
        myIntCallback = Chuck.CreateGetIntCallback(MyCallback);
    }
コード例 #14
0
    // ================= PUBLIC FACING ================== //


    // ----------------------------------------------------
    // name: ListenForEvent
    // desc: start checking chuck for eventToListenFor so
    //       that callback will be called when the event
    //       broadcasts (or signals, if it's its turn)
    // ----------------------------------------------------
    public void ListenForEvent(ChuckSubInstance chuck, string eventToListenFor, Action callback)
    {
        // cancel existing if it's happening
        StopListening();

        // start up again
        myVoidCallback = Chuck.CreateVoidCallback(MyCallback);
        userCallback   = callback;
        myChuck        = chuck;
        myEventName    = eventToListenFor;
        myChuck.StartListeningForChuckEvent(myEventName, myVoidCallback);
    }
コード例 #15
0
 private void Awake()
 {
     rb2d = GetComponent <Rigidbody2D>();
     PlayerSpriteHolder     = transform.Find("PlayerSpriteHolder").gameObject;
     spriteanimator         = PlayerSpriteHolder.transform.Find("PlayerSprite").gameObject.GetComponent <Animator>();
     health_slider.maxValue = PlayerCloud.life_max;
     health_slider.value    = PlayerCloud.life;
     speed              = 3.5f;
     isAtGoalZone       = false;
     chuck              = GetComponent <ChuckSubInstance>();
     speech_bubble_text = speech_bubble_panel.transform.GetChild(0).GetComponent <TextMeshProUGUI>();
     speech_bubble_panel.SetActive(false);
 }
コード例 #16
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();
    }
コード例 #17
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");
 }
コード例 #18
0
    void StartChuckMetronome(ChuckSubInstance myChuckTempo)
    {
        // instantiate Chuck Pitch Tracking code
        myChuckTempo.RunCode(@"

			100 => global float BEATS_PER_MIN;
			global Event mtrNotifier;
			while(true) 
			{
				mtrNotifier.broadcast();
				(60/BEATS_PER_MIN)::second => now;
			}
		"        );

        myMetronomeNotifier = gameObject.AddComponent <ChuckEventListener>();
        myMetronomeNotifier.ListenForEvent(myChuckTempo, "mtrNotifier", BroadcastBeat);
    }
    // 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);
    }
コード例 #20
0
    // Use this for initialization
    void Start()
    {
        myChuck            = GetComponent <ChuckSubInstance>();
        myGetPosCallback   = Chuck.CreateGetFloatCallback(GetPosCallback);
        myTimeStepCallback = Chuck.CreateVoidCallback(BeNotified1);

        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;
			}
		"        );

        myChuck.StartListeningForChuckEvent("notifier", myTimeStepCallback);
    }
コード例 #21
0
    void Start()
    {
        freq = freqMin + (y / (yMax - yMin)) * (freqMax - freqMin);

        chuck = GetComponent <ChuckSubInstance>();

        // TODO this is a hack to avoid playing sound when the model is not trained
        if (useInteractML && thereminParameter == 0)
        {
            return;
        }

        chuck?.RunCode(@"
			global SinOsc s;
			s => dac;
			while( true ) { 1::second => now; }
	    "    );
    }
コード例 #22
0
    void Start()
    {
        myChuck = GetComponent <ChuckSubInstance>();

        // broadcast "notifier" every 250 ms
        myChuck.RunCode(@"
            global Event notifier;
            while( true )
            {
                notifier.broadcast();
                250::ms => now;
            }
        ");

        // create a ChuckEventListener on this gameObject
        ChuckEventListener listener = gameObject.AddComponent <ChuckEventListener>();

        // call MyCallback() on the Update() thread after every broadcast from "notifier"
        listener.ListenForEvent(myChuck, "notifier", MyCallback);
    }
コード例 #23
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
    }
コード例 #24
0
    void Start()
    {
        // get reference to chuck instance
        myChuck = GetComponent <ChuckSubInstance>();
        // create the callback we will pass
        myCallback = Chuck.CreateVoidCallback(CallbackFunction);

        // run code: make a global event, and every 250 ms, broadcast it to all listeners
        myChuck.RunCode(@"
			global Event notifier;
			while( true )
			{
				notifier.broadcast();
				250::ms => now;
			}
		"        );

        // register myCallback as a listener of Event "notifier" until I tell it to stop
        myChuck.StartListeningForChuckEvent("notifier", myCallback);
    }
コード例 #25
0
    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);
    }
コード例 #26
0
    // Use this for initialization
    void Start()
    {
        myChuck = GetComponent <ChuckSubInstance>();

        myChuck.RunCode(@"
			global string filename;
			global Event playTheFile;

			playTheFile => now;

			SndBuf buf => dac;
			filename => buf.read;
			
			""I GOT YOUR FILE"" @=> filename;

			buf.length() => now;
		"        );

        mySyncer = gameObject.AddComponent <ChuckStringSyncer>();
        mySyncer.SyncString(myChuck, "filename");
    }
コード例 #27
0
 // Use this for initialization
 void Start()
 {
     myChuck = GetComponent <ChuckSubInstance>();
 }
コード例 #28
0
    // Use this for initialization
    void Start()
    {
        instrument_face = GetComponent <Collider>();

        if (attachedLight == null)
        {
            attachedLight = transform.GetComponentInChildren <Light>(); // get the light component
        }
        if (attachedClip == null)
        {
            attachedClip = transform.GetComponent <AudioSource>(); // get the audio component
        }
        if (attachedLight)
        {
            light_attached        = true;
            attachedLight.enabled = false;                              // light is not on when initializing
        }
        light_material = gameObject.GetComponent <Renderer>().material; // grab the material for possible lighting changes

        if (attachedClip)
        {
            clip_attached = true;
            clip_toggle   = false;
        }

        if (light_material == null)
        {
            gameObject.SetActive(false);
        }

        if (audiok == null)
        {
            audiok = GetComponent <ChuckSubInstance>();
        }

        if (audiok)
        {
            audio_enabled = true;
            audio_toggle  = false;


            GetComponent <ChuckSubInstance>().RunCode(@"
            fun void playHH() {
                Noise n => HPF f => ADSR e => dac;
                f.freq(7000.0);
                n.gain(.9);
                e.set(2::ms, (80+Math.random2(0, 60))::ms, 0.0, 120::ms);
                e.keyOn();
                100::ms => now;
                }
            global Event HHImpact;
            while(true)
            {
                HHImpact => now;
                spork~playHH();
            }");

            GetComponent <ChuckSubInstance>().RunCode(@"
            class Toms 
            { 
                Impulse i; // the attack 
                i => Gain g1 => Gain g1_fb => g1 => LPF g1_f => Gain TomFallFreq; // tom decay pitch envelope 
                i => Gain g2 => Gain g2_fb => g2 => LPF g2_f; // tom amp envelope 
    
                // drum sound oscillator to amp envelope to overdrive to LPF to output 
                TomFallFreq => SinOsc s => Gain ampenv => SinOsc s_ws => LPF s_f => Gain output; 
                Step BaseFreq => s; // base Tom pitch 
    
                g2_f => ampenv; // amp envelope of the drum sound 
                3 => ampenv.op; // set ampenv a multiplier 
                1 => s_ws.sync; // prepare the SinOsc to be used as a waveshaper for overdrive 
    
                // set default 
                100.0 => BaseFreq.next; 
                50.0 => TomFallFreq.gain; // tom initial pitch: 80 hz 
                // 1.0 - 1.0 / 4000 => g1_fb.gain; // tom pitch decay 
                .9998 => g1_fb.gain; // tom pitch decay 
                g1_f.set(200, 1); // set tom pitch attack 
                //1.0 - 1.0 / 5000 => g2_fb.gain; // tom amp decay 
                .9998 => g2_fb.gain; // tom amp decay 

                g2_f.set(80, 1); // set tomD amp attack 
                .5 => ampenv.gain; // overdrive gain 
                s_f.set(1000, 1); // set tom lowpass filter 
    
                fun void hit(float v) 
                { 
                    v => i.next; 
                } 
                fun void setBaseFreq(float f) 
                { 
                    f => BaseFreq.next; 
                }    
                fun void setFreq(float f) 
                { 
                    f => TomFallFreq.gain; 
                } 
                fun void setPitchDecay(float f) 
                { 
                    f => g1_fb.gain; 
                } 
                fun void setPitchAttack(float f) 
                { 
                    f => g1_f.freq; 
                } 
                fun void setDecay(float f) 
                { 
                    f => g2_fb.gain; 
                } 
                fun void setAttack(float f) 
                { 
                    f => g2_f.freq; 
                } 
                fun void setDriveGain(float g) 
                { 
                    g => ampenv.gain; 
                } 
                fun void setFilter(float f) 
                { 
                    f => s_f.freq; 
                } 
            } 

            Toms T; 
            T.output => dac; 

            fun void playTom(int x) {
                if (x == 1) {
                    T.setBaseFreq(190); 
                    T.hit(.4 + Math.random2f(0, 0.2)); }
                else if (x == 2) {
                    T.setBaseFreq(140); 
                    T.hit(.6 + Math.random2f(0, .2)); }
                else if (x == 3){
                    T.setBaseFreq(90);
                    T.hit(.8 + Math.random2f(0, .2));}
            }

            global int Choice;
            global Event TImpact;

            while(true)
            {
                TImpact => now;
                spork~playTom(Choice);
            }
");
        }
    }
コード例 #29
0
    // ChucK pitch tracking script contained here
    void StartChuckPitchTrack(ChuckSubInstance myChuckPitchTrack)
    {
        // instantiate Chuck Pitch Tracking code
        myChuckPitchTrack.RunCode(@"

			60.0 => global float midiPos;
			0.0 => global float timePos;
			
			// analysis
			adc => PoleZero dcblock => FFT fft => dac;

			// set to block DC
			.99 => dcblock.blockZero;
			// set FFT params
			1024 => fft.size;
			// window
			Windowing.hamming( fft.size() ) => fft.window;

			// to hold result
			UAnaBlob blob;
			// find sample rate
			second / samp => float srate;

			Mandolin foo => JCRev r => dac;
				.75 => r.gain;
				.025 => r.mix;
				Std.mtof(60) => foo.freq;
				Math.random2f( .6, .9 ) => foo.pluck;
				500::ms => now;

			// interpolate
			float target_freq, curr_freq, target_gain, curr_gain;
			spork ~ ramp_stuff();

			// go for it
			while( true )
			{
				// take fft
				fft.upchuck() @=> blob;
				// find peak
				0 => float max; int where;
				for( int i; i < blob.fvals().cap(); i++ )
				{
					// compare
					if( blob.fvals()[i] > max )
					{
						// save
						blob.fvals()[i] => max;
						i => where;      
					}    
				}  
				// set freq
				(where $ float) / fft.size() * srate => target_freq;
				
				// set gain
				(max / .8) => target_gain;
				
				// hop
				(fft.size()/2)::samp => now;
			}

				// interpolation
			fun void ramp_stuff()
			{
				// mysterious 'slew'
				0.025 => float slew;
				float m_cf;
				float m_pf;

				// infinite time loop
				0 => int count;
				-1.0 => float prev_freq;
				while (true)
				{
					(target_freq - curr_freq) * 5 * slew + curr_freq => curr_freq;
					(target_gain - curr_gain) * slew + curr_gain => curr_gain;
					if (prev_freq > -1.0 && curr_freq >= 110.0 && curr_freq <= 1760)  //plausible sung pitch
					{
						Math.round(Std.ftom(curr_freq)) => m_cf;
						Math.round(Std.ftom(prev_freq)) => m_pf;
						if (m_cf == m_pf)
						{
							count++;
							if (count >= 10)
							{
								//curr_freq => s.freq;
								//0 => s.gain;
								m_cf => midiPos;
							//<<< ""Note:"", midiPos >>>; //test to check input       
							}
						}
						else
						{
							0 => count;
							//0 => s.freq;
							//0 => s.gain;
						}
					}
					curr_freq => prev_freq;
					0.0025::second => now;
					0.0025 + timePos => timePos;
				}
			}
			
		"        );
    }
コード例 #30
0
 void Awake()
 {
     chuck_ = GetComponent <ChuckSubInstance>();
 }