Skip to content

Commit dc32ea2

Browse files
committed
Some changes to device name/alias getter and setters
1 parent 2951d8e commit dc32ea2

10 files changed

+54
-56
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_WaveInputDevice.cpp

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

14821482
//==============================================================================
1483-
juce::String WaveInputDevice::getSelectableDescription()
1484-
{
1485-
if (getDeviceType() == trackWaveDevice)
1486-
return getAlias() + " (" + getDeviceTypeDescription() + ")";
1487-
1488-
return InputDevice::getSelectableDescription();
1489-
}
1490-
14911483
bool WaveInputDevice::isStereoPair() const
14921484
{
14931485
return deviceDescription.getNumChannels() == 2;
@@ -1504,18 +1496,25 @@ void WaveInputDevice::setStereoPair (bool stereo)
15041496
engine.getDeviceManager().setDeviceNumChannels (*this, stereo ? 2 : 1);
15051497
}
15061498

1507-
juce::PopupMenu WaveInputDevice::createChannelGroupMenu()
1499+
juce::PopupMenu WaveInputDevice::createChannelGroupMenu (bool includeSetAllChannelsOptions)
15081500
{
15091501
juce::PopupMenu m;
15101502
auto& dm = engine.getDeviceManager();
15111503
uint32_t channelNum = 0;
1504+
auto currentNumChannels = deviceDescription.getNumChannels();
15121505

15131506
for (auto& option : dm.getPossibleChannelGroupsForDevice (*this, DeviceManager::maxNumChannelsPerDevice))
1514-
m.addItem (option, [this, &dm, num = ++channelNum] { dm.setDeviceNumChannels (*this, num); });
1507+
{
1508+
auto num = ++channelNum;
1509+
m.addItem (option, true, num == currentNumChannels, [this, &dm, num] { dm.setDeviceNumChannels (*this, num); });
1510+
}
15151511

1516-
m.addSeparator();
1517-
m.addItem ("Set all to mono channels", [&dm] { dm.setAllWaveInputsToNumChannels (1); });
1518-
m.addItem ("Set all to stereo pairs", [&dm] { dm.setAllWaveInputsToNumChannels (2); });
1512+
if (includeSetAllChannelsOptions)
1513+
{
1514+
m.addSeparator();
1515+
m.addItem ("Set all to mono channels", [&dm] { dm.setAllWaveInputsToNumChannels (1); });
1516+
m.addItem ("Set all to stereo pairs", [&dm] { dm.setAllWaveInputsToNumChannels (2); });
1517+
}
15191518

15201519
return m;
15211520
}

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

modules/tracktion_engine/plugins/internal/tracktion_InsertPlugin.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ static void getPossibleInputDeviceNames (Engine& e,
3131
hasAudio.setBit (s.size(), true);
3232

3333
s.add (in->getName());
34-
a.add (in->getAlias());
34+
a.add (in->getAliasOrName());
3535
}
3636
}
3737
}
@@ -63,7 +63,7 @@ static void getPossibleOutputDeviceNames (Engine& e,
6363
}
6464

6565
s.add (out->getName());
66-
a.add (out->getAlias());
66+
a.add (out->getAliasOrName());
6767
}
6868
}
6969
}

0 commit comments

Comments
 (0)