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