// Use this for initialization
 void Start()
 {
     chuck     = GetComponent <ChuckInstance> ();
     touchdown = false;
     s_type    = 0;
     octave    = 0;
 }
Esempio n. 2
0
    //float [] freqs = {261.63f, 293.66f, 329.63f, 349.23f, 392.00f, 440.0f, 493.88f, 523.25f};

    protected void Start()
    {
        rend     = GetComponent <Renderer> ();
        ci       = GetComponent <ChuckInstance> ();
        matColor = rend.material.color;
        GetComponent <ParticleSystem> ().Stop();
    }
    void Start()
    {
        myChuck = GetComponent <ChuckInstance>();

        for (int i = 0; i < acceptableKeys.GetLength(0); i++)
        {
//			acceptableKeys[i,2] = ((float)((i+1)*40.001)).ToString();
            acceptableKeys[i, 2] = (i + 72).ToString();
        }

        //slider change value callback
        mainSlider.onValueChanged.AddListener(delegate { ValueChangeCheck(); });

        t = (TextMesh)text.GetComponent(typeof(TextMesh));
    }
Esempio n. 4
0
    // Use this for initialization
    void Start()
    {
        myChuck             = GetComponent <ChuckInstance>();
        myGetTheIntCallback = myChuck.CreateGetIntCallback(GetTheInt);

        myChuck.RunCode(@"
			external int myExternalInt;
			while( true )
			{
				Math.random2( 300, 1000 ) => myExternalInt;
				10::ms => now;
			}
		"        );

        myChuck.GetInt("myExternalInt", myGetTheIntCallback);
    }
Esempio n. 5
0
    // Use this for initialization
    void Start()
    {
        newRound        = true;
        otherReady      = false;
        startTheTicker  = false;
        sent1000        = false;
        goToNextStep    = false;
        instructionMesh = (TextMesh)instructionText.GetComponent(typeof(TextMesh));

        prevBeat       = 0;
        beat           = 0;
        timeOfLastBeat = 0;
        beatBufferTime = .09f;
        prevBeatLength = 0;

        currLetter = 0;
        linePos    = 0.0f;

        topColor     = new Color32(255, 56, 129, 255);
        bottomColor  = new Color32(63, 56, 255, 255);
        correctColor = new Color32(56, 224, 101, 255);

        myChuck          = GetComponent <ChuckInstance> ();
        myGetIntCallback = Chuck.CreateGetIntCallback(GetIntCallback);
        myCallback       = Chuck.CreateVoidCallback(NewMessageReceived);
        message          = -1;
        newMessage       = false;

        mainScript = main.GetComponent <MainController> ();

        initialTickerX = ticker.transform.position.x;

        for (int i = 0; i < acceptableKeys.GetLength(0); i++)
        {
            acceptableKeys[i, 2] = (i + 72).ToString();
        }
        //set space to none
        acceptableKeys[acceptableKeys.GetLength(0) - 1, 2] = "0";

        //create container to have new keys added
        currKeysTop = new GameObject("currKeysTop");
        currKeysTop.AddComponent <MeshFilter>();
        currKeysTop.AddComponent <MeshRenderer>();
        currKeysBottom = new GameObject("currKeysBottom");
        currKeysBottom.AddComponent <MeshFilter>();
        currKeysBottom.AddComponent <MeshRenderer>();
    }
    // Use this for initialization
    void Start()
    {
        rb    = GetComponent <Rigidbody> ();
        chuck = GetComponentInParent <ChuckInstance> ();
//		chuck.RunCode (@"
//			fun void cupcakeTouchdown(float intensity)
//			{
//				BandedWG snd => dac;
//				(120 - intensity)=>snd.freq;
//				1 => snd.noteOn;
//				0.3::second => now;
//			}
//			external float freqIntensity;
//			external Event touchdownHappened;
//			while(true)
//			{
//				touchdownHappened => now;
//				spork ~ cupcakeTouchdown(freqIntensity);
//			}
//		");
    }
Esempio n. 7
0
    // Use this for initialization
    void Start()
    {
        chuck = GetComponent <ChuckInstance> ();
        chuck.RunCode(string.Format(@"
			external float bpm;
			{0} => bpm;
			fun void createSound(int midi, int type, int effect)
			{{
				JCRev r => Echo e => Echo e2 => dac;
				r => dac;
				240::ms => e.max => e.delay;
				480::ms => e2.max => e2.delay;
				.3 => e.gain;
				.2 => e2.gain;
				.03 => r.mix;
				StkInstrument snd;
				if (type == 1) {{
					Mandolin snd => r;
					play(snd, midi, effect);
				}} else if (type == 2) {{
					BlowHole snd => r;
					play(snd, midi, effect);
				}} else if (type == 3) {{
					ModalBar snd => r;
					play(snd, midi, effect);
				}} else if (type == 4) {{
					VoicForm snd => r;
					play(snd, midi, effect);
				}} else if (type == 5) {{
					TubeBell snd => r;
					play(snd, midi, effect);
				}} else {{
					BeeThree snd => r;
					play(snd, midi, effect);
				}}
			}}

			fun void play(StkInstrument snd, int midi, int effect) {{
				60.0 / bpm => float time;
				if (effect == 0) {{
					Std.mtof(midi) => snd.freq;
					1 => snd.noteOn;
					0.2::second => now;
					0 => snd.noteOff;
					0.8::second => now;
				}} else if (effect == 1) {{
					time / 4.0 => float pt;
					for (0 => int i; i < 4; i++) {{
						Std.mtof(midi + i) => snd.freq;
						1 => snd.noteOn;
						pt::second => now;
						0 => snd.noteOff;
					}}
					if (time < 1) {{
						(1 - time)::second => now;
					}}
				}} else if (effect == 2) {{
					time / 4.0 => float pt;
					for (3 => int i; i >= 0; i--) {{
						Std.mtof(midi + i) => snd.freq;
						1 => snd.noteOn;
						pt::second => now;
						0 => snd.noteOff;
					}}
					if (time < 1) {{
						(1 - time)::second => now;
					}}
				}} else if (effect == 3) {{
					time / 100.0 => float pt;
					for (0 => int i; i < 100; i++) {{
						Std.mtof(midi + i * 0.04) => snd.freq;
						1 => snd.noteOn;
						pt::second => now;
						0 => snd.noteOff;
					}}
					if (time < 1) {{
						(1 - time)::second => now;
					}}
				}} else if (effect == 4) {{
					time / 100.0 => float pt;
					for (99 => int i; i >= 0; i--) {{
						Std.mtof(midi + i * 0.04) => snd.freq;
						1 => snd.noteOn;
						pt::second => now;
						0 => snd.noteOff;
					}}
					if (time < 1) {{
						(1 - time)::second => now;
					}}
				}} else if (effect == 5) {{
					SndBuf buf => dac;
					""GetSchwifty.wav"" => string fileName;
					me.dir() + fileName => buf.read;
					0 => buf.pos;
					60.0 / (time * 106.0) => buf.rate;
					1.0 => buf.gain;
					buf.length() / buf.rate() => now;
				}}

			}}

			external int midi;
			external int type;
			external int effect;
			external Event genSound;
			while(true)
			{{
				genSound => now;
				spork ~ createSound(midi, type, effect);
			}}
		"        , GlobalVariables.bpm));
        cache       = new List <Vector4> ();
        mouth_stat  = 0;
        mouth_speed = -mouth_ro * GlobalVariables.bpm * 3.0f;
        mouth       = transform.GetChild(1).gameObject;
    }
    // Use this for initialization
    void Start()
    {
        if (sync)
        {
            chuck = GetComponent <ChuckInstance> ();
            float rate = Mathf.Max(GlobalVariables.bpm / 120.0f, 1.0f);
            chuck.RunCode(string.Format(@"
				external float bpm;
				{0} => bpm;
				fun void TriggerStickTouched(int idx)
				{{
					SndBuf buf => dac;
					string fileName;
					if (idx == 0) 
						""door-hinge1.wav"" => fileName;
					else
						""door-hinge2.wav"" => fileName;
					me.dir() + fileName => buf.read;
					0 => buf.pos;
					Math.max(bpm/120.0, 1.0) => buf.rate;
					0.1 => buf.gain;
					buf.length() / buf.rate() => now;
				}}
				fun void GenNoise(int i)
				{{
					if ( i > 0) {{
						SubNoise sn => Envelope env => dac;
						10 * i => sn.rate;
						0.1 => float value;
						60.0 / bpm => float time;
						value => env.target;
						time => env.time;
						value => env.value;
						env.keyOff(1);
						time::second => now;
					}}
				}}
				external int sndIdx;
				external int noiseIdx;
				external Event touchHappened;
				while(true)
				{{
					touchHappened => now;
					spork ~ TriggerStickTouched(sndIdx);
					spork ~ GenNoise(noiseIdx);
				}}
			"            , GlobalVariables.bpm));
        }
        tubes = new List <GameObject> ();
//		print (gen_cake_pos.Count);
        for (int i = 0; i < transform.parent.childCount; i++)
        {
            Transform tube = transform.parent.GetChild(i);
            if (tube.CompareTag("EmitterTube"))
            {
                tubes.Add(tube.gameObject);
//				GameObject butt = presser.GetChild (2).gameObject;
//				Vector3 pos = butt.transform.position;
//				gen_cake_pos.Add(new Vector3 (pos.x, pos.y - 5, pos.z));
//				int p_index = presser.GetComponent<EmitterPresserController> ().p_index;
//				print (p_index);
//				gen_cake_pos[p_index] = new Vector3 (pos.x, pos.y - 5, pos.z);
            }
        }
    }
Esempio n. 9
0
    // Initialization
    void Start()
    {
        updatedRound      = false;
        tickerStarted     = false;
        alreadyCorrect    = false;
        gotCorrect        = false;
        myPos             = 0.0f;
        previousPos       = 0.0f;
        step1Script       = step1.GetComponent <MyStepController> ();
        myChuck           = GetComponent <ChuckInstance> ();
        myGetPosCallback  = Chuck.CreateGetFloatCallback(GetPosCallback);
        myGetBeatCallback = Chuck.CreateGetFloatCallback(GetBeatCallback);

        currRound   = 0;
        staticLevel = 0;

        leftLevelScript  = leftLevel.GetComponent <LevelController> ();
        rightLevelScript = rightLevel.GetComponent <LevelController> ();

        levelMesh = (TextMesh)levelText.GetComponent(typeof(TextMesh));

        //set colors
        correctColor          = new Color32(56, 224, 101, 255);
        normalBackgroundColor = new Color32(63, 56, 255, 255);
        failBackgroundColor   = new Color32(255, 64, 89, 255);

        string initialIntroGain;

        if (playerNumber == 0)
        {
            initialIntroGain = ".3";
        }
        else
        {
            initialIntroGain = "0.0";
        }
        myChuck.RunCode(@"
						external Event gotCorrect;
						external Event startTicker;

						external Event keyFailTrigger;
						external Event endIntroMusic;

					    "                         + timestep + @" => external int timeStep;
						external float pos;
						external float count;

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

						Gain localIntroGain;
						"                         + initialIntroGain + @" => localIntroGain.gain;

						fun void fadeIntro(){
							endIntroMusic => now;
							.5 => float tempGain;
							while(tempGain >= 0.0){
								tempGain - .01 => tempGain;
								tempGain => localIntroGain.gain;
								150::ms => now;
							}
						}

						fun void playIntroMelody(){
							// sound file
							me.sourceDir() + ""IntroMusicShort.wav"" => string filename;
							<<< filename >>>;
							if( me.args() ) me.arg(0) => filename;						
							// the patch 
							SndBuf buf => localIntroGain => dac;
							0 => buf.pos;

							filename => buf.read;
							spork ~ fadeIntro();
							buf.length() => now;	
						}


						//play if they get a step correct
						fun void playCorrect() {
							gotCorrect => now;
							me.sourceDir() + ""keyDown.wav"" => string filename;
							if( me.args() ) me.arg(0) => filename;						
							SndBuf buf => localIntroGain => dac;
							0 => buf.pos;
							filename => buf.read;
							buf.length() => now;	
						}

						fun void keyFailSound(){
							while( true )
							{
								keyFailTrigger => now;
								me.sourceDir() + ""fail.wav"" => string filename;
								if( me.args() ) me.arg(0) => filename;						
								SndBuf buf => dac;
								0 => buf.pos;
								filename => buf.read;
								buf.length() => now;
							}
						}

						spork ~ keyFailSound();
						spork ~ playIntroMelody();

						class Chord {
						    
						    5 => int size;
						    
						    BlitSquare osc[5];
						    ADSR adsr[5];
						    
						    Gain g => dac;
						    
						    50::ms => dur attack;
						    25::ms => dur decay;
						    0.5 => float sustain;
						    25::ms => dur release;
						    
						    0.05 => g.gain;
						    
						    for (0 => int i; i < size; i++) {
						        osc[i] => adsr[i];
						        adsr[i] => g;
						        adsr[i].set(attack, decay, sustain, release);
						    }
						    
						    public void play(int num, int note) {
						        Std.mtof(note) => osc[num].freq;
						        1 => adsr[num].keyOn;
						    }
						    
						    public void softOff() {
						        for (0 => int i; i < size; i++) {
						            1 => adsr[i].keyOff;
									100::ms => now;
						        }
						    }
						    
						    public void hardOff() {
						        for (0 => int i; i < size; i++) {
						            0::ms => adsr[i].releaseTime;
						        }
						        softOff();
						        for (0 => int i; i < size; i++) {
						            release => adsr[i].releaseTime;
						        }
						    }
						    
						}

						class DrumSet {
						    // define hihat
						    Shakers hhs => JCRev r;
						    .025 => r.mix;
						    Std.mtof( 76 ) => hhs.freq;
						    
						    // Define Bassdrum
						    SinOsc s => ADSR bda;
						    80 => s.freq;
						    (0::ms, 10::ms, 0.0, 0::ms ) => bda.set;
						    
						    // define snare drum
						    Noise n => ADSR sna => Gain g;
						    0.15 => g.gain;
						    (0::ms, 25::ms, 0.0, 0::ms) => sna.set;
						    
						    
						    public void connect( UGen ugen ) {
						        r => ugen;
						        bda => ugen;
						        g => ugen;
						    }
						    
						    public void hh() {
						        1 => hhs.noteOn;
						    }
						    
						    public void bd() {
						        1 => bda.keyOn;
						    }
						    
						    public void sn() {
						        1 => sna.keyOn;
						    }
						}

						class Bass {
						    // BASS
						    SawOsc sb => LPF filt => ADSR a => Gain g2;
						    440 => filt.freq;
						    0.3 => filt.Q;
						    0.0 => g2.gain;
						    (10::ms, 45::ms, 0.5, 40::ms) => a.set; // Set ADSR envelope
						    
						    public void connect( UGen u ) {
						        g2 => u;
						    }
						    
						    public void bass( int tone ) {
						        Std.mtof( tone ) =>  sb.freq;
						        0.3 => g2.gain;
						        1 => a.keyOn;
						        125::ms => now;
						        1=> a.keyOff;
						    }
						}

						class BassDrumLoop {
						    
							Gain bdlGain => dac;
							bdlGain.gain(1);
						    DrumSet drm;
						    drm.connect( bdlGain );
						    
						    Bass bass;
						    bass.connect( bdlGain );
						    
						    [ 41, 41, 44, 46] @=> int bline[];
						    0 => int pos;
						    0 => count;
						    
						    250::ms => dur length;
						    
						    public void setLength(dur l) {
						        l => length;
						    }
						    
						    public void reset() {
						        0 => pos;
						        0 => count;
						    }
						    
						    public void setKey(int key) {
						        [ key, key, key + 3, key + 5] @=> bline;
						    }

							public void setGain(float gainToSet) {
							        bdlGain.gain(gainToSet);
							}

						    public void stop() {
								<<< ""trying to stop"" >>>;
						        setGain(0);
						    }
						    
						    public void play() {
						        while ( true ) {
						            drm.hh();
						            if ( count % 2 == 0 ) { drm.bd(); }
						            if ( count % 4 == 2 ) { drm.sn(); }
						            
						            if ( count % 2 == 0 ) { spork ~ bass.bass( bline[ pos % 4 ]); }
						            if ( count % 2 == 1 ) { spork ~ bass.bass( 12 + bline[ pos % 4 ]); }
						            
						            
						            1 + count => count;
						            if ( count % 4 == 0 ) { 1 + pos => pos; }
						            length => now;
						        }
						    }
						    
						}
						public class Global {
							static BassDrumLoop @ bdl;
							static Chord @ chord;
						}

						new BassDrumLoop @=> Global.bdl;
						new Chord @=> Global.chord;

						startTicker => now;
						while( true )
						{
							spork ~ updatePos();
							// spork ~ playCorrect();
							// 50::ms => now; //delay to make playCorrect not trigger twice
							timeStep::second => now;
						}						
					"                    );
    }