Пример #1
0
void time_test()
{
    static long elapsed_time = 0;
    static long last_read = 0;
    static long is_ticking = 0;
    static char a_is_pressed = 0;
    static char c_is_pressed = 0;
    static char last_seconds = 0;

    long current_time = get_ms();
    if(is_ticking)
        elapsed_time += current_time - last_read;

    last_read = current_time;

    if(button_is_pressed(BUTTON_A) && !a_is_pressed)
    {
        // reset
        a_is_pressed = 1;
        is_ticking = 0;
        elapsed_time = 0;
        if(!is_playing()) // only play once
            play_from_program_space(beep_button_a);
    }

    // find the end of the button press without stopping
    if(!button_is_pressed(BUTTON_A))
        a_is_pressed = 0;

    if(button_is_pressed(BUTTON_C) && !c_is_pressed)
    {
        // start/stop
        c_is_pressed = 1;
        is_ticking = !is_ticking;
        play_from_program_space(beep_button_c);
    }

    // find the end of the button press without stopping
    if(!button_is_pressed(BUTTON_C))
        c_is_pressed = 0;

    print_long((elapsed_time/1000/60/10)%10); // tens of minutes
    print_long((elapsed_time/1000/60)%10); // minutes
    print_character(':');
    print_long((elapsed_time/1000)%60/10); // tens of seconds
    char seconds = ((elapsed_time/1000)%60)%10;
    print_long(seconds); // seconds
    print_character('.');
    print_long((elapsed_time/100)%10); // tenths of seconds
    print_long((elapsed_time/10)%10); // hundredths of seconds

    // beep every second
    if(seconds != last_seconds && elapsed_time != 0 && !is_playing())
        play_from_program_space(timer_tick);
    last_seconds = seconds;
}
Пример #2
0
void test_delay()
{
  play_frequency(440,250,8); // should take exactly 250 ms
  delay_ms(200);

  printf("\ndelay1");
  assert(is_playing());

  delay_ms(100);
  
  printf("\ndelay2");
  assert(!is_playing());

}
Пример #3
0
void Music::yield() {
    if( !init_flag )
	return;

    int oldSongId = song_id;

    if( config.cd_music_volume ) {
	if( !is_playing() ) {
	    vga_front.temp_unlock();
	    //DEBUG_LOG("Music::yield(): play random");	//##
	    vga_front.temp_restore_lock();

	    int songId;

	    while(1) {
		songId = random_bgm_track(oldSongId);

		//--- only play Christmas music in December ---//

		if( songId==9 && info.game_month != 12 )
		    continue;

		//--- only play Graduation March music in May or June ---//

		if( songId==10 && info.game_month != 5 && info.game_month != 6 )
		    continue;

		play( songId, sys.cdrom_drive ? MUSIC_CD_THEN_WAV : 0 );
		return;
	    }
	}
    }
}
Пример #4
0
double CGlobalVars::reraiser_opp_balance()
{
	/*
	* Return reraiser opponent balance
	*
	* Examples:
	* -
	* -
	*/

	double dump = 0;
	double opp_balance = 0;

	for(int i = 0; i < k_MaxChairs; i++)
	{
		if (!is_playing(i))
			continue;

		if (CurState().m_player[i].m_currentbet > dump)
		{
			dump = CurState().m_player[i].m_currentbet;
			opp_balance = CurState().m_player[i].m_balance;
		}
	}

	return opp_balance;
}
Пример #5
0
int CGlobalVars::set_nopponentscalling()
{
	/*
	* number of opponents doing call
	*/

	int lok_count = 0;

	for(int i = 0; i < k_MaxChairs; i++)
	{
		if(i == userchair)
			continue;

		if (!is_playing(i))
			continue;

		if (CurState().m_player[i].m_currentbet > ncurrentbet-0.01 && CurState().m_player[i].m_currentbet < ncurrentbet+0.01)
				lok_count++;
	}

	if(lok_count-1 > 0)
		return lok_count-1;

	return 0;
}
Пример #6
0
void music_test()
{
    static char fugue_title_pos = 0;
    static long last_shift = 0;
    char c,i;

    if(get_ms() - last_shift > 250)
    {
        for(i=0; i<8; i++)
        {
            c = pgm_read_byte(fugue_title + fugue_title_pos + i);
            print_character(c);
        }
        last_shift = get_ms();

        fugue_title_pos ++;
        if(fugue_title_pos + 8 >= sizeof(fugue_title))
            fugue_title_pos = 0;
    }

    if(!is_playing())
    {
        play_from_program_space(fugue);
    }

    delay_ms(100);
}
Пример #7
0
void StreamPlayer::_notification(int p_what) {

	switch(p_what) {

		case NOTIFICATION_ENTER_TREE: {

			//set_idle_process(false); //don't annoy
			if (stream.is_valid() && !get_tree()->is_editor_hint()) {
				if (resume_pos>=0) {
					play(resume_pos);
					resume_pos=-1;
				} else if (autoplay) {
					play();
					autoplay = false; //this line fix autoplay issues
				}
			}

		} break;
		case NOTIFICATION_EXIT_TREE: {

			if (is_playing()) {
				resume_pos=get_pos();
			}
			stop(); //wathever it may be doing, stop
		} break;
	}
}
Пример #8
0
void AnimationPlayer::queue(const StringName &p_name) {

	if (!is_playing())
		play(p_name);
	else
		queued.push_back(p_name);
}
Пример #9
0
static portTASK_FUNCTION( vBlockingQueueProducer, pvParameters )
{
unsigned short usValue = 0;
xBlockingQueueParameters *pxQueueParameters;
short sErrorEverOccurred = pdFALSE;

	pxQueueParameters = ( xBlockingQueueParameters * ) pvParameters;

	for( ;; )
	{
		if( xQueueSend( pxQueueParameters->xQueue, ( void * ) &usValue, pxQueueParameters->xBlockTime ) != pdPASS )
		{
			sErrorEverOccurred = pdTRUE;
		}
		else
		{
			/* We have successfully posted a message, so increment the variable
			used to check we are still running. */
			if( sErrorEverOccurred == pdFALSE )
			{
				( *pxQueueParameters->psCheckVariable )++;
			}

			/* Increment the variable we are going to post next time round.  The
			consumer will expect the numbers to	follow in numerical order. */
			++usValue;
            
            play_from_program_space(PSTR("d"));
            while (is_playing()){};
    		red_led(1);     // Turn on the red LED.
	    	delay_ms(20);  // Wait for 20 ms.
		}
	}
}
Пример #10
0
bool CGlobalVars::IP()
{
	//////////////////////
	//In position check:
	//////////////////////

	// return true if we are in position

	//If the player is playing and the chair doesn't equal our chair
	// and the player's dealposition is greater than ours then
	//we are not in position

	for(int i=0; i < k_max_chairs; i++)
	{
		if(!is_playing(i))
			continue;

		if(userchair == i)
			continue;

		if(get_ac_dealpos(i) > get_dealposition())
			return false;
	}

	return true;
}
Пример #11
0
int
lockutmpmode(int unmode, int state)
{
    int             errorno = 0;

    if (currutmp->lockmode)
	errorno = LOCK_THIS;
    else if (state == LOCK_MULTI && is_playing(unmode))
	errorno = LOCK_MULTI;

    if (errorno) {
	clear();
	move(10, 20);
	if (errorno == LOCK_THIS)
	    prints("請先離開 %s 才能再 %s ",
		   ModeTypeTable[currutmp->lockmode],
		   ModeTypeTable[unmode]);
	else
	    prints("抱歉! 因為您目前多重登入所以無法使用 %s",
                   ModeTypeTable[unmode]);
	pressanykey();
	return errorno;
    }
    setutmpmode(unmode);
    currutmp->lockmode = unmode;
    return 0;
}
Пример #12
0
// Note that it's perfectly fine calling PlayStop() between calling PC_Pause and PC_StopPause. PC_StopPause will still work as it's supposed to.
void PC_Pause(void){
  R_ASSERT(THREADING_is_main_thread());

  //printf("   000 Enter pause %d\n", g_pausing_level);

  g_pausing_level++;

  //printf("   Enter pause %d\n", g_pausing_level);
  
  if (g_pausing_level > 1)
    return;
  
  g_was_playing = false;
  g_playtype = 0;
  g_was_playing_range = false;
  
  if (is_playing()){

    if(ATOMIC_GET(is_starting_up)==false){
      struct Tracker_Windows *window = root->song->tracker_windows;
      window->message = "Temporarily stopping player";
      window->message_duration_left = 100;
    }

    g_playtype = pc->playtype;
    g_was_playing_range = pc->is_playing_range;
    PlayStop();
    g_was_playing = true;
  }  
}
Пример #13
0
struct Blocks *InsertBlock(
                           NInt blockpos,
                           NInt num_tracks,
                           int num_lines,
                           const char *name
                           )
{
        R_ASSERT(is_playing()==false);

	struct Tracker_Windows *window=root->song->tracker_windows;
	struct WBlocks *wblock;

	struct Blocks *block;
          
        InsertBlock_IncBlockNums(blockpos);

        block=talloc(sizeof(struct Blocks));
          
        block->l.num=blockpos;
        NewBlock(block,num_tracks,num_lines,name);
        
        while(window!=NULL){
          wblock=talloc(sizeof(struct WBlocks));
          wblock->l.num=blockpos;
            
          NewWBlock(window,wblock,block);
            
          window=NextWindow(window);
        }

        return block;
}
Пример #14
0
// Called from Mixer.cpp after events are calculated, and before audio is created.
void RT_LPB_set_beat_position(struct SeqTrack *seqtrack, int audioblocksize){
  
  if (is_playing()==false)
    return;

  if (seqtrack->curr_seqblock==NULL)
    return;
  
  bool curr_num_beats_is_valid = true; // Might become false when switching block. If false, we must not set new curr_bpm value.

  LPB_Iterator *iterator = &seqtrack->lpb_iterator;
  
  set_new_num_beats_values(seqtrack, seqtrack->curr_seqblock, iterator, audioblocksize, &curr_num_beats_is_valid);
    
  double num_beats_till_next_time = iterator->next_num_beats - iterator->curr_num_beats;

#if DEBUG_BUGS
  R_ASSERT_NON_RELEASE(num_beats_till_next_time > 0);
#endif

  if (curr_num_beats_is_valid==true) {
    double bpm = num_beats_till_next_time * 60.0 * (double)pc->pfreq / (double)audioblocksize;
    //printf("bpm: %f, curr_num_beats: %f - %f (d: %f)\n", bpm,iterator->curr_num_beats,iterator->next_num_beats,num_beats_till_next_time);

    if (fabs(bpm-iterator->curr_bpm) > 0.001)
      iterator->curr_bpm = bpm;
  }

#if DEBUG_BUGS
  static double last = 0.0;
  printf("Num_beats: %f. (diff: %f). So far: %f\n", iterator->curr_num_beats, iterator->curr_num_beats-last, iterator->num_beats_played_so_far);
  last = iterator->curr_num_beats;
#endif
}
Пример #15
0
void loop()                     // run over and over again
{
  // wait here for one of the three buttons to be pushed
  unsigned char button = wait_for_button(ANY_BUTTON);
  clear();
  
  if (button == TOP_BUTTON)
  {
    play_from_program_space(fugue);

    print("Fugue!");
    lcd_goto_xy(0, 1);
    print("flash ->");
  }
  if (button == MIDDLE_BUTTON)
  {
    play("! V8 cdefgab>cbagfedc");
    print("C Major");
    lcd_goto_xy(0, 1);
    print("RAM ->");
  }
  if (button == BOTTOM_BUTTON)
  {
    if (is_playing())
    {
      stop_playing();
      print("stopped");
    }
    else
    {
      play_note(A(5), 200, 15);
      print("note A5"); 
    }
  }
}
Пример #16
0
bool FeMedia::tick()
{
	if (( !m_video ) && ( !m_audio ))
		return false;

	if ( m_video )
	{
		sf::Lock l( m_video->image_swap_mutex );
		if ( m_video->display_frame )
		{
			m_video->display_texture->update( m_video->display_frame );
			m_video->display_frame = NULL;
			return true;
		}
	}

	// restart if we are looping and done
	//
	if ( (m_imp->m_loop) && (!is_playing()) )
	{
		stop();
		play();
	}

	return false;
}
Пример #17
0
// -------- begin of function Music::change_volume --------//
void Music::change_volume(int vol) {
    if( !init_flag )
	return;

    if( is_playing() ) {
	audio.set_cd_volume(vol);
    }
}
Пример #18
0
void SOUNDCLIP::set_panning(int newPanning) {
    if (!is_playing()) { return; }
    
    int voice = get_voice();
    if (voice >= 0) {
        voice_set_pan(voice, newPanning);
        panning = newPanning;
    }
}
Пример #19
0
void* do_playing(void* _p)
{
    (void)_p;
    int i;
    while(Control.poll_active) {
        control_lock();
        for (i = 0; i < ACTIVE_NOTIFS_MAX; i ++) {
            if (actives[i].active && !actives[i].looping
                #ifdef _BOX_NOTIFY
                    && !actives[i].box
                #endif
            ) {
                if (!is_playing(actives[i].source)) {
                /* Close */                    
                    alSourceStop(actives[i].source);
                    alDeleteSources(1, &actives[i].source);
                    alDeleteBuffers(1,&actives[i].buffer);
                    memset(&actives[i], 0, sizeof(struct _ActiveNotifications));
                }
            }
        #ifdef _BOX_NOTIFY
            else if (actives[i].box && time(NULL) >= actives[i].n_timeout)
            {
                GError* ignore;
                notify_notification_close(actives[i].box, &ignore);
                actives[i].box = NULL;
                
                if(actives[i].id_indicator) *actives[i].id_indicator = -1; // reset indicator value

                if (!actives[i].looping && !is_playing(actives[i].source)) {
                /* stop source if not looping or playing, just terminate box */
                    alSourceStop(actives[i].source);
                    alDeleteSources(1, &actives[i].source);
                    alDeleteBuffers(1,&actives[i].buffer);
                    memset(&actives[i], 0, sizeof(struct _ActiveNotifications));
                }
            }
        #endif
        }
        control_unlock();
        usleep(10000);
    }
    pthread_exit(NULL);
}
Пример #20
0
// Called from ../audio/Juce_plugins.cpp
//
Ratio RT_Signature_get_current_Signature(const struct SeqTrack *seqtrack){
  if (is_playing())
    return seqtrack->signature_iterator.signature_value;
  else {
    if (root==NULL) // When does this happen?
      return ratio(4,4);
    else
      return root->signature;
  }
}
Пример #21
0
// Starts playback on the queued tracks.
void start_playing_queue() {
    in_main_thread([] {
        auto p_control = static_api_ptr_t<playback_control>();

        if (p_control->is_playing() || p_control->is_paused())
            p_control->next();
        else
            p_control->play_or_unpause();
    });
}
Пример #22
0
void AnimationPlayer::set_current_animation(const String &p_anim) {

	if (p_anim == "[stop]" || p_anim == "") {
		stop();
	} else if (!is_playing() || playback.assigned != p_anim) {
		play(p_anim);
	} else {
		// Same animation, do not replay from start
	}
}
Пример #23
0
bool SOUNDFILESAVER_write(float **outputs, int num_frames){
 PaUtil_FullMemoryBarrier();

  if(g_save_state==BEFORE_WRITING && is_playing()==false)
    return true;

  if(g_save_state==AFTER_WRITING)
    return true;

  bool ret=true;
  int i;
  float interleaved_data[num_frames*2];

  int pos=0;
  for(i=0;i<num_frames;i++){
    interleaved_data[pos++] = outputs[0][i];
    interleaved_data[pos++] = outputs[1][i];
  }

  //printf("Writing %d frames\n",num_frames);

  if(sf_writef_float(g_sndfile, interleaved_data, num_frames) != num_frames){
    g_saving_was_successful = false;
    ret = false;
  }

  if(g_save_state==IS_WRITING){
    if(is_playing()==false){
      g_save_state=POST_WRITING;
    }
  }

  if(g_save_state==POST_WRITING){
    g_post_writing_left -= (float)num_frames/MIXER_get_sample_rate();
    if(g_post_writing_left <= 0.0f){
      stop_writing();
      g_save_state=AFTER_WRITING;
    }
  }

  return ret;
}
Пример #24
0
void AnimationPlayer::set_current_animation(const String &p_anim) {

	if (is_playing()) {
		play(p_anim);
	} else {
		ERR_FAIL_COND(!animation_set.has(p_anim));
		playback.current.pos = 0;
		playback.current.from = &animation_set[p_anim];
		playback.assigned = p_anim;
	}
}
Пример #25
0
// -------- begin of function Music::change_volume --------//
void Music::change_volume(int vol)
{
	if( !init_flag )
		return;

	if( is_playing() )
	{
                AbsVolume absv(vol,0);
                audio.volume_long_wav(music_channel, DsVolume(absv));
	}
}
Пример #26
0
/* Wrappers for Pololu functions that may not be thread safe or like being delayed/swapped-out */
void rob_wait_play (const char * pSequence)
{
    vTaskSuspendAll();
    {
        play (pSequence);
        while (is_playing())
        {
        }
    }
    xTaskResumeAll();
}
Пример #27
0
void rob_wait_play_from_program_space (const char * pSequence)
{
    vTaskSuspendAll();
    {
        play_from_program_space (pSequence);
        while (is_playing())
        {
        }
    }
    xTaskResumeAll();
}
Пример #28
0
bool AnimationPlayer::_get(const StringName &p_name, Variant &r_ret) const {

	String name = p_name;

	if (name == "playback/speed") { //bw compatibility

		r_ret = speed_scale;
	} else if (name == "playback/active") {

		r_ret = is_active();
	} else if (name == "playback/play") {

		if (is_active() && is_playing())
			r_ret = playback.assigned;
		else
			r_ret = "[stop]";

	} else if (name.begins_with("anims/")) {

		String which = name.get_slicec('/', 1);

		r_ret = get_animation(which).get_ref_ptr();
	} else if (name.begins_with("next/")) {

		String which = name.get_slicec('/', 1);

		r_ret = animation_get_next(which);

	} else if (name == "blend_times") {

		Vector<BlendKey> keys;
		for (Map<BlendKey, float>::Element *E = blend_times.front(); E; E = E->next()) {

			keys.ordered_insert(E->key());
		}

		Array array;
		for (int i = 0; i < keys.size(); i++) {

			array.push_back(keys[i].from);
			array.push_back(keys[i].to);
			array.push_back(blend_times[keys[i]]);
		}

		r_ret = array;
	} else if (name == "autoplay") {
		r_ret = autoplay;

	} else
		return false;

	return true;
}
Пример #29
0
int CGlobalVars::set_adj_nopponentsraising()
{
	/*
	* 
	*/
	//This sub adjusts nopponentsraising that we use our functions to find
	// not OH's since there are bugs.

	//It adjusts nopponentsraising for preflop
	// to subtract if sb or bb isn't raising
	int adjusted_nopponentsraising = nopponentsraising;

	if (br == 1)
	{
		// If the player is the SB and the SB was posted and the player is playing
		// and the SB's currentbet is less bblind but greater than zero
		for (int i=0; i < k_MaxChairs; i++)
		{
			if (!is_playing(i))
				continue;

			if (get_ac_dealpos(i) == 1 && SB && currentbets[i] < get_bblind() && currentbets[i] > 0)
				adjusted_nopponentsraising--;
		}

		// If the player is the BB and the player is playing
		// and the BB's currentbet is less or equal to (less than rare but possible)
		// bblind but greater than zero
		for (int i=0; i < k_MaxChairs; i++)
		{
			if (!is_playing(i))
				continue;

			if (get_ac_dealpos(i) == 2 && currentbets[i] <= get_bblind() && currentbets[i] > 0)
				adjusted_nopponentsraising--;
		}
	}

	return adjusted_nopponentsraising;
}
Пример #30
0
bool AnimationPlayer::_get(const StringName& p_name,Variant &r_ret) const {

	String name=p_name;

	if (name=="playback/speed") { //bw compatibility
	
		r_ret=speed_scale;
	} else if (name=="playback/active") {

		r_ret=is_active();
	} else if (name=="playback/play") {

		if (is_active() && is_playing())
			r_ret=playback.assigned;
		else
			r_ret="[stop]";

	} else if (name.begins_with("anims/")) {
	
		String which=name.get_slicec('/',1);
		
		r_ret= get_animation(which).get_ref_ptr();
	} else if (name.begins_with("next/")) {

		String which=name.get_slicec('/',1);

		r_ret= animation_get_next(which);


	} else if (name=="blend_times") {
	
		Array array;

		array.resize(blend_times.size()*3);
		int idx=0;
		for(Map<BlendKey, float >::Element *E=blend_times.front();E;E=E->next()) {

			array.set(idx*3+0,E->key().from);
			array.set(idx*3+1,E->key().to);
			array.set(idx*3+2,E->get());
			idx++;
		}
		r_ret=array;
	} else if (name=="autoplay") {
		r_ret=autoplay;


	} else
		return false;

	return true;
}