Skip to content

Commit

Permalink
Add seq track input monitoring
Browse files Browse the repository at this point in the history
  • Loading branch information
FangCunWuChang committed Nov 27, 2024
1 parent 7625e29 commit 3379cd3
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 10 deletions.
46 changes: 46 additions & 0 deletions src/audioCore/action/ActionSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1792,6 +1792,52 @@ bool ActionSetSequencerTrackRecording::undo() {
ACTION_RESULT(false);
}

ActionSetSequencerTrackInputMonitoring::ActionSetSequencerTrackInputMonitoring(
int track, bool inputMonitoring)
: ACTION_DB{ track, inputMonitoring } {}

bool ActionSetSequencerTrackInputMonitoring::doAction() {
ACTION_CHECK_RENDERING(
"Don't do this while rendering.");

ACTION_UNSAVE_PROJECT();

ACTION_WRITE_TYPE(ActionSetSequencerTrackInputMonitoring);
ACTION_WRITE_DB();

if (auto graph = AudioCore::getInstance()->getGraph()) {
if (auto track = graph->getSourceProcessor(ACTION_DATA(track))) {
ACTION_DATA(oldInputMonitoring) = track->getInputMonitoring();

track->setInputMonitoring(ACTION_DATA(inputMonitoring));

this->output("Sequencer Track Input Monitoring: [" + juce::String(ACTION_DATA(track)) + "] " + juce::String{ track->getInputMonitoring() ? "ON" : "OFF" } + "\n");
ACTION_RESULT(true);
}
}
ACTION_RESULT(false);
}

bool ActionSetSequencerTrackInputMonitoring::undo() {
ACTION_CHECK_RENDERING(
"Don't do this while rendering.");

ACTION_UNSAVE_PROJECT();

ACTION_WRITE_TYPE_UNDO(ActionSetSequencerTrackInputMonitoring);
ACTION_WRITE_DB();

if (auto graph = AudioCore::getInstance()->getGraph()) {
if (auto track = graph->getSourceProcessor(ACTION_DATA(track))) {
track->setInputMonitoring(ACTION_DATA(oldInputMonitoring));

this->output("Undo Sequencer Track Input Monitoring: [" + juce::String(ACTION_DATA(track)) + "] " + juce::String{ track->getInputMonitoring() ? "ON" : "OFF" } + "\n");
ACTION_RESULT(true);
}
}
ACTION_RESULT(false);
}

ActionSetInstrOffline::ActionSetInstrOffline(
int instr, bool offline)
: ACTION_DB{ instr, offline } {}
Expand Down
23 changes: 23 additions & 0 deletions src/audioCore/action/ActionSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,29 @@ class ActionSetSequencerTrackRecording final : public ActionUndoableBase {
JUCE_LEAK_DETECTOR(ActionSetSequencerTrackRecording)
};

class ActionSetSequencerTrackInputMonitoring final : public ActionUndoableBase {
public:
ActionSetSequencerTrackInputMonitoring() = delete;
ActionSetSequencerTrackInputMonitoring(
int track, bool inputMonitoring);

bool doAction() override;
bool undo() override;
const juce::String getName() override {
return "Set Sequencer Track Input Monitoring";
};

private:
ACTION_DATABLOCK{
const int track;
const bool inputMonitoring;

bool oldInputMonitoring = false;
} ACTION_DB;

JUCE_LEAK_DETECTOR(ActionSetSequencerTrackInputMonitoring)
};

class ActionSetInstrOffline final : public ActionUndoableBase {
public:
ActionSetInstrOffline() = delete;
Expand Down
26 changes: 17 additions & 9 deletions src/audioCore/graph/SeqSourceProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,14 @@ bool SeqSourceProcessor::getMute() const {
return this->isMute;
}

void SeqSourceProcessor::setInputMonitoring(bool inputMonitoring) {
this->inputMonitoring = inputMonitoring;
}

bool SeqSourceProcessor::getInputMonitoring() const {
return this->inputMonitoring;
}

const juce::Array<float> SeqSourceProcessor::getOutputLevels() const {
juce::ScopedReadLock locker(audioLock::getLevelMeterLock());
return this->outputLevels;
Expand Down Expand Up @@ -578,10 +586,13 @@ void SeqSourceProcessor::processBlock(
if (buffer.getNumChannels() <= 0) { return; }
if (buffer.getNumSamples() <= 0) { return; }

/** Clear Audio Channel */
auto dspBlock = juce::dsp::AudioBlock<float>(buffer).getSubsetChannelBlock(
0, buffer.getNumChannels());
dspBlock.fill(0);
if (!this->inputMonitoring) {
/** Clear MIDI Buffer */
midiMessages.clear();

/** Clear Audio Buffer */
vMath::zeroAllAudioData(buffer);
}

/** Play Flag */
bool isPlaying = true;
Expand All @@ -597,11 +608,6 @@ void SeqSourceProcessor::processBlock(
/** Check Play State */
if (!position->getIsPlaying()) { isPlaying = false; }

/** Clear MIDI Buffer */
if ((isPlaying && position->getIsRecording()) || (this->recordingFlag == RecordState::NotRecording)) {
midiMessages.clear();
}

if (isPlaying && !(this->isMute)) {
/** Get Time */
double startTime = position->getTimeInSeconds().orFallback(-1);
Expand Down Expand Up @@ -746,6 +752,7 @@ bool SeqSourceProcessor::parse(
this->setCurrentMIDITrack(mes->miditrack());

this->setRecording(static_cast<RecordState>(mes->recordstate()));
this->setInputMonitoring(mes->inputmonitoring());
this->setMute(mes->muted());

return true;
Expand Down Expand Up @@ -796,6 +803,7 @@ std::unique_ptr<google::protobuf::Message> SeqSourceProcessor::serialize(
mes->set_miditrack(this->getCurrentMIDITrack());

mes->set_recordstate(static_cast<vsp4::SeqTrack::RecordState>(this->getRecording()));
mes->set_inputmonitoring(this->getInputMonitoring());
mes->set_muted(this->getMute());

return std::unique_ptr<google::protobuf::Message>(mes.release());
Expand Down
4 changes: 4 additions & 0 deletions src/audioCore/graph/SeqSourceProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ class SeqSourceProcessor final : public juce::AudioProcessorGraph,
void setMute(bool mute);
bool getMute() const;

void setInputMonitoring(bool inputMonitoring);
bool getInputMonitoring() const;

const juce::Array<float> getOutputLevels() const;

void syncARAContext();
Expand Down Expand Up @@ -151,6 +154,7 @@ class SeqSourceProcessor final : public juce::AudioProcessorGraph,
std::atomic<RecordState> recordingFlag = RecordState::NotRecording;

std::atomic_bool isMute = false;
std::atomic_bool inputMonitoring = false;

juce::Array<float> outputLevels;

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 @@ -79,5 +79,6 @@ enum class ActionType : unsigned int {
ActionSetSequencerTrackMute,
ActionSetEffect,
ActionSetSequencerMIDITrack,
ActionSetSequencerBlockTime
ActionSetSequencerBlockTime,
ActionSetSequencerTrackInputMonitoring
};

0 comments on commit 3379cd3

Please sign in to comment.