static void event_handler(const ALLEGRO_EVENT * event)
{
   int i;

   switch (event->type) {
      /* Was the X button on the window pressed? */
      case ALLEGRO_EVENT_DISPLAY_CLOSE:
         exiting = true;
         break;

      /* Was a key pressed? */
      case ALLEGRO_EVENT_KEY_CHAR:
         if (event->keyboard.keycode == ALLEGRO_KEY_LEFT) {
            double pos = al_get_audio_stream_position_secs(music_stream);
            pos -= 5.0;
            if (pos < 0.0)
               pos = 0.0;
            al_seek_audio_stream_secs(music_stream, pos);
         }
         else if (event->keyboard.keycode == ALLEGRO_KEY_RIGHT) {
            double pos = al_get_audio_stream_position_secs(music_stream);
            pos += 5.0;
            if (!al_seek_audio_stream_secs(music_stream, pos))
               printf("seek error!\n");
         }
         else if (event->keyboard.keycode == ALLEGRO_KEY_SPACE) {
            bool playing;
            playing = al_get_mixer_playing(al_get_default_mixer());
            playing = !playing;
            al_set_mixer_playing(al_get_default_mixer(), playing);
         }
         else if (event->keyboard.keycode == ALLEGRO_KEY_ESCAPE) {
            exiting = true;
         }
         break;

      case ALLEGRO_EVENT_MOUSE_BUTTON_DOWN:
         mouse_button[event->mouse.button] = 1;
         maybe_fiddle_sliders(event->mouse.x, event->mouse.y);
         break;
      case ALLEGRO_EVENT_MOUSE_AXES:
         maybe_fiddle_sliders(event->mouse.x, event->mouse.y);
         break;
      case ALLEGRO_EVENT_MOUSE_BUTTON_UP:
         mouse_button[event->mouse.button] = 0;
         break;
      case ALLEGRO_EVENT_MOUSE_LEAVE_DISPLAY:
         for (i = 0; i < 16; i++)
            mouse_button[i] = 0;
         break;

      /* Is it time for the next timer tick? */
      case ALLEGRO_EVENT_TIMER:
         logic();
         render();
         break;
   }
}
Beispiel #2
0
static int allua_audio_stream_seek_secs(lua_State * L)
{
   ALLUA_audio_stream audio_stream = allua_check_audio_stream(L, 1);
   double t = luaL_checknumber(L, 2);
   lua_pushboolean(L, al_seek_audio_stream_secs(audio_stream, t));
   return 1;
}
bool AllegroMusicSample5::Play()
{
	if ( !m_pInstance )
		return false;

	al_seek_audio_stream_secs( m_pInstance, 0 );

	return al_set_audio_stream_playing( m_pInstance, true );
}
static void maybe_fiddle_sliders(int mx, int my)
{
   double seek_pos;
   double w = al_get_display_width(display) - 20;

   if (!(mx >= 10 && mx < 10 + w && my >= 48 && my < 64)) {
      return;
   }

   seek_pos = al_get_audio_stream_length_secs(music_stream) * ((mx - 10) / w);
   if (mouse_button[1]) {
      al_seek_audio_stream_secs(music_stream, seek_pos);
   }
   else if (mouse_button[2]) {
      loop_end = seek_pos;
      al_set_audio_stream_loop_secs(music_stream, loop_start, loop_end);
   }
   else if (mouse_button[3]) {
      loop_start = seek_pos;
      al_set_audio_stream_loop_secs(music_stream, loop_start, loop_end);
   }
}
Beispiel #5
0
bool AudioStream::rewind()
{
	al_seek_audio_stream_secs(m_stream, 0);
	return al_rewind_audio_stream(m_stream);
}
Beispiel #6
0
void AudioStream::resume()
{
	al_set_audio_stream_playing(m_stream, true);
	assert(al_seek_audio_stream_secs(m_stream, m_lastPause));
}
Beispiel #7
0
void
seek_sound(sound_t* sound, int position)
{
	al_seek_audio_stream_secs(sound->stream, (double)position / 1000);
}