1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
/* TIATracker, (c) 2016 Andre "Kylearan" Wichmann.
* Website: https://bitbucket.org/kylearan/tiatracker
* Email: andre.wichmann@gmx.de
* See the file "license.txt" for information on usage and redistribution
* of this file.
*/
#include "note.h"
#include <stdexcept>
namespace Track {
const QList<Note::instrumentType> Note::insTypes{
Note::instrumentType::Hold,
Note::instrumentType::Instrument,
Note::instrumentType::Pause,
Note::instrumentType::Percussion,
Note::instrumentType::Slide
};
Note::Note()
{
}
/*************************************************************************/
void Note::toJson(QJsonObject &json) {
json["type"] = insTypes.indexOf(type);
json["number"] = instrumentNumber;
json["value"] = value;
}
/*************************************************************************/
bool Note::fromJson(const QJsonObject &json) {
int typeInt = json["type"].toInt();
if (typeInt < 0 || typeInt >= insTypes.size()) {
return false;
}
type = insTypes[typeInt];
instrumentNumber = json["number"].toInt();
// FIXME: Magic number
if (instrumentNumber < 0 || instrumentNumber > 22) {
return false;
}
value = json["value"].toInt();
return true;
}
}
|