Skip to content

Commit 894ceaa

Browse files
Add seq track input menu
1 parent 3930b02 commit 894ceaa

File tree

4 files changed

+110
-1
lines changed

4 files changed

+110
-1
lines changed

src/ui/component/sequencer/SeqTrackInputMonitoringComponent.cpp

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,20 +84,68 @@ void SeqTrackInputMonitoringComponent::mouseUp(const juce::MouseEvent& event) {
8484
this->changeInputMonitoring();
8585
}
8686
else if (event.mods.isRightButtonDown()) {
87-
this->changeInputMonitoring();
87+
this->showMenu();
8888
}
8989
}
9090
}
9191

9292
void SeqTrackInputMonitoringComponent::update(int index) {
9393
this->index = index;
9494
if (index > -1) {
95+
/** Get Input Monitoring State */
9596
this->inputMonitoring = quickAPI::getSeqTrackInputMonitoring(index);
9697

98+
/** Get Input Connections */
99+
this->midiInput = quickAPI::getSeqTrackMIDIInputFromDevice(index);
100+
this->audioInput = quickAPI::getSeqTrackAudioInputFromDevice(index);
101+
102+
/** Repaint */
97103
this->repaint();
98104
}
99105
}
100106

101107
void SeqTrackInputMonitoringComponent::changeInputMonitoring() {
102108
CoreActions::setSeqInputMonitoring(this->index, !(this->inputMonitoring));
103109
}
110+
111+
enum SeqInputMonitoringButtonActionType {
112+
MIDIInput = 1, AudioInput
113+
};
114+
115+
void SeqTrackInputMonitoringComponent::showMenu() {
116+
auto menu = this->createMenu();
117+
int result = menu.show();
118+
119+
switch (result) {
120+
case SeqInputMonitoringButtonActionType::MIDIInput:
121+
this->changeMIDIInput();
122+
break;
123+
case SeqInputMonitoringButtonActionType::AudioInput:
124+
this->changeAudioInput();
125+
break;
126+
}
127+
}
128+
129+
void SeqTrackInputMonitoringComponent::changeMIDIInput() {
130+
CoreActions::setSeqMIDIInputFromDevice(this->index, !this->midiInput);
131+
}
132+
133+
void SeqTrackInputMonitoringComponent::changeAudioInput() {
134+
juce::Array<std::tuple<int, int>> links;
135+
for (auto& [src, srcc, dst, dstc] : this->audioInput) {
136+
links.add({ srcc, dstc });
137+
}
138+
139+
CoreActions::setSeqAudioInputFromDeviceGUI(this->index, true, links);
140+
}
141+
142+
juce::PopupMenu SeqTrackInputMonitoringComponent::createMenu() {
143+
juce::PopupMenu menu;
144+
145+
menu.addItem(SeqInputMonitoringButtonActionType::MIDIInput,
146+
TRANS("MIDI Input"), true, this->midiInput);
147+
menu.addItem(SeqInputMonitoringButtonActionType::AudioInput,
148+
TRANS("Audio Input"), true, (this->audioInput.size() > 0));
149+
150+
return menu;
151+
}

src/ui/component/sequencer/SeqTrackInputMonitoringComponent.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,19 @@ class SeqTrackInputMonitoringComponent final
2020
int index = -1;
2121
bool inputMonitoring = false;
2222

23+
using MIDILink = std::tuple<int, int>;
24+
using AudioLink = std::tuple<int, int, int, int>;
25+
26+
bool midiInput = false;
27+
juce::Array<AudioLink> audioInput;
28+
2329
void changeInputMonitoring();
30+
void showMenu();
31+
32+
void changeMIDIInput();
33+
void changeAudioInput();
34+
35+
juce::PopupMenu createMenu();
2436

2537
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(SeqTrackInputMonitoringComponent)
2638
};

src/ui/misc/CoreActions.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,20 @@ void CoreActions::setSeqName(int index, const juce::String& name) {
392392
ActionDispatcher::getInstance()->dispatch(std::move(action));
393393
}
394394

395+
void CoreActions::setSeqMIDIInputFromDevice(int index, bool input) {
396+
auto action = input
397+
? std::unique_ptr<ActionBase>(new ActionAddSequencerTrackMidiInput{ index })
398+
: std::unique_ptr<ActionBase>(new ActionRemoveSequencerTrackMidiInput{ index });
399+
ActionDispatcher::getInstance()->dispatch(std::move(action));
400+
}
401+
402+
void CoreActions::setSeqAudioInputFromDevice(int index, int channel, int srcChannel, bool input) {
403+
auto action = input
404+
? std::unique_ptr<ActionBase>(new ActionAddSequencerTrackInputFromDevice{ srcChannel, index, channel })
405+
: std::unique_ptr<ActionBase>(new ActionRemoveSequencerTrackInputFromDevice{ srcChannel, index, channel });
406+
ActionDispatcher::getInstance()->dispatch(std::move(action));
407+
}
408+
395409
void CoreActions::setSeqMIDIOutputToMixer(
396410
int index, int mixerIndex, bool output) {
397411
auto action = output
@@ -1002,6 +1016,37 @@ void CoreActions::setSeqNameGUI(int index) {
10021016
CoreActions::askForNameGUIAsync(callback, defaultName);
10031017
}
10041018

1019+
void CoreActions::setSeqAudioInputFromDeviceGUI(int index, bool input,
1020+
const juce::Array<std::tuple<int, int>>& links) {
1021+
/** Callback */
1022+
auto callback = [index](int srcc, int dstc, bool input) {
1023+
CoreActions::setSeqAudioInputFromDevice(index, dstc, srcc, input);
1024+
};
1025+
1026+
/** Remove */
1027+
if (!input) {
1028+
for (auto& [srcc, dstc] : links) {
1029+
callback(srcc, dstc, false);
1030+
}
1031+
return;
1032+
}
1033+
1034+
/** Name */
1035+
juce::String deviceName = quickAPI::getAudioDeviceName(true);
1036+
juce::String trackName = TRANS("Sequencer Track") + " #" + juce::String{ index } + " " + quickAPI::getSeqTrackName(index);
1037+
1038+
/** Channels */
1039+
int deviceTotalChannels = quickAPI::getAudioDeviceChannelNum(true);
1040+
int trackTotalChannels = quickAPI::getSeqTrackInputChannelNum(index);
1041+
auto deviceChannelSet = juce::AudioChannelSet::discreteChannels(deviceTotalChannels);
1042+
auto trackChannelSet = quickAPI::getSeqTrackChannelSet(index);
1043+
1044+
/** Ask For Channels */
1045+
CoreActions::askForAudioChannelLinkGUIAsync(callback, links,
1046+
deviceChannelSet, trackChannelSet, deviceTotalChannels, trackTotalChannels,
1047+
deviceName, trackName, true);
1048+
}
1049+
10051050
void CoreActions::setSeqAudioOutputToMixerGUI(int index, int mixerIndex, bool output,
10061051
const juce::Array<std::tuple<int, int>>& links) {
10071052
/** Callback */

src/ui/misc/CoreActions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ class CoreActions final {
8585
static void insertSeq(int index, int type);
8686
static void setSeqColor(int index, const juce::Colour& color);
8787
static void setSeqName(int index, const juce::String& name);
88+
static void setSeqMIDIInputFromDevice(int index, bool input);
89+
static void setSeqAudioInputFromDevice(int index, int channel, int srcChannel, bool input);
8890
static void setSeqMIDIOutputToMixer(int index, int mixerIndex, bool output);
8991
static void setSeqAudioOutputToMixer(int index, int channel, int mixerIndex, int dstChannel, bool output);
9092
static void setSeqMute(int index, bool mute);
@@ -167,6 +169,8 @@ class CoreActions final {
167169
static void insertSeqGUI();
168170
static void setSeqColorGUI(int index);
169171
static void setSeqNameGUI(int index);
172+
static void setSeqAudioInputFromDeviceGUI(int index, bool input,
173+
const juce::Array<std::tuple<int, int>>& links);
170174
static void setSeqAudioOutputToMixerGUI(int index, int mixerIndex, bool output,
171175
const juce::Array<std::tuple<int, int>>& links);
172176
static void setSeqMIDITrackGUI(int index);

0 commit comments

Comments
 (0)