コード例 #1
0
ファイル: music.c プロジェクト: AlleyCat1976/Meridian59_103
/*
 * 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
}
コード例 #2
0
ファイル: FMain.cpp プロジェクト: Joincheng/lithtech
bool TForm_Main::OpenFile()
{
	//  STOP!!!
	c_Button_Stop->Click();

	// Let go...
	if (m_hSample)
	{
		AIL_release_sample_handle(m_hSample);
		m_hSample = NULL;
	}

	// Get rid of the buffer if it's already been loaded
	if (m_pFileBuffer)
	{
		AIL_mem_free_lock(m_pFileBuffer);
		m_pFileBuffer = NULL;
	}

	// Remember the file name
	m_CurFile = c_Edit_FileName->Text;

	// Er, don't load if it doesn't exist...
	if (!FileExists(m_CurFile))
	{
		m_CurFile = "";
		return false;
	}

	m_hSample = AIL_allocate_sample_handle(m_hDigDriver);
	if (!m_hSample)
	{
		ChangeStatus("Error allocating sample handle");
		m_CurFile = "";
		return false;
	}

	char *pFileName = m_CurFile.c_str();

	// Bind to the file
	m_pFileBuffer = AIL_file_read(pFileName, NULL);
	if (!m_pFileBuffer)
	{
		ChangeStatus("Error opening " + m_CurFile + " (" + IntToStr(AIL_file_error()) + ")");
		m_CurFile = "";
		return false;
	}

	// Get the file size
	m_iFileSize = AIL_file_size(pFileName);

	AIL_init_sample(m_hSample);

	AIL_set_named_sample_file(m_hSample, pFileName, m_pFileBuffer, m_iFileSize, 0);

	AIL_set_sample_loop_count(m_hSample, 0);

	AIL_set_sample_volume(m_hSample, 127);

	AIL_set_sample_processor(m_hSample, DP_FILTER, m_hCurFilter);

	ChangeStatus("Loaded " + m_CurFile);

	return true;
}
コード例 #3
0
ファイル: music.c プロジェクト: AlleyCat1976/Meridian59_103
/*
 * 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
}