Skip to content

Commit

Permalink
Add Dimmer tab to Moving Head Effect
Browse files Browse the repository at this point in the history
  • Loading branch information
AzGilrock committed Apr 27, 2024
1 parent bd95ba9 commit 209a6a8
Show file tree
Hide file tree
Showing 17 changed files with 650 additions and 8 deletions.
2 changes: 1 addition & 1 deletion macOS
32 changes: 32 additions & 0 deletions xLights/effects/MovingHeadEffect.cpp
Expand Up @@ -150,9 +150,11 @@ void MovingHeadEffect::RenderMovingHead(std::string mh_settings, int loc, const
bool pan_path_active = true;
bool tilt_path_active = true;
bool has_color_wheel = false;
bool has_dimmers = false;
std::string path_setting = "";
wxArrayString heads;
wxArrayString colors;
wxArrayString dimmers;
int groupings = 1;
wxArrayString all_cmds = wxSplit(mh_settings, ';');

Expand Down Expand Up @@ -231,6 +233,9 @@ void MovingHeadEffect::RenderMovingHead(std::string mh_settings, int loc, const
} else if( cmd_type == "Wheel" ) {
colors = wxSplit(settings, ',');
has_color_wheel = true;
} else if( cmd_type == "Dimmer" ) {
dimmers = wxSplit(settings, ',');
has_dimmers = true;
}
}

Expand All @@ -252,6 +257,11 @@ void MovingHeadEffect::RenderMovingHead(std::string mh_settings, int loc, const
WriteCmdToPixel(mhead->GetPanMotor(), pan_cmd, buffer);
WriteCmdToPixel(mhead->GetTiltMotor(), tilt_cmd, buffer);

if (has_dimmers && mhead->HasDimmerChannel()) {
uint32_t dimmer_channel = mhead->GetMHDimmerChannel();
CalculateDimmer(eff_pos, dimmers, dimmer_channel, buffer);
}

if( mhead->HasColorAbility() ) {
DmxColorAbility* mh_color = mhead->GetColorAbility();
if (mh_color != nullptr) {
Expand Down Expand Up @@ -331,6 +341,28 @@ xlColor MovingHeadEffect::GetWheelColor(double eff_pos, const wxArrayString& col
return c1;
}

void MovingHeadEffect::CalculateDimmer(double eff_pos, wxArrayString& dimmers, uint32_t dimmer_channel, RenderBuffer &buffer)
{
ValueCurve vc;
unsigned long num_pts = dimmers.size() / 2;
for( int i = 0; i < num_pts; ++i ) {
double x { wxAtof(dimmers[i*2]) };
double y { wxAtof(dimmers[i*2+1]) };
vc.SetValueAt( x, y );
}
vc.SetType("Custom");
vc.SetLimits(0, 255);
vc.SetActive(true);

uint8_t value = vc.GetOutputValueAtDivided(eff_pos, buffer.GetStartTimeMS(), buffer.GetEndTimeMS());

xlColor msb_c = xlBLACK;
msb_c.red = value;
msb_c.green = value;
msb_c.blue = value;

buffer.SetPixel(dimmer_channel - 1, 0, msb_c, false, false, true);
}

void MovingHeadEffect::GetValueCurvePosition(float& position, const std::string& settings, double eff_pos, RenderBuffer &buffer)
{
Expand Down
1 change: 1 addition & 0 deletions xLights/effects/MovingHeadEffect.h
Expand Up @@ -125,4 +125,5 @@ class MovingHeadEffect : public RenderableEffect
void GetValueCurvePosition(float& position, const std::string& settings, double eff_pos, RenderBuffer &buffer);
void CalculatePosition(int location, float& position, wxArrayString& heads, int groupings, float offset, float& delta );
void CalculatePathPositions(bool pan_path_active, bool tilt_path_active, float& pan_pos, float& tilt_pos, float time_offset, float path_scale, float delta, double eff_pos, const std::string& path_def);
void CalculateDimmer(double eff_pos, wxArrayString&dimmers, uint32_t dimmer_channel, RenderBuffer &buffer);
};
64 changes: 64 additions & 0 deletions xLights/effects/MovingHeadPanel.cpp
Expand Up @@ -75,6 +75,7 @@ const long MovingHeadPanel::ID_SLIDER_MHCycles = wxNewId();
const long MovingHeadPanel::IDD_TEXTCTRL_MHCycles = wxNewId();
const long MovingHeadPanel::ID_BUTTON_SavePreset = wxNewId();
const long MovingHeadPanel::ID_PANEL_Position = wxNewId();
const long MovingHeadPanel::ID_PANEL_Dimmer = wxNewId();
const long MovingHeadPanel::ID_BUTTON_MHPathContinue = wxNewId();
const long MovingHeadPanel::ID_BUTTON_MHPathClear = wxNewId();
const long MovingHeadPanel::ID_BUTTON_MHPathClose = wxNewId();
Expand Down Expand Up @@ -132,6 +133,7 @@ MovingHeadPanel::MovingHeadPanel(wxWindow* parent) : xlEffectPanel(parent)
wxFlexGridSizer* FlexGridSizerColorWheelSliders;
wxFlexGridSizer* FlexGridSizerControl;
wxFlexGridSizer* FlexGridSizerCycles;
wxFlexGridSizer* FlexGridSizerDimmer;
wxFlexGridSizer* FlexGridSizerFixtures;
wxFlexGridSizer* FlexGridSizerFixturesLabel;
wxFlexGridSizer* FlexGridSizerFixturesSelection;
Expand Down Expand Up @@ -273,6 +275,16 @@ MovingHeadPanel::MovingHeadPanel(wxWindow* parent) : xlEffectPanel(parent)
PanelPosition->SetSizer(FlexGridSizerPosition);
FlexGridSizerPosition->Fit(PanelPosition);
FlexGridSizerPosition->SetSizeHints(PanelPosition);
PanelDimmer = new wxPanel(Notebook1, ID_PANEL_Dimmer, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T("ID_PANEL_Dimmer"));
FlexGridSizerDimmer = new wxFlexGridSizer(0, 1, 0, 0);
FlexGridSizerDimmer->AddGrowableCol(0);
FlexGridSizerDimmerCanvas = new wxFlexGridSizer(1, 1, 0, 0);
FlexGridSizerDimmerCanvas->AddGrowableCol(0);
FlexGridSizerDimmerCanvas->AddGrowableRow(0);
FlexGridSizerDimmer->Add(FlexGridSizerDimmerCanvas, 1, wxTOP|wxLEFT|wxRIGHT|wxEXPAND, 5);
PanelDimmer->SetSizer(FlexGridSizerDimmer);
FlexGridSizerDimmer->Fit(PanelDimmer);
FlexGridSizerDimmer->SetSizeHints(PanelDimmer);
PanelPathing = new wxPanel(Notebook1, ID_PANEL_Pathing, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T("ID_PANEL_Pathing"));
FlexGridSizerPathing = new wxFlexGridSizer(0, 1, 0, 0);
FlexGridSizerPathing->AddGrowableCol(0);
Expand Down Expand Up @@ -378,6 +390,7 @@ MovingHeadPanel::MovingHeadPanel(wxWindow* parent) : xlEffectPanel(parent)
FlexGridSizer1->Fit(PanelStatus);
FlexGridSizer1->SetSizeHints(PanelStatus);
Notebook1->AddPage(PanelPosition, _("Position"), false);
Notebook1->AddPage(PanelDimmer, _("Dimmer"), false);
Notebook1->AddPage(PanelPathing, _("Pathing"), false);
Notebook1->AddPage(PanelControl, _("Control"), false);
Notebook1->AddPage(PanelStatus, _("Status"), false);
Expand Down Expand Up @@ -440,6 +453,8 @@ MovingHeadPanel::MovingHeadPanel(wxWindow* parent) : xlEffectPanel(parent)
// canvas
m_movingHeadCanvasPanel = new MovingHeadCanvasPanel(this, PanelPosition, wxID_ANY, wxDefaultPosition, wxSize(250, 250));
FlexGridSizerPositionCanvas->Add(m_movingHeadCanvasPanel, 0, wxALL | wxEXPAND);
m_movingHeadDimmerPanel = new MovingHeadDimmerPanel(this, PanelDimmer, wxID_ANY, wxDefaultPosition, wxSize(250, 125));
FlexGridSizerDimmerCanvas->Add(m_movingHeadDimmerPanel, 0, wxALL | wxEXPAND);
m_sketchCanvasPanel = new SketchCanvasPanel(this, PanelPathing, wxID_ANY, wxDefaultPosition, wxSize(250, 250));
FlexGridSizerPathCanvas->Add(m_sketchCanvasPanel, 0, wxALL | wxEXPAND);

Expand Down Expand Up @@ -1035,6 +1050,7 @@ static std::list<std::string> possettings = {"Heads", "Pan", "Tilt", "PanOffset"
"Pan VC", "Tilt VC", "PanOffset VC", "TiltOffset VC", "Groupings VC"};
static std::list<std::string> pathsettings = {"Path", "PathScale", "TimeOffset", "IgnorePan", "IgnoreTilt", "PathScale VC", "TimeOffset VC" };
static std::list<std::string> colorsettings = {"Color", "Wheel" };
static std::list<std::string> dimmersettings = {"Dimmer" };

void MovingHeadPanel::UpdateMHSettings()
{
Expand Down Expand Up @@ -1204,6 +1220,38 @@ void MovingHeadPanel::UpdatePathSettings()
}
}

void MovingHeadPanel::UpdateDimmerSettings()
{
if( recall ) return;

std::string dimmer_text{xlEMPTY_STRING};

RemoveSettings(dimmersettings);

if( m_movingHeadDimmerPanel != nullptr ) {
dimmer_text = m_movingHeadDimmerPanel->GetDimmerCommands();
}

if( dimmer_text != xlEMPTY_STRING ) {
for( int i = 1; i <= 8; ++i ) {
wxString checkbox_ctrl = wxString::Format("IDD_CHECKBOX_MH%d", i);
wxCheckBox* checkbox = (wxCheckBox*)(this->FindWindowByName(checkbox_ctrl));
if( checkbox != nullptr ) {
if( checkbox->IsChecked() ) {
wxString textbox_ctrl = wxString::Format("ID_TEXTCTRL_MH%d_Settings", i);
wxTextCtrl* mh_textbox = (wxTextCtrl*)(this->FindWindowByName(textbox_ctrl));
if( mh_textbox != nullptr ) {
std::string mh_settings = mh_textbox->GetValue();
mh_settings += ";";
mh_settings += dimmer_text;
mh_textbox->SetValue(mh_settings);
}
}
}
}
}
}

void MovingHeadPanel::UpdateStatusPanel()
{
std::string all_settings = xlEMPTY_STRING;
Expand All @@ -1219,6 +1267,7 @@ void MovingHeadPanel::UpdateStatusPanel()
bool pos_set = false;
bool path_set = false;
bool color_set = false;
bool dimmer_set = false;
for (size_t j = 0; j < all_cmds.size(); ++j )
{
std::string cmd = all_cmds[j];
Expand All @@ -1231,6 +1280,8 @@ void MovingHeadPanel::UpdateStatusPanel()
path_set = true;
} else if (cmd_type == "Color") {
color_set = true;
} else if (cmd_type == "Dimmer") {
dimmer_set = true;
}
}
if (pos_set) {
Expand Down Expand Up @@ -1259,6 +1310,9 @@ void MovingHeadPanel::UpdateStatusPanel()
if (color_set) {
all_settings += "Color: Active\n";
}
if (dimmer_set) {
all_settings += "Dimmer: Active\n";
}
all_settings += "\n";
}
}
Expand Down Expand Up @@ -1658,6 +1712,12 @@ void MovingHeadPanel::NotifyColorUpdated()
FireChangeEvent();
}

void MovingHeadPanel::NotifyDimmerUpdated()
{
UpdateDimmerSettings();
FireChangeEvent();
}

void MovingHeadPanel::OnCheckBox_MHClick(wxCommandEvent& event)
{
// update color panels since selected heads changed
Expand Down Expand Up @@ -1775,6 +1835,10 @@ void MovingHeadPanel::RecallSettings(const std::string mh_settings)
if( m_wheelColorPanel != nullptr ) {
m_wheelColorPanel->SetColours(settings);
}
} else if( cmd_type == "Dimmer" ) {
if( m_movingHeadDimmerPanel != nullptr ) {
m_movingHeadDimmerPanel->SetDimmerCommands(settings);
}
}
}
float pan = 0.0f;
Expand Down
15 changes: 13 additions & 2 deletions xLights/effects/MovingHeadPanel.h
Expand Up @@ -29,6 +29,7 @@
#include "EffectPanelUtils.h"
#include "MovingHeadPanels/MHColorPanel.h"
#include "MovingHeadPanels/MovingHeadCanvasPanel.h"
#include "MovingHeadPanels/MovingHeadDimmerPanel.h"
#include "MovingHeadPanels/MHRgbPickerPanel.h"
#include "MovingHeadPanels/MHColorWheelPanel.h"
#include "assist/SketchCanvasPanel.h"
Expand All @@ -41,8 +42,12 @@ class Model;
class MHPresetBitmapButton;
class MHPathPresetBitmapButton;

class MovingHeadPanel: public xlEffectPanel, public IMovingHeadCanvasParent, public ISketchCanvasParent,
public IMHRgbPickerPanelParent, public IMHColorWheelPanelParent
class MovingHeadPanel: public xlEffectPanel,
public IMovingHeadCanvasParent,
public IMovingHeadDimmerParent,
public ISketchCanvasParent,
public IMHRgbPickerPanelParent,
public IMHColorWheelPanelParent
{
public:

Expand Down Expand Up @@ -90,6 +95,7 @@ class MovingHeadPanel: public xlEffectPanel, public IMovingHeadCanvasParent, pub
wxCheckBox* CheckBox_MH8;
wxFlexGridSizer* FlexGridSizerColor;
wxFlexGridSizer* FlexGridSizerColorWheel;
wxFlexGridSizer* FlexGridSizerDimmerCanvas;
wxFlexGridSizer* FlexGridSizerPathCanvas;
wxFlexGridSizer* FlexGridSizerPathPresets;
wxFlexGridSizer* FlexGridSizerPathing;
Expand All @@ -102,6 +108,7 @@ class MovingHeadPanel: public xlEffectPanel, public IMovingHeadCanvasParent, pub
wxPanel* PanelColor;
wxPanel* PanelColorWheel;
wxPanel* PanelControl;
wxPanel* PanelDimmer;
wxPanel* PanelPathing;
wxPanel* PanelPosition;
wxPanel* PanelStatus;
Expand Down Expand Up @@ -167,6 +174,7 @@ class MovingHeadPanel: public xlEffectPanel, public IMovingHeadCanvasParent, pub
static const long IDD_TEXTCTRL_MHCycles;
static const long ID_BUTTON_SavePreset;
static const long ID_PANEL_Position;
static const long ID_PANEL_Dimmer;
static const long ID_BUTTON_MHPathContinue;
static const long ID_BUTTON_MHPathClear;
static const long ID_BUTTON_MHPathClose;
Expand Down Expand Up @@ -231,6 +239,7 @@ class MovingHeadPanel: public xlEffectPanel, public IMovingHeadCanvasParent, pub
void UpdateMHSettings();
void UpdateColorSettings();
void UpdatePathSettings();
void UpdateDimmerSettings();
void UpdateStatusPanel();
void RemoveSettings(std::list<std::string>& settings);
void AddSetting(const std::string& name, const std::string& ctrl_name, std::string& mh_settings);
Expand Down Expand Up @@ -267,6 +276,7 @@ class MovingHeadPanel: public xlEffectPanel, public IMovingHeadCanvasParent, pub
std::vector<MHPathPresetBitmapButton*> path_presets;

MovingHeadCanvasPanel* m_movingHeadCanvasPanel = nullptr;
MovingHeadDimmerPanel* m_movingHeadDimmerPanel = nullptr;
MHRgbPickerPanel* m_rgbColorPanel = nullptr;
MHColorWheelPanel* m_wheelColorPanel = nullptr;

Expand All @@ -286,6 +296,7 @@ class MovingHeadPanel: public xlEffectPanel, public IMovingHeadCanvasParent, pub

void NotifyPositionUpdated() override;
void NotifyColorUpdated() override;
void NotifyDimmerUpdated() override;

private:
bool canContinuePath() const;
Expand Down

0 comments on commit 209a6a8

Please sign in to comment.