Example #1
0
void drawSquares(GLenum mode)
{
    glPushName(0);
    if (mode == GL_SELECT)
        glLoadName(1);
    drawFretboard();

    string you="Your Turn",comp="Computer's Turn";
    
    if (mode == GL_SELECT)
        glLoadName(2);
    drawTimeline();
    
    if (mode == GL_SELECT)
        glLoadName(3);
    drawButton(5,-62,"metronome",8,g_metronome_on);
    
    if (mode == GL_SELECT)
        glLoadName(4);
    drawButton(85,-62,"sync",8,1);
    
    if (turn_cpu)
    {
        
        draw_string(25,-20,0,comp,70,2.5);
        for (int i=0;i<g_playComputer.size();i++)
        {
            
            if ( g_playComputer.at(i).startTime()<g_t && g_playComputer.at(i).endTime()>g_t)
                playNote(g_playComputer.at(i).pitch(),1);
            else
                playNote(g_playComputer.at(i).pitch(),0);
            
        }
    }
    else
    {
        glColor4f(1,0,0,1); 
        draw_string(38,-20,0,you,70,2.5);
    }
    
    drawParameter(95,-39,0,g_tempo,"tempo",mode,5);
    drawParameter(-10,-39,0,g_prob_rhythm,"rhythm variation",mode,7);
    drawParameter(25,-39,0,g_prob_melody,"melody variation",mode,9);
    drawParameter(65,-39,0,g_tradebars,"bars",mode,11);

    glPopName();
}
Example #2
0
int audioCallback( void * outputBuffer, void * inputBuffer, 
            unsigned int bufferSize, double streamTime,
            RtAudioStreamStatus status, void * userData )
{
    SAMPLE * out = (SAMPLE *)outputBuffer;
	SAMPLE acc[bufferSize*2];
    fluid_synth_write_float( g_synth, bufferSize, out, 0, 2, out, 1, 2 );
	for (int i=0;i<bufferSize*2;i++)
		acc[i]=out[i];
    fluid_synth_write_float( g_metronome, bufferSize, out, 0, 2, out, 1, 2 );
	for (int i=0;i<bufferSize*2;i++)
		out[i]+=acc[i];

    //turnaround - every n bars
    if (g_t >= g_trade)
	 	{
            g_timeline_x=0;
            turn_cpu=!(turn_cpu);
            //cout<<"swap"<<" "<<turn_cpu<<endl;
			
            //if the cpu plays - process once
            if (turn_cpu==1) 
            {   
                for (int i=0;i<g_current.size();i++)
                {
                        g_current[i].setEndTime(g_t-1);
                        g_playHuman.add(g_current[i]);
                        g_current.erase(g_current.begin()+i);
                }
                g_current.clear();
                //g_playHuman.printQ();
                g_playComputer = g_playHuman;
                g_playHuman.clear();
                //g_playComputer.printQ();
                g_playComputer.randomize(g_prob_melody,g_prob_rhythm,g_tradebars,g_trade);
                //g_playComputer.printQ();
                g_drumnote=50;
                g_played.clear();
                g_played.resize(g_playComputer.size(),0);
                g_stopped.clear();
                g_stopped.resize(g_playComputer.size(),0);
            }
            else
            {
                g_drumnote = 51;
                for (int i=40;i<110;i++)
                    fluid_synth_noteoff( g_synth, 1, i);
            }
            
	 		g_t=0;
            g_beat_played=0;
	 	}

    
    //if cpu, then please play
    if (turn_cpu && g_playComputer.size()>0 )
    {
     //   cout<<g_played.size();

        for (int i=0;i<g_playComputer.size();i++)
        {
        if ( g_playComputer.at(i).startTime()<=g_t && g_played[i]==0 )
        {

            fluid_synth_noteon( g_synth, 1, g_playComputer.at(i).pitch(),g_playComputer.at(i).velocity() );
            g_played[i]=1;
        }
        
        if ( (g_playComputer.at(i).startTime()+g_playComputer.at(i).duration()  <= g_t) && g_stopped[i]==0)
            {
                fluid_synth_noteon( g_synth, 1, g_playComputer.at(i).pitch(),0);
                g_stopped[i]=1;
            }       
        }
	}

    if (g_t==0 && g_metronome_on == 1)
         fluid_synth_noteon( g_metronome, 1, g_drumnote,90 );         
    if (g_t/g_beat > g_beat_played && g_metronome_on == 1 )
     {
         fluid_synth_noteon( g_metronome, 1, g_drumnote,90 );         
         g_beat_played++;
     }
    
    g_t += bufferSize;
    
    return 0;
}