Skip to content

Commit

Permalink
Add multiple recording states
Browse files Browse the repository at this point in the history
  • Loading branch information
FangCunWuChang committed Nov 26, 2024
1 parent 799ffb5 commit f0e554f
Show file tree
Hide file tree
Showing 15 changed files with 79 additions and 33 deletions.
2 changes: 1 addition & 1 deletion scripts/vcpkg
14 changes: 7 additions & 7 deletions src/audioCore/action/ActionSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1747,8 +1747,8 @@ bool ActionSetAudioSaveQualityOptionIndex::doAction() {
}

ActionSetSequencerTrackRecording::ActionSetSequencerTrackRecording(
int track, bool recording)
: ACTION_DB{ track, recording } {}
int track, quickAPI::RecordState recordState)
: ACTION_DB{ track, recordState } {}

bool ActionSetSequencerTrackRecording::doAction() {
ACTION_CHECK_RENDERING(
Expand All @@ -1761,11 +1761,11 @@ bool ActionSetSequencerTrackRecording::doAction() {

if (auto graph = AudioCore::getInstance()->getGraph()) {
if (auto track = graph->getSourceProcessor(ACTION_DATA(track))) {
ACTION_DATA(oldRecording) = track->getRecording();
ACTION_DATA(oldRecordState) = track->getRecording();

track->setRecording(ACTION_DATA(recording));
track->setRecording(ACTION_DATA(recordState));

this->output("Sequencer Track Recording: [" + juce::String(ACTION_DATA(track)) + "] " + juce::String{ track->getRecording() ? "ON" : "OFF" } + "\n");
this->output("Sequencer Track Recording: [" + juce::String(ACTION_DATA(track)) + "] " + juce::String{ track->getRecording() } + "\n");
ACTION_RESULT(true);
}
}
Expand All @@ -1783,9 +1783,9 @@ bool ActionSetSequencerTrackRecording::undo() {

if (auto graph = AudioCore::getInstance()->getGraph()) {
if (auto track = graph->getSourceProcessor(ACTION_DATA(track))) {
track->setRecording(ACTION_DATA(oldRecording));
track->setRecording(ACTION_DATA(oldRecordState));

this->output("Undo sequencer Track Recording: [" + juce::String(ACTION_DATA(track)) + "] " + juce::String{ track->getRecording() ? "ON" : "OFF" } + "\n");
this->output("Undo sequencer Track Recording: [" + juce::String(ACTION_DATA(track)) + "] " + juce::String{ track->getRecording() } + "\n");
ACTION_RESULT(true);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/audioCore/action/ActionSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,7 @@ class ActionSetSequencerTrackRecording final : public ActionUndoableBase {
public:
ActionSetSequencerTrackRecording() = delete;
ActionSetSequencerTrackRecording(
int track, bool recording);
int track, quickAPI::RecordState recordState);

bool doAction() override;
bool undo() override;
Expand All @@ -980,9 +980,9 @@ class ActionSetSequencerTrackRecording final : public ActionUndoableBase {
private:
ACTION_DATABLOCK{
const int track;
const bool recording;
const quickAPI::RecordState recordState;

bool oldRecording = false;
quickAPI::RecordState oldRecordState = quickAPI::RecordState::NotRecording;
} ACTION_DB;

JUCE_LEAK_DETECTOR(ActionSetSequencerTrackRecording)
Expand Down
2 changes: 1 addition & 1 deletion src/audioCore/command/CommandSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ AUDIOCORE_FUNC(setAudioSaveQualityOptionIndex) {

AUDIOCORE_FUNC(setSequencerTrackRecording) {
auto action = std::unique_ptr<ActionBase>(new ActionSetSequencerTrackRecording{
(int)luaL_checkinteger(L, 1), (bool)lua_toboolean(L, 2) });
(int)luaL_checkinteger(L, 1), (quickAPI::RecordState)luaL_checkinteger(L, 2) });
ActionDispatcher::getInstance()->dispatch(std::move(action));
return CommandFuncResult{ true, "" };
}
Expand Down
17 changes: 9 additions & 8 deletions src/audioCore/graph/SeqSourceProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,19 +515,20 @@ int SeqSourceProcessor::getTotalMIDITrackNum() const {
return SourceManager::getInstance()->getMIDITrackNum(this->midiSourceRef);
}

void SeqSourceProcessor::setRecording(bool recording) {
this->recordingFlag = recording;

void SeqSourceProcessor::setRecording(RecordState recordState) {
/** Sync ARA */
if (!recording) {
if (this->recordingFlag != RecordState::NotRecording
&& this->recordingFlag != recordState) {
this->syncARAContext();
}

this->recordingFlag = recordState;

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

bool SeqSourceProcessor::getRecording() const {
SeqSourceProcessor::RecordState SeqSourceProcessor::getRecording() const {
return this->recordingFlag;
}

Expand Down Expand Up @@ -597,7 +598,7 @@ void SeqSourceProcessor::processBlock(
if (!position->getIsPlaying()) { isPlaying = false; }

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

Expand Down Expand Up @@ -744,7 +745,7 @@ bool SeqSourceProcessor::parse(
}
this->setCurrentMIDITrack(mes->miditrack());

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

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

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

return std::unique_ptr<google::protobuf::Message>(mes.release());
Expand Down
16 changes: 13 additions & 3 deletions src/audioCore/graph/SeqSourceProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,18 @@ class SeqSourceProcessor final : public juce::AudioProcessorGraph,
int getCurrentMIDITrack() const;
int getTotalMIDITrackNum() const;

void setRecording(bool recording);
bool getRecording() const;
enum RecordState {
NotRecording = 0,

MIDINewTrackMode = 0x01,
MIDIInsertMode = 0x02,
MIDICoverMode = 0x03,

AudioInsertMode = 0x10,
AudioCoverMode = 0x20
};
void setRecording(RecordState recordState);
RecordState getRecording() const;

void setMute(bool mute);
bool getMute() const;
Expand Down Expand Up @@ -138,7 +148,7 @@ class SeqSourceProcessor final : public juce::AudioProcessorGraph,
uint64_t audioSourceRef = 0, midiSourceRef = 0;
std::atomic_int currentMIDITrack = 0;

std::atomic_bool recordingFlag = false;
std::atomic<RecordState> recordingFlag = RecordState::NotRecording;

std::atomic_bool isMute = false;

Expand Down
26 changes: 26 additions & 0 deletions src/audioCore/misc/RecordTemp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,32 @@ void RecordTemp::recordData(double timeSec,
}
}

void RecordTemp::setRecordMIDI(bool recordMIDI) {
juce::GenericScopedLock locker(this->lock);
this->recordMIDI = recordMIDI;
if (!recordMIDI) {
this->clearMIDI();
}
}

void RecordTemp::setRecordAudio(bool recordAudio) {
juce::GenericScopedLock locker(this->lock);
this->recordAudio = recordAudio;
if (!recordAudio) {
this->clearAudio();
}
}

bool RecordTemp::isRecordMIDI() const {
juce::GenericScopedLock locker(this->lock);
return this->recordMIDI;
}

bool RecordTemp::isRecordAudio() const {
juce::GenericScopedLock locker(this->lock);
return this->recordAudio;
}

void RecordTemp::clearAll() {
juce::GenericScopedLock locker(this->lock);
this->clearAudio();
Expand Down
5 changes: 5 additions & 0 deletions src/audioCore/misc/RecordTemp.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ class RecordTemp final : private juce::DeletedAtShutdown {
void recordData(double timeSec,
const juce::AudioBuffer<float>& buffer, const juce::MidiBuffer& midiMessages);

void setRecordMIDI(bool recordMIDI);
void setRecordAudio(bool recordAudio);
bool isRecordMIDI() const;
bool isRecordAudio() const;

void clearAll();
void clearMIDI();
void clearAudio();
Expand Down
4 changes: 2 additions & 2 deletions src/audioCore/quickAPI/QuickGet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -634,13 +634,13 @@ namespace quickAPI {
return false;
}

bool getSeqTrackRecording(int index) {
RecordState getSeqTrackRecording(int index) {
if (auto graph = AudioCore::getInstance()->getGraph()) {
if (auto track = graph->getSourceProcessor(index)) {
return track->getRecording();
}
}
return false;
return RecordState::NotRecording;
}

const juce::Array<float> getSeqTrackOutputLevel(int index) {
Expand Down
4 changes: 3 additions & 1 deletion src/audioCore/quickAPI/QuickGet.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <JuceHeader.h>
#include "../graph/PluginDecorator.h"
#include "../graph/SeqSourceProcessor.h"
#include "../source/SourceMIDITemp.h"
#include "../Utils.h"

Expand Down Expand Up @@ -116,6 +117,7 @@ namespace quickAPI {
const juce::AudioChannelSet getEffectChannelSet(int trackIndex, int index);
int getEffectInputChannelNum(int trackIndex, int index);

using RecordState = SeqSourceProcessor::RecordState;
int getSeqTrackNum();
const juce::String getSeqTrackName(int index);
const juce::Colour getSeqTrackColor(int index);
Expand All @@ -126,7 +128,7 @@ namespace quickAPI {
const juce::Array<MIDILink> getSeqTrackMIDIOutputToMixer(int index);
const juce::Array<AudioLink> getSeqTrackAudioOutputToMixer(int index);
bool getSeqTrackMute(int index);
bool getSeqTrackRecording(int index);
RecordState getSeqTrackRecording(int index);
const juce::Array<float> getSeqTrackOutputLevel(int index);
const juce::String getSeqTrackType(int index);
bool isSeqTrackHasAudioData(int index);
Expand Down
8 changes: 5 additions & 3 deletions src/ui/component/sequencer/SeqTrackRecComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ void SeqTrackRecComponent::paint(juce::Graphics& g) {

/** Color */
auto& laf = this->getLookAndFeel();
juce::Colour backgroundColor = laf.findColour(this->rec
juce::Colour backgroundColor = laf.findColour((this->rec > 0)
? juce::TextButton::ColourIds::buttonOnColourId
: juce::TextButton::ColourIds::buttonColourId);
juce::Colour iconColor = laf.findColour(this->rec
juce::Colour iconColor = laf.findColour((this->rec > 0)
? juce::TextButton::ColourIds::textColourOnId
: juce::TextButton::ColourIds::textColourOffId);

Expand Down Expand Up @@ -96,5 +96,7 @@ void SeqTrackRecComponent::update(int index) {
}

void SeqTrackRecComponent::changeRec() {
CoreActions::setSeqRec(this->index, !(this->rec));
/** TODO Change Recording State */
CoreActions::setSeqRec(this->index,
static_cast<quickAPI::RecordState>((this->rec > 0) ? 0 : 0x12));
}
2 changes: 1 addition & 1 deletion src/ui/component/sequencer/SeqTrackRecComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class SeqTrackRecComponent final

private:
int index = -1;
bool rec = false;
int rec = 0;

void changeRec();

Expand Down
2 changes: 1 addition & 1 deletion src/ui/misc/CoreActions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ void CoreActions::setSeqMuteAll(bool mute) {
}
}

void CoreActions::setSeqRec(int index, bool rec) {
void CoreActions::setSeqRec(int index, quickAPI::RecordState rec) {
auto action = std::unique_ptr<ActionBase>(new ActionSetSequencerTrackRecording{ index, rec });
ActionDispatcher::getInstance()->dispatch(std::move(action));
}
Expand Down
2 changes: 1 addition & 1 deletion src/ui/misc/CoreActions.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class CoreActions final {
static void setSeqMute(int index, bool mute);
static void setSeqSolo(int index);
static void setSeqMuteAll(bool mute);
static void setSeqRec(int index, bool rec);
static void setSeqRec(int index, quickAPI::RecordState rec);
static void setSeqMIDITrack(int index, int midiTrack);
static void setSeqAudioRef(int index, const juce::String& path,
const std::function<void(uint64_t)>& callback = {});
Expand Down
2 changes: 1 addition & 1 deletion test/testSource.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ AC.addSequencerBlock(0, 0, 300, 0);
AC.removeSequencerBlock(0, 0);

-- Seq Recording
AC.setSequencerTrackRecording(0, true);
AC.setSequencerTrackRecording(0, 0x21);

-- Audio Save Config
AC.setAudioSaveBitsPerSample(".wav", 32);
Expand Down

0 comments on commit f0e554f

Please sign in to comment.