-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
52200c9
commit 43f10ba
Showing
16 changed files
with
428 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
#include "ChannelLinkView.h" | ||
#include "../lookAndFeel/LookAndFeelFactory.h" | ||
#include "../misc/RCManager.h" | ||
#include "../Utils.h" | ||
|
||
ChannelLinkViewContent::ChannelLinkViewContent( | ||
const std::function<void(int, int, bool)>& callback, | ||
const juce::Array<std::tuple<int, int>>& initList, | ||
const juce::AudioChannelSet& srcChannels, const juce::AudioChannelSet& dstChannels, | ||
int srcChannelNum, int dstChannelNum, const juce::String& srcName, const juce::String& dstName, | ||
bool initIfEmpty) : callback(callback), srcChannels(srcChannels), dstChannels(dstChannels), | ||
srcChannelNum(srcChannelNum), dstChannelNum(dstChannelNum), | ||
srcName(srcName), dstName(dstName) { | ||
/** Create Temp */ | ||
this->temp.setRange(0, srcChannelNum * dstChannelNum, false); | ||
for (auto& [srcc, dstc] : initList) { | ||
this->temp.setBit(srcc * dstChannelNum + dstc); | ||
} | ||
|
||
/** Init If Empty */ | ||
if (initIfEmpty && initList.isEmpty()) { | ||
int channelNum = std::min(srcChannelNum, dstChannelNum); | ||
for (int i = 0; i < channelNum; i++) { | ||
this->setLink(i, i, true); | ||
} | ||
} | ||
|
||
/** Change Size */ | ||
auto size = this->getPreferedSize(); | ||
this->setBounds(0, 0, size.getX(), size.getY()); | ||
} | ||
|
||
juce::Point<int> ChannelLinkViewContent::getPreferedSize() const { | ||
auto screenSize = utils::getScreenSize(this); | ||
int paddingWidth = screenSize.getWidth() * 0.05; | ||
int paddingHeight = screenSize.getHeight() * 0.05; | ||
int titleWidth = screenSize.getWidth() * 0.05; | ||
int titleHeight = screenSize.getHeight() * 0.05; | ||
int cellWidth = screenSize.getWidth() * 0.025; | ||
int cellHeight = cellWidth; | ||
|
||
return { paddingWidth * 2 + titleWidth + cellWidth * (this->dstChannelNum + 2), | ||
paddingHeight * 2 + titleHeight + cellHeight * (this->srcChannelNum + 2) }; | ||
} | ||
|
||
void ChannelLinkViewContent::paint(juce::Graphics& g) { | ||
/** TODO */ | ||
} | ||
|
||
bool ChannelLinkViewContent::checkLink(int srcc, int dstc) { | ||
return this->temp[srcc * this->dstChannelNum + dstc]; | ||
} | ||
|
||
void ChannelLinkViewContent::setLink(int srcc, int dstc, bool link) { | ||
if (link) { | ||
this->temp.setBit(srcc * this->dstChannelNum + dstc); | ||
} | ||
else { | ||
this->temp.clearBit(srcc * this->dstChannelNum + dstc); | ||
} | ||
this->callback(srcc, dstc, link); | ||
} | ||
|
||
ChannelLinkView::ChannelLinkView( | ||
const std::function<void(int, int, bool)>& callback, | ||
const juce::Array<std::tuple<int, int>>& initList, | ||
const juce::AudioChannelSet& srcChannels, const juce::AudioChannelSet& dstChannels, | ||
int srcChannelNum, int dstChannelNum, const juce::String& srcName, const juce::String& dstName, | ||
bool initIfEmpty) | ||
: DocumentWindow(TRANS("Audio Channel Link"), juce::LookAndFeel::getDefaultLookAndFeel().findColour( | ||
juce::ResizableWindow::ColourIds::backgroundColourId), | ||
juce::DocumentWindow::closeButton, true) { | ||
this->setUsingNativeTitleBar(true); | ||
this->setResizable(true, false); | ||
|
||
/** Look And Feel */ | ||
this->setLookAndFeel( | ||
LookAndFeelFactory::getInstance()->forChannelLink()); | ||
|
||
/** Content */ | ||
this->content = std::make_unique<juce::Viewport>(TRANS("Channel Link")); | ||
this->content->setViewedComponent(new ChannelLinkViewContent{ | ||
callback, initList, srcChannels, dstChannels, | ||
srcChannelNum, dstChannelNum, srcName, dstName, initIfEmpty | ||
}); | ||
this->content->setScrollOnDragMode( | ||
juce::Viewport::ScrollOnDragMode::nonHover); | ||
this->setContentNonOwned(this->content.get(), false); | ||
|
||
/** Icon */ | ||
auto icon = RCManager::getInstance()->loadImage( | ||
utils::getResourceFile("logo.png")); | ||
this->setIcon(icon); | ||
this->getPeer()->setIcon(icon); | ||
|
||
/** Resize */ | ||
this->centreWithSize(800, 600); | ||
juce::MessageManager::callAsync( | ||
[comp = juce::Component::SafePointer(this)] { | ||
if (comp) { | ||
auto screenSize = utils::getScreenSize(comp); | ||
int width = screenSize.getWidth() / 2; | ||
int height = screenSize.getHeight() / 2; | ||
|
||
if (auto content = dynamic_cast<ChannelLinkViewContent*>( | ||
comp->content->getViewedComponent())) { | ||
auto size = content->getPreferedSize(); | ||
width = std::min(width, size.getX()); | ||
height = std::min(height, size.getY()); | ||
} | ||
|
||
comp->centreWithSize(width, height); | ||
} | ||
} | ||
); | ||
} | ||
|
||
void ChannelLinkView::paint(juce::Graphics& g) { | ||
/** Color */ | ||
auto& laf = this->getLookAndFeel(); | ||
juce::Colour backgroundColor = laf.findColour( | ||
juce::ResizableWindow::ColourIds::backgroundColourId); | ||
|
||
/** Background */ | ||
g.setColour(backgroundColor); | ||
g.fillAll(); | ||
} | ||
|
||
|
||
void ChannelLinkView::closeButtonPressed() { | ||
this->exitModalState(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#pragma once | ||
|
||
#include <JuceHeader.h> | ||
|
||
class ChannelLinkViewContent final : public juce::Component { | ||
public: | ||
ChannelLinkViewContent() = delete; | ||
ChannelLinkViewContent(const std::function<void(int, int, bool)>& callback, | ||
const juce::Array<std::tuple<int, int>>& initList, | ||
const juce::AudioChannelSet& srcChannels, const juce::AudioChannelSet& dstChannels, | ||
int srcChannelNum, int dstChannelNum, const juce::String& srcName, const juce::String& dstName, | ||
bool initIfEmpty); | ||
|
||
juce::Point<int> getPreferedSize() const; | ||
|
||
void paint(juce::Graphics& g) override; | ||
|
||
private: | ||
const std::function<void(int, int, bool)> callback; | ||
const juce::AudioChannelSet srcChannels, dstChannels; | ||
const int srcChannelNum, dstChannelNum; | ||
const juce::String srcName, dstName; | ||
|
||
juce::BigInteger temp; | ||
|
||
bool checkLink(int srcc, int dstc); | ||
void setLink(int srcc, int dstc, bool link); | ||
|
||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ChannelLinkViewContent) | ||
}; | ||
|
||
class ChannelLinkView final : public juce::DocumentWindow { | ||
public: | ||
ChannelLinkView() = delete; | ||
ChannelLinkView(const std::function<void(int, int, bool)>& callback, | ||
const juce::Array<std::tuple<int, int>>& initList, | ||
const juce::AudioChannelSet& srcChannels, const juce::AudioChannelSet& dstChannels, | ||
int srcChannelNum, int dstChannelNum, const juce::String& srcName, const juce::String& dstName, | ||
bool initIfEmpty); | ||
|
||
void paint(juce::Graphics& g) override; | ||
|
||
private: | ||
void closeButtonPressed() override; | ||
|
||
private: | ||
std::unique_ptr<juce::Viewport> content = nullptr; | ||
|
||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ChannelLinkView) | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.