There are many untranslated strings which are used repetitively in multiple files and/or multiple locations within the same file. For at least two reasons it might be appropriate to make a single static instance of the given string instead of having multiple duplicate versions. One reason is to conserve computer resources – probably not as much of a big deal nowadays when desktops and laptops have lots of RAM and stack memory but with the possibility of running Audacity on tablets where resources are more precious this may be becoming more important. The other reason is to avoid errors resulting from typos.
First, I would suggest the creation of new header file: staticStrings.h in which all of these static variables would be declared/defined.
Here are two typical cases:
Find all "wxT("WAV")", "Entire Solution", "*.cpp;*.h"
srcBatchCommands.cpp(482): bool exportedOkay = mExporter.Process(project, numChannels, wxT("WAV"), filename, false, 0.0, endTime);
srcexportExport.cpp(598): wxT("WAV"));
srcexportExportMultiple.cpp(222): wxT("WAV"));
srcexportExportPCM.cpp(326): SetFormat(wxT("WAV"),format);
Matching lines: 4 Matching files: 4 Total files searched: 793
In this case, in our new header file, I would suggest we have a static variable:
static wxString waveFormat(wxT("WAV"));
so, for instance the line in BatchCommands.cpp would now read:
bool exportedOkay = mExporter.Process(project, numChannels, waveFormat, filename, false, 0.0, endTime);
In the next case we see a couple of duplications:
if (gPrefs->Read(wxT("AudioIO/RecordingDevice"), wxT("")) == wxT("")) {
int i = AudioIO::getRecordDevIndex();
const PaDeviceInfo *info = Pa_GetDeviceInfo(i);
if (info) {
gPrefs->Write(wxT("/AudioIO/RecordingDevice"), DeviceName(info));
gPrefs->Write(wxT("/AudioIO/Host"), HostName(info));
}
}
if (gPrefs->Read(wxT("AudioIO/PlaybackDevice"), wxT("")) == wxT("")) {
int i = AudioIO::getPlayDevIndex();
const PaDeviceInfo *info = Pa_GetDeviceInfo(i);
if (info) {
gPrefs->Write(wxT("/AudioIO/PlaybackDevice"), DeviceName(info));
gPrefs->Write(wxT("/AudioIO/Host"), HostName(info));
and just looking at one of the strings “RecordingDevice”:
Find all "RecordingDevice", "Entire Solution", "*.cpp;*.h"
srcAudioIO.cpp(456): if (gPrefs->Read(wxT("AudioIO/RecordingDevice"), wxT("")) == wxT("")) {
srcAudioIO.cpp(460): gPrefs->Write(wxT("/AudioIO/RecordingDevice"), DeviceName(info));
srcAudioIO.cpp(2268): devName = gPrefs->Read(wxT("/AudioIO/RecordingDevice"), wxT(""));
srcAudioIO.cpp(2365): wxString recDevice = gPrefs->Read(wxT("/AudioIO/RecordingDevice"), wxT(""));
srcprefsDevicePrefs.cpp(72): mRecordDevice = gPrefs->Read(wxT("/AudioIO/RecordingDevice"), wxT(""));
srcprefsDevicePrefs.cpp(369): gPrefs->Write(wxT("/AudioIO/RecordingDevice"),
srcprefsMidiIOPrefs.cpp(76): mRecordDevice = gPrefs->Read(wxT("/MidiIO/RecordingDevice"), wxT(""));
srcprefsMidiIOPrefs.cpp(280): gPrefs->Write(wxT("/MidiIO/RecordingDevice"),
srctoolbarsDeviceToolBar.cpp(240): devName = gPrefs->Read(wxT("/AudioIO/RecordingDevice"), wxT(""));
srctoolbarsDeviceToolBar.cpp(595): wxString device = gPrefs->Read(wxT("/AudioIO/RecordingDevice"), wxT(""));
srctoolbarsDeviceToolBar.cpp(640): gPrefs->Write(wxT("/AudioIO/RecordingDevice"), in->deviceString);
Matching lines: 11 Matching files: 4 Total files searched: 793
we find it used 11 times in four files and two compounds (AudioIO/RecordingDevice & MidiIO/RecordingDevice), and in fact we may have discovered a typo because the very first instance:
AudioIO.cpp(456): if (gPrefs->Read(wxT("AudioIO/RecordingDevice"), wxT("")) == wxT(""))
is missing the leading "/"and we might always just be getting the default. In this case there are two possible solutions: 1) we could have 3 static variables:
static wxString prefAudioIO(wxT("/AudioIO"));
static wxString prefMidiIO(wxT("/MidiIO"));
static prefRecordingDevice(wxT("/RecordingDevice"));
and build the strings we need in the code, or 2) have 2 static variables:
static wxString prefAudioIORecordingDevice(wxT("/AudioIO/RecordingDevice"));
static wxString prefMidiIO(wxT("/MidiIORecordingDevice/RecordingDevice"));
In this specific case the second solution might be better because we never use “/RecordingDevice” independently. although we do use “/AudioIO” in other places.