bool MidiPlayerThread::start( const QString &path, int volume, double seek /* = -1 */ ) { qDebug() << "MidiPlayerThread::start"; unsigned short int mixer_options = 0; m_path = path; if ( open_alsa_output() == ( -1 ) ) { qDebug() << "MidiPlayerThread::start: error of open_alsa_output()..."; return false; } if ( WildMidi_Init( qPrintable( m_configFile ), m_sample_rate, mixer_options ) < 0 ) { qWarning( "MidiPlayerThread::start: unable to initialize WildMidi library" ); close_output(); return false; } m_midiPtr = WildMidi_Open ( qPrintable( m_path ) ); if ( !m_midiPtr ) { qWarning("MidiPlayerThread::start: unable to open file"); WildMidi_Shutdown(); close_output(); return false; } Tracks audios; audios.addID( 0 ); _WM_Info *wm_info = WildMidi_GetInfo( m_midiPtr ); m_totalTime = ( qint64 )wm_info->approx_total_samples / m_sample_rate; qDebug() << "total time is " << m_totalTime << " sec"; m_md->reset(); m_md->duration = m_totalTime; m_md->audio_rate = m_sample_rate; m_md->novideo = true; m_md->audios = audios; // m_md->type = TYPE_FILE; setVolume( volume ); if ( seek != ( -1 ) ) { goToSec( seek ); } QThread::start(); qDebug( "MidiPlayerThread: thread started" ); emit audioInfoChanged( audios ); return true; }
static int midi_init ( void ) { wildmidi_volume = Cvar_Get ("wildmidi_volume", "100", CVAR_ARCHIVE, NULL, "Set the Master Volume"); wildmidi_config = Cvar_Get ("wildmidi_config", "/etc/timidity.cfg", CVAR_ROM, NULL, "path/filename of timidity.cfg"); if (WildMidi_Init (wildmidi_config->string, snd_shm->speed, 0) == -1) return 1; midi_intiialized = 1; return 0; }
bool init(MidiFormat format, const char* patchLoc) { free(); s_mutex = Mutex::create(); s_midiFormat = format; if (s_midiFormat == MFMT_GUS_PATCH) { s_volume = c_volumeScale[0]; s_sampleRate = 32072.0; if (WildMidi_Init(patchLoc, 32072, WM_MO_ENHANCED_RESAMPLING) >= 0) { s_initialized = true; WildMidi_MasterVolume(100); return true; } } else if (s_midiFormat == MFMT_SOUND_FONT) { s_volume = c_volumeScale[1]; if (!loadFluidsythDLL()) { LOG( LOG_ERROR, "cannot find or load the \"libfluidsynth\" dynamic library." ); return false; } s_fluidSettings = new_fluid_settings(); fluid_settings_setstr(s_fluidSettings, "player.timing-source", "sample"); fluid_settings_setstr(s_fluidSettings, "synth.lock-memory", 0); fluid_settings_setstr(s_fluidSettings, "synth.chorus-active", "0"); s_fluidSynth = new_fluid_synth(s_fluidSettings); if (fluid_synth_sfload(s_fluidSynth, patchLoc, 1) < 0) { LOG( LOG_ERROR, "cannot load sound font \"%s\"", patchLoc ); unloadFluidsynthDLL(); return false; } s_fluidSeq = new_fluid_sequencer2(false); fluid_sequencer_register_fluidsynth(s_fluidSeq, s_fluidSynth); fluid_settings_getnum(s_fluidSettings, "synth.sample-rate", &s_sampleRate); s_initialized = true; s_fluidPlayer = new_fluid_player(s_fluidSynth); return true; } return false; }
static bool wildmidi_init(const struct config_param *param) { const char *config_file; int ret; config_file = config_get_block_string(param, "config_file", "/etc/timidity/timidity.cfg"); if (!g_file_test(config_file, G_FILE_TEST_IS_REGULAR)) { g_debug("configuration file does not exist: %s", config_file); return false; } ret = WildMidi_Init(config_file, WILDMIDI_SAMPLE_RATE, 0); return ret == 0; }
static gboolean wildmidi_open_config (void) { gchar *path = g_strdup (g_getenv ("WILDMIDI_CFG")); gint ret; GST_DEBUG ("trying %s", GST_STR_NULL (path)); if (path && (g_access (path, R_OK) == -1)) { g_free (path); path = NULL; } if (path == NULL) { path = g_build_path (G_DIR_SEPARATOR_S, g_get_home_dir (), ".wildmidirc", NULL); GST_DEBUG ("trying %s", path); if (path && (g_access (path, R_OK) == -1)) { g_free (path); path = NULL; } } if (path == NULL) { path = g_build_path (G_DIR_SEPARATOR_S, G_DIR_SEPARATOR_S "etc", "wildmidi.cfg", NULL); GST_DEBUG ("trying %s", path); if (path && (g_access (path, R_OK) == -1)) { g_free (path); path = NULL; } } if (path == NULL) { path = g_build_path (G_DIR_SEPARATOR_S, G_DIR_SEPARATOR_S "etc", "wildmidi", "wildmidi.cfg", NULL); GST_DEBUG ("trying %s", path); if (path && (g_access (path, R_OK) == -1)) { g_free (path); path = NULL; } } if (path == NULL) { path = g_strdup (WILDMIDI_CFG); GST_DEBUG ("trying %s", path); if (path && (g_access (path, R_OK) == -1)) { g_free (path); path = NULL; } } if (path == NULL) { path = g_build_path (G_DIR_SEPARATOR_S, G_DIR_SEPARATOR_S "etc", "timidity.cfg", NULL); GST_DEBUG ("trying %s", path); if (path && (g_access (path, R_OK) == -1)) { g_free (path); path = NULL; } } if (path == NULL) { path = g_build_path (G_DIR_SEPARATOR_S, G_DIR_SEPARATOR_S "etc", "timidity", "timidity.cfg", NULL); GST_DEBUG ("trying %s", path); if (path && (g_access (path, R_OK) == -1)) { g_free (path); path = NULL; } } if (path == NULL) { /* I've created a symlink to get it playing * ln -s /usr/share/timidity/timidity.cfg /etc/wildmidi.cfg * we could make it use : WILDMIDI_CFG * but unfortunately it fails to create a proper filename if the config * has a redirect * http://sourceforge.net/tracker/index.php?func=detail&aid=1657358&group_id=42635&atid=433744 */ GST_WARNING ("no config file, can't initialise"); return FALSE; } /* this also initializes a some filter and stuff and thus is slow */ ret = WildMidi_Init (path, WILDMIDI_RATE, 0); g_free (path); return (ret == 0); }