From aa350528dfbfc8175f140202252cfdc6dbf46aa8 Mon Sep 17 00:00:00 2001 From: Patric Stout Date: Mon, 4 Mar 2019 19:49:39 +0100 Subject: Remove: libtimidity support (NOT timidity support) libtimidity was introduced with the support for PSP. PSP has been dropped almost a year ago, but this music driver was not. This corrects that oversight. timidity (via extmidi) still works fine. This purely removes the libtimidity support, which was only really available for PSP. --- src/music/libtimidity.cpp | 128 ---------------------------------------------- 1 file changed, 128 deletions(-) delete mode 100644 src/music/libtimidity.cpp (limited to 'src/music/libtimidity.cpp') diff --git a/src/music/libtimidity.cpp b/src/music/libtimidity.cpp deleted file mode 100644 index 42c1e3c15..000000000 --- a/src/music/libtimidity.cpp +++ /dev/null @@ -1,128 +0,0 @@ -/* $Id$ */ - -/* - * This file is part of OpenTTD. - * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. - * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see . - */ - -/** @file libtimidity.cpp Playing music via the timidity library. */ - -#include "../stdafx.h" -#include "../openttd.h" -#include "../sound_type.h" -#include "../debug.h" -#include "libtimidity.h" -#include "midifile.hpp" -#include "../base_media_base.h" -#include -#include -#include -#include -#include -#include -#include -#include - -#include "../safeguards.h" - -/** The state of playing. */ -enum MidiState { - MIDI_STOPPED = 0, - MIDI_PLAYING = 1, -}; - -static struct { - MidIStream *stream; - MidSongOptions options; - MidSong *song; - - MidiState status; - uint32 song_length; - uint32 song_position; -} _midi; ///< Metadata about the midi we're playing. - -/** Factory for the libtimidity driver. */ -static FMusicDriver_LibTimidity iFMusicDriver_LibTimidity; - -const char *MusicDriver_LibTimidity::Start(const char * const *param) -{ - _midi.status = MIDI_STOPPED; - _midi.song = NULL; - - if (mid_init(param == NULL ? NULL : const_cast(param[0])) < 0) { - /* If init fails, it can be because no configuration was found. - * If it was not forced via param, try to load it without a - * configuration. Who knows that works. */ - if (param != NULL || mid_init_no_config() < 0) { - return "error initializing timidity"; - } - } - DEBUG(driver, 1, "successfully initialised timidity"); - - _midi.options.rate = 44100; - _midi.options.format = MID_AUDIO_S16LSB; - _midi.options.channels = 2; - _midi.options.buffer_size = _midi.options.rate; - - return NULL; -} - -void MusicDriver_LibTimidity::Stop() -{ - if (_midi.status == MIDI_PLAYING) this->StopSong(); - mid_exit(); -} - -void MusicDriver_LibTimidity::PlaySong(const MusicSongInfo &song) -{ - std::string filename = MidiFile::GetSMFFile(song); - - this->StopSong(); - if (filename.empty()) return; - - _midi.stream = mid_istream_open_file(filename.c_str()); - if (_midi.stream == NULL) { - DEBUG(driver, 0, "Could not open music file"); - return; - } - - _midi.song = mid_song_load(_midi.stream, &_midi.options); - mid_istream_close(_midi.stream); - _midi.song_length = mid_song_get_total_time(_midi.song); - - if (_midi.song == NULL) { - DEBUG(driver, 1, "Invalid MIDI file"); - return; - } - - mid_song_start(_midi.song); - _midi.status = MIDI_PLAYING; -} - -void MusicDriver_LibTimidity::StopSong() -{ - _midi.status = MIDI_STOPPED; - /* mid_song_free cannot handle NULL! */ - if (_midi.song != NULL) mid_song_free(_midi.song); - _midi.song = NULL; -} - -bool MusicDriver_LibTimidity::IsSongPlaying() -{ - if (_midi.status == MIDI_PLAYING) { - _midi.song_position = mid_song_get_time(_midi.song); - if (_midi.song_position >= _midi.song_length) { - _midi.status = MIDI_STOPPED; - _midi.song_position = 0; - } - } - - return (_midi.status == MIDI_PLAYING); -} - -void MusicDriver_LibTimidity::SetVolume(byte vol) -{ - if (_midi.song != NULL) mid_song_set_volume(_midi.song, vol); -} -- cgit v1.2.3-70-g09d2