diff options
-rw-r--r-- | include/adlmidi.h | 3 | ||||
-rw-r--r-- | libADLMIDI-test.pro | 1 | ||||
-rw-r--r-- | src/adlmidi.cpp | 12 | ||||
-rw-r--r-- | src/adlmidi_midiplay.cpp | 45 | ||||
-rw-r--r-- | src/adlmidi_private.hpp | 8 | ||||
-rw-r--r-- | utils/midiplay/adlmidiplay.cpp | 9 |
6 files changed, 78 insertions, 0 deletions
diff --git a/include/adlmidi.h b/include/adlmidi.h index a1289a0..00f478b 100644 --- a/include/adlmidi.h +++ b/include/adlmidi.h @@ -270,6 +270,9 @@ extern void adl_positionRewind(struct ADL_MIDIPlayer *device); /*Set tempo multiplier: 1.0 - original tempo, >1 - play faster, <1 - play slower */ extern void adl_setTempo(struct ADL_MIDIPlayer *device, double tempo); +/*Get a textual description of the channel state. For display only.*/ +extern int adl_describeChannels(struct ADL_MIDIPlayer *device, char *text, char *attr, size_t size); + /*Close and delete ADLMIDI device*/ extern void adl_close(struct ADL_MIDIPlayer *device); diff --git a/libADLMIDI-test.pro b/libADLMIDI-test.pro index d26a5f5..d98d6bd 100644 --- a/libADLMIDI-test.pro +++ b/libADLMIDI-test.pro @@ -19,6 +19,7 @@ LIBS += -lSDL2 -lpthread -ldl #DEFINES += ADLMIDI_USE_DOSBOX_OPL #DEFINES += ENABLE_BEGIN_SILENCE_SKIPPING #DEFINES += DEBUG_TRACE_ALL_EVENTS +#DEFINES += DEBUG_TRACE_ALL_CHANNELS QMAKE_CFLAGS += -std=c90 -pedantic QMAKE_CXXFLAGS += -std=c++98 -pedantic diff --git a/src/adlmidi.cpp b/src/adlmidi.cpp index 32872ef..3a1923a 100644 --- a/src/adlmidi.cpp +++ b/src/adlmidi.cpp @@ -757,6 +757,18 @@ ADLMIDI_EXPORT void adl_setTempo(struct ADL_MIDIPlayer *device, double tempo) } +ADLMIDI_EXPORT int adl_describeChannels(struct ADL_MIDIPlayer *device, char *str, char *attr, size_t size) +{ + if(!device) + return -1; + MIDIplay *play = reinterpret_cast<MIDIplay *>(device->adl_midiPlayer); + if(!play) + return -1; + play->describeChannels(str, attr, size); + return 0; +} + + ADLMIDI_EXPORT const char *adl_metaMusicTitle(struct ADL_MIDIPlayer *device) { #ifndef ADLMIDI_DISABLE_MIDI_SEQUENCER diff --git a/src/adlmidi_midiplay.cpp b/src/adlmidi_midiplay.cpp index 9841f73..76d54ab 100644 --- a/src/adlmidi_midiplay.cpp +++ b/src/adlmidi_midiplay.cpp @@ -1722,6 +1722,51 @@ void MIDIplay::updateGlide(double amount) } } +void MIDIplay::describeChannels(char *str, char *attr, size_t size) +{ + if (!str || size <= 0) + return; + + OPL3 &synth = m_synth; + uint32_t numChannels = synth.m_numChannels; + + uint32_t index = 0; + for(uint32_t i = 0; index < numChannels && index < size - 1; ++i) + { + const AdlChannel &adlChannel = m_chipChannels[i]; + + AdlChannel::LocationData *loc = adlChannel.users_first; + if(!loc) // off + { + str[index++] = '-'; + } + else if(loc->next) // arpeggio + { + str[index++] = '@'; + } + else // on + { + switch(synth.m_channelCategory[i]) + { + case OPL3::ChanCat_Regular: + str[index++] = '+'; + break; + case OPL3::ChanCat_4op_Master: + case OPL3::ChanCat_4op_Slave: + str[index++] = '#'; + break; + default: // rhythm-mode percussion + str[index++] = 'r'; + break; + } + } + + attr[index] = '\0'; // TODO + } + + str[index] = 0; + attr[index] = 0; +} #ifndef ADLMIDI_DISABLE_CPP_EXTRAS diff --git a/src/adlmidi_private.hpp b/src/adlmidi_private.hpp index 7b59003..858e33d 100644 --- a/src/adlmidi_private.hpp +++ b/src/adlmidi_private.hpp @@ -1428,6 +1428,14 @@ public: * @return Offset of the MIDI Channels, multiple to 16 */ size_t chooseDevice(const std::string &name); + + /** + * @brief Gets a textual description of the state of chip channels + * @param text character pointer for text + * @param attr character pointer for text attributes + * @param size number of characters available to write + */ + void describeChannels(char *text, char *attr, size_t size); }; // I think, this is useless inside of Library diff --git a/utils/midiplay/adlmidiplay.cpp b/utils/midiplay/adlmidiplay.cpp index 78b1235..bd0e498 100644 --- a/utils/midiplay/adlmidiplay.cpp +++ b/utils/midiplay/adlmidiplay.cpp @@ -634,6 +634,15 @@ int main(int argc, char **argv) break; #endif + #ifdef DEBUG_TRACE_ALL_CHANNELS + enum { TerminalColumns = 80 }; + char channelText[TerminalColumns + 1]; + char channelAttr[TerminalColumns + 1]; + adl_describeChannels(myDevice, channelText, channelAttr, sizeof(channelText)); + std::fprintf(stdout, "%*s\r", TerminalColumns, ""); // erase the line + std::fprintf(stdout, "%s\n", channelText); + #endif + #ifndef DEBUG_TRACE_ALL_EVENTS double time_pos = adl_positionTell(myDevice); std::fprintf(stdout, " \r"); |