| e8555c89 Andy McCall |
1 |
#ifndef IMGUI_MSXMUSICVIEWER_HH |
| 2 |
#define IMGUI_MSXMUSICVIEWER_HH |
| 3 |
|
| 4 |
#include "ImGuiPart.hh" |
| 5 |
|
| 6 |
#include <array> |
| 7 |
#include <cstdint> |
| 8 |
#include <functional> |
| 9 |
#include <span> |
| 10 |
#include <vector> |
| 11 |
|
| 12 |
namespace openmsx { |
| 13 |
|
| 14 |
class YM2413; |
| 15 |
|
| 16 |
class ImGuiMsxMusicViewer final : public ImGuiPart |
| 17 |
{ |
| 18 |
public: |
| 19 |
explicit ImGuiMsxMusicViewer(ImGuiManager& manager); |
| 20 |
void paint(MSXMotherBoard* motherBoard) override; |
| 21 |
|
| 22 |
private: |
| 23 |
struct Hover { |
| 24 |
Hover() = default; |
| 25 |
Hover(int r, uint8_t m) : reg(uint8_t(r)), mask(m) {} |
| 26 |
|
| 27 |
uint8_t reg = 255; |
| 28 |
uint8_t mask = 0; |
| 29 |
|
| 30 |
[[nodiscard]] bool match(const Hover& h) const { |
| 31 |
return h.reg == reg && ((h.mask & mask) != 0); |
| 32 |
} |
| 33 |
}; |
| 34 |
struct Hovers { |
| 35 |
Hovers() = default; |
| 36 |
explicit(false) Hovers(Hover h) : h1(h) {} |
| 37 |
Hovers(int r, uint8_t m) : h1(r, m) {} |
| 38 |
Hovers(int r1, uint8_t m1, int r2, uint8_t m2) : h1(r1, m1), h2(r2, m2) {} |
| 39 |
|
| 40 |
Hover h1, h2; |
| 41 |
|
| 42 |
[[nodiscard]] bool match(const Hovers& h) const { |
| 43 |
return h1.match(h.h1) || h1.match(h.h2) || |
| 44 |
h2.match(h.h1) || h2.match(h.h2); |
| 45 |
} |
| 46 |
}; |
| 47 |
using HoverList = std::vector<Hovers>; |
| 48 |
[[nodiscard]] static bool match(const HoverList& list, Hovers hovers); |
| 49 |
|
| 50 |
static constexpr int historySize = 60; |
| 51 |
struct ChipState { |
| 52 |
std::array<std::array<float, historySize>, 9 + 5> keyHistory = {}; |
| 53 |
HoverList hoverList; |
| 54 |
int selectedInstr = 0; |
| 55 |
}; |
| 56 |
|
| 57 |
void drawCell(ChipState& cs, HoverList& newHoverList, std::span<const uint8_t> regs, Hovers hovers, |
| 58 |
std::function<void(uint32_t)> func, |
| 59 |
float highlightWidth = 0.0f, gl::vec2* getPos = nullptr); |
| 60 |
|
| 61 |
void paintMelodicChannel(ChipState& cs, HoverList& newHoverList, std::span<const uint8_t, 64> regs, int ch); |
| 62 |
void paintRhythmChannel(ChipState& cs, HoverList& newHoverList, std::span<const uint8_t, 64> regs, int ch); |
| 63 |
void paintChannels(ChipState& cs, HoverList& newHoverList, std::span<const uint8_t, 64> regs); |
| 64 |
void paintInstrument(ChipState& cs, HoverList& newHoverList, std::span<const uint8_t, 64> regs); |
| 65 |
void paintRegisters(ChipState& cs, HoverList& newHoverList, std::span<const uint8_t, 64> regs); |
| 66 |
void paintMsxMusic(const YM2413& ym2413); |
| 67 |
|
| 68 |
public: |
| 69 |
bool show = false; |
| 70 |
|
| 71 |
private: |
| 72 |
std::map<std::string, ChipState, std::less<>> chips; |
| 73 |
}; |
| 74 |
|
| 75 |
} |
| 76 |
|
| 77 |
#endif |