2019-11-10 23:23:52 +00:00
|
|
|
/*
|
|
|
|
** i_music.cpp
|
|
|
|
** Plays music
|
|
|
|
**
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
** Copyright 1998-2010 Randy Heit
|
|
|
|
** All rights reserved.
|
|
|
|
**
|
|
|
|
** Redistribution and use in source and binary forms, with or without
|
|
|
|
** modification, are permitted provided that the following conditions
|
|
|
|
** are met:
|
|
|
|
**
|
|
|
|
** 1. Redistributions of source code must retain the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer.
|
|
|
|
** 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer in the
|
|
|
|
** documentation and/or other materials provided with the distribution.
|
|
|
|
** 3. The name of the author may not be used to endorse or promote products
|
|
|
|
** derived from this software without specific prior written permission.
|
|
|
|
**
|
|
|
|
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _WIN32
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <zlib.h>
|
|
|
|
|
2020-04-12 06:07:48 +00:00
|
|
|
#include <zmusic.h>
|
2019-11-10 23:23:52 +00:00
|
|
|
#include "m_argv.h"
|
2019-11-11 00:01:18 +00:00
|
|
|
#include "filesystem.h"
|
2019-11-10 23:23:52 +00:00
|
|
|
#include "c_dispatch.h"
|
|
|
|
#include "templates.h"
|
|
|
|
#include "stats.h"
|
2019-11-11 00:01:18 +00:00
|
|
|
#include "cmdlib.h"
|
2019-11-10 23:23:52 +00:00
|
|
|
#include "c_cvars.h"
|
|
|
|
#include "c_console.h"
|
|
|
|
#include "v_text.h"
|
2020-04-12 06:07:48 +00:00
|
|
|
#include "i_sound.h"
|
2019-11-10 23:23:52 +00:00
|
|
|
#include "i_soundfont.h"
|
|
|
|
#include "s_music.h"
|
2020-04-12 06:07:48 +00:00
|
|
|
#include "filereadermusicinterface.h"
|
2019-11-10 23:23:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void I_InitSoundFonts();
|
|
|
|
|
|
|
|
EXTERN_CVAR (Int, snd_samplerate)
|
|
|
|
EXTERN_CVAR (Int, snd_mididevice)
|
2020-01-07 00:11:19 +00:00
|
|
|
EXTERN_CVAR(Float, snd_mastervolume)
|
2020-04-12 06:07:48 +00:00
|
|
|
int nomusic = 0;
|
2019-11-10 23:23:52 +00:00
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
2020-04-12 06:07:48 +00:00
|
|
|
// CVAR snd_musicvolume
|
2019-11-10 23:23:52 +00:00
|
|
|
//
|
|
|
|
// Maximum volume of MOD/stream music.
|
|
|
|
//==========================================================================
|
|
|
|
|
2020-04-12 06:07:48 +00:00
|
|
|
CUSTOM_CVARD(Float, snd_musicvolume, 0.5, CVAR_ARCHIVE|CVAR_GLOBALCONFIG, "controls music volume")
|
2019-11-10 23:23:52 +00:00
|
|
|
{
|
2020-02-09 12:26:51 +00:00
|
|
|
if (self < 0.f)
|
|
|
|
self = 0.f;
|
|
|
|
else if (self > 1.f)
|
|
|
|
self = 1.f;
|
2019-11-10 23:23:52 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// Set general music volume.
|
2020-02-09 12:26:51 +00:00
|
|
|
ChangeMusicSetting(zmusic_snd_musicvolume, nullptr, self);
|
2019-11-11 20:50:20 +00:00
|
|
|
if (GSnd != nullptr)
|
|
|
|
{
|
2019-12-05 18:00:40 +00:00
|
|
|
GSnd->SetMusicVolume(clamp<float>(self * relative_volume * snd_mastervolume, 0, 1));
|
2019-11-11 20:50:20 +00:00
|
|
|
}
|
2019-11-10 23:23:52 +00:00
|
|
|
// For music not implemented through the digital sound system,
|
|
|
|
// let them know about the change.
|
|
|
|
if (mus_playing.handle != nullptr)
|
|
|
|
{
|
|
|
|
ZMusic_VolumeChanged(mus_playing.handle);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // If the music was stopped because volume was 0, start it now.
|
|
|
|
S_RestartMusic();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-28 02:18:58 +00:00
|
|
|
CUSTOM_CVARD(Bool, mus_enabled, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG, "enables/disables music")
|
|
|
|
{
|
|
|
|
if (self) S_RestartMusic();
|
|
|
|
else S_StopMusic(true);
|
|
|
|
}
|
|
|
|
|
2019-11-10 23:23:52 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// Callbacks for the music system.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2020-02-09 12:26:51 +00:00
|
|
|
static void zmusic_printfunc(int severity, const char* msg)
|
2019-11-10 23:23:52 +00:00
|
|
|
{
|
2020-02-09 12:26:51 +00:00
|
|
|
if (severity >= ZMUSIC_MSG_FATAL)
|
2019-11-10 23:23:52 +00:00
|
|
|
{
|
2020-02-09 12:26:51 +00:00
|
|
|
I_FatalError("%s", msg);
|
|
|
|
}
|
|
|
|
else if (severity >= ZMUSIC_MSG_ERROR)
|
|
|
|
{
|
|
|
|
Printf(TEXTCOLOR_RED "%s\n", msg);
|
|
|
|
}
|
|
|
|
else if (severity >= ZMUSIC_MSG_WARNING)
|
|
|
|
{
|
|
|
|
Printf(TEXTCOLOR_YELLOW "%s\n", msg);
|
|
|
|
}
|
|
|
|
else if (severity >= ZMUSIC_MSG_NOTIFY)
|
|
|
|
{
|
|
|
|
DPrintf(DMSG_SPAMMY, "%s\n", msg);
|
2019-11-10 23:23:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-09 12:26:51 +00:00
|
|
|
static FString strv;
|
|
|
|
static const char *mus_NicePath(const char* str)
|
2019-11-10 23:23:52 +00:00
|
|
|
{
|
2020-02-09 12:26:51 +00:00
|
|
|
strv = NicePath(str);
|
|
|
|
return strv.GetChars();
|
2019-11-10 23:23:52 +00:00
|
|
|
}
|
|
|
|
|
2020-02-09 12:26:51 +00:00
|
|
|
static const char* mus_pathToSoundFont(const char* sfname, int type)
|
2019-11-10 23:23:52 +00:00
|
|
|
{
|
2020-02-09 12:26:51 +00:00
|
|
|
auto info = sfmanager.FindSoundFont(sfname, type);
|
|
|
|
return info ? info->mFilename.GetChars() : nullptr;
|
2019-11-10 23:23:52 +00:00
|
|
|
}
|
|
|
|
|
2020-02-09 12:26:51 +00:00
|
|
|
static void* mus_openSoundFont(const char* sfname, int type)
|
2019-11-10 23:23:52 +00:00
|
|
|
{
|
2020-02-09 12:26:51 +00:00
|
|
|
return sfmanager.OpenSoundFont(sfname, type);
|
2019-11-10 23:23:52 +00:00
|
|
|
}
|
|
|
|
|
2020-02-09 12:26:51 +00:00
|
|
|
static ZMusicCustomReader* mus_sfopenfile(void* handle, const char* fn)
|
2019-11-10 23:23:52 +00:00
|
|
|
{
|
2020-02-09 12:26:51 +00:00
|
|
|
return reinterpret_cast<FSoundFontReader*>(handle)->open_interface(fn);
|
2019-11-10 23:23:52 +00:00
|
|
|
}
|
|
|
|
|
2020-02-09 12:26:51 +00:00
|
|
|
static void mus_sfaddpath(void *handle, const char* path)
|
2019-11-10 23:23:52 +00:00
|
|
|
{
|
2020-02-09 12:26:51 +00:00
|
|
|
reinterpret_cast<FSoundFontReader*>(handle)->AddPath(path);
|
2019-11-10 23:23:52 +00:00
|
|
|
}
|
|
|
|
|
2020-02-09 12:26:51 +00:00
|
|
|
static void mus_sfclose(void* handle)
|
|
|
|
{
|
|
|
|
reinterpret_cast<FSoundFontReader*>(handle)->close();
|
|
|
|
}
|
2019-11-10 23:23:52 +00:00
|
|
|
|
2020-04-12 06:07:48 +00:00
|
|
|
#ifndef ZMUSIC_LITE
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// Pass some basic working data to the music backend
|
|
|
|
// We do this once at startup for everything available.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
static void SetupGenMidi()
|
|
|
|
{
|
|
|
|
// The OPL renderer should not care about where this comes from.
|
|
|
|
// Note: No I_Error here - this needs to be consistent with the rest of the music code.
|
|
|
|
auto lump = fileSystem.CheckNumForName("GENMIDI", ns_global);
|
|
|
|
if (lump < 0)
|
|
|
|
{
|
|
|
|
Printf("No GENMIDI lump found. OPL playback not available.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto data = fileSystem.OpenFileReader(lump);
|
|
|
|
|
|
|
|
auto genmidi = data.Read();
|
|
|
|
if (genmidi.Size() < 8 + 175 * 36 || memcmp(genmidi.Data(), "#OPL_II#", 8)) return;
|
|
|
|
ZMusic_SetGenMidi(genmidi.Data()+8);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SetupWgOpn()
|
|
|
|
{
|
|
|
|
int lump = fileSystem.CheckNumForFullName("xg.wopn");
|
|
|
|
if (lump < 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
FileData data = fileSystem.ReadFile(lump);
|
|
|
|
ZMusic_SetWgOpn(data.GetMem(), (uint32_t)data.GetSize());
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SetupDMXGUS()
|
|
|
|
{
|
|
|
|
int lump = fileSystem.CheckNumForFullName("DMXGUS");
|
|
|
|
if (lump < 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
FileData data = fileSystem.ReadFile(lump);
|
|
|
|
ZMusic_SetDmxGus(data.GetMem(), (uint32_t)data.GetSize());
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2019-11-10 23:23:52 +00:00
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2020-04-12 06:07:48 +00:00
|
|
|
void I_InitMusic(void)
|
2019-11-10 23:23:52 +00:00
|
|
|
{
|
|
|
|
I_InitSoundFonts();
|
|
|
|
|
2020-04-12 06:07:48 +00:00
|
|
|
snd_musicvolume.Callback ();
|
|
|
|
|
|
|
|
nomusic = !!Args->CheckParm("-nomusic") || !!Args->CheckParm("-nosound");
|
2019-11-10 23:23:52 +00:00
|
|
|
|
|
|
|
snd_mididevice.Callback();
|
|
|
|
|
2020-02-09 12:26:51 +00:00
|
|
|
ZMusicCallbacks callbacks{};
|
2019-11-10 23:23:52 +00:00
|
|
|
|
2020-02-09 12:26:51 +00:00
|
|
|
callbacks.MessageFunc = zmusic_printfunc;
|
2019-11-10 23:23:52 +00:00
|
|
|
callbacks.NicePath = mus_NicePath;
|
|
|
|
callbacks.PathForSoundfont = mus_pathToSoundFont;
|
|
|
|
callbacks.OpenSoundFont = mus_openSoundFont;
|
2020-02-09 12:26:51 +00:00
|
|
|
callbacks.SF_OpenFile = mus_sfopenfile;
|
|
|
|
callbacks.SF_AddToSearchPath = mus_sfaddpath;
|
|
|
|
callbacks.SF_Close = mus_sfclose;
|
2019-11-10 23:23:52 +00:00
|
|
|
|
|
|
|
ZMusic_SetCallbacks(&callbacks);
|
2020-04-12 06:07:48 +00:00
|
|
|
#ifndef ZMUSIC_LITE
|
|
|
|
SetupGenMidi();
|
|
|
|
SetupDMXGUS();
|
|
|
|
SetupWgOpn();
|
|
|
|
#endif
|
2019-11-10 23:23:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
void I_SetRelativeVolume(float vol)
|
|
|
|
{
|
|
|
|
relative_volume = (float)vol;
|
2020-02-09 12:26:51 +00:00
|
|
|
ChangeMusicSetting(zmusic_relative_volume, nullptr, (float)vol);
|
2020-04-12 06:07:48 +00:00
|
|
|
snd_musicvolume.Callback();
|
2019-11-10 23:23:52 +00:00
|
|
|
}
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// Sets relative music volume. Takes $musicvolume in SNDINFO into consideration
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
void I_SetMusicVolume (double factor)
|
|
|
|
{
|
|
|
|
factor = clamp(factor, 0., 2.0);
|
|
|
|
I_SetRelativeVolume((float)factor);
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// test a relative music volume
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
CCMD(testmusicvol)
|
|
|
|
{
|
|
|
|
if (argv.argc() > 1)
|
|
|
|
{
|
|
|
|
I_SetRelativeVolume((float)strtod(argv[1], nullptr));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Printf("Current relative volume is %1.2f\n", relative_volume);
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// STAT music
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
ADD_STAT(music)
|
|
|
|
{
|
|
|
|
if (mus_playing.handle != nullptr)
|
|
|
|
{
|
2020-02-09 12:26:51 +00:00
|
|
|
return ZMusic_GetStats(mus_playing.handle);
|
2019-11-10 23:23:52 +00:00
|
|
|
}
|
|
|
|
return "No song playing";
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// Common loader for the dumpers.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2020-02-09 12:26:51 +00:00
|
|
|
static ZMusic_MidiSource GetMIDISource(const char *fn)
|
2019-11-10 23:23:52 +00:00
|
|
|
{
|
|
|
|
FString src = fn;
|
|
|
|
if (src.Compare("*") == 0) src = mus_playing.name;
|
|
|
|
|
2020-04-12 06:07:48 +00:00
|
|
|
auto lump = fileSystem.CheckNumForName(src, ns_music);
|
|
|
|
if (lump < 0) lump = fileSystem.CheckNumForFullName(src);
|
2019-11-10 23:23:52 +00:00
|
|
|
if (lump < 0)
|
|
|
|
{
|
|
|
|
Printf("Cannot find MIDI lump %s.\n", src.GetChars());
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-11-11 00:01:18 +00:00
|
|
|
auto wlump = fileSystem.OpenFileReader(lump);
|
2019-11-10 23:23:52 +00:00
|
|
|
|
|
|
|
uint32_t id[32 / 4];
|
|
|
|
|
|
|
|
if (wlump.Read(id, 32) != 32 || wlump.Seek(-32, FileReader::SeekCur) != 0)
|
|
|
|
{
|
|
|
|
Printf("Unable to read lump %s\n", src.GetChars());
|
|
|
|
return nullptr;
|
|
|
|
}
|
2020-02-09 12:26:51 +00:00
|
|
|
auto type = ZMusic_IdentifyMIDIType(id, 32);
|
2019-11-10 23:23:52 +00:00
|
|
|
if (type == MIDI_NOTMIDI)
|
|
|
|
{
|
|
|
|
Printf("%s is not MIDI-based.\n", src.GetChars());
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto data = wlump.Read();
|
2020-02-09 12:26:51 +00:00
|
|
|
auto source = ZMusic_CreateMIDISource(data.Data(), data.Size(), type);
|
2019-11-10 23:23:52 +00:00
|
|
|
|
|
|
|
if (source == nullptr)
|
|
|
|
{
|
2020-02-09 12:26:51 +00:00
|
|
|
Printf("Unable to open %s: %s\n", src.GetChars(), ZMusic_GetLastError());
|
2019-11-10 23:23:52 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return source;
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// CCMD writewave
|
|
|
|
//
|
|
|
|
// If the current song can be represented as a waveform, dump it to
|
|
|
|
// the specified file on disk. The sample rate parameter is merely a
|
|
|
|
// suggestion, and the dumper is free to ignore it.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2020-04-12 06:07:48 +00:00
|
|
|
UNSAFE_CCMD (writewave)
|
2019-11-10 23:23:52 +00:00
|
|
|
{
|
|
|
|
if (argv.argc() >= 3 && argv.argc() <= 7)
|
|
|
|
{
|
|
|
|
auto source = GetMIDISource(argv[1]);
|
|
|
|
if (source == nullptr) return;
|
|
|
|
|
|
|
|
EMidiDevice dev = MDEV_DEFAULT;
|
2020-04-12 06:07:48 +00:00
|
|
|
#ifndef ZMUSIC_LITE
|
2019-11-10 23:23:52 +00:00
|
|
|
if (argv.argc() >= 6)
|
|
|
|
{
|
2020-04-12 06:07:48 +00:00
|
|
|
if (!stricmp(argv[5], "WildMidi")) dev = MDEV_WILDMIDI;
|
|
|
|
else if (!stricmp(argv[5], "GUS")) dev = MDEV_GUS;
|
|
|
|
else if (!stricmp(argv[5], "Timidity") || !stricmp(argv[5], "Timidity++")) dev = MDEV_TIMIDITY;
|
2019-11-10 23:23:52 +00:00
|
|
|
else if (!stricmp(argv[5], "FluidSynth")) dev = MDEV_FLUIDSYNTH;
|
|
|
|
else if (!stricmp(argv[5], "OPL")) dev = MDEV_OPL;
|
2020-04-12 06:07:48 +00:00
|
|
|
else if (!stricmp(argv[5], "OPN")) dev = MDEV_OPN;
|
|
|
|
else if (!stricmp(argv[5], "ADL")) dev = MDEV_ADL;
|
2019-11-10 23:23:52 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
Printf("%s: Unknown MIDI device\n", argv[5]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2020-04-12 06:07:48 +00:00
|
|
|
#endif
|
2019-11-10 23:23:52 +00:00
|
|
|
// We must stop the currently playing music to avoid interference between two synths.
|
|
|
|
auto savedsong = mus_playing;
|
|
|
|
S_StopMusic(true);
|
|
|
|
if (dev == MDEV_DEFAULT && snd_mididevice >= 0) dev = MDEV_FLUIDSYNTH; // The Windows system synth cannot dump a wave.
|
2020-02-09 12:26:51 +00:00
|
|
|
if (!ZMusic_MIDIDumpWave(source, dev, argv.argc() < 6 ? nullptr : argv[6], argv[2], argv.argc() < 4 ? 0 : (int)strtol(argv[3], nullptr, 10), argv.argc() < 5 ? 0 : (int)strtol(argv[4], nullptr, 10)))
|
2019-11-10 23:23:52 +00:00
|
|
|
{
|
2020-02-09 12:26:51 +00:00
|
|
|
Printf("MIDI dump of %s failed: %s\n",argv[1], ZMusic_GetLastError());
|
2019-11-10 23:23:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
S_ChangeMusic(savedsong.name, savedsong.baseorder, savedsong.loop, true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Printf ("Usage: writewave <midi> <filename> [subsong] [sample rate] [synth] [soundfont]\n"
|
|
|
|
" - use '*' as song name to dump the currently playing song\n"
|
|
|
|
" - use 0 for subsong and sample rate to play the default\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// CCMD writemidi
|
|
|
|
//
|
|
|
|
// Writes a given MIDI song to disk. This does not affect playback anymore,
|
|
|
|
// like older versions did.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2020-04-12 06:07:48 +00:00
|
|
|
UNSAFE_CCMD(writemidi)
|
2019-11-10 23:23:52 +00:00
|
|
|
{
|
|
|
|
if (argv.argc() != 3)
|
|
|
|
{
|
|
|
|
Printf("Usage: writemidi <midisong> <filename> - use '*' as song name to dump the currently playing song\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto source = GetMIDISource(argv[1]);
|
2020-02-09 12:26:51 +00:00
|
|
|
if (source == nullptr)
|
2019-11-10 23:23:52 +00:00
|
|
|
{
|
2020-02-09 12:26:51 +00:00
|
|
|
Printf("Unable to open %s: %s\n", argv[1], ZMusic_GetLastError());
|
2019-11-10 23:23:52 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-02-09 12:26:51 +00:00
|
|
|
if (!ZMusic_WriteSMF(source, argv[1], 1))
|
2019-11-10 23:23:52 +00:00
|
|
|
{
|
2020-02-09 12:26:51 +00:00
|
|
|
Printf("Unable to write %s\n", argv[1]);
|
2019-11-10 23:23:52 +00:00
|
|
|
}
|
|
|
|
}
|