Skip to content

Commit

Permalink
Add synth operations
Browse files Browse the repository at this point in the history
  • Loading branch information
FangCunWuChang committed Jun 14, 2024
1 parent 5dc3209 commit 5002aee
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/translates/zh-CN/main.txt
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ countries: cn
"Instrument Offline" = "乐器离线"
"Offline" = "离线"
"Select MIDI Track" = "选择 MIDI 轨道"
"Synth" = "合成"

"Type:" = "类型:"
"Instrument:" = "乐器:"
Expand Down
4 changes: 4 additions & 0 deletions src/audioCore/graph/SeqSourceProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ void SeqSourceProcessor::updateIndex(int index) {
this->index = index;
this->srcs.updateIndex(index);

if (auto synthThread = dynamic_cast<SynthThread*>(this->synthThread.get())) {
synthThread->setIndex(index);
}

/** Callback */
UICallbackAPI<int>::invoke(UICallbackType::SeqChanged, index);
}
Expand Down
18 changes: 18 additions & 0 deletions src/audioCore/misc/SynthThread.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "SynthThread.h"
#include "../graph/SeqSourceProcessor.h"
#include "../uiCallback/UICallback.h"
#include "../misc/AudioLock.h"
#include "../misc/PlayPosition.h"
#include "../Utils.h"
Expand All @@ -11,6 +12,10 @@ SynthThread::~SynthThread() {
this->stopThread(5000);
}

void SynthThread::setIndex(int index) {
this->index = index;
}

void SynthThread::synthNow() {
/** Check Thread Running */
if (this->isThreadRunning()) { return; }
Expand All @@ -33,6 +38,10 @@ void SynthThread::synthNow() {
this->parent->prepareAudioData(length);
}

/** State Changed */
UICallbackAPI<int, bool>::invoke(
UICallbackType::SynthStateChanged, this->index, true);

/** Start Thread */
this->startThread();
}
Expand Down Expand Up @@ -186,4 +195,13 @@ void SynthThread::run() {

/** Reset Play Head */
plugin->setPlayHead(oldPlayHead);

/** State Changed */
int index = this->index;
juce::MessageManager::callAsync(
[index] {
UICallbackAPI<int, bool>::invoke(
UICallbackType::SynthStateChanged, index, false);
}
);
}
2 changes: 2 additions & 0 deletions src/audioCore/misc/SynthThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ class SynthThread final : public juce::Thread {
SynthThread(SeqSourceProcessor* parent);
~SynthThread();

void setIndex(int index);
void synthNow();

protected:
void run() override;

private:
SeqSourceProcessor* const parent;
std::atomic_int index = -1;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(SynthThread)
};
1 change: 1 addition & 0 deletions src/audioCore/uiCallback/UICallbackType.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ enum class UICallbackType : int {
TempoChanged,
SeqDataRefChanged,
PluginSearchMessage,
SynthStateChanged,

TypeMaxNum
};
11 changes: 10 additions & 1 deletion src/ui/component/sequencer/SeqTrackComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ void SeqTrackComponent::updateData() {
this->content->updateData();
}

void SeqTrackComponent::updateSynthState(bool state) {
this->updateDataRef();
}

void SeqTrackComponent::resized() {
/** Size */
auto screenSize = utils::getScreenSize(this);
Expand Down Expand Up @@ -585,7 +589,7 @@ void SeqTrackComponent::instrMenuShow() {
}

enum SeqMenuActionType {
Add = 1, Remove1, MIDITrack
Add = 1, Remove1, MIDITrack, Synth
};

void SeqTrackComponent::menuShow() {
Expand All @@ -605,6 +609,10 @@ void SeqTrackComponent::menuShow() {
CoreActions::setSeqMIDITrackGUI(this->index);
break;
}
case SeqMenuActionType::Synth: {
CoreActions::synthSeq(this->index);
break;
}
}
}

Expand Down Expand Up @@ -672,6 +680,7 @@ juce::PopupMenu SeqTrackComponent::createMenu() const {
menu.addItem(SeqMenuActionType::Add, TRANS("Add"));
menu.addItem(SeqMenuActionType::Remove1, TRANS("Remove"));
menu.addItem(SeqMenuActionType::MIDITrack, TRANS("Select MIDI Track"));
menu.addItem(SeqMenuActionType::Synth, TRANS("Synth"));

return menu;
}
Expand Down
1 change: 1 addition & 0 deletions src/ui/component/sequencer/SeqTrackComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class SeqTrackComponent final
void updateMixerTrack();
void updateDataRef();
void updateData();
void updateSynthState(bool state);

void resized() override;
void paint(juce::Graphics& g) override;
Expand Down
17 changes: 17 additions & 0 deletions src/ui/component/sequencer/SeqView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ void SeqView::TrackList::updateData(int index) {
}
}

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

void SeqView::TrackList::updateHPos(double pos, double itemSize) {
/** Size */
auto screenSize = utils::getScreenSize(this);
Expand Down Expand Up @@ -455,6 +461,13 @@ SeqView::SeqView()
}
}
);
CoreCallbacks::getInstance()->addSynthStatus(
[comp = SeqView::SafePointer(this)](int index, bool state) {
if (comp) {
comp->updateSynthState(index, state);
}
}
);

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

void SeqView::updateSynthState(int index, bool state) {
this->trackList->updateSynthState(index, state);
}

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/sequencer/SeqView.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class SeqView final
void updateMixerTrack(int index);
void updateDataRef(int index);
void updateData(int index);
void updateSynthState(int index, bool state);

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

Expand Down Expand Up @@ -64,6 +65,7 @@ class SeqView final
void updateMixerTrack();
void updateDataRef(int index);
void updateData(int index);
void updateSynthState(int index, bool state);

void updateHPos(double pos, double itemSize);
void updateVPos(double pos, double itemSize);
Expand Down
5 changes: 5 additions & 0 deletions src/ui/misc/CoreActions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,11 @@ void CoreActions::setSeqMIDIRef(int index, const juce::String& path, bool getTem
ActionDispatcher::getInstance()->dispatch(std::move(action));
}

void CoreActions::synthSeq(int index) {
auto action = std::unique_ptr<ActionBase>(new ActionSynth{ index });
ActionDispatcher::getInstance()->dispatch(std::move(action));
}

void CoreActions::removeSeq(int index) {
auto action = std::unique_ptr<ActionBase>(new ActionRemoveSequencerTrack{ index });
ActionDispatcher::getInstance()->dispatch(std::move(action));
Expand Down
1 change: 1 addition & 0 deletions src/ui/misc/CoreActions.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class CoreActions final {
static void setSeqMIDITrack(int index, int midiTrack);
static void setSeqAudioRef(int index, const juce::String& path);
static void setSeqMIDIRef(int index, const juce::String& path, bool getTempo);
static void synthSeq(int index);
static void removeSeq(int index);

static void addTempoLabel(double time, double tempo);
Expand Down
14 changes: 14 additions & 0 deletions src/ui/misc/CoreCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ CoreCallbacks::CoreCallbacks() {
[](const juce::String& mes) {
CoreCallbacks::getInstance()->invokePluginSearchMes(mes);
});
UICallbackAPI<int, bool>::set(UICallbackType::SynthStateChanged,
[](int index, bool status) {
CoreCallbacks::getInstance()->invokeSynthStatus(index, status);
});
}

void CoreCallbacks::addError(const ErrorCallback& callback) {
Expand Down Expand Up @@ -164,6 +168,10 @@ void CoreCallbacks::addPluginSearchMes(const PluginSearchMesCallback& callback)
this->pluginSearchMesChanged.add(callback);
}

void CoreCallbacks::addSynthStatus(const SynthStatusCallback& callback) {
this->synthStatus.add(callback);
}

void CoreCallbacks::invokeError(
const juce::String& title, const juce::String& mes) const {
for (auto& i : this->error) {
Expand Down Expand Up @@ -285,6 +293,12 @@ void CoreCallbacks::invokePluginSearchMes(const juce::String& mes) const {
}
}

void CoreCallbacks::invokeSynthStatus(int index, bool status) const {
for (auto& i : this->synthStatus) {
i(index, status);
}
}

CoreCallbacks* CoreCallbacks::getInstance() {
return CoreCallbacks::instance ? CoreCallbacks::instance
: (CoreCallbacks::instance = new CoreCallbacks{});
Expand Down
4 changes: 4 additions & 0 deletions src/ui/misc/CoreCallbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class CoreCallbacks final : private juce::DeletedAtShutdown {
void addSeqDataRefChanged(const SeqDataRefChangedCallback& callback);
using PluginSearchMesCallback = std::function<void(const juce::String&)>;
void addPluginSearchMes(const PluginSearchMesCallback& callback);
using SynthStatusCallback = std::function<void(int, bool)>;
void addSynthStatus(const SynthStatusCallback& callback);

void invokeError(const juce::String& title, const juce::String& mes) const;
void invokePlayingStatus(bool status) const;
Expand All @@ -63,6 +65,7 @@ class CoreCallbacks final : private juce::DeletedAtShutdown {
void invokeSeqRecChanged(int index) const;
void invokeSeqDataRefChanged(int index) const;
void invokePluginSearchMes(const juce::String& mes) const;
void invokeSynthStatus(int index, bool status) const;

private:
juce::Array<ErrorCallback> error;
Expand All @@ -85,6 +88,7 @@ class CoreCallbacks final : private juce::DeletedAtShutdown {
juce::Array<SeqRecChangedCallback> seqRecChanged;
juce::Array<SeqDataRefChangedCallback> seqDataRefChanged;
juce::Array<PluginSearchMesCallback> pluginSearchMesChanged;
juce::Array<SynthStatusCallback> synthStatus;

public:
static CoreCallbacks* getInstance();
Expand Down

0 comments on commit 5002aee

Please sign in to comment.