Skip to content

Commit

Permalink
EXPERIMENTAL_MIDI_IN redone with constexpr if
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul-Licameli committed Apr 15, 2024
1 parent 54475f5 commit 21cbb07
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 72 deletions.
18 changes: 10 additions & 8 deletions libraries/lib-note-track/NoteTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,8 @@ void NoteTrack::WriteXML(XMLWriter &xmlFile) const
#include "AudioIOBase.h"
#include "portmidi.h"

// FIXME: When EXPERIMENTAL_MIDI_IN is added (eventually) this should also be enabled -- Poke
// FIXME: When Experimental::MidiIn is added (eventually) this should also be
// enabled -- Poke
wxString GetMIDIDeviceInfo()
{
wxStringOutputStream o;
Expand All @@ -904,7 +905,8 @@ wxString GetMIDIDeviceInfo()
s << XO("Default recording device number: %d\n").Format( recDeviceNum );
s << XO("Default playback device number: %d\n").Format( playDeviceNum );

auto recDevice = MIDIRecordingDevice.Read();
const auto recDevice =
Experimental::MidiIn ? MIDIRecordingDevice->Read() : wxString{};
auto playDevice = MIDIPlaybackDevice.Read();

// This gets info on all available audio devices (input and output)
Expand Down Expand Up @@ -969,19 +971,19 @@ wxString GetMIDIDeviceInfo()

// Not internationalizing these alpha-only messages
s << wxT("==============================\n");
#ifdef EXPERIMENTAL_MIDI_IN
s << wxT("EXPERIMENTAL_MIDI_IN is enabled\n");
#else
s << wxT("EXPERIMENTAL_MIDI_IN is NOT enabled\n");
#endif
if constexpr (Experimental::MidiIn)
s << wxT("Experimental::MidiIn is enabled\n");
else
s << wxT("Experimental::MidiIn is NOT enabled\n");

#endif

return o.GetString();
}

StringSetting MIDIPlaybackDevice{ L"/MidiIO/PlaybackDevice", L"" };
StringSetting MIDIRecordingDevice{ L"/MidiIO/RecordingDevice", L"" };
ConditionallyPresent<StringSetting, Experimental::MidiIn> MIDIRecordingDevice{
L"/MidiIO/RecordingDevice", L"" };
IntSetting MIDISynthLatency_ms{ L"/MidiIO/SynthLatency", 5 };

#endif // USE_MIDI
8 changes: 7 additions & 1 deletion libraries/lib-note-track/NoteTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@

#include <utility>
#include "AudioIOSequences.h"
#include "ConditionallyPresent.h"
#include "CRTPBase.h"
#include "Prefs.h"
#include "PlayableTrack.h"

namespace Experimental {
constexpr bool MidiIn = false;
}

#if defined(USE_MIDI)

// define this switch to play MIDI during redisplay to sonify run times
Expand Down Expand Up @@ -217,7 +222,8 @@ class NOTE_TRACK_API NoteTrack final
};

extern NOTE_TRACK_API StringSetting MIDIPlaybackDevice;
extern NOTE_TRACK_API StringSetting MIDIRecordingDevice;
extern NOTE_TRACK_API
ConditionallyPresent<StringSetting, Experimental::MidiIn> MIDIRecordingDevice;
extern NOTE_TRACK_API IntSetting MIDISynthLatency_ms;

ENUMERATE_TRACK_TYPE(NoteTrack);
Expand Down
2 changes: 0 additions & 2 deletions src/Experimental.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ set( EXPERIMENTAL_OPTIONS_LIST
# EQ accelerated code
#EQ_SSE_THREADED

#MIDI_IN

# JKC, 17 Aug 2017
# Enables the MIDI note stretching feature, which currently
# a) Is broken on Linux (Bug 1646)
Expand Down
110 changes: 55 additions & 55 deletions src/prefs/MidiIOPrefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ other settings.
whether or not to play other tracks while recording one (duplex).
*//********************************************************************/


#include "MidiIOPrefs.h"

#include <wx/defs.h>
Expand All @@ -33,6 +31,7 @@ other settings.

#include <portmidi.h>

#include "Experimental.h"
#include "NoteTrack.h"
#include "Prefs.h"
#include "ShuttleGui.h"
Expand Down Expand Up @@ -83,9 +82,10 @@ void MidiIOPrefs::Populate()

// Get current setting for devices
mPlayDevice = MIDIPlaybackDevice.Read();
#ifdef EXPERIMENTAL_MIDI_IN
mRecordDevice = MIDIRecordingDevice.Read();
#endif

if constexpr (Experimental::MidiIn)
mRecordDevice = MIDIRecordingDevice->Read();

// mRecordChannels = gPrefs->Read(wxT("/MidiIO/RecordChannels"), 2L);

//------------------------- Main section --------------------
Expand Down Expand Up @@ -164,26 +164,26 @@ void MidiIOPrefs::PopulateOrExchange( ShuttleGui & S )
S.EndMultiColumn();
}
S.EndStatic();
#ifdef EXPERIMENTAL_MIDI_IN
S.StartStatic(XO("Recording"));
{
S.StartMultiColumn(2);
if constexpr (Experimental::MidiIn) {
S.StartStatic(XO("Recording"));
{
S.Id(RecordID);
mRecord = S.AddChoice(XO("De&vice:"),
{} );

S.Id(ChannelsID);
/*
mChannels = S.AddChoice(XO("&Channels:"),
wxEmptyString,
{} );
*/
S.StartMultiColumn(2);
{
S.Id(RecordID);
mRecord = S.AddChoice(XO("De&vice:"),
{} );

S.Id(ChannelsID);
/*
mChannels = S.AddChoice(XO("&Channels:"),
wxEmptyString,
{} );
*/
}
S.EndMultiColumn();
}
S.EndMultiColumn();
S.EndStatic();
}
S.EndStatic();
#endif
S.EndScroller();

}
Expand All @@ -197,9 +197,8 @@ void MidiIOPrefs::OnHost(wxCommandEvent & WXUNUSED(e))
int nDevices = Pm_CountDevices();

mPlay->Clear();
#ifdef EXPERIMENTAL_MIDI_IN
mRecord->Clear();
#endif
if constexpr (Experimental::MidiIn)
mRecord->Clear();

wxArrayStringEx playnames;
wxArrayStringEx recordnames;
Expand All @@ -219,40 +218,41 @@ void MidiIOPrefs::OnHost(wxCommandEvent & WXUNUSED(e))
mPlay->SetSelection(index);
}
}
#ifdef EXPERIMENTAL_MIDI_IN
if (info->input) {
recordnames.push_back(name);
index = mRecord->Append(name, (void *) info);
if (device == mRecordDevice) {
mRecord->SetSelection(index);
if constexpr (Experimental::MidiIn)
if (info->input) {
recordnames.push_back(name);
index = mRecord->Append(name, (void *) info);
if (device == mRecordDevice) {
mRecord->SetSelection(index);
}
}
}
#endif
}
}

if (mPlay->GetCount() == 0) {
playnames.push_back(_("No devices found"));
mPlay->Append(playnames[0], (void *) NULL);
}
#ifdef EXPERIMENTAL_MIDI_IN
if (mRecord->GetCount() == 0) {
recordnames.push_back(_("No devices found"));
mRecord->Append(recordnames[0], (void *) NULL);
}
#endif

if constexpr (Experimental::MidiIn)
if (mRecord->GetCount() == 0) {
recordnames.push_back(_("No devices found"));
mRecord->Append(recordnames[0], (void *) NULL);
}

if (mPlay->GetCount() && mPlay->GetSelection() == wxNOT_FOUND) {
mPlay->SetSelection(0);
}
#ifdef EXPERIMENTAL_MIDI_IN
if (mRecord->GetCount() && mRecord->GetSelection() == wxNOT_FOUND) {
mRecord->SetSelection(0);
}
#endif

if constexpr (Experimental::MidiIn)
if (mRecord->GetCount() && mRecord->GetSelection() == wxNOT_FOUND) {
mRecord->SetSelection(0);
}

ShuttleGui::SetMinSize(mPlay, playnames);
#ifdef EXPERIMENTAL_MIDI_IN
ShuttleGui::SetMinSize(mRecord, recordnames);
#endif

if constexpr (Experimental::MidiIn)
ShuttleGui::SetMinSize(mRecord, recordnames);
// OnDevice(e);
}

Expand All @@ -270,15 +270,15 @@ bool MidiIOPrefs::Commit()
wxString(wxSafeConvertMB2WX(info->interf)),
wxString(wxSafeConvertMB2WX(info->name))));
}
#ifdef EXPERIMENTAL_MIDI_IN
info = (const PmDeviceInfo *) mRecord->GetClientData(mRecord->GetSelection());
if (info) {
MidiRecordingDevice.Write(
wxString::Format(wxT("%s: %s"),
wxString(wxSafeConvertMB2WX(info->interf)),
wxString(wxSafeConvertMB2WX(info->name))));
if constexpr (Experimental::MidiIn) {
info = (const PmDeviceInfo *) mRecord->GetClientData(mRecord->GetSelection());
if (info) {
MIDIRecordingDevice->Write(
wxString::Format(wxT("%s: %s"),
wxString(wxSafeConvertMB2WX(info->interf)),
wxString(wxSafeConvertMB2WX(info->name))));
}
}
#endif
MIDISynthLatency_ms.Invalidate();
return gPrefs->Flush();
}
Expand Down
13 changes: 7 additions & 6 deletions src/prefs/MidiIOPrefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,18 @@ class MidiIOPrefs final : public PrefsPanel
wxArrayStringEx mHostLabels;

wxString mPlayDevice;
#ifdef EXPERIMENTAL_MIDI_IN
wxString mRecordDevice;
#endif


// long mRecordChannels;

wxChoice *mHost;
wxChoice *mPlay;
wxTextCtrl *mLatency;
#ifdef EXPERIMENTAL_MIDI_IN
wxChoice *mRecord;
#endif

// These two are for Experimental::MidiIn
wxString mRecordDevice;
wxChoice *mRecord{};

// wxChoice *mChannels;

DECLARE_EVENT_TABLE()
Expand Down

0 comments on commit 21cbb07

Please sign in to comment.