Skip to content

Commit

Permalink
Add ActionSetSequencerBlockTime
Browse files Browse the repository at this point in the history
  • Loading branch information
FangCunWuChang committed Jun 6, 2024
1 parent c688c24 commit 51f80a8
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 1 deletion.
42 changes: 42 additions & 0 deletions src/audioCore/action/ActionSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2097,3 +2097,45 @@ bool ActionSetSequencerMIDITrack::undo() {
this->output("Can't undo set seq MIDI track: [" + juce::String(ACTION_DATA(track)) + "] " + juce::String{ ACTION_DATA(midiTrack) } + "\n");
ACTION_RESULT(false);
}

ActionSetSequencerBlockTime::ActionSetSequencerBlockTime(
int track, int index, const BlockTime& time)
: ACTION_DB{ track, index, time } {}

bool ActionSetSequencerBlockTime::doAction() {
ACTION_UNSAVE_PROJECT();

ACTION_WRITE_TYPE(ActionSetSequencerBlockTime);
ACTION_WRITE_DB();

if (auto graph = AudioCore::getInstance()->getGraph()) {
if (auto track = graph->getSourceProcessor(ACTION_DATA(track))) {
ACTION_DATA(oldTime) = track->getSeq(ACTION_DATA(index));
ACTION_DATA(newIndex) = track->resetSeqTime(ACTION_DATA(index), ACTION_DATA(time));
if (ACTION_DATA(newIndex) >= 0) {
this->output("Set seq block time: [" + juce::String(ACTION_DATA(track)) + "] " + juce::String{ ACTION_DATA(index) } + "\n");
ACTION_RESULT(true);
}
}
}
this->output("Can't set seq block time: [" + juce::String(ACTION_DATA(track)) + "] " + juce::String{ ACTION_DATA(index) } + "\n");
ACTION_RESULT(false);
}

bool ActionSetSequencerBlockTime::undo() {
ACTION_UNSAVE_PROJECT();

ACTION_WRITE_TYPE_UNDO(ActionSetSequencerBlockTime);
ACTION_WRITE_DB();

if (auto graph = AudioCore::getInstance()->getGraph()) {
if (auto track = graph->getSourceProcessor(ACTION_DATA(track))) {
track->resetSeqTime(ACTION_DATA(newIndex), ACTION_DATA(oldTime));

this->output("Undo set seq block time: [" + juce::String(ACTION_DATA(track)) + "] " + juce::String{ ACTION_DATA(index) } + "\n");
ACTION_RESULT(true);
}
}
this->output("Can't undo set seq block time: [" + juce::String(ACTION_DATA(track)) + "] " + juce::String{ ACTION_DATA(index) } + "\n");
ACTION_RESULT(false);
}
25 changes: 25 additions & 0 deletions src/audioCore/action/ActionSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -1126,3 +1126,28 @@ class ActionSetSequencerMIDITrack final : public ActionUndoableBase {

JUCE_LEAK_DETECTOR(ActionSetSequencerMIDITrack)
};

class ActionSetSequencerBlockTime final : public ActionUndoableBase {
public:
using BlockTime = std::tuple<double, double, double>;
ActionSetSequencerBlockTime() = delete;
ActionSetSequencerBlockTime(
int track, int index, const BlockTime& time);

bool doAction() override;
bool undo() override;
const juce::String getName() override {
return "Set Sequencer Block Time";
};

private:
ACTION_DATABLOCK{
const int track, index;
const BlockTime time;

int newIndex = -1;
BlockTime oldTime{};
} ACTION_DB;

JUCE_LEAK_DETECTOR(ActionSetSequencerBlockTime)
};
5 changes: 5 additions & 0 deletions src/audioCore/graph/SeqSourceProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ bool SeqSourceProcessor::stickSeqWithNext(int index) {
return this->srcs.stickWithNext(index);
}

int SeqSourceProcessor::resetSeqTime(
int index, const SourceList::SeqBlock& block) {
return this->srcs.resetTime(index, block);
}

void SeqSourceProcessor::setTrackName(const juce::String& name) {
this->trackName = name;

Expand Down
1 change: 1 addition & 0 deletions src/audioCore/graph/SeqSourceProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class SeqSourceProcessor final : public juce::AudioProcessorGraph,
const SourceList::SeqBlock getSeq(int index) const;
bool splitSeq(int index, double time);
bool stickSeqWithNext(int index);
int resetSeqTime(int index, const SourceList::SeqBlock& block);

void setTrackName(const juce::String& name);
const juce::String getTrackName() const;
Expand Down
8 changes: 8 additions & 0 deletions src/audioCore/graph/SourceList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,14 @@ bool SourceList::stickWithNext(int index) {
return false;
}

int SourceList::resetTime(int index, const SeqBlock& block) {
juce::ScopedWriteLock locker(audioLock::getAudioLock());

if (index < 0 || index >= this->list.size()) { return -1; }
this->remove(index);
return this->add(block);
}

void SourceList::clearGraph() {
juce::ScopedWriteLock locker(audioLock::getAudioLock());
this->list.clear();
Expand Down
2 changes: 2 additions & 0 deletions src/audioCore/graph/SourceList.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class SourceList final : public Serializable {
bool split(int index, double time);
bool stickWithNext(int index);

int resetTime(int index, const SeqBlock& block);

void clearGraph();

public:
Expand Down
3 changes: 2 additions & 1 deletion src/audioCore/recovery/ActionType.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,6 @@ enum class ActionType : unsigned int {
ActionSetSequencerTrackColor,
ActionSetSequencerTrackMute,
ActionSetEffect,
ActionSetSequencerMIDITrack
ActionSetSequencerMIDITrack,
ActionSetSequencerBlockTime
};

0 comments on commit 51f80a8

Please sign in to comment.