2021-02-26 19:31:24 +01:00
|
|
|
#pragma once
|
2021-04-13 20:31:51 +02:00
|
|
|
#include <core/global/globals.hpp>
|
|
|
|
#include <helper/version/check.hpp>
|
2021-02-26 19:31:24 +01:00
|
|
|
#include <nlohmann/json.hpp>
|
|
|
|
|
|
|
|
namespace nlohmann
|
|
|
|
{
|
|
|
|
template <> struct adl_serializer<Soundux::Objects::Sound>
|
|
|
|
{
|
|
|
|
static void to_json(json &j, const Soundux::Objects::Sound &obj)
|
|
|
|
{
|
|
|
|
j = {{"name", obj.name},
|
|
|
|
{"hotkeys", obj.hotkeys},
|
|
|
|
{"hotkeySequence",
|
|
|
|
Soundux::Globals::gHotKeys.getKeySequence(obj.hotkeys)}, //* For frontend and config readability
|
|
|
|
{"id", obj.id},
|
|
|
|
{"path", obj.path},
|
2021-03-10 08:36:08 +01:00
|
|
|
{"isFavorite", obj.isFavorite},
|
2021-02-26 19:31:24 +01:00
|
|
|
{"modifiedDate", obj.modifiedDate}};
|
|
|
|
}
|
|
|
|
static void from_json(const json &j, Soundux::Objects::Sound &obj)
|
|
|
|
{
|
|
|
|
j.at("name").get_to(obj.name);
|
|
|
|
j.at("hotkeys").get_to(obj.hotkeys);
|
|
|
|
j.at("id").get_to(obj.id);
|
|
|
|
j.at("path").get_to(obj.path);
|
|
|
|
j.at("modifiedDate").get_to(obj.modifiedDate);
|
2021-03-10 08:36:08 +01:00
|
|
|
if (j.find("isFavorite") != j.end())
|
2021-03-09 20:38:09 +01:00
|
|
|
{
|
2021-03-10 08:36:08 +01:00
|
|
|
j.at("isFavorite").get_to(obj.isFavorite);
|
2021-03-09 20:38:09 +01:00
|
|
|
}
|
2021-02-26 19:31:24 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
template <> struct adl_serializer<Soundux::Objects::AudioDevice>
|
|
|
|
{
|
|
|
|
static void to_json(json &j, const Soundux::Objects::AudioDevice &obj)
|
|
|
|
{
|
|
|
|
j = {{"name", obj.name}, {"isDefault", obj.isDefault}};
|
|
|
|
}
|
|
|
|
static void from_json(const json &j, Soundux::Objects::AudioDevice &obj)
|
|
|
|
{
|
|
|
|
j.at("name").get_to(obj.name);
|
|
|
|
j.at("isDefault").get_to(obj.isDefault);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
template <> struct adl_serializer<Soundux::Objects::PlayingSound>
|
|
|
|
{
|
|
|
|
static void to_json(json &j, const Soundux::Objects::PlayingSound &obj)
|
|
|
|
{
|
|
|
|
j = {
|
|
|
|
{"sound", obj.sound}, {"id", obj.id},
|
|
|
|
{"length", obj.length}, {"paused", obj.paused},
|
|
|
|
{"lengthInMs", obj.lengthInMs}, {"repeat", obj.repeat},
|
|
|
|
{"readFrames", obj.readFrames}, {"readInMs", obj.readInMs},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
static void from_json(const json &j, Soundux::Objects::PlayingSound &obj)
|
|
|
|
{
|
|
|
|
j.at("sound").get_to(obj.sound);
|
|
|
|
j.at("paused").get_to(obj.paused);
|
|
|
|
j.at("repeat").get_to(obj.repeat);
|
|
|
|
j.at("id").get_to(obj.id);
|
|
|
|
j.at("length").get_to(obj.length);
|
|
|
|
j.at("lengthInMs").get_to(obj.lengthInMs);
|
|
|
|
j.at("readFrames").get_to(obj.readFrames);
|
|
|
|
j.at("readInMs").get_to(obj.readInMs);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
template <> struct adl_serializer<Soundux::Objects::Settings>
|
|
|
|
{
|
|
|
|
static void to_json(json &j, const Soundux::Objects::Settings &obj)
|
|
|
|
{
|
|
|
|
j = {{"allowOverlapping", obj.allowOverlapping},
|
|
|
|
{"output", obj.output},
|
|
|
|
{"gridView", obj.gridView},
|
2021-03-22 18:28:44 +01:00
|
|
|
{"sortMode", obj.sortMode},
|
2021-02-26 19:31:24 +01:00
|
|
|
{"darkTheme", obj.darkTheme},
|
|
|
|
{"stopHotkey", obj.stopHotkey},
|
2021-03-24 18:55:37 +01:00
|
|
|
{"syncVolumes", obj.syncVolumes},
|
2021-02-26 19:31:24 +01:00
|
|
|
{"selectedTab", obj.selectedTab},
|
2021-03-12 19:37:02 +01:00
|
|
|
{"launchPadMode", obj.launchPadMode},
|
2021-03-31 16:44:23 +02:00
|
|
|
{"pushToTalkKeys", obj.pushToTalkKeys},
|
2021-02-26 19:31:24 +01:00
|
|
|
{"tabHotkeysOnly", obj.tabHotkeysOnly},
|
2021-03-29 18:17:33 +02:00
|
|
|
{"minimizeToTray", obj.minimizeToTray},
|
2021-02-26 19:31:24 +01:00
|
|
|
{"remoteVolume", obj.remoteVolume},
|
2021-03-14 13:17:19 +01:00
|
|
|
{"muteDuringPlayback", obj.muteDuringPlayback},
|
2021-02-26 19:31:24 +01:00
|
|
|
{"useAsDefaultDevice", obj.useAsDefaultDevice},
|
|
|
|
{"localVolume", obj.localVolume}};
|
|
|
|
}
|
|
|
|
static void from_json(const json &j, Soundux::Objects::Settings &obj)
|
|
|
|
{
|
|
|
|
j.at("allowOverlapping").get_to(obj.allowOverlapping);
|
|
|
|
j.at("output").get_to(obj.output);
|
|
|
|
j.at("gridView").get_to(obj.gridView);
|
|
|
|
j.at("darkTheme").get_to(obj.darkTheme);
|
|
|
|
j.at("stopHotkey").get_to(obj.stopHotkey);
|
|
|
|
j.at("localVolume").get_to(obj.localVolume);
|
|
|
|
j.at("selectedTab").get_to(obj.selectedTab);
|
|
|
|
j.at("remoteVolume").get_to(obj.remoteVolume);
|
|
|
|
j.at("tabHotkeysOnly").get_to(obj.tabHotkeysOnly);
|
|
|
|
j.at("useAsDefaultDevice").get_to(obj.useAsDefaultDevice);
|
2021-03-12 19:37:02 +01:00
|
|
|
if (j.find("launchPadMode") != j.end())
|
|
|
|
{
|
|
|
|
j.at("launchPadMode").get_to(obj.launchPadMode);
|
|
|
|
}
|
2021-03-14 13:17:19 +01:00
|
|
|
if (j.find("muteDuringPlayback") != j.end())
|
|
|
|
{
|
|
|
|
j.at("muteDuringPlayback").get_to(obj.muteDuringPlayback);
|
|
|
|
}
|
2021-03-22 18:28:44 +01:00
|
|
|
if (j.find("sortMode") != j.end())
|
|
|
|
{
|
|
|
|
j.at("sortMode").get_to(obj.sortMode);
|
|
|
|
}
|
2021-03-24 18:55:37 +01:00
|
|
|
if (j.find("syncVolumes") != j.end())
|
|
|
|
{
|
|
|
|
j.at("syncVolumes").get_to(obj.syncVolumes);
|
|
|
|
}
|
2021-03-29 18:17:33 +02:00
|
|
|
if (j.find("minimizeToTray") != j.end())
|
|
|
|
{
|
|
|
|
j.at("minimizeToTray").get_to(obj.minimizeToTray);
|
|
|
|
}
|
2021-03-31 16:44:23 +02:00
|
|
|
if (j.find("pushToTalkKeys") != j.end())
|
|
|
|
{
|
|
|
|
j.at("pushToTalkKeys").get_to(obj.pushToTalkKeys);
|
|
|
|
}
|
2021-02-26 19:31:24 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
template <> struct adl_serializer<Soundux::Objects::Tab>
|
|
|
|
{
|
|
|
|
static void to_json(json &j, const Soundux::Objects::Tab &obj)
|
|
|
|
{
|
|
|
|
j = {{"id", obj.id}, {"name", obj.name}, {"path", obj.path}, {"sounds", obj.sounds}};
|
|
|
|
}
|
|
|
|
static void from_json(const json &j, Soundux::Objects::Tab &obj)
|
|
|
|
{
|
|
|
|
j.at("id").get_to(obj.id);
|
|
|
|
j.at("name").get_to(obj.name);
|
|
|
|
j.at("path").get_to(obj.path);
|
|
|
|
j.at("sounds").get_to(obj.sounds);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
template <> struct adl_serializer<Soundux::Objects::Data>
|
|
|
|
{
|
|
|
|
static void to_json(json &j, const Soundux::Objects::Data &obj)
|
|
|
|
{
|
|
|
|
j = {{"height", obj.height},
|
|
|
|
{"width", obj.width},
|
|
|
|
{"tabs", obj.tabs},
|
|
|
|
{"soundIdCounter", obj.soundIdCounter}};
|
|
|
|
}
|
|
|
|
static void from_json(const json &j, Soundux::Objects::Data &obj)
|
|
|
|
{
|
|
|
|
j.at("soundIdCounter").get_to(obj.soundIdCounter);
|
|
|
|
j.at("height").get_to(obj.height);
|
|
|
|
j.at("width").get_to(obj.width);
|
|
|
|
j.at("tabs").get_to(obj.tabs);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
template <> struct adl_serializer<Soundux::Objects::Config>
|
|
|
|
{
|
|
|
|
static void to_json(json &j, const Soundux::Objects::Config &obj)
|
|
|
|
{
|
|
|
|
j = {{"data", obj.data}, {"settings", obj.settings}};
|
|
|
|
}
|
|
|
|
static void from_json(const json &j, Soundux::Objects::Config &obj)
|
|
|
|
{
|
|
|
|
j.at("data").get_to(obj.data);
|
|
|
|
j.at("settings").get_to(obj.settings);
|
|
|
|
}
|
|
|
|
};
|
2021-03-19 21:22:32 +01:00
|
|
|
template <> struct adl_serializer<Soundux::Objects::VersionStatus>
|
|
|
|
{
|
|
|
|
static void to_json(json &j, const Soundux::Objects::VersionStatus &obj)
|
|
|
|
{
|
|
|
|
j = {{"current", obj.current}, {"latest", obj.latest}, {"outdated", obj.outdated}};
|
|
|
|
}
|
|
|
|
static void from_json(const json &j, Soundux::Objects::VersionStatus &obj)
|
|
|
|
{
|
|
|
|
j.at("latest").get_to(obj.latest);
|
|
|
|
j.at("current").get_to(obj.current);
|
|
|
|
j.at("outdated").get_to(obj.outdated);
|
|
|
|
}
|
|
|
|
};
|
2021-02-26 19:31:24 +01:00
|
|
|
#if defined(__linux__)
|
|
|
|
template <> struct adl_serializer<Soundux::Objects::PulseRecordingStream>
|
|
|
|
{
|
|
|
|
static void to_json(json &j, const Soundux::Objects::PulseRecordingStream &obj)
|
|
|
|
{
|
|
|
|
j = {{"id", obj.id},
|
2021-03-17 21:15:00 +01:00
|
|
|
{"pid", obj.pid},
|
2021-02-26 19:31:24 +01:00
|
|
|
{"name", obj.name},
|
|
|
|
{"driver", obj.driver},
|
|
|
|
{"source", obj.source},
|
2021-03-17 21:15:00 +01:00
|
|
|
{"appIcon", obj.appIcon},
|
2021-03-17 15:33:32 +01:00
|
|
|
{"application", obj.application},
|
2021-02-26 19:31:24 +01:00
|
|
|
{"resampleMethod", obj.resampleMethod}};
|
|
|
|
}
|
|
|
|
static void from_json(const json &j, Soundux::Objects::PulseRecordingStream &obj)
|
|
|
|
{
|
|
|
|
j.at("id").get_to(obj.id);
|
2021-03-17 21:15:00 +01:00
|
|
|
j.at("pid").get_to(obj.pid);
|
2021-02-26 19:31:24 +01:00
|
|
|
j.at("name").get_to(obj.name);
|
|
|
|
j.at("driver").get_to(obj.driver);
|
|
|
|
j.at("source").get_to(obj.source);
|
2021-03-17 21:15:00 +01:00
|
|
|
j.at("appIcon").get_to(obj.appIcon);
|
2021-03-17 15:33:32 +01:00
|
|
|
j.at("application").get_to(obj.application);
|
2021-02-26 19:31:24 +01:00
|
|
|
j.at("resampleMethod").get_to(obj.resampleMethod);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
template <> struct adl_serializer<Soundux::Objects::PulsePlaybackStream>
|
|
|
|
{
|
|
|
|
static void to_json(json &j, const Soundux::Objects::PulsePlaybackStream &obj)
|
|
|
|
{
|
2021-03-17 15:33:32 +01:00
|
|
|
j = {{"id", obj.id},
|
2021-03-17 21:15:00 +01:00
|
|
|
{"pid", obj.pid},
|
2021-03-17 15:33:32 +01:00
|
|
|
{"name", obj.name},
|
|
|
|
{"sink", obj.sink},
|
|
|
|
{"driver", obj.driver},
|
2021-03-17 21:15:00 +01:00
|
|
|
{"appIcon", obj.appIcon},
|
2021-03-17 15:33:32 +01:00
|
|
|
{"application", obj.application}};
|
2021-02-26 19:31:24 +01:00
|
|
|
}
|
|
|
|
static void from_json(const json &j, Soundux::Objects::PulsePlaybackStream &obj)
|
|
|
|
{
|
|
|
|
j.at("id").get_to(obj.id);
|
2021-03-17 21:15:00 +01:00
|
|
|
j.at("pid").get_to(obj.pid);
|
2021-02-26 19:31:24 +01:00
|
|
|
j.at("name").get_to(obj.name);
|
|
|
|
j.at("sink").get_to(obj.sink);
|
|
|
|
j.at("driver").get_to(obj.driver);
|
2021-03-17 21:15:00 +01:00
|
|
|
j.at("appIcon").get_to(obj.appIcon);
|
2021-03-17 15:33:32 +01:00
|
|
|
j.at("application").get_to(obj.application);
|
2021-02-26 19:31:24 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
} // namespace nlohmann
|