osb/source/frontend/StarVoiceLuaBindings.cpp

46 lines
1.8 KiB
C++
Raw Normal View History

2023-07-19 11:12:14 +00:00
#include "StarLuaConverters.hpp"
2023-07-18 07:36:51 +00:00
#include "StarVoiceLuaBindings.hpp"
#include "StarVoice.hpp"
2023-07-19 11:12:14 +00:00
2023-07-18 07:36:51 +00:00
namespace Star {
2023-07-19 11:12:14 +00:00
typedef Voice::SpeakerId SpeakerId;
2023-07-19 13:16:59 +00:00
LuaCallbacks LuaBindings::makeVoiceCallbacks() {
2023-07-18 07:36:51 +00:00
LuaCallbacks callbacks;
2023-07-19 13:16:59 +00:00
auto voice = Voice::singletonPtr();
2023-07-19 11:12:14 +00:00
callbacks.registerCallbackWithSignature<StringList>("devices", bind(&Voice::availableDevices, voice));
callbacks.registerCallback( "getSettings", [voice]() -> Json { return voice->saveJson(); });
callbacks.registerCallback("mergeSettings", [voice](Json const& settings) { voice->loadJson(settings); });
2023-07-19 11:12:14 +00:00
// i have an alignment addiction i'm so sorry
callbacks.registerCallback("setSpeakerMuted", [voice](SpeakerId speakerId, bool muted) { voice->speaker(speakerId)->muted = muted; });
callbacks.registerCallback( "speakerMuted", [voice](SpeakerId speakerId) { return (bool)voice->speaker(speakerId)->muted; });
// it just looks so neat to me!!
callbacks.registerCallback("setSpeakerVolume", [voice](SpeakerId speakerId, float volume) { voice->speaker(speakerId)->volume = volume; });
callbacks.registerCallback( "speakerVolume", [voice](SpeakerId speakerId) { return (float)voice->speaker(speakerId)->volume; });
callbacks.registerCallback("speakerPosition", [voice](SpeakerId speakerId) { return voice->speaker(speakerId)->position; });
2023-07-19 13:16:59 +00:00
callbacks.registerCallback("speaker", [voice](Maybe<SpeakerId> speakerId) {
if (speakerId)
return voice->speaker(*speakerId)->toJson();
else
return voice->localSpeaker()->toJson();
});
2023-07-18 07:36:51 +00:00
callbacks.registerCallback("speakers", [voice](Maybe<bool> onlyPlaying) -> List<Json> {
List<Json> list;
2023-07-19 11:12:14 +00:00
for (auto& speaker : voice->sortedSpeakers(onlyPlaying.value(true)))
list.append(speaker->toJson());
2023-07-18 07:36:51 +00:00
return list;
});
return callbacks;
}
}