view DPF-Prymula-audioplugins/plugins/CloneChannel/DistrhoUICloneChannel.cpp @ 10:4dc186728822

immposiblerush-0.230919-2
author prymula <prymula76@outlook.com>
date Sun, 04 Feb 2024 23:27:00 +0100
parents 84e66ea83026
children
line wrap: on
line source

/*
 * DISTRHO CloneChannel - Copyright (C) 2023 Przemysław R. Pietraszczyk
 * Based  on DPF'ied SoulForce.
 * Copyright (C) 2006 Niall Moody
 * Copyright (C) 2015-2021 Filipe Coelho <falktx@falktx.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */

#include "DistrhoUICloneChannel.hpp"
#include "DistrhoPluginCloneChannel.hpp"

START_NAMESPACE_DISTRHO

namespace Art = DistrhoArtworkCloneChannel;

// -----------------------------------------------------------------------  
DistrhoUICloneChannel::DistrhoUICloneChannel()
    : UI(Art::backgroundWidth, Art::backgroundHeight, true),
      fImgBackground(Art::backgroundData, Art::backgroundWidth, Art::backgroundHeight, kImageFormatBGR)
{
    // switches
    fSwitchSource = new ImageSwitch(this,
                        Image(Art::switch_leftData, Art::switch_leftWidth, Art::switch_leftHeight, kImageFormatBGR),
                        Image(Art::switch_rightData, Art::switch_rightWidth, Art::switch_rightHeight, kImageFormatBGR));
    fSwitchSource->setId(DistrhoPluginCloneChannel::kParameterSource);
    fSwitchSource->setAbsolutePos(116, 191);
    fSwitchSource->setCallback(this);
    
    fSwitchSource2 = new ImageSwitch(this,
                        Image(Art::switch_leftData, Art::switch_leftWidth, Art::switch_leftHeight, kImageFormatBGR),
                        Image(Art::switch_rightData, Art::switch_rightWidth, Art::switch_rightHeight, kImageFormatBGR));
    fSwitchSource2->setId(DistrhoPluginCloneChannel::kParameterSource2);
    fSwitchSource2->setAbsolutePos(116, 251);
    fSwitchSource2->setCallback(this);

    // set initial values
    programLoaded(0);
}

// -----------------------------------------------------------------------
// DSP Callbacks

void DistrhoUICloneChannel::parameterChanged(uint32_t index, float value)
{
    switch (index)
    {
    case DistrhoPluginCloneChannel::kParameterSource:
        fSwitchSource->setDown(value > 0.5f);
        break;
    case DistrhoPluginCloneChannel::kParameterSource2:
        fSwitchSource2->setDown(value > 0.5f);
        break;
    }
}

void DistrhoUICloneChannel::programLoaded(uint32_t index)
{
    switch(index)
    {
    case DistrhoPluginCloneChannel::kProgramDefault:
        fSwitchSource->setDown(false);
        fSwitchSource2->setDown(false);
        break;
    case DistrhoPluginCloneChannel::kProgramStayDown:
        fSwitchSource->setDown(false);
        fSwitchSource2->setDown(false);
        break;
    case DistrhoPluginCloneChannel::kProgramLookingForTheWorld:
        fSwitchSource->setDown(false);
        fSwitchSource2->setDown(false);
        break;
    case DistrhoPluginCloneChannel::kProgramGuerillaLove:
        fSwitchSource->setDown(false);
        fSwitchSource2->setDown(false);
        break;
    case DistrhoPluginCloneChannel::kProgramTumbleToThePower:
        fSwitchSource->setDown(false);
        fSwitchSource2->setDown(false);
        break;
    case DistrhoPluginCloneChannel::kProgramDoYourselfFavour:
        fSwitchSource->setDown(true);
        fSwitchSource2->setDown(true);
        break;
    case DistrhoPluginCloneChannel::kProgramPastIsPast:
        fSwitchSource->setDown(true);
        fSwitchSource2->setDown(true);
        break;
    case DistrhoPluginCloneChannel::kProgramYouAndOnlyYou:
        fSwitchSource->setDown(false);
        fSwitchSource2->setDown(false);
        break;
    case DistrhoPluginCloneChannel::kProgramCloneChannel:
        fSwitchSource->setDown(true);
        fSwitchSource2->setDown(true);
        break;
    }
}

// -----------------------------------------------------------------------
// Widget Callbacks
void DistrhoUICloneChannel::imageSwitchClicked(ImageSwitch* imageSwitch, bool down)
{
    const uint buttonId(imageSwitch->getId());

    editParameter(buttonId, true);
    setParameterValue(buttonId, down ? 1.0f : 0.0f);
    editParameter(buttonId, false);
}

void DistrhoUICloneChannel::onDisplay()
{
    const GraphicsContext& context(getGraphicsContext());

    fImgBackground.draw(context);
}

// -----------------------------------------------------------------------

UI* createUI()
{
    return new DistrhoUICloneChannel();
}

// -----------------------------------------------------------------------

END_NAMESPACE_DISTRHO