2016-05-09 07:22:58 +00:00
|
|
|
#include "amuse/amuse.hpp"
|
|
|
|
#include "amuse/BooBackend.hpp"
|
2016-05-11 04:48:08 +00:00
|
|
|
#include "boo/boo.hpp"
|
2016-05-10 02:31:05 +00:00
|
|
|
#include "logvisor/logvisor.hpp"
|
2016-05-09 07:22:58 +00:00
|
|
|
#include <thread>
|
2017-09-20 09:22:46 +00:00
|
|
|
|
|
|
|
#define EMITTER_TEST 0
|
2016-05-09 07:22:58 +00:00
|
|
|
|
2016-05-14 04:46:39 +00:00
|
|
|
static logvisor::Module Log("amuseplay");
|
2016-05-10 05:32:31 +00:00
|
|
|
|
2016-05-21 03:10:39 +00:00
|
|
|
#if __GNUC__
|
2016-07-14 04:54:46 +00:00
|
|
|
__attribute__((__format__(__printf__, 3, 4)))
|
2016-05-21 03:10:39 +00:00
|
|
|
#endif
|
2016-07-14 04:54:46 +00:00
|
|
|
static inline void
|
|
|
|
SNPrintf(boo::SystemChar* str, size_t maxlen, const boo::SystemChar* format, ...)
|
2016-05-21 03:10:39 +00:00
|
|
|
{
|
|
|
|
va_list va;
|
|
|
|
va_start(va, format);
|
|
|
|
#if _WIN32
|
|
|
|
_vsnwprintf(str, maxlen, format, va);
|
|
|
|
#else
|
|
|
|
vsnprintf(str, maxlen, format, va);
|
|
|
|
#endif
|
|
|
|
va_end(va);
|
|
|
|
}
|
|
|
|
|
2016-05-11 04:48:08 +00:00
|
|
|
struct AppCallback;
|
|
|
|
|
|
|
|
struct EventCallback : boo::IWindowCallback
|
2016-05-09 07:22:58 +00:00
|
|
|
{
|
2016-05-11 04:48:08 +00:00
|
|
|
AppCallback& m_app;
|
2016-05-15 06:48:26 +00:00
|
|
|
bool m_tracking = false;
|
2016-07-14 04:54:46 +00:00
|
|
|
|
2016-05-11 04:48:08 +00:00
|
|
|
public:
|
|
|
|
void charKeyDown(unsigned long charCode, boo::EModifierKey mods, bool isRepeat);
|
|
|
|
void charKeyUp(unsigned long charCode, boo::EModifierKey mods);
|
|
|
|
void specialKeyDown(boo::ESpecialKey key, boo::EModifierKey mods, bool isRepeat);
|
|
|
|
void specialKeyUp(boo::ESpecialKey key, boo::EModifierKey mods);
|
2018-05-25 06:37:27 +00:00
|
|
|
void resized(const boo::SWindowRect&, bool) {}
|
2016-05-11 04:48:08 +00:00
|
|
|
|
2016-05-16 22:21:37 +00:00
|
|
|
void mouseDown(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey);
|
2016-05-16 20:20:29 +00:00
|
|
|
void mouseUp(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey);
|
2016-05-15 06:48:26 +00:00
|
|
|
void mouseMove(const boo::SWindowCoord& coord);
|
|
|
|
|
2016-05-11 04:48:08 +00:00
|
|
|
EventCallback(AppCallback& app) : m_app(app) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct AppCallback : boo::IApplicationCallback
|
|
|
|
{
|
|
|
|
int m_argc;
|
|
|
|
const boo::SystemChar** m_argv;
|
|
|
|
|
|
|
|
/* Boo window and events */
|
|
|
|
EventCallback m_eventRec;
|
|
|
|
boo::DeferredWindowEvents<EventCallback> m_events;
|
2017-07-17 02:55:14 +00:00
|
|
|
std::shared_ptr<boo::IWindow> m_win;
|
2016-05-11 04:48:08 +00:00
|
|
|
|
|
|
|
/* Amuse engine */
|
2017-12-07 04:34:45 +00:00
|
|
|
std::unique_ptr<amuse::BooBackendVoiceAllocator> m_booBackend;
|
|
|
|
std::unique_ptr<amuse::Engine> m_engine;
|
2016-05-19 02:19:43 +00:00
|
|
|
int m_groupId = -1;
|
2016-05-11 04:48:08 +00:00
|
|
|
bool m_sfxGroup;
|
|
|
|
|
|
|
|
/* Song playback selection */
|
|
|
|
int m_setupId = -1;
|
2016-05-15 21:56:23 +00:00
|
|
|
int m_chanId = 0;
|
2016-05-15 06:48:26 +00:00
|
|
|
int8_t m_octave = 4;
|
|
|
|
int8_t m_velocity = 64;
|
2018-07-29 03:37:06 +00:00
|
|
|
amuse::ObjToken<amuse::Sequencer> m_seq;
|
2016-05-30 22:46:43 +00:00
|
|
|
amuse::ContainerRegistry::SongData* m_arrData = nullptr;
|
2016-05-11 04:48:08 +00:00
|
|
|
|
|
|
|
/* SFX playback selection */
|
|
|
|
int m_sfxId = -1;
|
2018-07-29 03:37:06 +00:00
|
|
|
amuse::ObjToken<amuse::Voice> m_vox;
|
2016-05-15 06:48:26 +00:00
|
|
|
size_t m_lastVoxCount = 0;
|
2016-05-20 22:56:25 +00:00
|
|
|
int8_t m_lastChanProg = -1;
|
2016-05-11 04:48:08 +00:00
|
|
|
|
|
|
|
/* Control state */
|
2016-07-04 03:35:37 +00:00
|
|
|
float m_volume = 0.8f;
|
2016-05-15 06:48:26 +00:00
|
|
|
float m_modulation = 0.f;
|
|
|
|
float m_pitchBend = 0.f;
|
2016-05-14 04:46:39 +00:00
|
|
|
bool m_updateDisp = false;
|
2016-05-11 04:48:08 +00:00
|
|
|
bool m_running = true;
|
|
|
|
bool m_wantsNext = false;
|
|
|
|
bool m_wantsPrev = false;
|
2016-05-31 10:16:52 +00:00
|
|
|
bool m_breakout = false;
|
2016-05-16 20:20:29 +00:00
|
|
|
int m_panicCount = 0;
|
2016-05-10 02:31:05 +00:00
|
|
|
|
2017-09-20 09:22:46 +00:00
|
|
|
#if EMITTER_TEST
|
|
|
|
amuse::Vector3f m_pos = {};
|
|
|
|
amuse::Vector3f m_dir = {0.f, 0.f, 0.f};
|
|
|
|
amuse::Vector3f m_listenerDir = {0.f, 40.f, 0.f};
|
|
|
|
std::shared_ptr<amuse::Emitter> m_emitter;
|
|
|
|
std::shared_ptr<amuse::Listener> m_listener;
|
|
|
|
#endif
|
|
|
|
|
2016-05-15 06:48:26 +00:00
|
|
|
void UpdateSongDisplay()
|
|
|
|
{
|
|
|
|
size_t voxCount = 0;
|
2016-05-16 20:20:29 +00:00
|
|
|
int program = 0;
|
2016-05-15 06:48:26 +00:00
|
|
|
if (m_seq)
|
2016-05-16 20:20:29 +00:00
|
|
|
{
|
2016-05-15 06:48:26 +00:00
|
|
|
voxCount = m_seq->getVoiceCount();
|
2016-05-16 20:20:29 +00:00
|
|
|
program = m_seq->getChanProgram(m_chanId);
|
|
|
|
}
|
2016-07-14 04:54:46 +00:00
|
|
|
printf(
|
|
|
|
"\r "
|
|
|
|
"\r %" PRISize " Setup %d, Chan %d, Prog %d, Octave: %d, Vel: %d, VOL: %d%%\r",
|
|
|
|
voxCount, m_setupId, m_chanId, program, m_octave, m_velocity, int(std::rint(m_volume * 100)));
|
2016-05-15 06:48:26 +00:00
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SelectSong(int setupId)
|
|
|
|
{
|
|
|
|
m_setupId = setupId;
|
|
|
|
if (m_seq)
|
2016-05-19 10:12:32 +00:00
|
|
|
{
|
2017-02-27 05:24:58 +00:00
|
|
|
m_seq->stopSong(0.f, true);
|
2016-05-19 10:12:32 +00:00
|
|
|
m_seq->kill();
|
|
|
|
}
|
2016-05-15 06:48:26 +00:00
|
|
|
m_seq = m_engine->seqPlay(m_groupId, setupId, nullptr);
|
2016-07-14 06:16:00 +00:00
|
|
|
m_engine->setVolume(m_volume);
|
2016-05-19 02:19:43 +00:00
|
|
|
|
|
|
|
if (m_arrData)
|
2016-05-30 22:46:43 +00:00
|
|
|
m_seq->playSong(m_arrData->m_data.get(), false);
|
2016-05-19 02:19:43 +00:00
|
|
|
|
2016-05-15 06:48:26 +00:00
|
|
|
UpdateSongDisplay();
|
|
|
|
}
|
|
|
|
|
2017-02-15 06:01:39 +00:00
|
|
|
void SongLoop(const amuse::SongGroupIndex& index, boo::IAudioVoiceEngine& booEngine)
|
2016-05-10 05:32:31 +00:00
|
|
|
{
|
2016-07-14 04:54:46 +00:00
|
|
|
printf(
|
|
|
|
"░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░\n"
|
|
|
|
"░░░ ████ ████ ┃ ████ ████ ████ ┃ ████ ████ ░░░\n"
|
|
|
|
"░░░ ████ ████ ┃ ████ ████ ████ ┃ ████ ████ ░░░\n"
|
|
|
|
"░░░ ▌W▐█ ▌E▐█ ┃ ▌T▐█ ▌Y▐█ ▌U▐█ ┃ ▌O▐█ ▌P▐█ ░░░\n"
|
|
|
|
"░░░ │ │ ┃ │ │ │ ┃ │ │ ░░░\n"
|
|
|
|
"░░░ A │ S │ D ┃ F │ G │ H │ J ┃ K │ L │ ; ░░░\n"
|
|
|
|
"░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░\n"
|
|
|
|
"<left/right>: cycle MIDI setup, <up/down>: volume, <space>: PANIC\n"
|
|
|
|
"<tab>: sustain pedal, <window-Y>: pitch wheel, <window-X>: mod wheel\n"
|
|
|
|
"<Z/X>: octave, <C/V>: velocity, <B/N>: channel, <,/.>: program, <Q>: quit\n");
|
|
|
|
|
2018-07-20 16:49:24 +00:00
|
|
|
std::map<amuse::SongId, std::array<amuse::SongGroupIndex::MIDISetup, 16>> sortEntries(index.m_midiSetups.cbegin(),
|
|
|
|
index.m_midiSetups.cend());
|
2016-05-11 04:48:08 +00:00
|
|
|
auto setupIt = sortEntries.cbegin();
|
|
|
|
if (setupIt != sortEntries.cend())
|
2016-05-19 02:19:43 +00:00
|
|
|
{
|
|
|
|
if (m_setupId == -1)
|
|
|
|
SelectSong(setupIt->first);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while (setupIt != sortEntries.cend() && setupIt->first != m_setupId)
|
|
|
|
++setupIt;
|
|
|
|
if (setupIt == sortEntries.cend())
|
|
|
|
setupIt = sortEntries.cbegin();
|
|
|
|
SelectSong(setupIt->first);
|
|
|
|
}
|
|
|
|
}
|
2016-05-11 04:48:08 +00:00
|
|
|
|
|
|
|
while (m_running)
|
2016-05-10 05:32:31 +00:00
|
|
|
{
|
2016-05-11 04:48:08 +00:00
|
|
|
m_events.dispatchEvents();
|
|
|
|
|
|
|
|
if (m_wantsNext)
|
|
|
|
{
|
|
|
|
m_wantsNext = false;
|
2016-05-15 06:48:26 +00:00
|
|
|
auto nextIt = setupIt;
|
|
|
|
++nextIt;
|
|
|
|
if (nextIt != sortEntries.cend())
|
|
|
|
{
|
|
|
|
++setupIt;
|
|
|
|
SelectSong(setupIt->first);
|
|
|
|
m_updateDisp = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_wantsPrev)
|
|
|
|
{
|
|
|
|
m_wantsPrev = false;
|
|
|
|
if (setupIt != sortEntries.cbegin())
|
|
|
|
{
|
|
|
|
--setupIt;
|
|
|
|
SelectSong(setupIt->first);
|
|
|
|
m_updateDisp = false;
|
|
|
|
}
|
|
|
|
}
|
2016-05-11 04:48:08 +00:00
|
|
|
|
2016-05-16 20:20:29 +00:00
|
|
|
if (m_seq && m_panicCount)
|
|
|
|
{
|
|
|
|
if (m_panicCount > 1)
|
|
|
|
{
|
|
|
|
m_seq->allOff(true);
|
|
|
|
m_panicCount = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
m_seq->allOff(false);
|
|
|
|
m_updateDisp = true;
|
|
|
|
}
|
|
|
|
|
2016-05-15 06:48:26 +00:00
|
|
|
if (m_updateDisp)
|
|
|
|
{
|
|
|
|
m_updateDisp = false;
|
|
|
|
UpdateSongDisplay();
|
2016-05-11 04:48:08 +00:00
|
|
|
}
|
|
|
|
|
2017-02-15 06:01:39 +00:00
|
|
|
m_win->waitForRetrace(&booEngine);
|
2016-05-15 06:48:26 +00:00
|
|
|
|
2016-05-15 21:56:23 +00:00
|
|
|
size_t voxCount;
|
2016-05-20 22:56:25 +00:00
|
|
|
int8_t progId;
|
2016-05-15 21:56:23 +00:00
|
|
|
if (m_seq)
|
2016-05-20 22:56:25 +00:00
|
|
|
{
|
2016-05-15 21:56:23 +00:00
|
|
|
voxCount = m_seq->getVoiceCount();
|
2016-05-20 22:56:25 +00:00
|
|
|
progId = m_seq->getChanProgram(m_chanId);
|
|
|
|
}
|
2016-05-15 21:56:23 +00:00
|
|
|
else
|
2016-05-20 22:56:25 +00:00
|
|
|
{
|
2016-05-15 21:56:23 +00:00
|
|
|
voxCount = 0;
|
2016-05-20 22:56:25 +00:00
|
|
|
progId = -1;
|
|
|
|
}
|
2016-05-15 21:56:23 +00:00
|
|
|
|
2016-05-20 22:56:25 +00:00
|
|
|
if (m_lastVoxCount != voxCount || m_lastChanProg != progId)
|
2016-05-15 06:48:26 +00:00
|
|
|
{
|
|
|
|
m_lastVoxCount = voxCount;
|
2016-05-20 22:56:25 +00:00
|
|
|
m_lastChanProg = progId;
|
2016-05-15 06:48:26 +00:00
|
|
|
UpdateSongDisplay();
|
|
|
|
}
|
|
|
|
|
2016-05-31 10:16:52 +00:00
|
|
|
if (m_breakout)
|
|
|
|
{
|
|
|
|
m_breakout = false;
|
|
|
|
m_seq->allOff(true);
|
|
|
|
m_seq.reset();
|
|
|
|
break;
|
|
|
|
}
|
2016-05-10 05:32:31 +00:00
|
|
|
}
|
2016-05-11 04:48:08 +00:00
|
|
|
}
|
2016-05-10 05:32:31 +00:00
|
|
|
|
2016-05-14 04:46:39 +00:00
|
|
|
void UpdateSFXDisplay()
|
|
|
|
{
|
|
|
|
bool playing = m_vox && m_vox->state() == amuse::VoiceState::Playing;
|
2017-09-20 09:22:46 +00:00
|
|
|
#if EMITTER_TEST
|
|
|
|
printf(
|
|
|
|
"\r "
|
|
|
|
"\r %c SFX %d, VOL: %d%% POS: (%f,%f)\r",
|
|
|
|
playing ? '>' : ' ', m_sfxId, int(std::rint(m_volume * 100)), m_pos[0], m_pos[1]);
|
|
|
|
#else
|
2016-07-14 04:54:46 +00:00
|
|
|
printf(
|
|
|
|
"\r "
|
|
|
|
"\r %c SFX %d, VOL: %d%%\r",
|
|
|
|
playing ? '>' : ' ', m_sfxId, int(std::rint(m_volume * 100)));
|
2017-09-20 09:22:46 +00:00
|
|
|
#endif
|
2016-05-14 04:46:39 +00:00
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SelectSFX(int sfxId)
|
|
|
|
{
|
|
|
|
m_sfxId = sfxId;
|
2016-05-17 00:55:58 +00:00
|
|
|
|
|
|
|
bool playing = m_vox && m_vox->state() == amuse::VoiceState::Playing;
|
|
|
|
if (playing)
|
|
|
|
{
|
2017-09-20 09:22:46 +00:00
|
|
|
#if EMITTER_TEST
|
|
|
|
if (m_emitter)
|
|
|
|
m_emitter->getVoice()->keyOff();
|
|
|
|
m_emitter = m_engine->addEmitter(m_pos, m_dir, 100.f, 0.f, m_sfxId, 0.f, 1.f, true);
|
|
|
|
m_vox = m_emitter->getVoice();
|
|
|
|
#else
|
2016-05-17 00:55:58 +00:00
|
|
|
m_vox->keyOff();
|
|
|
|
m_vox = m_engine->fxStart(m_sfxId, m_volume, 0.f);
|
2017-09-20 09:22:46 +00:00
|
|
|
#endif
|
2016-05-17 00:55:58 +00:00
|
|
|
}
|
|
|
|
|
2016-05-14 04:46:39 +00:00
|
|
|
UpdateSFXDisplay();
|
|
|
|
}
|
|
|
|
|
2017-02-15 06:01:39 +00:00
|
|
|
void SFXLoop(const amuse::SFXGroupIndex& index, boo::IAudioVoiceEngine& booEngine)
|
2016-05-11 04:48:08 +00:00
|
|
|
{
|
2016-05-14 22:38:37 +00:00
|
|
|
printf("<space>: keyon/keyoff, <left/right>: cycle SFX, <up/down>: volume, <Q>: quit\n");
|
2016-05-10 05:32:31 +00:00
|
|
|
|
2016-10-09 01:39:04 +00:00
|
|
|
m_seq = m_engine->seqPlay(m_groupId, 0, nullptr);
|
|
|
|
|
2018-07-20 16:49:24 +00:00
|
|
|
std::map<amuse::SFXId, amuse::SFXGroupIndex::SFXEntry> sortEntries(index.m_sfxEntries.cbegin(),
|
|
|
|
index.m_sfxEntries.cend());
|
2016-05-11 04:48:08 +00:00
|
|
|
auto sfxIt = sortEntries.cbegin();
|
|
|
|
if (sfxIt != sortEntries.cend())
|
2016-05-14 04:46:39 +00:00
|
|
|
SelectSFX(sfxIt->first);
|
2016-05-11 04:48:08 +00:00
|
|
|
|
2017-09-20 09:22:46 +00:00
|
|
|
#if EMITTER_TEST
|
|
|
|
float emitterTheta = 0.f;
|
|
|
|
float zeroVec[3] = {};
|
|
|
|
float heading[3] = {0.f, 1.f, 0.f};
|
|
|
|
float up[3] = {0.f, 0.f, 1.f};
|
|
|
|
m_listener = m_engine->addListener(zeroVec, m_listenerDir, heading, up, 5.f, 5.f, 1000.f, 1.f);
|
|
|
|
#endif
|
|
|
|
|
2016-05-11 04:48:08 +00:00
|
|
|
while (m_running)
|
2016-05-10 05:32:31 +00:00
|
|
|
{
|
2017-09-20 09:22:46 +00:00
|
|
|
#if EMITTER_TEST
|
|
|
|
//float dist = std::sin(emitterTheta * 0.25f);
|
|
|
|
m_pos[0] = std::cos(emitterTheta) * 5.f;
|
|
|
|
m_pos[1] = std::sin(emitterTheta) * 5.f;
|
|
|
|
if (m_emitter)
|
|
|
|
m_emitter->setVectors(m_pos, m_dir);
|
|
|
|
emitterTheta += 1.f / 60.f;
|
|
|
|
m_updateDisp = true;
|
|
|
|
#endif
|
|
|
|
|
2016-05-11 04:48:08 +00:00
|
|
|
m_events.dispatchEvents();
|
2016-05-14 04:46:39 +00:00
|
|
|
|
|
|
|
if (m_wantsNext)
|
|
|
|
{
|
|
|
|
m_wantsNext = false;
|
|
|
|
auto nextIt = sfxIt;
|
|
|
|
++nextIt;
|
|
|
|
if (nextIt != sortEntries.cend())
|
|
|
|
{
|
|
|
|
++sfxIt;
|
|
|
|
SelectSFX(sfxIt->first);
|
|
|
|
m_updateDisp = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_wantsPrev)
|
|
|
|
{
|
|
|
|
m_wantsPrev = false;
|
|
|
|
if (sfxIt != sortEntries.cbegin())
|
|
|
|
{
|
|
|
|
--sfxIt;
|
|
|
|
SelectSFX(sfxIt->first);
|
|
|
|
m_updateDisp = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_updateDisp)
|
|
|
|
{
|
|
|
|
m_updateDisp = false;
|
|
|
|
UpdateSFXDisplay();
|
|
|
|
}
|
|
|
|
|
2017-02-15 06:01:39 +00:00
|
|
|
m_win->waitForRetrace(&booEngine);
|
2016-05-14 22:38:37 +00:00
|
|
|
|
|
|
|
if (m_vox && m_vox->state() == amuse::VoiceState::Dead)
|
|
|
|
{
|
|
|
|
m_vox.reset();
|
2017-09-20 09:22:46 +00:00
|
|
|
#if EMITTER_TEST
|
|
|
|
m_emitter.reset();
|
|
|
|
#endif
|
2016-05-14 22:38:37 +00:00
|
|
|
UpdateSFXDisplay();
|
|
|
|
}
|
|
|
|
|
2016-05-31 10:16:52 +00:00
|
|
|
if (m_breakout)
|
|
|
|
{
|
|
|
|
m_breakout = false;
|
|
|
|
m_vox.reset();
|
2017-09-20 09:22:46 +00:00
|
|
|
#if EMITTER_TEST
|
|
|
|
m_emitter.reset();
|
|
|
|
#endif
|
2016-10-09 01:39:04 +00:00
|
|
|
m_seq->allOff(true);
|
|
|
|
m_seq.reset();
|
2016-05-31 10:16:52 +00:00
|
|
|
break;
|
|
|
|
}
|
2016-05-10 05:32:31 +00:00
|
|
|
}
|
2017-09-20 09:22:46 +00:00
|
|
|
|
|
|
|
#if EMITTER_TEST
|
|
|
|
m_engine->removeListener(m_listener.get());
|
|
|
|
m_listener.reset();
|
|
|
|
#endif
|
2016-05-10 05:32:31 +00:00
|
|
|
}
|
2016-05-11 04:48:08 +00:00
|
|
|
|
2016-05-16 02:40:18 +00:00
|
|
|
void charKeyDownRepeat(unsigned long charCode)
|
|
|
|
{
|
2016-05-16 20:20:29 +00:00
|
|
|
charCode = tolower(charCode);
|
|
|
|
|
2016-05-16 02:40:18 +00:00
|
|
|
if (m_seq && m_chanId != -1)
|
|
|
|
{
|
|
|
|
switch (charCode)
|
|
|
|
{
|
|
|
|
case 'z':
|
|
|
|
m_octave = amuse::clamp(-1, m_octave - 1, 8);
|
|
|
|
m_updateDisp = true;
|
|
|
|
break;
|
|
|
|
case 'x':
|
|
|
|
m_octave = amuse::clamp(-1, m_octave + 1, 8);
|
|
|
|
m_updateDisp = true;
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
m_velocity = amuse::clamp(0, m_velocity - 1, 127);
|
|
|
|
m_updateDisp = true;
|
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
m_velocity = amuse::clamp(0, m_velocity + 1, 127);
|
|
|
|
m_updateDisp = true;
|
|
|
|
break;
|
2016-05-16 20:20:29 +00:00
|
|
|
case 'b':
|
|
|
|
m_chanId = amuse::clamp(0, m_chanId - 1, 15);
|
|
|
|
m_updateDisp = true;
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
m_chanId = amuse::clamp(0, m_chanId + 1, 15);
|
|
|
|
m_updateDisp = true;
|
|
|
|
break;
|
|
|
|
case ',':
|
|
|
|
m_seq->prevChanProgram(m_chanId);
|
|
|
|
m_updateDisp = true;
|
|
|
|
break;
|
|
|
|
case '.':
|
|
|
|
m_seq->nextChanProgram(m_chanId);
|
|
|
|
m_updateDisp = true;
|
|
|
|
break;
|
2016-07-14 04:54:46 +00:00
|
|
|
default:
|
|
|
|
break;
|
2016-05-16 02:40:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-11 04:48:08 +00:00
|
|
|
void charKeyDown(unsigned long charCode)
|
2016-05-10 05:32:31 +00:00
|
|
|
{
|
2016-05-15 06:48:26 +00:00
|
|
|
charCode = tolower(charCode);
|
|
|
|
if (charCode == 'q')
|
2016-05-14 04:46:39 +00:00
|
|
|
{
|
|
|
|
m_running = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-05-11 04:48:08 +00:00
|
|
|
if (m_sfxGroup)
|
2016-05-10 05:32:31 +00:00
|
|
|
{
|
2016-05-11 04:48:08 +00:00
|
|
|
switch (charCode)
|
|
|
|
{
|
|
|
|
case ' ':
|
2016-10-09 01:39:04 +00:00
|
|
|
if (m_seq)
|
|
|
|
m_seq->allOff(true);
|
2016-05-11 04:48:08 +00:00
|
|
|
if (m_vox && m_vox->state() == amuse::VoiceState::Playing)
|
|
|
|
m_vox->keyOff();
|
|
|
|
else if (m_sfxId != -1)
|
2017-09-20 09:22:46 +00:00
|
|
|
{
|
|
|
|
#if EMITTER_TEST
|
|
|
|
m_emitter = m_engine->addEmitter(m_pos, m_dir, 100.f, 0.f, m_sfxId, 0.f, 1.f, true);
|
|
|
|
m_vox = m_emitter->getVoice();
|
|
|
|
#else
|
2016-05-14 04:46:39 +00:00
|
|
|
m_vox = m_engine->fxStart(m_sfxId, m_volume, 0.f);
|
2017-09-20 09:22:46 +00:00
|
|
|
#endif
|
|
|
|
}
|
2016-05-14 04:46:39 +00:00
|
|
|
m_updateDisp = true;
|
2016-07-14 04:54:46 +00:00
|
|
|
default:
|
|
|
|
break;
|
2016-05-11 04:48:08 +00:00
|
|
|
}
|
2016-05-10 05:32:31 +00:00
|
|
|
}
|
2016-05-15 06:48:26 +00:00
|
|
|
else if (m_seq && m_chanId != -1)
|
2016-05-10 05:32:31 +00:00
|
|
|
{
|
2016-05-16 20:20:29 +00:00
|
|
|
bool setPanic = false;
|
|
|
|
|
2016-05-15 06:48:26 +00:00
|
|
|
switch (charCode)
|
|
|
|
{
|
2016-05-16 20:20:29 +00:00
|
|
|
case ' ':
|
|
|
|
++m_panicCount;
|
|
|
|
setPanic = true;
|
|
|
|
break;
|
2016-05-15 06:48:26 +00:00
|
|
|
case 'z':
|
|
|
|
m_octave = amuse::clamp(-1, m_octave - 1, 8);
|
2016-05-16 02:40:18 +00:00
|
|
|
m_updateDisp = true;
|
2016-05-15 06:48:26 +00:00
|
|
|
break;
|
|
|
|
case 'x':
|
|
|
|
m_octave = amuse::clamp(-1, m_octave + 1, 8);
|
2016-05-16 02:40:18 +00:00
|
|
|
m_updateDisp = true;
|
2016-05-15 06:48:26 +00:00
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
m_velocity = amuse::clamp(0, m_velocity - 1, 127);
|
2016-05-16 02:40:18 +00:00
|
|
|
m_updateDisp = true;
|
2016-05-15 06:48:26 +00:00
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
m_velocity = amuse::clamp(0, m_velocity + 1, 127);
|
2016-05-16 02:40:18 +00:00
|
|
|
m_updateDisp = true;
|
2016-05-15 06:48:26 +00:00
|
|
|
break;
|
2016-05-16 20:20:29 +00:00
|
|
|
case 'b':
|
|
|
|
m_chanId = amuse::clamp(0, m_chanId - 1, 15);
|
|
|
|
m_updateDisp = true;
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
m_chanId = amuse::clamp(0, m_chanId + 1, 15);
|
|
|
|
m_updateDisp = true;
|
|
|
|
break;
|
|
|
|
case ',':
|
|
|
|
m_seq->prevChanProgram(m_chanId);
|
|
|
|
m_updateDisp = true;
|
|
|
|
break;
|
|
|
|
case '.':
|
|
|
|
m_seq->nextChanProgram(m_chanId);
|
|
|
|
m_updateDisp = true;
|
|
|
|
break;
|
2016-05-15 06:48:26 +00:00
|
|
|
case '\t':
|
|
|
|
m_seq->setCtrlValue(m_chanId, 64, 127);
|
|
|
|
break;
|
|
|
|
case 'a':
|
|
|
|
m_seq->keyOn(m_chanId, (m_octave + 1) * 12, m_velocity);
|
|
|
|
break;
|
|
|
|
case 'w':
|
|
|
|
m_seq->keyOn(m_chanId, (m_octave + 1) * 12 + 1, m_velocity);
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
m_seq->keyOn(m_chanId, (m_octave + 1) * 12 + 2, m_velocity);
|
|
|
|
break;
|
|
|
|
case 'e':
|
|
|
|
m_seq->keyOn(m_chanId, (m_octave + 1) * 12 + 3, m_velocity);
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
m_seq->keyOn(m_chanId, (m_octave + 1) * 12 + 4, m_velocity);
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
m_seq->keyOn(m_chanId, (m_octave + 1) * 12 + 5, m_velocity);
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
m_seq->keyOn(m_chanId, (m_octave + 1) * 12 + 6, m_velocity);
|
|
|
|
break;
|
|
|
|
case 'g':
|
|
|
|
m_seq->keyOn(m_chanId, (m_octave + 1) * 12 + 7, m_velocity);
|
|
|
|
break;
|
|
|
|
case 'y':
|
|
|
|
m_seq->keyOn(m_chanId, (m_octave + 1) * 12 + 8, m_velocity);
|
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
m_seq->keyOn(m_chanId, (m_octave + 1) * 12 + 9, m_velocity);
|
|
|
|
break;
|
|
|
|
case 'u':
|
|
|
|
m_seq->keyOn(m_chanId, (m_octave + 1) * 12 + 10, m_velocity);
|
|
|
|
break;
|
|
|
|
case 'j':
|
|
|
|
m_seq->keyOn(m_chanId, (m_octave + 1) * 12 + 11, m_velocity);
|
|
|
|
break;
|
|
|
|
case 'k':
|
|
|
|
m_seq->keyOn(m_chanId, (m_octave + 1) * 12 + 12, m_velocity);
|
|
|
|
break;
|
|
|
|
case 'o':
|
|
|
|
m_seq->keyOn(m_chanId, (m_octave + 1) * 12 + 13, m_velocity);
|
|
|
|
break;
|
|
|
|
case 'l':
|
|
|
|
m_seq->keyOn(m_chanId, (m_octave + 1) * 12 + 14, m_velocity);
|
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
m_seq->keyOn(m_chanId, (m_octave + 1) * 12 + 15, m_velocity);
|
|
|
|
break;
|
|
|
|
case ';':
|
|
|
|
case ':':
|
|
|
|
m_seq->keyOn(m_chanId, (m_octave + 1) * 12 + 16, m_velocity);
|
|
|
|
break;
|
2016-07-14 04:54:46 +00:00
|
|
|
default:
|
|
|
|
break;
|
2016-05-15 06:48:26 +00:00
|
|
|
}
|
2016-05-16 20:20:29 +00:00
|
|
|
|
|
|
|
if (!setPanic)
|
|
|
|
m_panicCount = 0;
|
2016-05-10 05:32:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-11 04:48:08 +00:00
|
|
|
void charKeyUp(unsigned long charCode)
|
|
|
|
{
|
2016-05-15 06:48:26 +00:00
|
|
|
charCode = tolower(charCode);
|
|
|
|
|
|
|
|
if (!m_sfxGroup && m_chanId != -1)
|
|
|
|
{
|
|
|
|
switch (charCode)
|
|
|
|
{
|
|
|
|
case '\t':
|
|
|
|
m_seq->setCtrlValue(m_chanId, 64, 0);
|
|
|
|
break;
|
|
|
|
case 'a':
|
|
|
|
m_seq->keyOff(m_chanId, (m_octave + 1) * 12, m_velocity);
|
|
|
|
break;
|
|
|
|
case 'w':
|
|
|
|
m_seq->keyOff(m_chanId, (m_octave + 1) * 12 + 1, m_velocity);
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
m_seq->keyOff(m_chanId, (m_octave + 1) * 12 + 2, m_velocity);
|
|
|
|
break;
|
|
|
|
case 'e':
|
|
|
|
m_seq->keyOff(m_chanId, (m_octave + 1) * 12 + 3, m_velocity);
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
m_seq->keyOff(m_chanId, (m_octave + 1) * 12 + 4, m_velocity);
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
m_seq->keyOff(m_chanId, (m_octave + 1) * 12 + 5, m_velocity);
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
m_seq->keyOff(m_chanId, (m_octave + 1) * 12 + 6, m_velocity);
|
|
|
|
break;
|
|
|
|
case 'g':
|
|
|
|
m_seq->keyOff(m_chanId, (m_octave + 1) * 12 + 7, m_velocity);
|
|
|
|
break;
|
|
|
|
case 'y':
|
|
|
|
m_seq->keyOff(m_chanId, (m_octave + 1) * 12 + 8, m_velocity);
|
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
m_seq->keyOff(m_chanId, (m_octave + 1) * 12 + 9, m_velocity);
|
|
|
|
break;
|
|
|
|
case 'u':
|
|
|
|
m_seq->keyOff(m_chanId, (m_octave + 1) * 12 + 10, m_velocity);
|
|
|
|
break;
|
|
|
|
case 'j':
|
|
|
|
m_seq->keyOff(m_chanId, (m_octave + 1) * 12 + 11, m_velocity);
|
|
|
|
break;
|
|
|
|
case 'k':
|
|
|
|
m_seq->keyOff(m_chanId, (m_octave + 1) * 12 + 12, m_velocity);
|
|
|
|
break;
|
|
|
|
case 'o':
|
|
|
|
m_seq->keyOff(m_chanId, (m_octave + 1) * 12 + 13, m_velocity);
|
|
|
|
break;
|
|
|
|
case 'l':
|
|
|
|
m_seq->keyOff(m_chanId, (m_octave + 1) * 12 + 14, m_velocity);
|
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
m_seq->keyOff(m_chanId, (m_octave + 1) * 12 + 15, m_velocity);
|
|
|
|
break;
|
|
|
|
case ';':
|
|
|
|
case ':':
|
|
|
|
m_seq->keyOff(m_chanId, (m_octave + 1) * 12 + 16, m_velocity);
|
|
|
|
break;
|
2016-07-14 04:54:46 +00:00
|
|
|
default:
|
|
|
|
break;
|
2016-05-15 06:48:26 +00:00
|
|
|
}
|
|
|
|
}
|
2016-05-11 04:48:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int appMain(boo::IApplication* app)
|
|
|
|
{
|
|
|
|
/* Event window */
|
2018-01-07 09:27:58 +00:00
|
|
|
m_win = app->newWindow(_S("amuseplay"));
|
2016-05-11 04:48:08 +00:00
|
|
|
m_win->setCallback(&m_events);
|
2016-05-14 04:46:39 +00:00
|
|
|
m_win->setWindowFrame(100, 100, 100, 100);
|
|
|
|
m_win->setStyle(~boo::EWindowStyle::Resize);
|
2016-05-11 04:48:08 +00:00
|
|
|
m_win->showWindow();
|
2017-11-05 06:16:06 +00:00
|
|
|
boo::ObjToken<boo::ITextureR> tex;
|
2018-05-25 06:37:27 +00:00
|
|
|
m_win->getMainContextDataFactory()->commitTransaction([&](boo::IGraphicsDataFactory::Context& ctx) {
|
2018-05-06 22:47:03 +00:00
|
|
|
tex = ctx.newRenderTexture(100, 100, boo::TextureClampMode::Repeat, 1, 0);
|
2017-11-05 06:16:06 +00:00
|
|
|
return true;
|
2018-05-25 06:37:27 +00:00
|
|
|
} BooTrace);
|
2016-05-14 04:46:39 +00:00
|
|
|
boo::IGraphicsCommandQueue* q = m_win->getCommandQueue();
|
|
|
|
q->setRenderTarget(tex);
|
|
|
|
q->clearTarget();
|
|
|
|
q->resolveDisplay(tex);
|
|
|
|
q->execute();
|
2016-05-11 04:48:08 +00:00
|
|
|
|
|
|
|
/* Load data */
|
2016-05-27 05:30:43 +00:00
|
|
|
if (m_argc < 2)
|
2016-05-31 22:09:38 +00:00
|
|
|
{
|
|
|
|
Log.report(logvisor::Error, "needs group path argument");
|
2018-05-28 20:26:55 +00:00
|
|
|
return 1;
|
2016-05-31 22:09:38 +00:00
|
|
|
}
|
2016-05-11 04:48:08 +00:00
|
|
|
|
2016-06-13 05:47:07 +00:00
|
|
|
amuse::ContainerRegistry::Type cType = amuse::ContainerRegistry::DetectContainerType(m_argv[1]);
|
2016-05-27 05:30:43 +00:00
|
|
|
if (cType == amuse::ContainerRegistry::Type::Invalid)
|
2016-05-31 22:09:38 +00:00
|
|
|
{
|
|
|
|
Log.report(logvisor::Error, "invalid/no data at path argument");
|
2018-05-28 20:26:55 +00:00
|
|
|
return 1;
|
2016-05-31 22:09:38 +00:00
|
|
|
}
|
2016-06-13 05:47:07 +00:00
|
|
|
Log.report(logvisor::Info, _S("Found '%s' Audio Group data"), amuse::ContainerRegistry::TypeToName(cType));
|
2016-05-27 05:30:43 +00:00
|
|
|
|
2016-06-13 05:47:07 +00:00
|
|
|
std::vector<std::pair<amuse::SystemString, amuse::IntrusiveAudioGroupData>> data =
|
|
|
|
amuse::ContainerRegistry::LoadContainer(m_argv[1]);
|
2016-05-27 05:30:43 +00:00
|
|
|
if (data.empty())
|
2016-05-31 22:09:38 +00:00
|
|
|
{
|
|
|
|
Log.report(logvisor::Error, "invalid/no data at path argument");
|
2018-05-28 20:26:55 +00:00
|
|
|
return 1;
|
2016-05-31 22:09:38 +00:00
|
|
|
}
|
2016-05-27 05:30:43 +00:00
|
|
|
|
|
|
|
std::list<amuse::AudioGroupProject> m_projs;
|
2018-07-20 16:49:24 +00:00
|
|
|
std::map<amuse::GroupId, std::pair<std::pair<amuse::SystemString, amuse::IntrusiveAudioGroupData>*,
|
2018-07-29 03:37:06 +00:00
|
|
|
amuse::ObjToken<amuse::SongGroupIndex>>>
|
2016-07-14 04:54:46 +00:00
|
|
|
allSongGroups;
|
2018-07-20 16:49:24 +00:00
|
|
|
std::map<amuse::GroupId, std::pair<std::pair<amuse::SystemString, amuse::IntrusiveAudioGroupData>*,
|
2018-07-29 03:37:06 +00:00
|
|
|
amuse::ObjToken<amuse::SFXGroupIndex>>>
|
2016-07-14 04:54:46 +00:00
|
|
|
allSFXGroups;
|
2016-05-27 05:30:43 +00:00
|
|
|
size_t totalGroups = 0;
|
|
|
|
|
|
|
|
for (auto& grp : data)
|
2016-05-19 02:19:43 +00:00
|
|
|
{
|
2016-05-27 05:30:43 +00:00
|
|
|
/* Load project to assemble group list */
|
2016-05-28 02:28:59 +00:00
|
|
|
m_projs.push_back(amuse::AudioGroupProject::CreateAudioGroupProject(grp.second));
|
2016-05-27 05:30:43 +00:00
|
|
|
amuse::AudioGroupProject& proj = m_projs.back();
|
|
|
|
totalGroups += proj.sfxGroups().size() + proj.songGroups().size();
|
|
|
|
|
2016-07-14 04:54:46 +00:00
|
|
|
for (auto it = proj.songGroups().begin(); it != proj.songGroups().end(); ++it)
|
2018-07-29 03:37:06 +00:00
|
|
|
allSongGroups[it->first] = std::make_pair(&grp, it->second);
|
2016-05-19 02:19:43 +00:00
|
|
|
|
2016-07-14 04:54:46 +00:00
|
|
|
for (auto it = proj.sfxGroups().begin(); it != proj.sfxGroups().end(); ++it)
|
2018-07-29 03:37:06 +00:00
|
|
|
allSFXGroups[it->first] = std::make_pair(&grp, it->second);
|
2016-05-27 05:30:43 +00:00
|
|
|
}
|
2016-05-11 04:48:08 +00:00
|
|
|
|
2016-05-31 10:16:52 +00:00
|
|
|
while (m_running)
|
2016-05-19 02:19:43 +00:00
|
|
|
{
|
2016-05-31 10:16:52 +00:00
|
|
|
m_groupId = -1;
|
|
|
|
m_setupId = -1;
|
2016-05-30 22:46:43 +00:00
|
|
|
|
2016-05-31 10:16:52 +00:00
|
|
|
/* Attempt loading song */
|
2016-06-13 05:47:07 +00:00
|
|
|
std::vector<std::pair<amuse::SystemString, amuse::ContainerRegistry::SongData>> songs;
|
2016-05-31 10:16:52 +00:00
|
|
|
if (m_argc > 2)
|
2016-06-13 05:47:07 +00:00
|
|
|
songs = amuse::ContainerRegistry::LoadSongs(m_argv[2]);
|
2016-06-01 03:05:13 +00:00
|
|
|
else
|
2016-06-13 05:47:07 +00:00
|
|
|
songs = amuse::ContainerRegistry::LoadSongs(m_argv[1]);
|
2016-05-30 22:46:43 +00:00
|
|
|
|
2016-06-01 03:05:13 +00:00
|
|
|
if (songs.size())
|
|
|
|
{
|
|
|
|
bool play = true;
|
|
|
|
if (m_argc <= 2)
|
2016-05-31 10:16:52 +00:00
|
|
|
{
|
2016-06-01 03:05:13 +00:00
|
|
|
bool prompt = true;
|
|
|
|
while (true)
|
2016-05-31 10:16:52 +00:00
|
|
|
{
|
2016-06-01 03:05:13 +00:00
|
|
|
if (prompt)
|
|
|
|
{
|
|
|
|
printf("Play Song? (Y/N): ");
|
|
|
|
prompt = false;
|
|
|
|
}
|
|
|
|
char userSel;
|
|
|
|
if (scanf("%c", &userSel) <= 0 || userSel == '\n')
|
|
|
|
continue;
|
|
|
|
userSel = tolower(userSel);
|
|
|
|
if (userSel == 'n')
|
|
|
|
play = false;
|
|
|
|
else if (userSel != 'y')
|
|
|
|
{
|
|
|
|
prompt = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
2016-05-31 10:16:52 +00:00
|
|
|
}
|
2016-06-01 03:05:13 +00:00
|
|
|
}
|
2016-05-31 10:16:52 +00:00
|
|
|
|
2016-06-01 03:05:13 +00:00
|
|
|
if (play)
|
|
|
|
{
|
|
|
|
/* Get song selection from user */
|
|
|
|
if (songs.size() > 1)
|
2016-05-31 22:16:46 +00:00
|
|
|
{
|
2016-06-01 03:05:13 +00:00
|
|
|
/* Ask user to specify which song */
|
|
|
|
printf("Multiple Songs discovered:\n");
|
|
|
|
int idx = 0;
|
|
|
|
for (const auto& pair : songs)
|
|
|
|
{
|
2016-07-03 22:41:31 +00:00
|
|
|
const amuse::ContainerRegistry::SongData& sngData = pair.second;
|
|
|
|
int16_t grpId = sngData.m_groupId;
|
|
|
|
int16_t setupId = sngData.m_setupId;
|
|
|
|
if (sngData.m_groupId == -1 && sngData.m_setupId != -1)
|
|
|
|
{
|
|
|
|
for (const auto& pair : allSongGroups)
|
|
|
|
{
|
|
|
|
for (const auto& setup : pair.second.second->m_midiSetups)
|
|
|
|
{
|
|
|
|
if (setup.first == sngData.m_setupId)
|
|
|
|
{
|
|
|
|
grpId = pair.first;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (grpId != -1)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-07-14 04:54:46 +00:00
|
|
|
amuse::Printf(_S(" %d %s (Group %d, Setup %d)\n"), idx++, pair.first.c_str(), grpId,
|
|
|
|
setupId);
|
2016-06-01 03:05:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int userSel = 0;
|
|
|
|
printf("Enter Song Number: ");
|
|
|
|
if (scanf("%d", &userSel) <= 0)
|
|
|
|
{
|
|
|
|
Log.report(logvisor::Error, "unable to parse prompt");
|
2018-05-28 20:26:55 +00:00
|
|
|
return 1;
|
2016-06-01 03:05:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (userSel < songs.size())
|
|
|
|
{
|
|
|
|
m_arrData = &songs[userSel].second;
|
|
|
|
m_groupId = m_arrData->m_groupId;
|
|
|
|
m_setupId = m_arrData->m_setupId;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Log.report(logvisor::Error, "unable to find Song %d", userSel);
|
2018-05-28 20:26:55 +00:00
|
|
|
return 1;
|
2016-06-01 03:05:13 +00:00
|
|
|
}
|
2016-05-31 22:16:46 +00:00
|
|
|
}
|
2016-06-01 03:05:13 +00:00
|
|
|
else if (songs.size() == 1)
|
2016-05-31 10:16:52 +00:00
|
|
|
{
|
2016-06-01 03:05:13 +00:00
|
|
|
m_arrData = &songs[0].second;
|
2016-05-31 10:16:52 +00:00
|
|
|
m_groupId = m_arrData->m_groupId;
|
|
|
|
m_setupId = m_arrData->m_setupId;
|
|
|
|
}
|
2016-05-30 22:46:43 +00:00
|
|
|
}
|
2016-05-31 22:09:38 +00:00
|
|
|
}
|
2016-05-30 22:46:43 +00:00
|
|
|
|
2016-07-03 22:41:31 +00:00
|
|
|
/* Get group selection via setup search */
|
|
|
|
if (m_groupId == -1 && m_setupId != -1)
|
|
|
|
{
|
|
|
|
for (const auto& pair : allSongGroups)
|
|
|
|
{
|
|
|
|
for (const auto& setup : pair.second.second->m_midiSetups)
|
|
|
|
{
|
|
|
|
if (setup.first == m_setupId)
|
|
|
|
{
|
|
|
|
m_groupId = pair.first;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (m_groupId != -1)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get group selection via user */
|
2016-05-31 10:16:52 +00:00
|
|
|
if (m_groupId != -1)
|
2016-05-11 04:48:08 +00:00
|
|
|
{
|
2016-05-31 10:16:52 +00:00
|
|
|
if (allSongGroups.find(m_groupId) != allSongGroups.end())
|
|
|
|
m_sfxGroup = false;
|
|
|
|
else if (allSFXGroups.find(m_groupId) != allSFXGroups.end())
|
|
|
|
m_sfxGroup = true;
|
|
|
|
else
|
2016-05-31 22:16:46 +00:00
|
|
|
{
|
|
|
|
Log.report(logvisor::Error, "unable to find Group %d", m_groupId);
|
2018-05-28 20:26:55 +00:00
|
|
|
return 1;
|
2016-05-31 22:16:46 +00:00
|
|
|
}
|
2016-05-11 04:48:08 +00:00
|
|
|
}
|
2016-05-31 10:16:52 +00:00
|
|
|
else if (totalGroups > 1)
|
2016-05-11 04:48:08 +00:00
|
|
|
{
|
2016-05-31 10:16:52 +00:00
|
|
|
/* Ask user to specify which group in project */
|
|
|
|
printf("Multiple Audio Groups discovered:\n");
|
|
|
|
for (const auto& pair : allSFXGroups)
|
|
|
|
{
|
2018-07-29 03:37:06 +00:00
|
|
|
amuse::Printf(_S(" %d %s (SFXGroup) %" PRISize " sfx-entries\n"), pair.first.id,
|
2016-07-14 04:54:46 +00:00
|
|
|
pair.second.first->first.c_str(), pair.second.second->m_sfxEntries.size());
|
2016-05-31 10:16:52 +00:00
|
|
|
}
|
|
|
|
for (const auto& pair : allSongGroups)
|
|
|
|
{
|
2016-07-14 04:54:46 +00:00
|
|
|
amuse::Printf(_S(" %d %s (SongGroup) %" PRISize " normal-pages, %" PRISize
|
|
|
|
" drum-pages, %" PRISize " MIDI-setups\n"),
|
2018-07-29 03:37:06 +00:00
|
|
|
pair.first.id, pair.second.first->first.c_str(), pair.second.second->m_normPages.size(),
|
2016-07-14 04:54:46 +00:00
|
|
|
pair.second.second->m_drumPages.size(), pair.second.second->m_midiSetups.size());
|
2016-05-31 10:16:52 +00:00
|
|
|
}
|
2016-05-11 04:48:08 +00:00
|
|
|
|
2016-05-31 10:16:52 +00:00
|
|
|
int userSel = 0;
|
|
|
|
printf("Enter Group Number: ");
|
|
|
|
if (scanf("%d", &userSel) <= 0)
|
2016-05-31 22:16:46 +00:00
|
|
|
{
|
|
|
|
Log.report(logvisor::Error, "unable to parse prompt");
|
2018-05-28 20:26:55 +00:00
|
|
|
return 1;
|
2016-05-31 22:16:46 +00:00
|
|
|
}
|
2016-05-09 07:22:58 +00:00
|
|
|
|
2016-05-31 10:16:52 +00:00
|
|
|
if (allSongGroups.find(userSel) != allSongGroups.end())
|
|
|
|
{
|
|
|
|
m_groupId = userSel;
|
|
|
|
m_sfxGroup = false;
|
|
|
|
}
|
|
|
|
else if (allSFXGroups.find(userSel) != allSFXGroups.end())
|
|
|
|
{
|
|
|
|
m_groupId = userSel;
|
|
|
|
m_sfxGroup = true;
|
|
|
|
}
|
|
|
|
else
|
2016-05-31 22:16:46 +00:00
|
|
|
{
|
|
|
|
Log.report(logvisor::Error, "unable to find Group %d", userSel);
|
2018-05-28 20:26:55 +00:00
|
|
|
return 1;
|
2016-05-31 22:16:46 +00:00
|
|
|
}
|
2016-05-11 04:48:08 +00:00
|
|
|
}
|
2016-05-31 10:16:52 +00:00
|
|
|
else if (totalGroups == 1)
|
2016-05-11 04:48:08 +00:00
|
|
|
{
|
2016-05-31 10:16:52 +00:00
|
|
|
/* Load one and only group */
|
|
|
|
if (allSongGroups.size())
|
|
|
|
{
|
|
|
|
const auto& pair = *allSongGroups.cbegin();
|
|
|
|
m_groupId = pair.first;
|
|
|
|
m_sfxGroup = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const auto& pair = *allSFXGroups.cbegin();
|
|
|
|
m_groupId = pair.first;
|
|
|
|
m_sfxGroup = true;
|
|
|
|
}
|
2016-05-11 04:48:08 +00:00
|
|
|
}
|
|
|
|
else
|
2016-05-31 22:09:38 +00:00
|
|
|
{
|
2016-05-31 22:16:46 +00:00
|
|
|
Log.report(logvisor::Error, "empty project");
|
2018-05-28 20:26:55 +00:00
|
|
|
return 1;
|
2016-05-31 22:09:38 +00:00
|
|
|
}
|
2016-05-31 10:16:52 +00:00
|
|
|
|
|
|
|
/* Make final group selection */
|
|
|
|
amuse::IntrusiveAudioGroupData* selData = nullptr;
|
2018-07-29 03:37:06 +00:00
|
|
|
amuse::ObjToken<amuse::SongGroupIndex> songIndex;
|
|
|
|
amuse::ObjToken<amuse::SFXGroupIndex> sfxIndex;
|
2016-05-31 10:16:52 +00:00
|
|
|
auto songSearch = allSongGroups.find(m_groupId);
|
|
|
|
if (songSearch != allSongGroups.end())
|
2016-05-11 04:48:08 +00:00
|
|
|
{
|
2016-05-31 10:16:52 +00:00
|
|
|
selData = &songSearch->second.first->second;
|
|
|
|
songIndex = songSearch->second.second;
|
2016-05-11 04:48:08 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-05-31 10:16:52 +00:00
|
|
|
auto sfxSearch = allSFXGroups.find(m_groupId);
|
|
|
|
if (sfxSearch != allSFXGroups.end())
|
|
|
|
{
|
|
|
|
selData = &sfxSearch->second.first->second;
|
|
|
|
sfxIndex = sfxSearch->second.second;
|
|
|
|
}
|
2016-05-11 04:48:08 +00:00
|
|
|
}
|
|
|
|
|
2016-05-31 10:16:52 +00:00
|
|
|
if (!selData)
|
2016-05-27 05:30:43 +00:00
|
|
|
{
|
2016-05-31 22:16:46 +00:00
|
|
|
Log.report(logvisor::Error, "unable to select audio group data");
|
2018-05-28 20:26:55 +00:00
|
|
|
return 1;
|
2016-05-27 05:30:43 +00:00
|
|
|
}
|
|
|
|
|
2016-05-31 10:16:52 +00:00
|
|
|
/* Build voice engine */
|
|
|
|
std::unique_ptr<boo::IAudioVoiceEngine> voxEngine = boo::NewAudioVoiceEngine();
|
2017-12-07 04:34:45 +00:00
|
|
|
m_booBackend.reset(new amuse::BooBackendVoiceAllocator(*voxEngine));
|
|
|
|
m_engine.reset(new amuse::Engine(*m_booBackend, amuse::AmplitudeMode::PerSample));
|
2016-05-27 05:30:43 +00:00
|
|
|
|
2016-05-31 10:16:52 +00:00
|
|
|
/* Load group into engine */
|
|
|
|
const amuse::AudioGroup* group = m_engine->addAudioGroup(*selData);
|
|
|
|
if (!group)
|
2016-05-27 05:30:43 +00:00
|
|
|
{
|
2016-05-31 22:16:46 +00:00
|
|
|
Log.report(logvisor::Error, "unable to add audio group");
|
2018-05-28 20:26:55 +00:00
|
|
|
return 1;
|
2016-05-27 05:30:43 +00:00
|
|
|
}
|
|
|
|
|
2016-05-31 10:16:52 +00:00
|
|
|
/* Enter playback loop */
|
|
|
|
if (m_sfxGroup)
|
2017-02-15 06:01:39 +00:00
|
|
|
SFXLoop(*sfxIndex, *voxEngine);
|
2016-05-31 10:16:52 +00:00
|
|
|
else
|
2017-02-15 06:01:39 +00:00
|
|
|
SongLoop(*songIndex, *voxEngine);
|
2016-06-01 03:05:13 +00:00
|
|
|
|
2018-05-06 22:47:03 +00:00
|
|
|
m_vox.reset();
|
|
|
|
m_seq.reset();
|
2017-12-07 04:34:45 +00:00
|
|
|
m_engine.reset();
|
|
|
|
m_booBackend.reset();
|
2016-06-01 03:05:13 +00:00
|
|
|
printf("\n\n");
|
2016-05-31 22:09:38 +00:00
|
|
|
}
|
2016-05-11 04:48:08 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2016-05-09 07:22:58 +00:00
|
|
|
|
2016-07-14 04:54:46 +00:00
|
|
|
void appQuitting(boo::IApplication*) { m_running = false; }
|
2016-05-09 07:22:58 +00:00
|
|
|
|
2016-05-11 04:48:08 +00:00
|
|
|
AppCallback(int argc, const boo::SystemChar** argv)
|
2016-07-14 04:54:46 +00:00
|
|
|
: m_argc(argc), m_argv(argv), m_eventRec(*this), m_events(m_eventRec)
|
|
|
|
{
|
|
|
|
}
|
2016-05-11 04:48:08 +00:00
|
|
|
};
|
2016-05-09 07:22:58 +00:00
|
|
|
|
2016-05-11 04:48:08 +00:00
|
|
|
void EventCallback::charKeyDown(unsigned long charCode, boo::EModifierKey mods, bool isRepeat)
|
|
|
|
{
|
|
|
|
if (isRepeat)
|
2016-05-16 02:40:18 +00:00
|
|
|
m_app.charKeyDownRepeat(charCode);
|
|
|
|
else
|
|
|
|
m_app.charKeyDown(charCode);
|
2016-05-11 04:48:08 +00:00
|
|
|
}
|
|
|
|
|
2016-07-14 04:54:46 +00:00
|
|
|
void EventCallback::charKeyUp(unsigned long charCode, boo::EModifierKey mods) { m_app.charKeyUp(charCode); }
|
2016-05-11 04:48:08 +00:00
|
|
|
|
|
|
|
void EventCallback::specialKeyDown(boo::ESpecialKey key, boo::EModifierKey mods, bool isRepeat)
|
|
|
|
{
|
|
|
|
switch (key)
|
2016-05-09 07:22:58 +00:00
|
|
|
{
|
2016-05-11 04:48:08 +00:00
|
|
|
case boo::ESpecialKey::Left:
|
|
|
|
m_app.m_wantsPrev = true;
|
|
|
|
break;
|
|
|
|
case boo::ESpecialKey::Right:
|
|
|
|
m_app.m_wantsNext = true;
|
|
|
|
break;
|
2016-05-14 04:46:39 +00:00
|
|
|
case boo::ESpecialKey::Up:
|
|
|
|
if (m_app.m_volume < 1.f)
|
|
|
|
m_app.m_volume = amuse::clamp(0.f, m_app.m_volume + 0.05f, 1.f);
|
2016-07-14 06:16:00 +00:00
|
|
|
m_app.m_engine->setVolume(m_app.m_volume);
|
2016-05-14 04:46:39 +00:00
|
|
|
m_app.m_updateDisp = true;
|
|
|
|
break;
|
|
|
|
case boo::ESpecialKey::Down:
|
|
|
|
if (m_app.m_volume > 0.f)
|
|
|
|
m_app.m_volume = amuse::clamp(0.f, m_app.m_volume - 0.05f, 1.f);
|
2016-07-14 06:16:00 +00:00
|
|
|
m_app.m_engine->setVolume(m_app.m_volume);
|
2016-05-14 04:46:39 +00:00
|
|
|
m_app.m_updateDisp = true;
|
|
|
|
break;
|
2016-05-31 10:16:52 +00:00
|
|
|
case boo::ESpecialKey::Esc:
|
|
|
|
m_app.m_breakout = true;
|
2016-07-14 04:54:46 +00:00
|
|
|
default:
|
|
|
|
break;
|
2016-05-09 07:22:58 +00:00
|
|
|
}
|
2016-05-11 04:48:08 +00:00
|
|
|
}
|
|
|
|
|
2016-07-14 04:54:46 +00:00
|
|
|
void EventCallback::specialKeyUp(boo::ESpecialKey key, boo::EModifierKey mods) {}
|
2016-05-11 04:48:08 +00:00
|
|
|
|
2016-05-16 22:21:37 +00:00
|
|
|
void EventCallback::mouseDown(const boo::SWindowCoord& coord, boo::EMouseButton, boo::EModifierKey)
|
|
|
|
{
|
|
|
|
m_tracking = true;
|
|
|
|
m_app.m_pitchBend = amuse::clamp(-1.f, coord.norm[1] * 2.f - 1.f, 1.f);
|
|
|
|
if (m_app.m_vox)
|
|
|
|
m_app.m_vox->setPitchWheel(m_app.m_pitchBend);
|
|
|
|
if (m_app.m_seq && m_app.m_chanId != -1)
|
|
|
|
m_app.m_seq->setPitchWheel(m_app.m_chanId, m_app.m_pitchBend);
|
|
|
|
}
|
|
|
|
|
2016-05-16 20:20:29 +00:00
|
|
|
void EventCallback::mouseUp(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey)
|
|
|
|
{
|
|
|
|
m_tracking = false;
|
|
|
|
m_app.m_pitchBend = 0.f;
|
2016-05-16 22:21:37 +00:00
|
|
|
if (m_app.m_vox)
|
|
|
|
m_app.m_vox->setPitchWheel(m_app.m_pitchBend);
|
2016-05-16 20:20:29 +00:00
|
|
|
if (m_app.m_seq && m_app.m_chanId != -1)
|
|
|
|
m_app.m_seq->setPitchWheel(m_app.m_chanId, m_app.m_pitchBend);
|
|
|
|
}
|
|
|
|
|
2016-05-15 06:48:26 +00:00
|
|
|
void EventCallback::mouseMove(const boo::SWindowCoord& coord)
|
|
|
|
{
|
|
|
|
if (m_tracking)
|
|
|
|
{
|
|
|
|
m_app.m_modulation = amuse::clamp(0.f, coord.norm[0], 1.f);
|
|
|
|
if (m_app.m_vox)
|
|
|
|
m_app.m_vox->setCtrlValue(1, m_app.m_modulation * 127.f);
|
|
|
|
if (m_app.m_seq && m_app.m_chanId != -1)
|
|
|
|
m_app.m_seq->setCtrlValue(m_app.m_chanId, 1, m_app.m_modulation * 127.f);
|
|
|
|
|
|
|
|
m_app.m_pitchBend = amuse::clamp(-1.f, coord.norm[1] * 2.f - 1.f, 1.f);
|
|
|
|
if (m_app.m_vox)
|
|
|
|
m_app.m_vox->setPitchWheel(m_app.m_pitchBend);
|
|
|
|
if (m_app.m_seq && m_app.m_chanId != -1)
|
|
|
|
m_app.m_seq->setPitchWheel(m_app.m_chanId, m_app.m_pitchBend);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-11 04:48:08 +00:00
|
|
|
#if _WIN32
|
|
|
|
int wmain(int argc, const boo::SystemChar** argv)
|
|
|
|
#else
|
|
|
|
int main(int argc, const boo::SystemChar** argv)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
logvisor::RegisterConsoleLogger();
|
2016-09-11 01:25:32 +00:00
|
|
|
logvisor::RegisterStandardExceptions();
|
2016-05-11 04:48:08 +00:00
|
|
|
AppCallback app(argc, argv);
|
2018-01-10 06:18:15 +00:00
|
|
|
int ret = boo::ApplicationRun(boo::IApplication::EPlatformType::Auto, app,
|
|
|
|
_S("amuseplay"), _S("Amuse Player"),
|
|
|
|
argc, argv, {}, 1, 1, false);
|
2016-05-11 04:48:08 +00:00
|
|
|
printf("IM DYING!!\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if _WIN32
|
2016-09-11 01:25:32 +00:00
|
|
|
#include <shellapi.h>
|
2016-05-11 04:48:08 +00:00
|
|
|
int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR lpCmdLine, int)
|
|
|
|
{
|
|
|
|
int argc = 0;
|
2018-05-28 20:26:55 +00:00
|
|
|
const boo::SystemChar** argv;
|
|
|
|
if (lpCmdLine[0])
|
|
|
|
argv = (const wchar_t**)(CommandLineToArgvW(lpCmdLine, &argc));
|
2016-05-11 04:48:08 +00:00
|
|
|
static boo::SystemChar selfPath[1024];
|
|
|
|
GetModuleFileNameW(nullptr, selfPath, 1024);
|
|
|
|
static const boo::SystemChar* booArgv[32] = {};
|
|
|
|
booArgv[0] = selfPath;
|
2018-05-28 20:26:55 +00:00
|
|
|
for (int i=0 ; i<argc ; ++i)
|
|
|
|
booArgv[i+1] = argv[i];
|
2016-05-09 07:22:58 +00:00
|
|
|
|
2016-05-11 04:48:08 +00:00
|
|
|
logvisor::CreateWin32Console();
|
2016-05-23 05:33:50 +00:00
|
|
|
SetConsoleOutputCP(65001);
|
2016-07-14 04:54:46 +00:00
|
|
|
return wmain(argc + 1, booArgv);
|
2016-05-09 07:22:58 +00:00
|
|
|
}
|
2016-05-11 04:48:08 +00:00
|
|
|
#endif
|