Skip to content

Commit 3cc98f9

Browse files
committed
Refactored InputDevice and OutputDevice to have a common base class
1 parent 65d3132 commit 3cc98f9

23 files changed

+192
-169
lines changed

modules/tracktion_engine/model/tracks/tracktion_AudioTrack.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,7 @@ AudioTrack::AudioTrack (Edit& ed, const juce::ValueTree& v)
125125
desc.channels = { ChannelIndex (0, juce::AudioChannelSet::left),
126126
ChannelIndex (1, juce::AudioChannelSet::right) };
127127

128-
waveInputDevice = std::make_unique<WaveInputDevice> (edit.engine, TRANS("Track Wave Input"),
129-
desc, InputDevice::trackWaveDevice);
128+
waveInputDevice = std::make_unique<WaveInputDevice> (edit.engine, desc, InputDevice::trackWaveDevice);
130129

131130
midiInputDevice = std::make_unique<VirtualMidiInputDevice> (edit.engine, itemIDString,
132131
InputDevice::trackMidiDevice,
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
,--. ,--. ,--. ,--.
3+
,-' '-.,--.--.,--,--.,---.| |,-.,-' '-.`--' ,---. ,--,--, Copyright 2024
4+
'-. .-'| .--' ,-. | .--'| /'-. .-',--.| .-. || \ Tracktion Software
5+
| | | | \ '-' \ `--.| \ \ | | | |' '-' '| || | Corporation
6+
`---' `--' `--`--'`---'`--'`--' `---' `--' `---' `--''--' www.tracktion.com
7+
8+
Tracktion Engine uses a GPL/commercial licence - see LICENCE.md for details.
9+
*/
10+
11+
namespace tracktion { inline namespace engine
12+
{
13+
14+
IODevice::IODevice (Engine& e, juce::String n, juce::String idToUse)
15+
: engine (e), deviceID (std::move (idToUse)), name (std::move (n))
16+
{
17+
alias = engine.getPropertyStorage().getPropertyItem (SettingID::invalid, getAliasPropName());
18+
}
19+
20+
IODevice::~IODevice()
21+
{
22+
}
23+
24+
juce::String IODevice::getAliasPropName() const
25+
{
26+
return "devicealias_" + deviceID;
27+
}
28+
29+
juce::String IODevice::getAlias() const
30+
{
31+
if (alias.isNotEmpty())
32+
return alias;
33+
34+
return getName();
35+
}
36+
37+
void IODevice::setAlias (const juce::String& a)
38+
{
39+
if (alias != a)
40+
{
41+
alias = a.substring (0, 40).trim();
42+
43+
if (alias == getName())
44+
alias = {};
45+
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+
}
53+
54+
changed();
55+
}
56+
}
57+
58+
juce::String IODevice::getSelectableDescription()
59+
{
60+
return name + " (" + TRANS(getDeviceTypeDescription()) + ")";
61+
}
62+
63+
bool IODevice::isEnabled() const
64+
{
65+
return enabled;
66+
}
67+
68+
69+
70+
}} // namespace tracktion { inline namespace engine
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
,--. ,--. ,--. ,--.
3+
,-' '-.,--.--.,--,--.,---.| |,-.,-' '-.`--' ,---. ,--,--, Copyright 2024
4+
'-. .-'| .--' ,-. | .--'| /'-. .-',--.| .-. || \ Tracktion Software
5+
| | | | \ '-' \ `--.| \ \ | | | |' '-' '| || | Corporation
6+
`---' `--' `--`--'`---'`--'`--' `---' `--' `---' `--''--' www.tracktion.com
7+
8+
Tracktion Engine uses a GPL/commercial licence - see LICENCE.md for details.
9+
*/
10+
11+
namespace tracktion { inline namespace engine
12+
{
13+
14+
/**
15+
A base class for input/output devices.
16+
17+
See InputDevice and OutputDevice for more details.
18+
*/
19+
class IODevice : public Selectable
20+
{
21+
public:
22+
//==============================================================================
23+
IODevice (Engine&, juce::String name, juce::String deviceID);
24+
~IODevice() override;
25+
26+
//==============================================================================
27+
const juce::String& getName() const { return name; }
28+
juce::String getDeviceID() const { return deviceID; }
29+
30+
bool isEnabled() const;
31+
virtual void setEnabled (bool) = 0;
32+
33+
virtual bool isMidi() const = 0;
34+
virtual bool isTrackDevice() const = 0;
35+
virtual juce::String getDeviceTypeDescription() const = 0;
36+
37+
/// the alias is the name shown in the draggable input device components
38+
juce::String getAlias() const;
39+
void setAlias (const juce::String& newAlias);
40+
41+
juce::String getSelectableDescription() override;
42+
43+
//==============================================================================
44+
Engine& engine;
45+
46+
protected:
47+
std::atomic<bool> enabled { false };
48+
49+
const juce::String deviceID, name;
50+
51+
private:
52+
juce::String alias;
53+
juce::String getAliasPropName() const;
54+
55+
const juce::String& getType() const; // Deprecated: use getDeviceTypeDescription() instead
56+
};
57+
58+
59+
}} // namespace tracktion { inline namespace engine

modules/tracktion_engine/playback/devices/tracktion_InputDevice.cpp

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -11,59 +11,21 @@
1111
namespace tracktion { inline namespace engine
1212
{
1313

14-
InputDevice::InputDevice (Engine& e, juce::String t, juce::String n, juce::String idToUse)
15-
: engine (e), type (t), deviceID (std::move (idToUse)), name (n)
14+
InputDevice::InputDevice (Engine& e, juce::String n, juce::String idToUse)
15+
: IODevice (e, std::move (n), std::move (idToUse))
1616
{
17-
alias = e.getPropertyStorage().getPropertyItem (SettingID::invalid, getAliasPropName());
1817
}
1918

2019
InputDevice::~InputDevice()
2120
{
2221
}
2322

24-
juce::String InputDevice::getAliasPropName() const
25-
{
26-
return type + "in_" + name + "_alias";
27-
}
28-
2923
bool InputDevice::isTrackDevice() const
3024
{
3125
return getDeviceType() == trackWaveDevice
3226
|| getDeviceType() == trackMidiDevice;
3327
}
3428

35-
juce::String InputDevice::getAlias() const
36-
{
37-
if (alias.trim().isNotEmpty())
38-
return alias;
39-
40-
return getName();
41-
}
42-
43-
void InputDevice::setAlias (const juce::String& a)
44-
{
45-
if (alias != a)
46-
{
47-
alias = a.substring (0, 40).trim();
48-
49-
if (alias == getName())
50-
alias = {};
51-
52-
if (! isTrackDevice())
53-
{
54-
if (alias.isNotEmpty())
55-
engine.getPropertyStorage().setPropertyItem (SettingID::invalid, getAliasPropName(), alias);
56-
else
57-
engine.getPropertyStorage().removePropertyItem (SettingID::invalid, getAliasPropName());
58-
}
59-
}
60-
}
61-
62-
bool InputDevice::isEnabled() const
63-
{
64-
return enabled;
65-
}
66-
6729
void InputDevice::setMonitorMode (MonitorMode newMode)
6830
{
6931
if (monitorMode == newMode)
@@ -75,11 +37,6 @@ void InputDevice::setMonitorMode (MonitorMode newMode)
7537
saveProps();
7638
}
7739

78-
juce::String InputDevice::getSelectableDescription()
79-
{
80-
return name + " (" + type + ")";
81-
}
82-
8340
void InputDevice::setRetrospectiveLock (Engine& e, const juce::Array<InputDeviceInstance*>& devices, bool lock)
8441
{
8542
const juce::ScopedLock sl (e.getDeviceManager().deviceManager.getAudioCallbackLock());

modules/tracktion_engine/playback/devices/tracktion_InputDevice.h

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace tracktion { inline namespace engine
1818
For each InputDevice, there may be multiple InputDeviceInstance objects, for
1919
all the active EditPlaybackContexts
2020
*/
21-
class InputDevice : public Selectable
21+
class InputDevice : public IODevice
2222
{
2323
public:
2424
/** enum to allow quick querying of the device type. */
@@ -32,28 +32,16 @@ class InputDevice : public Selectable
3232
};
3333

3434
//==============================================================================
35-
InputDevice (Engine&, juce::String type, juce::String name, juce::String deviceID);
35+
InputDevice (Engine&, juce::String name, juce::String deviceID);
3636
~InputDevice() override;
3737

3838
//==============================================================================
39-
const juce::String& getName() const { return name; }
40-
const juce::String& getType() const { return type; }
41-
42-
juce::String getDeviceID() const { return deviceID; }
43-
4439
virtual DeviceType getDeviceType() const = 0;
45-
bool isTrackDevice() const;
46-
47-
/** the alias is the name shown in the draggable input device components */
48-
juce::String getAlias() const;
49-
void setAlias (const juce::String& newAlias);
40+
bool isTrackDevice() const override;
5041

5142
virtual bool isAvailableToEdit() const { return isEnabled(); }
5243

53-
bool isEnabled() const;
54-
virtual void setEnabled (bool) = 0;
55-
56-
virtual bool isMidi() const { return false; }
44+
bool isMidi() const override { return false; }
5745

5846
/** Enum to describe monitor modes. */
5947
enum class MonitorMode
@@ -76,24 +64,14 @@ class InputDevice : public Selectable
7664
virtual void updateRetrospectiveBufferLength (double length) = 0;
7765

7866
//==============================================================================
79-
juce::String getSelectableDescription() override;
80-
8167
virtual void saveProps() = 0;
8268

83-
Engine& engine;
8469
LevelMeasurer levelMeasurer;
8570

8671
protected:
87-
std::atomic<bool> enabled { false };
8872
MonitorMode monitorMode = MonitorMode::automatic;
8973
MonitorMode defaultMonitorMode = MonitorMode::automatic;
9074
bool retrospectiveRecordLock = false;
91-
92-
private:
93-
const juce::String type, deviceID, name;
94-
juce::String alias;
95-
96-
juce::String getAliasPropName() const;
9775
};
9876

9977

modules/tracktion_engine/playback/devices/tracktion_MidiInputDevice.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,8 @@ struct RetrospectiveMidiBuffer
330330
};
331331

332332
//==============================================================================
333-
MidiInputDevice::MidiInputDevice (Engine& e, juce::String deviceType, juce::String deviceName, juce::String deviceIDToUse)
334-
: InputDevice (e, std::move (deviceType), std::move (deviceName), std::move (deviceIDToUse))
333+
MidiInputDevice::MidiInputDevice (Engine& e, juce::String deviceName, juce::String deviceIDToUse)
334+
: InputDevice (e, std::move (deviceName), std::move (deviceIDToUse))
335335
{
336336
enabled = true;
337337
levelMeasurer.setShowMidi (true);

modules/tracktion_engine/playback/devices/tracktion_MidiInputDevice.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class MidiInputDevice : public InputDevice,
1818
private juce::MidiKeyboardStateListener
1919
{
2020
public:
21-
MidiInputDevice (Engine&, juce::String type, juce::String name, juce::String deviceID);
21+
MidiInputDevice (Engine&, juce::String name, juce::String deviceID);
2222
~MidiInputDevice() override;
2323

2424
virtual juce::String openDevice() = 0;

modules/tracktion_engine/playback/devices/tracktion_MidiOutputDevice.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ class MidiClockGenerator
262262

263263
//==============================================================================
264264
MidiOutputDevice::MidiOutputDevice (Engine& e, juce::MidiDeviceInfo info)
265-
: OutputDevice (e, NEEDS_TRANS("MIDI Output"), info.name, info.identifier),
265+
: OutputDevice (e, info.name, "midiout_" + juce::String::toHexString (info.identifier.hashCode())),
266266
deviceInfo (std::move (info))
267267
{
268268
enabled = true;

modules/tracktion_engine/playback/devices/tracktion_MidiOutputDevice.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ class MidiOutputDevice : public OutputDevice
1818
MidiOutputDevice (Engine&, juce::MidiDeviceInfo);
1919
~MidiOutputDevice() override;
2020

21+
juce::String getDeviceTypeDescription() const override { return NEEDS_TRANS("MIDI Output"); }
22+
2123
juce::String openDevice() override;
2224
void closeDevice() override;
2325

modules/tracktion_engine/playback/devices/tracktion_OutputDevice.cpp

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -11,63 +11,15 @@
1111
namespace tracktion { inline namespace engine
1212
{
1313

14-
OutputDevice::OutputDevice (Engine& e, juce::String t, juce::String n, juce::String idToUse)
15-
: engine (e), type (t),
16-
deviceID ("out_" + juce::String::toHexString ((t + idToUse).hashCode())),
17-
name (n)
14+
OutputDevice::OutputDevice (Engine& e, juce::String n, juce::String idToUse)
15+
: IODevice (e, std::move (n), std::move (idToUse))
1816
{
19-
alias = engine.getPropertyStorage().getPropertyItem (SettingID::invalid, getAliasPropName());
2017
}
2118

2219
OutputDevice::~OutputDevice()
2320
{
2421
}
2522

26-
juce::String OutputDevice::getAliasPropName() const
27-
{
28-
return type + "out_" + name + "_alias";
29-
}
30-
31-
juce::String OutputDevice::getName() const
32-
{
33-
return name;
34-
}
35-
36-
juce::String OutputDevice::getAlias() const
37-
{
38-
if (alias.isNotEmpty())
39-
return alias;
40-
41-
return getName();
42-
}
43-
44-
void OutputDevice::setAlias (const juce::String& a)
45-
{
46-
if (alias != a)
47-
{
48-
alias = a.substring (0, 40).trim();
49-
50-
if (alias == getName())
51-
alias = {};
52-
53-
if (alias.isNotEmpty())
54-
engine.getPropertyStorage().setPropertyItem (SettingID::invalid, getAliasPropName(), alias);
55-
else
56-
engine.getPropertyStorage().removePropertyItem (SettingID::invalid, getAliasPropName());
57-
58-
changed();
59-
}
60-
}
61-
62-
juce::String OutputDevice::getSelectableDescription()
63-
{
64-
return name + " (" + TRANS(type) + ")";
65-
}
66-
67-
bool OutputDevice::isEnabled() const
68-
{
69-
return enabled;
70-
}
7123

7224
//==============================================================================
7325
OutputDeviceInstance::OutputDeviceInstance (OutputDevice& d, EditPlaybackContext& c)

0 commit comments

Comments
 (0)