Skip to content

Commit

Permalink
Made visualization style for pulse configurable (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
micheldebree committed Sep 15, 2023
1 parent 31662fa commit ba56af0
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ BraceWrapping:
AfterExternBlock: true
BeforeCatch: false
BeforeElse: true
# BeforeLambdaBody: true
BeforeLambdaBody: true
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
Expand Down
16 changes: 11 additions & 5 deletions SIDFactoryII/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// The config.ini file contains the factory default settings. You can change these if you want, but it may be overwritten
// when you download and paste the next release. This is where the user.ini file comes in handy. If you want to make sure
// that your personal settings remain sticky, copy the changed entries to the user.ini file (you may have to create the
// file first). All entries in user.ini will always override the corresponding entries in the config.ini file.
// file first). All entries in user.ini will always override the corresponding entries in the config.ini file.
//
// A genuine settings dialog box is planned for a future release of SID Factory II.
//
Expand Down Expand Up @@ -48,18 +48,18 @@ Editor.Driver.Default = "sf2driver11_04_01.prg" // This determin
Editor.Skip.Intro = 0 // If you set this to 1, the black intro screen with logo and credits will never be shown.
Editor.Follow.Play = 0 // If you set this to 1, follow play is on by default.
Editor.Follow.Play = 0 // If you set this to 1, follow play is on by default.
Editor.Sequence.Highlights = 0 // If you set this to 1, sequence highlights are on by default.
Editor.Sequence.Highlights = 0 // If you set this to 1, sequence highlights are on by default.
Editor.Confirm.QuickSave = 1 // If you set this to 1, a confirmation dialog pops up when quick saving
// If set to 0, the quick save is performed without asking for confirmation
//
// PLAYBACK OPTIONS
//
Playback.StopEmulationIfDriverStops = 1 // If the driver stops (at the end of a jingle, for instance), setting this value to non-zero
Playback.StopEmulationIfDriverStops = 1 // If the driver stops (at the end of a jingle, for instance), setting this value to non-zero
// will stop the emulation and follow play also.
// Virtual piano keyboard layout
Expand All @@ -82,6 +82,12 @@ Window.Scaling = 1.0 // Scale window contents. Pixels
Window.Scaling.Smooth = 1 // If you set this to 1, scaling will smooth pixels.
// Set to 0 will use "nearest neighbour" scaling.
//
// Visualizers
//
Visualizer.PulseWidth.Style = 0 // The way pulse width is visualized
// 0 = absolute value, 1 = alternative style
//
// OVERLAY
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,30 @@
#include "runtime/editor/datasources/datasource_sidregistersbuffer.h"
#include "runtime/execution/executionhandler.h"
#include "runtime/execution/flightrecorder.h"
#include "utils/configfile.h"
#include "utils/global.h"
#include "utils/usercolors.h"

using namespace Foundation;
using namespace Utility;
using namespace Utility::Config;

namespace Editor
{
VisualizerComponentPulseFilterState::VisualizerComponentPulseFilterState
(
int inID,
Foundation::DrawField* inDrawField,
int inX,
int inY,
int inWidth,
int inHeight,
std::shared_ptr<DataSourceSIDRegistersBufferAfLastDriverUpdate> inDataSource
)
: VisualizerComponentBase(inID, inDrawField, inX, inY, inWidth, inHeight)
, m_DataSource(inDataSource)
int inID,
Foundation::DrawField* inDrawField,
int inX,
int inY,
int inWidth,
int inHeight,
std::shared_ptr<DataSourceSIDRegistersBufferAfLastDriverUpdate> inDataSource)
: VisualizerComponentBase(inID, inDrawField, inX, inY, inWidth, inHeight)
, m_DataSource(inDataSource)
{
ConfigFile& config_file = Global::instance().GetConfig();
m_PulseWidthStyle = GetSingleConfigurationValue<ConfigValueInt>(config_file, "Visualizer.PulseWidth.Style", 0);
}


Expand Down Expand Up @@ -64,7 +68,7 @@ namespace Editor

const auto get_pulse_value = [&data_source](unsigned int inChannel) -> unsigned short
{
if(inChannel > 2)
if (inChannel > 2)
return 0;

const unsigned int offset = inChannel * 7;
Expand All @@ -79,13 +83,13 @@ namespace Editor

const auto is_channel_filtered = [&data_source](unsigned int inChannel) -> bool
{
if(inChannel > 2)
if (inChannel > 2)
return false;

return (data_source[0x17] & (1 << inChannel)) != 0;
};

for(unsigned int i = 0; i < 3; ++i)
for (unsigned int i = 0; i < 3; ++i)
{
DrawBarWithCenterDivider(bar_x, bar_y, bar_width, bar_height, get_pulse_value(i), 0x0fff, is_channel_filtered(i) ? color_bar_filtered_channel : color_bar, color_bar_fill, color_background);
bar_y += bar_spacing;
Expand All @@ -107,18 +111,18 @@ namespace Editor


void VisualizerComponentPulseFilterState::DrawBar(
int inX,
int inY,
int inWidth,
int inHeight,
int inValue,
int inMaxValue,
const Foundation::Color& inBarColor,
const Foundation::Color& inBarColorFill)
int inX,
int inY,
int inWidth,
int inHeight,
int inValue,
int inMaxValue,
const Foundation::Color& inBarColor,
const Foundation::Color& inBarColorFill)
{
m_DrawField->DrawBox(inBarColor, inX, inY, inWidth, inHeight);

if(inValue > 0)
if (inValue > 0)
{
float width_fraction = static_cast<float>(inValue) / static_cast<float>(inMaxValue);
int width = static_cast<int>(static_cast<float>(inWidth) * (width_fraction < 0 ? 0 : (width_fraction > 1.0f ? 1.0f : width_fraction)));
Expand All @@ -129,26 +133,34 @@ namespace Editor


void VisualizerComponentPulseFilterState::DrawBarWithCenterDivider(
int inX,
int inY,
int inWidth,
int inHeight,
int inValue,
int inMaxValue,
const Foundation::Color& inBarColor,
const Foundation::Color& inBarColorFill,
const Foundation::Color& inDividerColor)
int inX,
int inY,
int inWidth,
int inHeight,
int inValue,
int inMaxValue,
const Foundation::Color& inBarColor,
const Foundation::Color& inBarColorFill,
const Foundation::Color& inDividerColor)
{
m_DrawField->DrawBox(inBarColor, inX, inY, inWidth, inHeight);

if(inValue > 0)
if (inValue > 0)
{
int abs_value = inValue > 0x800 ? 0x1000 - inValue : inValue;
float width_fraction = static_cast<float>(abs_value) / static_cast<float>(inMaxValue);
int width = static_cast<int>(static_cast<float>(inWidth) * (width_fraction < 0 ? 0 : (width_fraction > 1.0f ? 1.0f : width_fraction)));

int x = inValue > 0x800 ? inX + (inWidth - width) : inX;
m_DrawField->DrawBox(inBarColorFill, x, inY + 1, width, inHeight - 2);
if (m_PulseWidthStyle == 1)
{
int abs_value = inValue > 0x800 ? 0x1000 - inValue : inValue;
float width_fraction = static_cast<float>(abs_value) / static_cast<float>(inMaxValue);
int width = static_cast<int>(static_cast<float>(inWidth) * (width_fraction < 0 ? 0 : (width_fraction > 1.0f ? 1.0f : width_fraction)));
int x = inValue > 0x800 ? inX + (inWidth - width) : inX;
m_DrawField->DrawBox(inBarColorFill, x, inY + 1, width, inHeight - 2);
}
else
{
float width_fraction = static_cast<float>(inValue) / static_cast<float>(inMaxValue);
int width = static_cast<int>(static_cast<float>(inWidth) * (width_fraction < 0 ? 0 : (width_fraction > 1.0f ? 1.0f : width_fraction)));
m_DrawField->DrawBox(inBarColorFill, inX, inY + 1, width, inHeight - 2);
}
}

m_DrawField->DrawVerticalLine(inDividerColor, inX + inWidth / 2, inY, inY + inHeight);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ namespace Editor
{
public:
VisualizerComponentPulseFilterState(
int inID,
Foundation::DrawField* inDrawField,
int inX,
int inY,
int inWidth,
int inID,
Foundation::DrawField* inDrawField,
int inX,
int inY,
int inWidth,
int inHeight,
std::shared_ptr<DataSourceSIDRegistersBufferAfLastDriverUpdate> inDataSource
);
Expand Down Expand Up @@ -50,7 +50,8 @@ namespace Editor
const Foundation::Color& inBarColor,
const Foundation::Color& inBarColorFill,
const Foundation::Color& inDividerColor);

std::shared_ptr<DataSourceSIDRegistersBufferAfLastDriverUpdate> m_DataSource;
int m_PulseWidthStyle;
};
}
7 changes: 7 additions & 0 deletions dist/documentation/user.default.ini
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ Window.Scaling = 1.0 // Scale window contents. Pixels
// (or accept the glitch).
Window.Scaling.Smooth = 1 // If you set this to 1, scaling will smooth pixels.
// Set to 0 will use "nearest neighbour" scaling.

//
// Visualizers
//
Visualizer.PulseWidth.Style = 0 // The way pulse width is visualized
// 0 = absolute value, 1 = alternative style

//
// OVERLAY
//
Expand Down

0 comments on commit ba56af0

Please sign in to comment.