Skip to content

Commit

Permalink
Add options to disable the audio system for audio recordings
Browse files Browse the repository at this point in the history
For one session the audio system can be disabled from the command line using the --disable-audio flag
This option is particularly useful for troubleshooting crashes on startup.
For future sessions the audio system can be disabled from the preferences by enabling the "Disable audio" checkbox.
  • Loading branch information
rolandlo committed Aug 22, 2023
1 parent 655f58f commit 9619943
Show file tree
Hide file tree
Showing 10 changed files with 200 additions and 59 deletions.
32 changes: 29 additions & 3 deletions src/core/control/Control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@

using std::string;

Control::Control(GApplication* gtkApp, GladeSearchpath* gladeSearchPath): gtkApp(gtkApp) {
Control::Control(GApplication* gtkApp, GladeSearchpath* gladeSearchPath, bool disableAudio): gtkApp(gtkApp) {
this->undoRedo = new UndoRedoHandler(this);
this->undoRedo->addUndoRedoListener(this);
this->isBlocking = false;
Expand All @@ -132,7 +132,8 @@ Control::Control(GApplication* gtkApp, GladeSearchpath* gladeSearchPath): gtkApp
this->pageTypes = new PageTypeHandler(gladeSearchPath);
this->newPageType = std::make_unique<PageTypeMenu>(this->pageTypes, settings, true, true);

this->audioController = new AudioController(this->settings, this);
this->audioController =
(disableAudio || this->settings->isAudioDisabled()) ? nullptr : new AudioController(this->settings, this);

this->scrollHandler = new ScrollHandler(this);

Expand Down Expand Up @@ -1001,6 +1002,10 @@ void Control::actionPerformed(ActionType type, ActionGroup group, GtkToolButton*

case ACTION_AUDIO_RECORD: {
bool result = false;
if (!audioController) {
g_warning("Audio has been disabled");
return;
}
if (enabled) {
result = audioController->startRecording();
} else {
Expand All @@ -1019,6 +1024,10 @@ void Control::actionPerformed(ActionType type, ActionGroup group, GtkToolButton*
}

case ACTION_AUDIO_PAUSE_PLAYBACK:
if (!audioController) {
g_warning("Audio has been disabled");
return;
}
if (enabled) {
this->getAudioController()->pausePlayback();
} else {
Expand All @@ -1027,14 +1036,29 @@ void Control::actionPerformed(ActionType type, ActionGroup group, GtkToolButton*
break;

case ACTION_AUDIO_SEEK_FORWARDS:
if (!audioController) {
g_warning("Audio has been disabled");
return;
}

this->getAudioController()->seekForwards();
break;

case ACTION_AUDIO_SEEK_BACKWARDS:
if (!audioController) {
g_warning("Audio has been disabled");
return;
}

this->getAudioController()->seekBackwards();
break;

case ACTION_AUDIO_STOP_PLAYBACK:
if (!audioController) {
g_warning("Audio has been disabled");
return;
}

this->getAudioController()->stopPlayback();
break;

Expand Down Expand Up @@ -2784,7 +2808,9 @@ void Control::quit(bool allowCancel) {
return;
}

audioController->stopRecording();
if (audioController) {
audioController->stopRecording();
}
this->scheduler->lock();
this->scheduler->removeAllJobs();
this->scheduler->unlock();
Expand Down
2 changes: 1 addition & 1 deletion src/core/control/Control.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class Control:
public ClipboardListener,
public ProgressListener {
public:
Control(GApplication* gtkApp, GladeSearchpath* gladeSearchPath);
Control(GApplication* gtkApp, GladeSearchpath* gladeSearchPath, bool disableAudio);
Control(Control const&) = delete;
Control(Control&&) = delete;
auto operator=(Control const&) -> Control& = delete;
Expand Down
5 changes: 4 additions & 1 deletion src/core/control/XournalMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ struct XournalMainPrivate {
gboolean exportNoBackground = false;
gboolean exportNoRuling = false;
gboolean progressiveMode = false;
gboolean disableAudio = false;
std::unique_ptr<GladeSearchpath> gladePath;
std::unique_ptr<Control> control;
std::unique_ptr<MainWindow> win;
Expand Down Expand Up @@ -452,7 +453,7 @@ void on_startup(GApplication* application, XMPtr app_data) {
initResourcePath(app_data->gladePath.get(), "ui/about.glade");
initResourcePath(app_data->gladePath.get(), "ui/xournalpp.css", false);

app_data->control = std::make_unique<Control>(application, app_data->gladePath.get());
app_data->control = std::make_unique<Control>(application, app_data->gladePath.get(), app_data->disableAudio);

// Set up icons
{
Expand Down Expand Up @@ -641,6 +642,8 @@ auto XournalMain::run(int argc, char** argv) -> int {
"<input>", nullptr},
GOptionEntry{"version", 0, 0, G_OPTION_ARG_NONE, &app_data.showVersion,
_("Get version of xournalpp"), nullptr},
GOptionEntry{"disable-audio", 0, 0, G_OPTION_ARG_NONE, &app_data.disableAudio,
_("Disable audio for this session"), nullptr},
GOptionEntry{nullptr}}; // Must be terminated by a nullptr. See gtk doc
g_application_add_main_option_entries(G_APPLICATION(app), options.data());

Expand Down
14 changes: 14 additions & 0 deletions src/core/control/settings/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ void Settings::loadDefault() {
this->useStockIcons = false;
this->scrollbarHideType = SCROLLBAR_HIDE_NONE;
this->disableScrollbarFadeout = false;
this->disableAudio = false;

// Set this for autosave frequency in minutes.
this->autosaveTimeout = 3;
Expand Down Expand Up @@ -550,6 +551,8 @@ void Settings::parseItem(xmlDocPtr doc, xmlNodePtr cur) {
}
} else if (xmlStrcmp(name, reinterpret_cast<const xmlChar*>("disableScrollbarFadeout")) == 0) {
this->disableScrollbarFadeout = xmlStrcmp(value, reinterpret_cast<const xmlChar*>("true")) == 0;
} else if (xmlStrcmp(name, reinterpret_cast<const xmlChar*>("disableAudio")) == 0) {
this->disableAudio = xmlStrcmp(value, reinterpret_cast<const xmlChar*>("true")) == 0;
} else if (xmlStrcmp(name, reinterpret_cast<const xmlChar*>("audioSampleRate")) == 0) {
this->audioSampleRate = tempg_ascii_strtod(reinterpret_cast<const char*>(value), nullptr);
} else if (xmlStrcmp(name, reinterpret_cast<const xmlChar*>("audioGain")) == 0) {
Expand Down Expand Up @@ -978,6 +981,7 @@ void Settings::save() {
SAVE_BOOL_PROP(useStockIcons);

SAVE_BOOL_PROP(disableScrollbarFadeout);
SAVE_BOOL_PROP(disableAudio);

if (this->scrollbarHideType == SCROLLBAR_HIDE_BOTH) {
xmlNode = saveProperty("scrollbarHideType", "both", root);
Expand Down Expand Up @@ -2236,6 +2240,16 @@ void Settings::setScrollbarFadeoutDisabled(bool disable) {
save();
}

auto Settings::isAudioDisabled() const -> bool { return disableAudio; }

void Settings::setAudioDisabled(bool disable) {
if (disableAudio == disable) {
return;
}
disableAudio = disable;
save();
}

//////////////////////////////////////////////////

SAttribute::SAttribute() {
Expand Down
8 changes: 8 additions & 0 deletions src/core/control/settings/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,9 @@ class Settings {
bool isScrollbarFadeoutDisabled() const;
void setScrollbarFadeoutDisabled(bool disable);

bool isAudioDisabled() const;
void setAudioDisabled(bool disable);

std::string const& getDefaultSaveName() const;
void setDefaultSaveName(const std::string& name);

Expand Down Expand Up @@ -704,6 +707,11 @@ class Settings {
*/
bool disableScrollbarFadeout{};

/**
* Disable the audio system
*/
bool disableAudio{};

/**
* The selected Toolbar name
*/
Expand Down
6 changes: 3 additions & 3 deletions src/core/control/tools/InputHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ auto InputHandler::createStroke(Control* control) -> std::unique_ptr<Stroke> {
if (h->getToolType() == TOOL_PEN) {
s->setToolType(StrokeTool::PEN);

if (control->getAudioController()->isRecording()) {
fs::path audioFilename = control->getAudioController()->getAudioFilename();
size_t sttime = control->getAudioController()->getStartTime();
if (auto* audioController = control->getAudioController(); audioController && audioController->isRecording()) {
fs::path audioFilename = audioController->getAudioFilename();
size_t sttime = audioController->getStartTime();
size_t milliseconds = ((g_get_monotonic_time() / 1000) - sttime);
s->setTimestamp(milliseconds);
s->setAudioFilename(audioFilename);
Expand Down
2 changes: 1 addition & 1 deletion src/core/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ void MainWindow::updateToolbarMenu() {
void MainWindow::createToolbar() {
toolbarSelected(control->getSettings()->getSelectedToolbar());

if (!this->control->getAudioController()->isPlaying()) {
if (auto* audioController = this->control->getAudioController(); audioController && !audioController->isPlaying()) {
this->getToolMenuHandler()->disableAudioPlaybackButtons();
}

Expand Down
8 changes: 6 additions & 2 deletions src/core/gui/PageViewFindObjectHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,12 @@ class PlayObject: public BaseSelectObject {
// Assume path exists
fn = path / fn;
}
auto* ac = view->getXournal()->getControl()->getAudioController();
bool success = ac->startPlayback(fn, (unsigned int)ts);
auto* audioController = view->getXournal()->getControl()->getAudioController();
if (!audioController) {
g_warning("Audio has been disabled");
return false;
}
bool success = audioController->startPlayback(fn, (unsigned int)ts);
playbackStatus = {success, std::move(fn)};
return success;
}
Expand Down
93 changes: 54 additions & 39 deletions src/core/gui/dialog/SettingsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,17 @@ SettingsDialog::SettingsDialog(GladeSearchpath* gladeSearchPath, Settings* setti
}),
this);

g_signal_connect(get("cbDisableAudio"), "toggled",
G_CALLBACK(+[](GtkToggleButton* togglebutton, SettingsDialog* self) {
self->disableWithCheckbox("cbDisableAudio", "sidAudio1");
self->disableWithCheckbox("cbDisableAudio", "sidAudio2");
self->disableWithCheckbox("cbDisableAudio", "sidAudio3");
self->disableWithCheckbox("cbDisableAudio", "sidAudio4");
self->disableWithCheckbox("cbDisableAudio", "sidAudioLbl");
}),
this);


g_signal_connect(get("cbDisableTouchOnPenNear"), "toggled",
G_CALLBACK(+[](GtkToggleButton* togglebutton, SettingsDialog* self) {
self->enableWithCheckbox("cbDisableTouchOnPenNear", "boxInternalHandRecognition");
Expand Down Expand Up @@ -360,6 +371,7 @@ void SettingsDialog::load() {
loadCheckbox("cbHideHorizontalScrollbar", settings->getScrollbarHideType() & SCROLLBAR_HIDE_HORIZONTAL);
loadCheckbox("cbHideVerticalScrollbar", settings->getScrollbarHideType() & SCROLLBAR_HIDE_VERTICAL);
loadCheckbox("cbDisableScrollbarFadeout", settings->isScrollbarFadeoutDisabled());
loadCheckbox("cbDisableAudio", settings->isAudioDisabled());
loadCheckbox("cbEnablePressureInference", settings->isPressureGuessingEnabled());
loadCheckbox("cbTouchDrawing", settings->getTouchDrawingEnabled());
loadCheckbox("cbDisableGtkInertialScroll", !settings->getGtkTouchInertialScrollingEnabled());
Expand Down Expand Up @@ -607,50 +619,52 @@ void SettingsDialog::load() {
touch.getInt("timeout", timeoutMs);
gtk_spin_button_set_value(GTK_SPIN_BUTTON(get("spTouchDisableTimeout")), timeoutMs / 1000.0);

this->audioInputDevices = this->control->getAudioController()->getInputDevices();
gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(get("cbAudioInputDevice")), "", "System default");
gtk_combo_box_set_active(GTK_COMBO_BOX(get("cbAudioInputDevice")), 0);
for (auto& audioInputDevice: this->audioInputDevices) {
gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(get("cbAudioInputDevice")), "",
audioInputDevice.getDeviceName().c_str());
}
for (size_t i = 0; i < this->audioInputDevices.size(); i++) {
if (this->audioInputDevices[i].getSelected()) {
gtk_combo_box_set_active(GTK_COMBO_BOX(get("cbAudioInputDevice")), static_cast<gint>(i + 1));
if (this->control->getAudioController()) {
this->audioInputDevices = this->control->getAudioController()->getInputDevices();
gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(get("cbAudioInputDevice")), "", "System default");
gtk_combo_box_set_active(GTK_COMBO_BOX(get("cbAudioInputDevice")), 0);
for (auto& audioInputDevice: this->audioInputDevices) {
gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(get("cbAudioInputDevice")), "",
audioInputDevice.getDeviceName().c_str());
}
for (size_t i = 0; i < this->audioInputDevices.size(); i++) {
if (this->audioInputDevices[i].getSelected()) {
gtk_combo_box_set_active(GTK_COMBO_BOX(get("cbAudioInputDevice")), static_cast<gint>(i + 1));
}
}
}

this->audioOutputDevices = this->control->getAudioController()->getOutputDevices();
gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(get("cbAudioOutputDevice")), "", "System default");
gtk_combo_box_set_active(GTK_COMBO_BOX(get("cbAudioOutputDevice")), 0);
for (auto& audioOutputDevice: this->audioOutputDevices) {
gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(get("cbAudioOutputDevice")), "",
audioOutputDevice.getDeviceName().c_str());
}
for (size_t i = 0; i < this->audioOutputDevices.size(); i++) {
if (this->audioOutputDevices[i].getSelected()) {
gtk_combo_box_set_active(GTK_COMBO_BOX(get("cbAudioOutputDevice")), static_cast<gint>(i + 1));
this->audioOutputDevices = this->control->getAudioController()->getOutputDevices();
gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(get("cbAudioOutputDevice")), "", "System default");
gtk_combo_box_set_active(GTK_COMBO_BOX(get("cbAudioOutputDevice")), 0);
for (auto& audioOutputDevice: this->audioOutputDevices) {
gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(get("cbAudioOutputDevice")), "",
audioOutputDevice.getDeviceName().c_str());
}
for (size_t i = 0; i < this->audioOutputDevices.size(); i++) {
if (this->audioOutputDevices[i].getSelected()) {
gtk_combo_box_set_active(GTK_COMBO_BOX(get("cbAudioOutputDevice")), static_cast<gint>(i + 1));
}
}
}

switch (static_cast<int>(settings->getAudioSampleRate())) {
case 16000:
gtk_combo_box_set_active(GTK_COMBO_BOX(get("cbAudioSampleRate")), 0);
break;
case 96000:
gtk_combo_box_set_active(GTK_COMBO_BOX(get("cbAudioSampleRate")), 2);
break;
case 192000:
gtk_combo_box_set_active(GTK_COMBO_BOX(get("cbAudioSampleRate")), 3);
break;
case 44100:
default:
gtk_combo_box_set_active(GTK_COMBO_BOX(get("cbAudioSampleRate")), 1);
break;
}
switch (static_cast<int>(settings->getAudioSampleRate())) {
case 16000:
gtk_combo_box_set_active(GTK_COMBO_BOX(get("cbAudioSampleRate")), 0);
break;
case 96000:
gtk_combo_box_set_active(GTK_COMBO_BOX(get("cbAudioSampleRate")), 2);
break;
case 192000:
gtk_combo_box_set_active(GTK_COMBO_BOX(get("cbAudioSampleRate")), 3);
break;
case 44100:
default:
gtk_combo_box_set_active(GTK_COMBO_BOX(get("cbAudioSampleRate")), 1);
break;
}

gtk_spin_button_set_value(GTK_SPIN_BUTTON(get("spAudioGain")), settings->getAudioGain());
gtk_spin_button_set_value(GTK_SPIN_BUTTON(get("spDefaultSeekTime")), settings->getDefaultSeekTime());
gtk_spin_button_set_value(GTK_SPIN_BUTTON(get("spAudioGain")), settings->getAudioGain());
gtk_spin_button_set_value(GTK_SPIN_BUTTON(get("spDefaultSeekTime")), settings->getDefaultSeekTime());
}

this->latexPanel.load(settings->latexSettings);
}
Expand Down Expand Up @@ -683,6 +697,7 @@ void SettingsDialog::save() {
settings->setInputSystemTPCButtonEnabled(getCheckbox("cbInputSystemTPCButton"));
settings->setInputSystemDrawOutsideWindowEnabled(getCheckbox("cbInputSystemDrawOutsideWindow"));
settings->setScrollbarFadeoutDisabled(getCheckbox("cbDisableScrollbarFadeout"));
settings->setAudioDisabled(getCheckbox("cbDisableAudio"));

settings->setStabilizerAveragingMethod(static_cast<StrokeStabilizer::AveragingMethod>(
gtk_combo_box_get_active(GTK_COMBO_BOX(get("cbStabilizerAveragingMethods")))));
Expand Down

0 comments on commit 9619943

Please sign in to comment.