Beispiel #1
0
/*
 * NewMusic:  Start playing new music.  type gives type of sound (MIDI, 
 *   music).  rsc gives resource id of file.
 */
void NewMusic(WPARAM type, ID rsc)
{
   char *filename, fname[MAX_PATH + FILENAME_MAX];
   
   // NULL rsc => abort midi in progress
   if( !rsc )
   {
      if( ( type == SOUND_MIDI ) && ( playing_midi ) )
      {
#ifdef M59_MSS
         AIL_end_sample( hseqImmediate );
#else
         mciSendCommand(midi_element, MCI_CLOSE, 0, 0); 
#endif
         playing_midi = False;
      }
      else if( ( type == SOUND_MUSIC ) && ( playing_music ) )
      {
#ifdef M59_MSS
         AIL_end_sample( hseqBackground );
#else
         mciSendCommand(midi_element, MCI_CLOSE, 0, 0); 
#endif
         playing_music = False;
         return;
      }
      return;
   }

   if( (filename = LookupNameRsc(rsc)) == NULL )
      return;

   sprintf(fname, "%s\\%.*s", music_dir, FILENAME_MAX, filename);

   switch (type)
   {
   case SOUND_MIDI:
      PlayMidiFile(hMain, fname);
#ifndef M59_MSS
      debug(("NewMusic MIDI, element = %d\n", midi_element));
#endif
      break;

   case SOUND_MUSIC:
      PlayMusicFile(hMain, fname);
#ifndef M59_MSS
      debug(("NewMusic music, element = %d\n", midi_element));
#endif
      break;
   }
}
Beispiel #2
0
/*
 * MusicAbort:  Turn off currently playing music
 */
void MusicAbort(void)
{
   if (!has_midi)
      return;

   if (playing_music || playing_midi)
   {
#ifdef M59_MSS
      AIL_end_sample(hseqBackground);
      AIL_end_sample(hseqImmediate);
#else
      mciSendCommand(MCI_ALL_DEVICE_ID, MCI_CLOSE, 0, 0);
#endif
   }

   playing_music = False;
   music_pos = 0;
}
 //
 // Stop voice playing
 //
 void Stop()
 {
   if (flag3D)
   {
     AIL_end_3D_sample(handle3D);
   }
   else
   {
     AIL_end_sample(handle2D);
   }
 }
Beispiel #4
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
}