XJ music engine  1.9.6
In-game runtime engine for XJ music.
Instrument.h
Go to the documentation of this file.
1 // Copyright (c) XJ Music Inc. (https://xjmusic.com) All Rights Reserved.
2 
3 #ifndef XJMUSIC_INSTRUMENT_H
4 #define XJMUSIC_INSTRUMENT_H
5 
6 #include <string>
7 
8 #include "ContentEntity.h"
9 #include "InstrumentConfig.h"
11 
12 namespace XJ {
13 
14  class Instrument : public ContentEntity {
15  public:
16  enum Type {
21  Pad,
27  };
28 
29  enum Mode {
32  Loop
33  };
34 
35  enum State {
37  Published
38  };
39 
40  Instrument() = default;
41 
46  std::string name{};
48  float volume{0};
49  bool isDeleted{false};
51 
57  static Type parseType(const std::string &value);
58 
64  static Mode parseMode(const std::string &value);
65 
71  static State parseState(const std::string &value);
72 
78  static std::string toString(const Type &type);
79 
85  static std::string toString(const Mode &mode);
86 
92  static std::string toString(const State &state);
93 
99  static const std::vector<std::string> &toStrings(std::vector<Type> types);
100  };
106  inline void from_json(const json &json, Instrument &entity) {
107  EntityUtils::setRequired(json, "id", entity.id);
108  EntityUtils::setRequired(json, "libraryId", entity.libraryId);
109  entity.state = Instrument::parseState(json.at("state").get<std::string>());
110  entity.type = Instrument::parseType(json.at("type").get<std::string>());
111  entity.mode = Instrument::parseMode(json.at("mode").get<std::string>());
112  EntityUtils::setIfNotNull(json, "name", entity.name);
113  EntityUtils::setIfNotNull(json, "volume", entity.volume);
114  EntityUtils::setIfNotNull(json, "isDeleted", entity.isDeleted);
115  EntityUtils::setIfNotNull(json, "updatedAt", entity.updatedAt);
116 
117  if (json.contains("config") && json.at("config").is_string()) {
118  const auto configStr = json.at("config").get<std::string>();
119  entity.config = InstrumentConfig(configStr);
120  }
121  }
122 
123 
124 }// namespace XJ
125 
126 #endif//XJMUSIC_INSTRUMENT_H
nlohmann::json json
Definition: EntityUtils.h:14
Definition: ContentEntity.h:12
UUID id
Definition: ContentEntity.h:17
static long long currentTimeMillis()
Definition: EntityUtils.h:62
static void setIfNotNull(const json &json, const std::string &key, std::string &value)
Definition: EntityUtils.cpp:27
static void setRequired(const json &json, const std::string &key, UUID &value)
Definition: EntityUtils.cpp:16
Definition: InstrumentConfig.h:14
Definition: Instrument.h:14
Instrument()=default
Mode
Definition: Instrument.h:29
@ Loop
Definition: Instrument.h:32
@ Event
Definition: Instrument.h:31
@ Chord
Definition: Instrument.h:30
UUID libraryId
Definition: Instrument.h:42
long long updatedAt
Definition: Instrument.h:50
static State parseState(const std::string &value)
Definition: Instrument.cpp:57
static Mode parseMode(const std::string &value)
Definition: Instrument.cpp:49
State
Definition: Instrument.h:35
@ Draft
Definition: Instrument.h:36
@ Published
Definition: Instrument.h:37
static const std::vector< std::string > & toStrings(std::vector< Type > types)
Definition: Instrument.cpp:79
bool isDeleted
Definition: Instrument.h:49
Mode mode
Definition: Instrument.h:45
Type type
Definition: Instrument.h:44
State state
Definition: Instrument.h:43
static Type parseType(const std::string &value)
Definition: Instrument.cpp:41
static std::string toString(const Type &type)
Definition: Instrument.cpp:65
float volume
Definition: Instrument.h:48
Type
Definition: Instrument.h:16
@ Pad
Definition: Instrument.h:21
@ Sticky
Definition: Instrument.h:24
@ Transition
Definition: Instrument.h:26
@ Bass
Definition: Instrument.h:18
@ Stripe
Definition: Instrument.h:25
@ Stab
Definition: Instrument.h:23
@ Drum
Definition: Instrument.h:19
@ Percussion
Definition: Instrument.h:22
@ Hook
Definition: Instrument.h:20
@ Background
Definition: Instrument.h:17
std::string name
Definition: Instrument.h:46
InstrumentConfig config
Definition: Instrument.h:47
Definition: ActiveAudio.h:11
std::string UUID
Definition: EntityUtils.h:28
void from_json(const json &json, Instrument &entity)
Definition: Instrument.h:106