Skip to content

Commit 2e56e62

Browse files
committed
Some changes to device name/alias getter and setters
1 parent b37b25d commit 2e56e62

11 files changed

+66
-61
lines changed

modules/tracktion_engine/model/tracks/tracktion_TrackOutput.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ juce::String TrackOutput::getDescriptiveOutputName() const
205205
}
206206

207207
if (auto dev = getOutputDevice (false))
208-
return dev->getAlias();
208+
return dev->getAliasOrName();
209209

210210
return outputDevice;
211211
}
@@ -288,7 +288,7 @@ void TrackOutput::getPossibleOutputDeviceNames (const juce::Array<AudioTrack*>&
288288
}
289289

290290
s.add (out->getName());
291-
a.add (out->getAlias());
291+
a.add (out->getAliasOrName());
292292
}
293293
}
294294
}

modules/tracktion_engine/playback/devices/tracktion_IODevice.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,38 +26,39 @@ juce::String IODevice::getAliasPropName() const
2626
return "devicealias_" + deviceID;
2727
}
2828

29-
juce::String IODevice::getAlias() const
29+
juce::String IODevice::getAliasOrName() const
3030
{
31-
if (alias.isNotEmpty())
32-
return alias;
31+
return alias.isNotEmpty() ? alias : name;
32+
}
3333

34-
return getName();
34+
juce::String IODevice::getAliasIfSet() const
35+
{
36+
return alias;
3537
}
3638

3739
void IODevice::setAlias (const juce::String& a)
3840
{
39-
if (alias != a)
40-
{
41-
alias = a.substring (0, 40).trim();
41+
auto newAlias = a.substring (0, 50).trim();
4242

43-
if (alias == getName())
44-
alias = {};
43+
if (newAlias == getName())
44+
newAlias = {};
4545

46-
if (! isTrackDevice())
47-
{
48-
if (alias.isNotEmpty())
49-
engine.getPropertyStorage().setPropertyItem (SettingID::invalid, getAliasPropName(), alias);
50-
else
51-
engine.getPropertyStorage().removePropertyItem (SettingID::invalid, getAliasPropName());
52-
}
46+
if (alias != newAlias)
47+
{
48+
alias = newAlias;
49+
50+
if (alias.isNotEmpty() && ! isTrackDevice())
51+
engine.getPropertyStorage().setPropertyItem (SettingID::invalid, getAliasPropName(), alias);
52+
else
53+
engine.getPropertyStorage().removePropertyItem (SettingID::invalid, getAliasPropName());
5354

5455
changed();
5556
}
5657
}
5758

5859
juce::String IODevice::getSelectableDescription()
5960
{
60-
return name + " (" + TRANS(getDeviceTypeDescription()) + ")";
61+
return getAliasOrName() + " (" + TRANS(getDeviceTypeDescription()) + ")";
6162
}
6263

6364
bool IODevice::isEnabled() const
@@ -66,5 +67,4 @@ bool IODevice::isEnabled() const
6667
}
6768

6869

69-
7070
}} // namespace tracktion { inline namespace engine

modules/tracktion_engine/playback/devices/tracktion_IODevice.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ class IODevice : public Selectable
2424
~IODevice() override;
2525

2626
//==============================================================================
27-
const juce::String& getName() const { return name; }
28-
juce::String getDeviceID() const { return deviceID; }
27+
const juce::String& getName() const { return name; }
28+
juce::String getDeviceID() const { return deviceID; }
2929

3030
bool isEnabled() const;
3131
virtual void setEnabled (bool) = 0;
@@ -35,8 +35,11 @@ class IODevice : public Selectable
3535
virtual juce::String getDeviceTypeDescription() const = 0;
3636

3737
/// the alias is the name shown in the draggable input device components
38-
juce::String getAlias() const;
3938
void setAlias (const juce::String& newAlias);
39+
/// Returns the alias if set, otherwise the name.
40+
juce::String getAliasOrName() const;
41+
/// Returns the alias, or an empty string if not set.
42+
juce::String getAliasIfSet() const;
4043

4144
juce::String getSelectableDescription() override;
4245

modules/tracktion_engine/playback/devices/tracktion_VirtualMidiInputDevice.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,4 @@ void VirtualMidiInputDevice::handleMessageFromPhysicalDevice (PhysicalMidiInputD
134134
handleIncomingMidiMessage (m, dev.getMPESourceID());
135135
}
136136

137-
juce::String VirtualMidiInputDevice::getSelectableDescription()
138-
{
139-
if (getDeviceType() == trackMidiDevice)
140-
return getAlias() + " (" + getDeviceTypeDescription() + ")";
141-
142-
return MidiInputDevice::getSelectableDescription();
143-
}
144-
145137
}} // namespace tracktion { inline namespace engine

modules/tracktion_engine/playback/devices/tracktion_VirtualMidiInputDevice.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ class VirtualMidiInputDevice : public MidiInputDevice
2121

2222
using MidiInputDevice::handleIncomingMidiMessage;
2323
void handleIncomingMidiMessage (const juce::MidiMessage&, MPESourceID) override;
24-
juce::String getSelectableDescription() override;
2524

2625
void setEnabled (bool) override;
2726
void loadProps() override;

modules/tracktion_engine/playback/devices/tracktion_WaveDeviceDescription.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -572,13 +572,20 @@ static juce::String getDefaultChannelName (bool isInput, uint32_t index)
572572
.replace ("123", std::to_string (index + 1));
573573
}
574574

575+
static void replaceBareNumbersWithNames (juce::StringArray& channelNames, bool isInput)
576+
{
577+
for (int i = 0; i < channelNames.size(); ++i)
578+
if (channelNames[i].trim() != juce::String (i + 1))
579+
return;
580+
581+
for (int i = 0; i < channelNames.size(); ++i)
582+
if (channelNames[i].trim() == juce::String (i + 1))
583+
channelNames.set (i, getDefaultChannelName (isInput, (uint32_t) i));
584+
}
585+
575586
static void refreshNamesInList (std::vector<WaveDeviceDescription>& descriptions, juce::StringArray channelNames, bool isInput)
576587
{
577-
if (channelNames.size() <= 2)
578-
{
579-
channelNames.set (0, getDefaultChannelName (isInput, 0));
580-
channelNames.set (1, getDefaultChannelName (isInput, 1));
581-
}
588+
replaceBareNumbersWithNames (channelNames, isInput);
582589

583590
for (auto& desc : descriptions)
584591
{

modules/tracktion_engine/playback/devices/tracktion_WaveInputDevice.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,14 +1518,6 @@ void WaveInputDevice::saveProps()
15181518
}
15191519

15201520
//==============================================================================
1521-
juce::String WaveInputDevice::getSelectableDescription()
1522-
{
1523-
if (getDeviceType() == trackWaveDevice)
1524-
return getAlias() + " (" + getDeviceTypeDescription() + ")";
1525-
1526-
return InputDevice::getSelectableDescription();
1527-
}
1528-
15291521
bool WaveInputDevice::isStereoPair() const
15301522
{
15311523
return deviceDescription.getNumChannels() == 2;
@@ -1542,18 +1534,25 @@ void WaveInputDevice::setStereoPair (bool stereo)
15421534
engine.getDeviceManager().setDeviceNumChannels (*this, stereo ? 2 : 1);
15431535
}
15441536

1545-
juce::PopupMenu WaveInputDevice::createChannelGroupMenu()
1537+
juce::PopupMenu WaveInputDevice::createChannelGroupMenu (bool includeSetAllChannelsOptions)
15461538
{
15471539
juce::PopupMenu m;
15481540
auto& dm = engine.getDeviceManager();
15491541
uint32_t channelNum = 0;
1542+
auto currentNumChannels = deviceDescription.getNumChannels();
15501543

15511544
for (auto& option : dm.getPossibleChannelGroupsForDevice (*this, DeviceManager::maxNumChannelsPerDevice))
1552-
m.addItem (option, [this, &dm, num = ++channelNum] { dm.setDeviceNumChannels (*this, num); });
1545+
{
1546+
auto num = ++channelNum;
1547+
m.addItem (option, true, num == currentNumChannels, [this, &dm, num] { dm.setDeviceNumChannels (*this, num); });
1548+
}
15531549

1554-
m.addSeparator();
1555-
m.addItem ("Set all to mono channels", [&dm] { dm.setAllWaveInputsToNumChannels (1); });
1556-
m.addItem ("Set all to stereo pairs", [&dm] { dm.setAllWaveInputsToNumChannels (2); });
1550+
if (includeSetAllChannelsOptions)
1551+
{
1552+
m.addSeparator();
1553+
m.addItem ("Set all to mono channels", [&dm] { dm.setAllWaveInputsToNumChannels (1); });
1554+
m.addItem ("Set all to stereo pairs", [&dm] { dm.setAllWaveInputsToNumChannels (2); });
1555+
}
15571556

15581557
return m;
15591558
}

modules/tracktion_engine/playback/devices/tracktion_WaveInputDevice.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class WaveInputDevice : public InputDevice
4141
double getRecordAdjustmentMs() const { return recordAdjustMs; }
4242
bool isStereoPair() const;
4343
void setStereoPair (bool);
44-
juce::PopupMenu createChannelGroupMenu();
44+
juce::PopupMenu createChannelGroupMenu (bool includeSetAllChannelsOptions);
4545
juce::Array<int> getAvailableBitDepths() const;
4646
void setBitDepth (int);
4747
int getBitDepth() const { return bitDepth; }
@@ -71,8 +71,6 @@ class WaveInputDevice : public InputDevice
7171
void updateRetrospectiveBufferLength (double length) override;
7272

7373
//==============================================================================
74-
juce::String getSelectableDescription() override;
75-
7674
const WaveDeviceDescription deviceDescription;
7775

7876
protected:

modules/tracktion_engine/playback/devices/tracktion_WaveOutputDevice.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,18 +143,25 @@ void WaveOutputDevice::setStereoPair (bool stereo)
143143
engine.getDeviceManager().setDeviceNumChannels (*this, stereo ? 2 : 1);
144144
}
145145

146-
juce::PopupMenu WaveOutputDevice::createChannelGroupMenu()
146+
juce::PopupMenu WaveOutputDevice::createChannelGroupMenu (bool includeSetAllChannelsOptions)
147147
{
148148
juce::PopupMenu m;
149149
auto& dm = engine.getDeviceManager();
150150
uint32_t channelNum = 0;
151+
auto currentNumChannels = deviceDescription.getNumChannels();
151152

152153
for (auto& option : dm.getPossibleChannelGroupsForDevice (*this, DeviceManager::maxNumChannelsPerDevice))
153-
m.addItem (option, [this, &dm, num = ++channelNum] { dm.setDeviceNumChannels (*this, num); });
154+
{
155+
auto num = ++channelNum;
156+
m.addItem (option, true, num == currentNumChannels, [this, &dm, num] { dm.setDeviceNumChannels (*this, num); });
157+
}
154158

155-
m.addSeparator();
156-
m.addItem ("Set all to mono channels", [&dm] { dm.setAllWaveOutputsToNumChannels (1); });
157-
m.addItem ("Set all to stereo pairs", [&dm] { dm.setAllWaveOutputsToNumChannels (2); });
159+
if (includeSetAllChannelsOptions)
160+
{
161+
m.addSeparator();
162+
m.addItem ("Set all to mono channels", [&dm] { dm.setAllWaveOutputsToNumChannels (1); });
163+
m.addItem ("Set all to stereo pairs", [&dm] { dm.setAllWaveOutputsToNumChannels (2); });
164+
}
158165

159166
return m;
160167
}

modules/tracktion_engine/playback/devices/tracktion_WaveOutputDevice.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class WaveOutputDevice : public OutputDevice
4848

4949
bool isStereoPair() const;
5050
void setStereoPair (bool);
51-
juce::PopupMenu createChannelGroupMenu();
51+
juce::PopupMenu createChannelGroupMenu (bool includeSetAllChannelsOptions);
5252

5353
WaveOutputDeviceInstance* createInstance (EditPlaybackContext&);
5454

0 commit comments

Comments
 (0)