Exemple #1
0
//---------------------------------------------------------------------------
void __fastcall TForm_Main::c_Button_PlayClick(TObject *Sender)
{
	if (!m_hSample)
		return;

	AIL_set_sample_processor(m_hSample, DP_FILTER, m_hCurFilter);

	// Reset the current property, just in case it got lost..
	//AdjustProperty(0.0f);
	// Play
	c_TrackBar_PanChange(Sender);
	AIL_set_sample_ms_position(m_hSample, 0);
	AIL_start_sample(m_hSample);

	// Reset the property values based on our cache
	int iCurProperty = 0;
	RIB_INTERFACE_ENTRY ribAttrib;
	HINTENUM enumerator(HINTENUM_FIRST);
	while ((iCurProperty < m_iNumProperties) &&
		AIL_enumerate_filter_sample_attributes(m_hCurFilter, &enumerator, &ribAttrib))
	{
		AIL_set_filter_sample_preference(m_hSample, ribAttrib.entry_name, &m_fProperties[iCurProperty]);
		++iCurProperty;
	}
}
Exemple #2
0
/*
 * UnpauseMusic:  Restore saved position of background music.
 *   Assumes that background music has been restarted.
 */
void UnpauseMusic(void)
{
#ifdef M59_MSS
   if (!has_midi)
      return;

   if (music_pos)
      AIL_resume_sample(hseqBackground);
   else
      AIL_start_sample(hseqBackground);
   debug(( "Unpausing music.\n" ));
#else
   MCI_SEEK_PARMS mciSeekParms;
   MCI_SET_PARMS  mciSetParms;

   if (!has_midi)
      return;

   /* Set time format */
   mciSetParms.dwTimeFormat = time_format;
   mciSendCommand(midi_element, MCI_SET,
      MCI_SET_TIME_FORMAT, (DWORD)(LPVOID) &mciSetParms);

   mciSeekParms.dwTo = music_pos;
   mciSendCommand(midi_element, MCI_SEEK,
      MCI_TO, (DWORD)(LPVOID) &mciSeekParms);
   debug(("Unpausing to  position = %ld\n", music_pos));
#endif
}
      //
      // Play2D
      //
      // Play a record as a 2D sample (TRUE if actually started)
      //
      Bool Play2D
      (
        Effect *e, Record *r, S32 vol, U32 owner, F32 priority, S32 loop, S32 pan
      )
      {
        ASSERT(e);
        ASSERT(r);

        // Request a 2D voice
        Voice *voice = Request(priority, FALSE, e->GetVoiceIndex());

        if (!voice)
        {
          return (FALSE);
        }

        // Request the cache data
        Cache::Item *item = Cache::Request(r);

        if (!item)
        {
          // Unable to load data
          return (FALSE);
        }

        // Stop any sounds from this owner
        if (owner != NO_OWNER) 
        {
          Output::StopByOwner(owner);
        }

        // The current time
        U32 time = AIL_ms_count();

        // Are we under the minimum repeat time
        if ((time - r->lastUse) < MIN_REPEATTIME)
        {
          return (FALSE);
        }

        // Save info about this use
        r->lastUse = time;

        // Initialise the voice
        AIL_init_sample(voice->handle2D);

        // Initialise the sound effect data
        if (!AIL_set_sample_file(voice->handle2D, item->data, 0))
        {
          LOG_WARN(("Ignoring possibly corrupted file '%s'", r->Name()));
          r->valid = FALSE;
          return (FALSE);
        }

        // Setup the voice
        voice->effect = e;
        voice->record = r;
        voice->owner = owner;
        voice->priority = priority;

        // Set the volume
        AIL_set_sample_volume(voice->handle2D, vol);

        // Set the stereo panning
        AIL_set_sample_pan(voice->handle2D, pan);

        // Set the loop count for this voice
        AIL_set_sample_loop_count(voice->handle2D, loop);

        // Start the sample playing
        AIL_start_sample(voice->handle2D);

        return (TRUE);
      }
Exemple #4
0
/*
 * PlayMusicFile:  Play given MIDI file and notify given window when done.
 *   If background music had been playing, it picks up where it left off.
 *   Returns 0 if successful, MCI error code otherwise.
 */
DWORD PlayMusicFile(HWND hWndNotify, char *fname)
{
   if (!has_midi)
      return 0;

#ifdef M59_MSS
   char *ext;

   // If a sequence was paused, resume it
   if (music_pos != 0)
   {
      UnpauseMusic();
      return 0;
   }

   // free memory from previous background music
   if (pMIDIBackground)
      AIL_mem_free_lock(pMIDIBackground);

   // First try MP3 file
   ext = strstr( _strlwr( fname ), ".mid" );
   if( ext != NULL )
      strcpy( ext, ".mp3" );

   // load the file
   pMIDIBackground = (BYTE *) AIL_file_read( fname, NULL );
   if( !pMIDIBackground )
   {
      // Next try xmi file
      ext = strstr(fname, ".mp3" );
      if( ext != NULL )
         strcpy( ext, ".xmi" );
      
      pMIDIBackground = (BYTE *) AIL_file_read( fname, NULL );
      if( !pMIDIBackground )
      {
         debug(( "Failed to load music file %s.\n", fname ));
         return 0;
      }
   }

   // initialize the sequence
   if (!AIL_set_named_sample_file(hseqBackground, fname, pMIDIBackground,
                                  AIL_file_size(fname), 0 ) )
   {
      debug(( "Failed to init music sequence %s.\n", fname ));
      return 0;
   }

   // set to loop indefinitely
   AIL_set_sample_loop_count( hseqBackground, 0 );

   // Set volume
   float vol = ((float) config.music_volume) / CONFIG_MAX_VOLUME;
   AIL_set_sample_volume_levels(hseqBackground, vol, vol );

   // start playing
   AIL_start_sample( hseqBackground );
   debug(( "Playing music file %s.\n", fname ));
   playing_music = True;
   return 0;


#else
   DWORD dwReturn;
   MCI_PLAY_PARMS mciPlayParms;
   char temp[81];

   if ((dwReturn = OpenMidiFile(fname)) != 0)
     {
       debug(("OpenMidiFile error code = %d\n", dwReturn));
       mciGetErrorString(dwReturn, temp, 80);
       debug((temp));
       return dwReturn;
     }

   /* If already playing music, pick up where we left off */
   if (music_pos != 0)
      UnpauseMusic();

   /*
    * Begin playback. The window procedure function
    * for the parent window is notified with an
    * MM_MCINOTIFY message when playback is complete.
    * The window procedure then closes the device.
    */
   mciPlayParms.dwCallback = (DWORD) hWndNotify;
   if (dwReturn = mciSendCommand(midi_element, MCI_PLAY,
                                 MCI_NOTIFY, (DWORD)(LPVOID) &mciPlayParms)) 
   {
      mciGetErrorString(dwReturn, temp, 80);
      debug((temp));
      
      mciSendCommand(midi_element, MCI_CLOSE, 0, 0);
      
      return dwReturn;
   }

   debug(("Playing music file, element = %d\n", midi_element));
   ResetMusicVolume();
   playing_music = True;
   return 0;
#endif
}
Exemple #5
0
/*
 * PlayMidiFile:  Play given MIDI file and notify given window when done.
 *   Returns 0 if successful, MCI error code otherwise.
 */
DWORD PlayMidiFile(HWND hWndNotify, char *fname)
{
   if (!has_midi)
      return 0;

#ifdef M59_MSS
   // If a sample was playing, end it
   if( AIL_sample_status( hseqImmediate ) != SMP_DONE )
      AIL_end_sample( hseqImmediate );

   // free memory from previous MIDI file
   if( pMIDIImmediate )
      AIL_mem_free_lock( pMIDIImmediate );

   // First try MP3 file
   char *ext = strstr( _strlwr( fname ), ".mid" );
   if( ext != NULL )
      strcpy( ext, ".mp3" );

   // load the file
   pMIDIImmediate = (BYTE *) AIL_file_read( fname, NULL );
   if( !pMIDIImmediate )
   {
      // Next try xmi file
      ext = strstr(fname, ".mp3" );
      if( ext != NULL )
         strcpy( ext, ".xmi" );
      
      pMIDIImmediate = (BYTE *) AIL_file_read( fname, NULL );
      if( !pMIDIImmediate )
      {
         debug(( "Failed to load music file %s.\n", fname ));
         return 0;
      }
   }

   // Initialize the sample
   if (!AIL_set_named_sample_file(hseqImmediate, fname, pMIDIImmediate,
                                  AIL_file_size(fname), 0))
   {
      debug(( "Failed to init music file.\n" ));
      return 0;
   }

   // Set volume
   float vol = ((float) config.music_volume) / CONFIG_MAX_VOLUME;
   AIL_set_sample_volume_levels(hseqImmediate, vol, vol );

   // start playing
   AIL_start_sample(hseqImmediate);

   // Set end-of-sample callback so we can unpause
   //	the background music when done playing.
   AIL_register_EOS_callback(hseqImmediate, MIDIDoneCallback);

   debug(( "Playing music file %s.\n", fname ));
   playing_midi = True;
   return 0;
#else
   {
      DWORD dwReturn;
      MCI_PLAY_PARMS mciPlayParms;

      if ((dwReturn = OpenMidiFile(fname)) != 0)
      {
        return dwReturn;
      }

      /*
       * Begin playback. The window procedure function
       * for the parent window is notified with an
       * MM_MCINOTIFY message when playback is complete.
       * The window procedure then closes the device.
       */
      mciPlayParms.dwCallback = (DWORD) hWndNotify;
      if (dwReturn = mciSendCommand(midi_element, MCI_PLAY,
                                    MCI_NOTIFY, (DWORD)(LPVOID) &mciPlayParms)) 
      {
         mciSendCommand(midi_element, MCI_CLOSE, 0, 0);
         return dwReturn;
      }
      
      debug(("Playing MIDI file, element = %d\n", midi_element));
      ResetMusicVolume();
      playing_midi = True;
      return 0;
   }
#endif
}