openMSX
ImGuiSCCViewer.cc
Go to the documentation of this file.
1#include "ImGuiSCCViewer.hh"
2#include "MSXMotherBoard.hh"
3#include "MSXDevice.hh"
4#include "SoundDevice.hh"
5#include "MSXMixer.hh"
6#include "SCC.hh"
7
8namespace openmsx {
9
11 : ImGuiPart(manager_)
12{
13}
14
15
16void paintSCC(const SCC& scc);
17
19{
20 if (!show) return;
21 if (!motherBoard) return;
22
23 im::Window("SCC Viewer", &show, [&] {
24 bool noDevices = true;
25 for (auto& info: motherBoard->getMSXMixer().getDeviceInfos()) {
26 if (auto* device = dynamic_cast<SCC*>(info.device)) {
27 noDevices = false;
28 paintSCC(*device);
29 }
30 }
31 if (noDevices) {
32 ImGui::TextUnformatted("No SCC devices currently present in the system.");
33 }
34
35 });
36}
37
38void paintSCC(const SCC& scc) {
39 im::TreeNode(scc.getName().c_str(), ImGuiTreeNodeFlags_DefaultOpen, [&] {
40 const auto& waveData = scc.getWaveData();
41 for (auto [channelNr, channelWaveData] : enumerate(waveData)) {
42 auto getFloatData = [](void* data, int idx) {
43 return float(static_cast<const int8_t*>(data)[idx]);
44 };
45 const auto scale = 2.0f;
46 auto size = scale * gl::vec2{32.0f, 64.0f} + 2.0f * gl::vec2(ImGui::GetStyle().FramePadding);
47 ImGui::PlotHistogram("",
48 getFloatData,
49 const_cast<int8_t*>(channelWaveData.data()),
50 channelWaveData.size(),
51 0, nullptr,
52 -128.0f, 127.0f,
53 size);
54 if (channelNr < (waveData.size() - 1)) ImGui::SameLine();
55 }
56 });
57}
58
59} // namespace openmsx
ImGuiSCCViewer(ImGuiManager &manager)
void paint(MSXMotherBoard *motherBoard) override
const auto & getDeviceInfos() const
Definition MSXMixer.hh:141
const std::string & getName() const
Get the unique name that identifies this sound device.
void TextUnformatted(const std::string &str)
Definition ImGuiUtils.hh:24
void Window(const char *name, bool *p_open, ImGuiWindowFlags flags, std::invocable<> auto next)
Definition ImGuiCpp.hh:63
bool TreeNode(const char *label, ImGuiTreeNodeFlags flags, std::invocable<> auto next)
Definition ImGuiCpp.hh:302
This file implemented 3 utility functions:
Definition Autofire.cc:11
void paintSCC(const SCC &scc)