Skip to content

Commit

Permalink
Add seq block name
Browse files Browse the repository at this point in the history
  • Loading branch information
FangCunWuChang committed May 11, 2024
1 parent 5a06741 commit cee590a
Show file tree
Hide file tree
Showing 17 changed files with 192 additions and 3 deletions.
26 changes: 26 additions & 0 deletions src/audioCore/graph/SeqSourceProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,14 @@ void SeqSourceProcessor::initAudio(double sampleRate, double length) {
/** Update Resample Source */
this->updateAudioResampler();

/** Update Name */
this->audioName = juce::String{};

/** Set Flag */
this->audioChanged();

/** Callback */
UICallbackAPI<int>::invoke(UICallbackType::SeqDataRefChanged, this->index);
}

void SeqSourceProcessor::initMIDI() {
Expand All @@ -313,8 +319,14 @@ void SeqSourceProcessor::initMIDI() {
this->midiData = std::make_unique<juce::MidiFile>();
this->midiData->addTrack(juce::MidiMessageSequence{});

/** Update Name */
this->midiName = juce::String{};

/** Set Flag */
this->midiChanged();

/** Callback */
UICallbackAPI<int>::invoke(UICallbackType::SeqDataRefChanged, this->index);
}

void SeqSourceProcessor::setAudio(double sampleRate,
Expand All @@ -337,6 +349,9 @@ void SeqSourceProcessor::setAudio(double sampleRate,

/** Set Flag */
this->audioChanged();

/** Callback */
UICallbackAPI<int>::invoke(UICallbackType::SeqDataRefChanged, this->index);
}

void SeqSourceProcessor::setMIDI(
Expand All @@ -350,6 +365,9 @@ void SeqSourceProcessor::setMIDI(

/** Set Flag */
this->midiChanged();

/** Callback */
UICallbackAPI<int>::invoke(UICallbackType::SeqDataRefChanged, this->index);
}

const std::tuple<double, juce::AudioSampleBuffer> SeqSourceProcessor::getAudio() const {
Expand Down Expand Up @@ -450,6 +468,14 @@ const juce::String SeqSourceProcessor::getMIDIFileName() const {
return utils::getLegalFileName(name) + extension;
}

const juce::String SeqSourceProcessor::getAudioName() const {
return this->audioName;
}

const juce::String SeqSourceProcessor::getMIDIName() const {
return this->midiName;
}

void SeqSourceProcessor::audioChanged() {
this->audioSavedFlag = false;
}
Expand Down
4 changes: 3 additions & 1 deletion src/audioCore/graph/SeqSourceProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class SeqSourceProcessor final : public juce::AudioProcessorGraph,
void loadMIDI(const juce::String& path, bool getTempo = false);
const juce::String getAudioFileName() const;
const juce::String getMIDIFileName() const;
const juce::String getAudioName() const;
const juce::String getMIDIName() const;
void audioChanged();
void midiChanged();
void audioSaved();
Expand Down Expand Up @@ -109,7 +111,7 @@ class SeqSourceProcessor final : public juce::AudioProcessorGraph,
std::unique_ptr<google::protobuf::Message> serialize() const override;

private:
int index = -1;
std::atomic_int index = -1;

const juce::AudioChannelSet audioChannels;

Expand Down
18 changes: 18 additions & 0 deletions src/audioCore/quickAPI/QuickGet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,24 @@ namespace quickAPI {
return "";
}

const juce::String getSeqTrackDataRefAudio(int index) {
if (auto graph = AudioCore::getInstance()->getGraph()) {
if (auto track = graph->getSourceProcessor(index)) {
return track->getAudioName();
}
}
return "";
}

const juce::String getSeqTrackDataRefMIDI(int index) {
if (auto graph = AudioCore::getInstance()->getGraph()) {
if (auto track = graph->getSourceProcessor(index)) {
return track->getMIDIName();
}
}
return "";
}

int getMixerTrackNum() {
if (auto graph = AudioCore::getInstance()->getGraph()) {
return graph->getTrackNum();
Expand Down
2 changes: 2 additions & 0 deletions src/audioCore/quickAPI/QuickGet.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ namespace quickAPI {
bool getSeqTrackRecording(int index);
const juce::Array<float> getSeqTrackOutputLevel(int index);
const juce::String getSeqTrackType(int index);
const juce::String getSeqTrackDataRefAudio(int index);
const juce::String getSeqTrackDataRefMIDI(int index);

int getMixerTrackNum();
const juce::String getMixerTrackName(int index);
Expand Down
1 change: 1 addition & 0 deletions src/audioCore/uiCallback/UICallbackType.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ enum class UICallbackType : int {
SeqMuteChanged,
SeqRecChanged,
TempoChanged,
SeqDataRefChanged,

TypeMaxNum
};
4 changes: 4 additions & 0 deletions src/ui/component/SeqTrackComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ void SeqTrackComponent::updateMixerTrack() {
this->audioOutput->update(this->index);
}

void SeqTrackComponent::updateDataRef() {
this->content->updateDataRef();
}

void SeqTrackComponent::resized() {
/** Size */
auto screenSize = utils::getScreenSize(this);
Expand Down
1 change: 1 addition & 0 deletions src/ui/component/SeqTrackComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class SeqTrackComponent final
void updateInstr();
void updateHPos(double pos, double itemSize);
void updateMixerTrack();
void updateDataRef();

void resized() override;
void paint(juce::Graphics& g) override;
Expand Down
56 changes: 55 additions & 1 deletion src/ui/component/SeqTrackContentViewer.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#include "SeqTrackContentViewer.h"
#include "../lookAndFeel/LookAndFeelFactory.h"
#include "../Utils.h"
#include "../../audioCore/AC_API.h"

SeqTrackContentViewer::SeqTrackContentViewer() {
/** TODO */
/** Look And Feel */
this->setLookAndFeel(
LookAndFeelFactory::getInstance()->forSeqBlock());
}

void SeqTrackContentViewer::setCompressed(bool isCompressed) {
Expand All @@ -18,6 +21,18 @@ void SeqTrackContentViewer::update(int index) {

this->trackColor = quickAPI::getSeqTrackColor(index);

auto& laf = this->getLookAndFeel();
if (utils::isLightColor(this->trackColor)) {
this->nameColor = laf.findColour(
juce::Label::ColourIds::textWhenEditingColourId);
}
else {
this->nameColor = laf.findColour(
juce::Label::ColourIds::textColourId);
}

this->updateDataRef();

this->repaint();
}
}
Expand Down Expand Up @@ -62,11 +77,36 @@ void SeqTrackContentViewer::updateHPos(double pos, double itemSize) {
this->repaint();
}

void SeqTrackContentViewer::updateDataRef() {
this->audioName = quickAPI::getSeqTrackDataRefAudio(this->index);
this->midiName = quickAPI::getSeqTrackDataRefMIDI(this->index);

this->blockNameCombined = this->audioName
+ ((this->audioName.isNotEmpty() && this->midiName.isNotEmpty()) ? " + " : "")
+ this->midiName;

this->repaint();
}

void SeqTrackContentViewer::paint(juce::Graphics& g) {
/** Size */
auto screenSize = utils::getScreenSize(this);
float paddingHeight = screenSize.getHeight() * 0.0025;
float blockRadius = screenSize.getHeight() * 0.005;
float outlineThickness = screenSize.getHeight() * 0.0015;

float blockPaddingHeight = screenSize.getHeight() * 0.01;
float blockPaddingWidth = screenSize.getWidth() * 0.01;

float blockNameFontHeight = screenSize.getHeight() * 0.015;

/** Color */
auto& laf = this->getLookAndFeel();
juce::Colour outlineColor = laf.findColour(
juce::Label::ColourIds::outlineColourId);

/** Font */
juce::Font blockNameFont(blockNameFontHeight);

/** Blocks */
for (auto block : this->blockTemp) {
Expand All @@ -75,11 +115,25 @@ void SeqTrackContentViewer::paint(juce::Graphics& g) {
float startPos = (block->startTime - this->secStart) / (this->secEnd - this->secStart) * this->getWidth();
float endPos = (block->endTime - this->secStart) / (this->secEnd - this->secStart) * this->getWidth();

/** Rect */
juce::Rectangle<float> blockRect(
startPos, paddingHeight,
endPos - startPos, this->getHeight() - paddingHeight * 2);
g.setColour(this->trackColor.withAlpha(0.5f));
g.fillRoundedRectangle(blockRect, blockRadius);
g.setColour(outlineColor);
g.drawRoundedRectangle(blockRect, blockRadius, outlineThickness);

/** Name */
float nameStartPos = std::max(startPos, 0.f) + blockPaddingWidth;
float nameEndPos = std::min(endPos, (float)this->getWidth()) - blockPaddingWidth;
juce::Rectangle<float> nameRect(
nameStartPos, this->compressed ? 0 : blockPaddingHeight,
nameEndPos - nameStartPos, this->compressed ? this->getHeight() : blockNameFontHeight);
g.setColour(this->nameColor);
g.setFont(blockNameFont);
g.drawFittedText(this->blockNameCombined, nameRect.toNearestInt(),
juce::Justification::centredLeft, 1, 1.f);
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/ui/component/SeqTrackContentViewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class SeqTrackContentViewer final : public juce::Component {
void update(int index);
void updateBlock(int blockIndex);
void updateHPos(double pos, double itemSize);
void updateDataRef();

void paint(juce::Graphics& g) override;

Expand All @@ -19,7 +20,9 @@ class SeqTrackContentViewer final : public juce::Component {
int index = -1;
double pos = 0, itemSize = 0;
double secStart = 0, secEnd = 0;
juce::Colour trackColor;
juce::Colour trackColor, nameColor;
juce::String audioName, midiName;
juce::String blockNameCombined;

struct BlockItem final {
double startTime = 0, endTime = 0, offset = 0;
Expand Down
17 changes: 17 additions & 0 deletions src/ui/component/SeqView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ void SeqView::TrackList::updateMixerTrack() {
}
}

void SeqView::TrackList::updateDataRef(int index) {
if (index >= 0 && index < this->list.size()) {
this->list[index]->updateDataRef();
}
}

void SeqView::TrackList::updateHPos(double pos, double itemSize) {
for (auto i : this->list) {
i->updateHPos(pos, itemSize);
Expand Down Expand Up @@ -219,6 +225,13 @@ SeqView::SeqView()
}
}
);
CoreCallbacks::getInstance()->addSeqDataRefChanged(
[comp = SeqView::SafePointer(this)](int index) {
if (comp) {
comp->updateDataRef(index);
}
}
);

/** Init Temp */
this->gridTemp = std::make_unique<juce::Image>(
Expand Down Expand Up @@ -512,6 +525,10 @@ void SeqView::updateMixerTrack(int /*index*/) {
this->trackList->updateMixerTrack();
}

void SeqView::updateDataRef(int index) {
this->trackList->updateDataRef(index);
}

std::tuple<double, double> SeqView::getViewArea(
double pos, double itemSize) const {
double secStart = pos / itemSize;
Expand Down
2 changes: 2 additions & 0 deletions src/ui/component/SeqView.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class SeqView final
void updateInstr(int index);
void updateLevelMeter() override;
void updateMixerTrack(int index);
void updateDataRef(int index);

std::tuple<double, double> getViewArea(double pos, double itemSize) const;

Expand All @@ -47,6 +48,7 @@ class SeqView final
void updateRec(int index);
void updateInstr(int index);
void updateMixerTrack();
void updateDataRef(int index);

void updateHPos(double pos, double itemSize);
void updateVPos(double pos, double itemSize);
Expand Down
8 changes: 8 additions & 0 deletions src/ui/lookAndFeel/LookAndFeelFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "SeqTrackLookAndFeel.h"
#include "SeqTrackNameLookAndFeel.h"
#include "InstrNameLookAndFeel.h"
#include "SeqBlockLookAndFeel.h"
#include "../misc/ColorMap.h"
#include <FlowUI.h>

Expand Down Expand Up @@ -130,6 +131,9 @@ void LookAndFeelFactory::initialise() {

/** Instr Name */
this->instrNameLAF = std::make_unique<InstrNameLookAndFeel>();

/** Seq Block */
this->seqBlockLAF = std::make_unique<SeqBlockLookAndFeel>();
}

void LookAndFeelFactory::setDefaultSansSerifTypeface(juce::Typeface::Ptr typeface) {
Expand Down Expand Up @@ -233,6 +237,10 @@ juce::LookAndFeel_V4* LookAndFeelFactory::forInstrName() const {
return this->instrNameLAF.get();
}

juce::LookAndFeel_V4* LookAndFeelFactory::forSeqBlock() const {
return this->seqBlockLAF.get();
}

LookAndFeelFactory* LookAndFeelFactory::getInstance() {
return LookAndFeelFactory::instance ? LookAndFeelFactory::instance
: (LookAndFeelFactory::instance = new LookAndFeelFactory{});
Expand Down
2 changes: 2 additions & 0 deletions src/ui/lookAndFeel/LookAndFeelFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class LookAndFeelFactory final : private juce::DeletedAtShutdown {
juce::LookAndFeel_V4* forSeqTrack() const;
juce::LookAndFeel_V4* forSeqTrackName() const;
juce::LookAndFeel_V4* forInstrName() const;
juce::LookAndFeel_V4* forSeqBlock() const;

private:
std::unique_ptr<juce::LookAndFeel> mainLAF = nullptr;
Expand Down Expand Up @@ -60,6 +61,7 @@ class LookAndFeelFactory final : private juce::DeletedAtShutdown {
std::unique_ptr<juce::LookAndFeel_V4> seqTrackLAF = nullptr;
std::unique_ptr<juce::LookAndFeel_V4> seqTrackNameLAF = nullptr;
std::unique_ptr<juce::LookAndFeel_V4> instrNameLAF = nullptr;
std::unique_ptr<juce::LookAndFeel_V4> seqBlockLAF = nullptr;

public:
static LookAndFeelFactory* getInstance();
Expand Down
19 changes: 19 additions & 0 deletions src/ui/lookAndFeel/SeqBlockLookAndFeel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "SeqBlockLookAndFeel.h"
#include "../misc/ColorMap.h"

SeqBlockLookAndFeel::SeqBlockLookAndFeel()
: MainLookAndFeel() {
/** Block */
this->setColour(juce::Label::ColourIds::backgroundColourId,
ColorMap::getInstance()->get("ThemeColorB2"));
this->setColour(juce::Label::ColourIds::textColourId,
ColorMap::getInstance()->get("ThemeColorB10"));/**< Block Name Light */
this->setColour(juce::Label::ColourIds::outlineColourId,
ColorMap::getInstance()->get("ThemeColorB6"));/**< Block Outline */
this->setColour(juce::Label::ColourIds::backgroundWhenEditingColourId,
ColorMap::getInstance()->get("ThemeColorB2"));
this->setColour(juce::Label::ColourIds::textWhenEditingColourId,
ColorMap::getInstance()->get("ThemeColorB0"));/**< Block Name Dark */
this->setColour(juce::Label::ColourIds::outlineWhenEditingColourId,
ColorMap::getInstance()->get("ThemeColorA2"));/**< Block Hovered Outline */
}
12 changes: 12 additions & 0 deletions src/ui/lookAndFeel/SeqBlockLookAndFeel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#include <JuceHeader.h>
#include "MainLookAndFeel.h"

class SeqBlockLookAndFeel : public MainLookAndFeel {
public:
SeqBlockLookAndFeel();

private:
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(SeqBlockLookAndFeel)
};
Loading

0 comments on commit cee590a

Please sign in to comment.