-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Change cmeta to be text files - Sequences can be put in folders: - If a node has a non-node folder, it looks through it and all it's children for sequences. - If there are sequences, whether directly or in folders, in the Custom Music folder, they're considered too. The cmeta is read and the sequence is added to the node of the category, or if music shuffle is mixed, to the root node. - Change Underground node to Ganon's Castle
- Loading branch information
Showing
6 changed files
with
266 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
#include <iostream> | ||
#include <fstream> | ||
#include <string> | ||
#include <sstream> | ||
#include <algorithm> | ||
#include <cctype> | ||
|
||
#include "cmeta_interpreter.hpp" | ||
|
||
static const std::string CMETAKEY_BANKS = "banks"; | ||
static const std::string CMETAKEY_CHFLAGS = "chFlags"; | ||
static const std::string CMETAKEY_VOLUME = "volume"; | ||
static const std::string CMETAKEY_CATEGORY = "category"; | ||
|
||
CMetaInterpreter::CMetaInterpreter(std::string path) : banks{ 7, 7, 7, 7 }, channelFlags(-1), volume(0x7F) { | ||
// Set banks to Orchestra by default | ||
// Enable all channel flags by default | ||
// 100% volume (assumed, as it's unsigned) by default | ||
|
||
std::fstream f(path); | ||
std::string f_out; | ||
while (std::getline(f, f_out)) { | ||
std::stringstream ss(f_out); | ||
std::string key; | ||
std::string value; | ||
std::getline(ss, key, '='); | ||
std::getline(ss, value, '='); | ||
|
||
// Removes leading and trailing spaces, tabs, and newline characters | ||
const auto sanitizeInput = [](std::string& str) { | ||
std::replace(str.begin(), str.end(), '\t', ' '); | ||
str.erase(0, str.find_first_not_of(' ')); | ||
str.erase(str.find_last_not_of(' ') + 1); | ||
while (str.back() == '\n' || str.back() == '\r') { | ||
str.pop_back(); | ||
} | ||
}; | ||
|
||
sanitizeInput(key); | ||
sanitizeInput(value); | ||
|
||
const auto getIntFromValue = [](std::string value) { | ||
if (value.length() > 2) { | ||
// Hexadecimal | ||
if (value[0] == '0' && value[1] == 'x') { | ||
return std::stoi(value, nullptr, 16); | ||
} | ||
// Binary | ||
else if (value[0] == '0' && value[1] == 'b') { | ||
value.erase(0, 2); | ||
return std::stoi(value, nullptr, 2); | ||
} | ||
} | ||
// Percentage, decimal (Should only be used for volume) | ||
if (value.back() == '%') { | ||
value.pop_back(); | ||
return std::min(0xFF, (int)(0xFF * (std::stoi(value) / 200.0f))); | ||
} | ||
// Decimal | ||
return std::stoi(value); | ||
}; | ||
|
||
if (key == CMETAKEY_BANKS) { | ||
// Effectively treat all non-alphanumerical symbols as separators | ||
for (size_t i = 0; i < value.length(); i++) { | ||
if (!isalnum(value.at(i))) { | ||
value.at(i) = ' '; | ||
} | ||
} | ||
std::stringstream bs(value); | ||
u8 i = 0; | ||
std::string bs_out; | ||
while (std::getline(bs, bs_out, ' ')) { | ||
// Two spaces in a row gives an empty token; skip them | ||
if (bs_out.empty()) { | ||
continue; | ||
} | ||
// At most four banks can be set | ||
if (i >= 4) { | ||
break; | ||
} | ||
banks.at(i) = getIntFromValue(bs_out); | ||
i++; | ||
} | ||
} else if (key == CMETAKEY_CHFLAGS) { | ||
channelFlags = getIntFromValue(value); | ||
} else if (key == CMETAKEY_VOLUME) { | ||
volume = getIntFromValue(value); | ||
} else if (key == CMETAKEY_CATEGORY) { | ||
category = value; | ||
if (category.front() == '!') { | ||
category.erase(0, category.find_first_not_of('!')); | ||
} | ||
} | ||
} | ||
|
||
f.close(); | ||
} | ||
|
||
CMetaInterpreter::~CMetaInterpreter() = default; | ||
|
||
const std::array<u32, 4>& CMetaInterpreter::GetBanks() { | ||
return banks; | ||
} | ||
|
||
u16 CMetaInterpreter::GetChannelFlags() { | ||
return channelFlags; | ||
} | ||
|
||
u8 CMetaInterpreter::GetVolume() { | ||
return volume; | ||
} | ||
|
||
const std::string& CMetaInterpreter::GetCategory() { | ||
return category; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#pragma once | ||
|
||
#include <3ds.h> | ||
#include <string> | ||
#include <array> | ||
|
||
class CMetaInterpreter { | ||
public: | ||
CMetaInterpreter(std::string path); | ||
~CMetaInterpreter(); | ||
|
||
const std::array<u32, 4>& GetBanks(); | ||
u16 GetChannelFlags(); | ||
u8 GetVolume(); | ||
const std::string& GetCategory(); | ||
|
||
private: | ||
std::array<u32, 4> banks; | ||
u16 channelFlags; | ||
u8 volume; | ||
std::string category; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.