Skip to content

Commit

Permalink
Update SourceComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
FangCunWuChang committed Jan 19, 2024
1 parent a9acba1 commit 3d6bd14
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 35 deletions.
6 changes: 6 additions & 0 deletions src/audioCore/source/CloneableSource.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "CloneableSource.h"
#include "../misc/AudioLock.h"
#include "../uiCallback/UICallback.h"

std::atomic_int CloneableSource::globalCounter = 0;

Expand Down Expand Up @@ -83,6 +84,11 @@ int CloneableSource::getId() const {

void CloneableSource::setName(const juce::String& name) {
this->name = name;

/** Callback */
juce::MessageManager::callAsync([] {
UICallbackAPI<int>::invoke(UICallbackType::SourceChanged, -1);
});
}

const juce::String CloneableSource::getName() const {
Expand Down
5 changes: 5 additions & 0 deletions src/audioCore/source/CloneableSynthSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ void CloneableSynthSource::setSynthesizer(
DMDA::PluginHandler handShakeHandler(
[](DMDA::Context* context) { context->handShake(); });
this->synthesizer->getExtensions(handShakeHandler);

/** Callback */
juce::MessageManager::callAsync([] {
UICallbackAPI<int>::invoke(UICallbackType::SourceChanged, -1);
});
}

const juce::String CloneableSynthSource::getSynthesizerName() const {
Expand Down
27 changes: 27 additions & 0 deletions src/ui/component/SourceComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ void SourceComponent::update(int index, bool selected) {
this->sampleRate = quickAPI::getSourceSampleRate(index);
this->isIOTask = quickAPI::checkSourceIOTask(index);
this->isSynthing = quickAPI::checkSourceSynthing(index);

this->setTooltip(this->createTooltip());
}

this->repaint();
Expand Down Expand Up @@ -330,3 +332,28 @@ juce::var SourceComponent::getDragSourceDescription() const {

return juce::var{ object.release() };
}

juce::String SourceComponent::createTooltip() const {
juce::String result =
"#" + juce::String{ this->id } + " " + this->nameEditor->getText() + "\n"
+ TRANS("Type:") + " " + this->typeName + "\n"
+ TRANS("Length:") + " " + juce::String{ this->length } + "s\n";

if (this->type == quickAPI::SourceType::AudioSource || this->type == quickAPI::SourceType::SynthSource) {
result += (TRANS("Channels:") + " " + juce::String{ this->channels } + "\n");
}
if (this->type == quickAPI::SourceType::MIDISource || this->type == quickAPI::SourceType::SynthSource) {
result += (TRANS("Tracks:") + " " + juce::String{ this->tracks } + "\n");
}
if (this->type == quickAPI::SourceType::MIDISource || this->type == quickAPI::SourceType::SynthSource) {
result += (TRANS("Events:") + " " + juce::String{ this->events } + "\n");
}
if (this->type == quickAPI::SourceType::SynthSource) {
result += (TRANS("Synthesizer:") + " " + this->synthesizer + "\n");
}
if (this->type == quickAPI::SourceType::AudioSource || this->type == quickAPI::SourceType::SynthSource) {
result += (TRANS("Sample Rate:") + " " + juce::String{ this->sampleRate } + "Hz\n");
}

return result;
}
4 changes: 3 additions & 1 deletion src/ui/component/SourceComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

class SourceComponent final
: public juce::Component,
public juce::DragAndDropTarget {
public juce::DragAndDropTarget,
public juce::SettableTooltipClient {
public:
SourceComponent(const std::function<void(int)>& selectCallback);

Expand Down Expand Up @@ -51,6 +52,7 @@ class SourceComponent final
juce::PopupMenu createNewMenu() const;

juce::var getDragSourceDescription() const;
juce::String createTooltip() const;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(SourceComponent)
};
33 changes: 1 addition & 32 deletions src/ui/dataModel/SourceListModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ int SourceListModel::getNumRows() {

void SourceListModel::paintListBoxItem(int rowNumber, juce::Graphics& g,
int width, int height, bool rowIsSelected) {
/** TODO */
/** Nothing To Do */
}

juce::Component* SourceListModel::refreshComponentForRow(
Expand Down Expand Up @@ -42,37 +42,6 @@ void SourceListModel::backgroundClicked(const juce::MouseEvent& event) {
}
}

juce::String SourceListModel::getTooltipForRow(int row) {
auto type = quickAPI::getSourceType(row);

juce::String result =
"#" + juce::String{ quickAPI::getSourceId(row) } + " " + quickAPI::getSourceName(row) + "\n"
+ TRANS("Type:") + " " + quickAPI::getSourceTypeName(row) + "\n"
+ TRANS("Length:") + " " + juce::String{ quickAPI::getSourceLength(row) } + "s\n";

if (type == quickAPI::SourceType::AudioSource || type == quickAPI::SourceType::SynthSource) {
result += (TRANS("Channels:") + " " + juce::String{ quickAPI::getSourceChannelNum(row) } + "\n");
}
if (type == quickAPI::SourceType::MIDISource || type == quickAPI::SourceType::SynthSource) {
result += (TRANS("Tracks:") + " " + juce::String{ quickAPI::getSourceTrackNum(row) } + "\n");
}
if (type == quickAPI::SourceType::MIDISource || type == quickAPI::SourceType::SynthSource) {
result += (TRANS("Events:") + " " + juce::String{ quickAPI::getSourceEventNum(row) } + "\n");
}
if (type == quickAPI::SourceType::SynthSource) {
result += (TRANS("Synthesizer:") + " " + juce::String{ quickAPI::getSourceSynthesizerName(row) } + "\n");
}
if (type == quickAPI::SourceType::AudioSource || type == quickAPI::SourceType::SynthSource) {
result += (TRANS("Sample Rate:") + " " + juce::String{ quickAPI::getSourceSampleRate(row) } + "\n");
}

return result;
}

juce::MouseCursor SourceListModel::getMouseCursorForRow(int row) {
return juce::MouseCursor::PointingHandCursor;
}

enum SourceListActionType {
NewAudio = 1,
NewMIDI,
Expand Down
2 changes: 0 additions & 2 deletions src/ui/dataModel/SourceListModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ class SourceListModel final : public juce::ListBoxModel {
juce::Component* existingComponentToUpdate) override;
juce::String getNameForRow(int rowNumber) override;
void backgroundClicked(const juce::MouseEvent&) override;
juce::String getTooltipForRow(int row) override;
juce::MouseCursor getMouseCursorForRow(int row) override;

private:
const std::function<void(int)> selectCallback;
Expand Down

0 comments on commit 3d6bd14

Please sign in to comment.