diff options
Diffstat (limited to 'tools/mid2agb')
-rw-r--r-- | tools/mid2agb/Makefile | 2 | ||||
-rw-r--r-- | tools/mid2agb/agb.cpp | 97 | ||||
-rw-r--r-- | tools/mid2agb/main.cpp | 9 | ||||
-rw-r--r-- | tools/mid2agb/midi.cpp | 10 |
4 files changed, 107 insertions, 11 deletions
diff --git a/tools/mid2agb/Makefile b/tools/mid2agb/Makefile index 4dc2f12..77f96db 100644 --- a/tools/mid2agb/Makefile +++ b/tools/mid2agb/Makefile @@ -1,6 +1,6 @@ CXX := g++ -CXXFLAGS := -std=c++11 -O2 -s -Wall -Wno-switch -Werror +CXXFLAGS := -std=c++11 -O2 -Wall -Wno-switch -Werror SRCS := agb.cpp error.cpp main.cpp midi.cpp tables.cpp diff --git a/tools/mid2agb/agb.cpp b/tools/mid2agb/agb.cpp index 9ff1efa..d4d79f1 100644 --- a/tools/mid2agb/agb.cpp +++ b/tools/mid2agb/agb.cpp @@ -38,6 +38,9 @@ static bool s_noteChanged; static bool s_velocityChanged; static bool s_inPattern; static int s_extendedCommand; +static int s_memaccOp; +static int s_memaccParam1; +static int s_memaccParam2; void PrintAgbHeader() { @@ -247,6 +250,84 @@ void PrintSeqLoopLabel(const Event& event) ResetTrackVars(); } +void PrintMemAcc(const Event& event) +{ + switch (s_memaccOp) + { + case 0x00: + PrintByte("MEMACC, mem_set, 0x%02X, %u", s_memaccParam1, event.param2); + break; + case 0x01: + PrintByte("MEMACC, mem_add, 0x%02X, %u", s_memaccParam1, event.param2); + break; + case 0x02: + PrintByte("MEMACC, mem_sub, 0x%02X, %u", s_memaccParam1, event.param2); + break; + case 0x03: + PrintByte("MEMACC, mem_mem_set, 0x%02X, 0x%02X", s_memaccParam1, event.param2); + break; + case 0x04: + PrintByte("MEMACC, mem_mem_add, 0x%02X, 0x%02X", s_memaccParam1, event.param2); + break; + case 0x05: + PrintByte("MEMACC, mem_mem_sub, 0x%02X, 0x%02X", s_memaccParam1, event.param2); + break; + // TODO: everything else + case 0x06: + break; + case 0x07: + break; + case 0x08: + break; + case 0x09: + break; + case 0x0A: + break; + case 0x0B: + break; + case 0x0C: + break; + case 0x0D: + break; + case 0x0E: + break; + case 0x0F: + break; + case 0x10: + break; + case 0x11: + break; + case 0x46: + break; + case 0x47: + break; + case 0x48: + break; + case 0x49: + break; + case 0x4A: + break; + case 0x4B: + break; + case 0x4C: + break; + case 0x4D: + break; + case 0x4E: + break; + case 0x4F: + break; + case 0x50: + break; + case 0x51: + break; + default: + break; + } + + PrintWait(event.time); +} + void PrintExtendedOp(const Event& event) { // TODO: support for other extended commands @@ -280,16 +361,19 @@ void PrintControllerOp(const Event& event) break; case 0x0C: case 0x10: - // TODO: memacc + PrintMemAcc(event); break; case 0x0D: - // TODO: memacc var + s_memaccOp = event.param2; + PrintWait(event.time); break; case 0x0E: - // TODO: memacc var + s_memaccParam1 = event.param2; + PrintWait(event.time); break; case 0x0F: - // TODO: memacc var + s_memaccParam2 = event.param2; + PrintWait(event.time); break; case 0x11: std::fprintf(g_outputFile, "%s_%u_L%u:\n", g_asmLabel.c_str(), g_agbTrack, event.param2); @@ -334,8 +418,6 @@ void PrintAgbTrack(std::vector<Event>& events) { std::fprintf(g_outputFile, "\n@**************** Track %u (Midi-Chn.%u) ****************@\n\n", g_agbTrack, g_midiChan + 1); std::fprintf(g_outputFile, "%s_%u:\n", g_asmLabel.c_str(), g_agbTrack); - PrintWait(g_initialWait); - PrintByte("KEYSH , %s_key%+d", g_asmLabel.c_str(), 0); int wholeNoteCount = 0; int loopEndBlockNum = 0; @@ -359,6 +441,9 @@ void PrintAgbTrack(std::vector<Event>& events) if (!foundVolBeforeNote) PrintByte("\tVOL , 127*%s_mvl/mxv", g_asmLabel.c_str()); + PrintWait(g_initialWait); + PrintByte("KEYSH , %s_key%+d", g_asmLabel.c_str(), 0); + for (unsigned i = 0; events[i].type != EventType::EndOfTrack; i++) { const Event& event = events[i]; diff --git a/tools/mid2agb/main.cpp b/tools/mid2agb/main.cpp index 03feabd..ea2b294 100644 --- a/tools/mid2agb/main.cpp +++ b/tools/mid2agb/main.cpp @@ -138,7 +138,7 @@ int main(int argc, char** argv) if (option[0] == '-' && option[1] != '\0') { - const char *arg = GetArgument(argc, argv, i); + const char *arg; switch (std::toupper(option[1])) { @@ -146,29 +146,34 @@ int main(int argc, char** argv) g_exactGateTime = true; break; case 'G': + arg = GetArgument(argc, argv, i); if (arg == nullptr) PrintUsage(); g_voiceGroup = std::stoi(arg); break; case 'L': + arg = GetArgument(argc, argv, i); if (arg == nullptr) PrintUsage(); - g_asmLabel = std::stoi(arg); + g_asmLabel = arg; break; case 'N': g_compressionEnabled = false; break; case 'P': + arg = GetArgument(argc, argv, i); if (arg == nullptr) PrintUsage(); g_priority = std::stoi(arg); break; case 'R': + arg = GetArgument(argc, argv, i); if (arg == nullptr) PrintUsage(); g_reverb = std::stoi(arg); break; case 'V': + arg = GetArgument(argc, argv, i); if (arg == nullptr) PrintUsage(); g_masterVolume = std::stoi(arg); diff --git a/tools/mid2agb/midi.cpp b/tools/mid2agb/midi.cpp index 09480e1..fa7d9ce 100644 --- a/tools/mid2agb/midi.cpp +++ b/tools/mid2agb/midi.cpp @@ -780,7 +780,7 @@ int CalculateCompressionScore(std::vector<Event>& events, int index) std::uint8_t lastVelocity = 0x80u; EventType lastType = events[index].type; std::int32_t lastDuration = 0x80000000; - std::uint8_t lastNote = 0x80u; + std::uint8_t lastNote = 0x40u; if (events[index].time > 0) score++; @@ -844,7 +844,7 @@ int CalculateCompressionScore(std::vector<Event>& events, int index) lastType = events[i].type; if (events[i].time) - ++score; + score++; } return score; @@ -852,6 +852,12 @@ int CalculateCompressionScore(std::vector<Event>& events, int index) bool IsCompressionMatch(std::vector<Event>& events, int index1, int index2) { + if (events[index1].type != events[index2].type || + events[index1].note != events[index2].note || + events[index1].param1 != events[index2].param1 || + events[index1].time != events[index2].time) + return false; + index1++; index2++; |