| 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 |
|
| 11 |
namespace openmsx { |
| 12 |
|
| 13 |
ImGuiSCCViewer::ImGuiSCCViewer(ImGuiManager& manager_) |
| 14 |
: ImGuiPart(manager_) |
| 15 |
{ |
| 16 |
} |
| 17 |
|
| 18 |
static 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 |
|
| 40 |
void 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 (const 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 |
} |