Skip to content

Commit

Permalink
add sound effect after break ends
Browse files Browse the repository at this point in the history
Closes #10
  • Loading branch information
AllanChain committed Nov 16, 2024
1 parent 2d99d1c commit 4e9d70c
Show file tree
Hide file tree
Showing 14 changed files with 200 additions and 5 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ name: Build app

on:
push:
branches:
- '*'
tags:
- '*'

Expand All @@ -26,7 +28,7 @@ jobs:
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v4
- uses: AllanChain/[email protected]
- uses: AllanChain/install-qt-static-custom@v6.8
- uses: ilammy/msvc-dev-cmd@v1
if: contains(matrix.os, 'windows')

Expand Down Expand Up @@ -70,6 +72,7 @@ jobs:
release:
runs-on: ubuntu-latest
needs: build
if: startsWith(github.ref, 'refs/tags/')
steps:
- uses: actions/checkout@v4
with:
Expand Down
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ endif()

include(GNUInstallDirs)

find_package(QT NAMES Qt6 REQUIRED COMPONENTS Widgets)
find_package(Qt6 REQUIRED COMPONENTS Widgets)
find_package(QT NAMES Qt6 REQUIRED COMPONENTS Widgets Multimedia)
find_package(Qt6 REQUIRED COMPONENTS Widgets Multimedia)

file(GLOB PROJECT_SOURCES "src/*.cpp" "src/*.h" "resources/index.qrc")

Expand All @@ -41,7 +41,7 @@ qt_add_executable(sane-break
)

target_include_directories(sane-break PRIVATE "src" ${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries(sane-break PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
target_link_libraries(sane-break PRIVATE Qt6::Widgets Qt6::Multimedia)

if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
file(GLOB PROJECT_SOURCES_LINUX "src/linux/*")
Expand Down
2 changes: 2 additions & 0 deletions resources/index.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<file>images/icon_tray.png</file>
<file>images/icon_tray-pause.png</file>
<file>images/icon-256.png</file>
<file>sounds/bell.mp3</file>
<file>sounds/wood.mp3</file>
<file>style.css</file>
<file>NOTICE.md</file>
</qresource>
Expand Down
1 change: 1 addition & 0 deletions resources/sounds/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.bak
88 changes: 88 additions & 0 deletions resources/sounds/bell.mmp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?xml version="1.0"?>
<!DOCTYPE lmms-project>
<lmms-project creatorversion="1.2.2" type="song" version="1.0" creator="LMMS">
<head mastervol="100" masterpitch="0" bpm="140" timesig_numerator="4" timesig_denominator="4"/>
<song>
<trackcontainer maximized="0" height="300" type="song" visible="1" minimized="0" x="5" width="600" y="5">
<track type="0" muted="0" solo="0" name="Mallets">
<instrumenttrack fxch="0" usemasterpitch="1" basenote="57" pan="0" pitch="0" pitchrange="1" vol="100">
<instrument name="malletsstk">
<malletsstk lfo_speed="64" adsr="64" oldversion="0" vib_freq="0" preset="9" strike="1" crossfade="64" vib_gain="0" version="1" position="64" velocity="64" pressure="64" spread="0" hardness="64" stick_mix="0" modulator="64" lfo_depth="64"/>
</instrument>
<eldata fcut="14000" fwet="0" ftype="0" fres="0.5">
<elvol dec="0.5" sustain="0.5" ctlenvamt="0" lshp="0" lspd="0.1" lpdel="0" lspd_numerator="4" lamt="0" latt="0" pdel="0" rel="0.1" hold="0.5" amt="0" lspd_syncmode="0" userwavefile="" lspd_denominator="4" x100="0" att="0"/>
<elcut dec="0.5" sustain="0.5" ctlenvamt="0" lshp="0" lspd="0.1" lpdel="0" lspd_numerator="4" lamt="0" latt="0" pdel="0" rel="0.1" hold="0.5" amt="0" lspd_syncmode="0" userwavefile="" lspd_denominator="4" x100="0" att="0"/>
<elres dec="0.5" sustain="0.5" ctlenvamt="0" lshp="0" lspd="0.1" lpdel="0" lspd_numerator="4" lamt="0" latt="0" pdel="0" rel="0.1" hold="0.5" amt="0" lspd_syncmode="0" userwavefile="" lspd_denominator="4" x100="0" att="0"/>
</eldata>
<chordcreator chordrange="1" chord-enabled="0" chord="0"/>
<arpeggiator arprange="1" arp="0" arptime_denominator="4" arptime_numerator="4" arptime="200" arp-enabled="0" arpskip="0" arptime_syncmode="0" arpmode="0" arpmiss="0" arpgate="100" arpdir="0" arpcycle="0"/>
<midiport writable="0" fixedinputvelocity="-1" fixedoutputvelocity="-1" outputchannel="1" inputchannel="0" outputprogram="1" basevelocity="63" inputcontroller="0" outputcontroller="0" fixedoutputnote="-1" readable="0"/>
<fxchain numofeffects="0" enabled="0"/>
</instrumenttrack>
<pattern type="1" muted="0" pos="0" steps="16" name="Mallets">
<note pan="0" len="480" pos="48" key="60" vol="100"/>
</pattern>
</track>
<track type="0" muted="0" solo="0" name="Mallets">
<instrumenttrack fxch="1" usemasterpitch="1" basenote="57" pan="0" pitch="0" pitchrange="1" vol="13.6">
<instrument name="malletsstk">
<malletsstk lfo_speed="64" adsr="64" oldversion="0" vib_freq="0" preset="8" strike="1" crossfade="64" vib_gain="0" version="1" position="64" velocity="64" pressure="64" spread="0" hardness="64" stick_mix="0" modulator="64" lfo_depth="64"/>
</instrument>
<eldata fcut="14000" fwet="0" ftype="0" fres="0.5">
<elvol dec="0.5" sustain="0.5" ctlenvamt="0" lshp="0" lspd="0.1" lpdel="0" lspd_numerator="4" lamt="0" latt="0" pdel="0" rel="0.1" hold="0.5" amt="0" lspd_syncmode="0" userwavefile="" lspd_denominator="4" x100="0" att="0"/>
<elcut dec="0.5" sustain="0.5" ctlenvamt="0" lshp="0" lspd="0.1" lpdel="0" lspd_numerator="4" lamt="0" latt="0" pdel="0" rel="0.1" hold="0.5" amt="0" lspd_syncmode="0" userwavefile="" lspd_denominator="4" x100="0" att="0"/>
<elres dec="0.5" sustain="0.5" ctlenvamt="0" lshp="0" lspd="0.1" lpdel="0" lspd_numerator="4" lamt="0" latt="0" pdel="0" rel="0.1" hold="0.5" amt="0" lspd_syncmode="0" userwavefile="" lspd_denominator="4" x100="0" att="0"/>
</eldata>
<chordcreator chordrange="1" chord-enabled="0" chord="0"/>
<arpeggiator arprange="1" arp="0" arptime_denominator="4" arptime_numerator="4" arptime="200" arp-enabled="0" arpskip="0" arptime_syncmode="0" arpmode="0" arpmiss="0" arpgate="100" arpdir="0" arpcycle="0"/>
<midiport writable="0" fixedinputvelocity="-1" fixedoutputvelocity="-1" outputchannel="1" inputchannel="0" outputprogram="1" basevelocity="63" inputcontroller="0" outputcontroller="0" fixedoutputnote="-1" readable="0"/>
<fxchain numofeffects="0" enabled="0"/>
</instrumenttrack>
<pattern type="1" muted="0" pos="0" steps="16" name="Mallets">
<note pan="0" len="72" pos="0" key="52" vol="100"/>
<note pan="0" len="24" pos="72" key="52" vol="100"/>
<note pan="0" len="48" pos="96" key="52" vol="100"/>
<note pan="0" len="48" pos="144" key="53" vol="100"/>
<note pan="0" len="72" pos="192" key="50" vol="100"/>
<note pan="0" len="24" pos="264" key="50" vol="100"/>
<note pan="0" len="48" pos="288" key="48" vol="100"/>
<note pan="0" len="48" pos="336" key="50" vol="100"/>
<note pan="0" len="48" pos="384" key="52" vol="100"/>
<note pan="0" len="48" pos="432" key="48" vol="100"/>
<note pan="0" len="48" pos="480" key="50" vol="100"/>
</pattern>
</track>
</trackcontainer>
<track type="6" muted="0" solo="0" name="Automation track">
<automationtrack/>
<automationpattern prog="0" mute="0" len="192" pos="0" tens="1" name="Numerator"/>
<automationpattern prog="0" mute="0" len="192" pos="0" tens="1" name="Denominator"/>
<automationpattern prog="0" mute="0" len="192" pos="0" tens="1" name="Tempo"/>
<automationpattern prog="0" mute="0" len="192" pos="0" tens="1" name="Master volume"/>
<automationpattern prog="0" mute="0" len="192" pos="0" tens="1" name="Master pitch"/>
</track>
<fxmixer maximized="0" height="333" visible="0" minimized="0" x="5" width="543" y="310">
<fxchannel muted="0" volume="1" soloed="0" num="0" name="Master">
<fxchain numofeffects="0" enabled="0"/>
</fxchannel>
<fxchannel muted="0" volume="1" soloed="0" num="1" name="Mallets">
<fxchain numofeffects="0" enabled="0"/>
<send channel="0" amount="1"/>
</fxchannel>
<fxchannel muted="0" volume="1" soloed="0" num="2" name="FX 2">
<fxchain numofeffects="0" enabled="0"/>
<send channel="0" amount="1"/>
</fxchannel>
</fxmixer>
<ControllerRackView maximized="0" height="200" visible="1" minimized="0" x="680" width="350" y="310"/>
<pianoroll maximized="0" height="480" visible="1" minimized="0" x="301" width="860" y="239"/>
<automationeditor maximized="0" height="400" visible="0" minimized="0" x="1" width="860" y="1"/>
<projectnotes maximized="0" height="400" visible="0" minimized="0" x="700" width="800" y="10"><![CDATA[<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
p, li { white-space: pre-wrap; }
</style></head><body style=" font-family:'Noto Sans CJK SC'; font-size:11pt; font-weight:400; font-style:normal;">
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html>]]></projectnotes>
<timeline lp1pos="576" lpstate="0" lp0pos="0"/>
<controllers/>
</song>
</lmms-project>
Binary file added resources/sounds/bell.mp3
Binary file not shown.
62 changes: 62 additions & 0 deletions resources/sounds/wood.mmp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?xml version="1.0"?>
<!DOCTYPE lmms-project>
<lmms-project creatorversion="1.2.2" type="song" version="1.0" creator="LMMS">
<head masterpitch="0" timesig_denominator="4" bpm="140" mastervol="100" timesig_numerator="4"/>
<song>
<trackcontainer height="300" type="song" minimized="0" visible="1" x="5" y="5" width="600" maximized="0">
<track type="0" muted="0" name="Mallets" solo="0">
<instrumenttrack vol="100" pitchrange="1" pan="0" basenote="57" usemasterpitch="1" pitch="0" fxch="0">
<instrument name="malletsstk">
<malletsstk velocity="64" strike="1" oldversion="0" hardness="64" spread="0" position="64" vib_gain="0" crossfade="64" adsr="64" stick_mix="0" version="1" vib_freq="0" modulator="64" preset="0" lfo_speed="64" lfo_depth="64" pressure="64"/>
</instrument>
<eldata ftype="0" fres="0.5" fcut="14000" fwet="0">
<elvol x100="0" pdel="0" latt="0" lspd_numerator="4" lspd_syncmode="0" dec="0.5" lshp="0" ctlenvamt="0" rel="0.1" att="0" lamt="0" amt="0" lpdel="0" hold="0.5" userwavefile="" lspd_denominator="4" sustain="0.5" lspd="0.1"/>
<elcut x100="0" pdel="0" latt="0" lspd_numerator="4" lspd_syncmode="0" dec="0.5" lshp="0" ctlenvamt="0" rel="0.1" att="0" lamt="0" amt="0" lpdel="0" hold="0.5" userwavefile="" lspd_denominator="4" sustain="0.5" lspd="0.1"/>
<elres x100="0" pdel="0" latt="0" lspd_numerator="4" lspd_syncmode="0" dec="0.5" lshp="0" ctlenvamt="0" rel="0.1" att="0" lamt="0" amt="0" lpdel="0" hold="0.5" userwavefile="" lspd_denominator="4" sustain="0.5" lspd="0.1"/>
</eldata>
<chordcreator chordrange="1" chord="0" chord-enabled="0"/>
<arpeggiator arptime_numerator="4" arpmiss="0" arp="0" arpcycle="0" arpgate="100" arprange="1" arpskip="0" arptime="200" arpmode="0" arptime_denominator="4" arp-enabled="0" arpdir="0" arptime_syncmode="0"/>
<midiport outputprogram="1" readable="0" outputchannel="1" outputcontroller="0" inputcontroller="0" fixedinputvelocity="-1" writable="0" basevelocity="63" inputchannel="0" fixedoutputnote="-1" fixedoutputvelocity="-1"/>
<fxchain numofeffects="0" enabled="0"/>
</instrumenttrack>
<pattern type="1" pos="0" muted="0" name="Mallets" steps="16">
<note vol="100" key="64" pan="0" pos="48" len="36"/>
<note vol="100" key="65" pan="0" pos="84" len="12"/>
<note vol="100" key="67" pan="0" pos="96" len="24"/>
<note vol="100" key="69" pan="0" pos="120" len="24"/>
<note vol="100" key="72" pan="0" pos="144" len="48"/>
<note vol="100" key="71" pan="0" pos="192" len="24"/>
<note vol="100" key="64" pan="0" pos="216" len="48"/>
<note vol="100" key="67" pan="0" pos="264" len="48"/>
<note vol="100" key="69" pan="0" pos="312" len="24"/>
<note vol="100" key="67" pan="0" pos="336" len="24"/>
<note vol="100" key="64" pan="0" pos="360" len="24"/>
<note vol="100" key="60" pan="0" pos="384" len="48"/>
</pattern>
</track>
</trackcontainer>
<track type="6" muted="0" name="Automation track" solo="0">
<automationtrack/>
<automationpattern pos="0" mute="0" name="Numerator" tens="1" prog="0" len="192"/>
<automationpattern pos="0" mute="0" name="Denominator" tens="1" prog="0" len="192"/>
<automationpattern pos="0" mute="0" name="Tempo" tens="1" prog="0" len="192"/>
<automationpattern pos="0" mute="0" name="Master volume" tens="1" prog="0" len="192"/>
<automationpattern pos="0" mute="0" name="Master pitch" tens="1" prog="0" len="192"/>
</track>
<fxmixer height="333" minimized="0" visible="1" x="5" y="310" width="543" maximized="0">
<fxchannel soloed="0" volume="1" muted="0" num="0" name="Master">
<fxchain numofeffects="0" enabled="0"/>
</fxchannel>
</fxmixer>
<ControllerRackView height="200" minimized="0" visible="1" x="680" y="310" width="350" maximized="0"/>
<pianoroll height="480" minimized="0" visible="1" x="346" y="177" width="860" maximized="0"/>
<automationeditor height="400" minimized="0" visible="0" x="1" y="1" width="860" maximized="0"/>
<projectnotes height="400" minimized="0" visible="0" x="700" y="10" width="800" maximized="0"><![CDATA[<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
p, li { white-space: pre-wrap; }
</style></head><body style=" font-family:'Noto Sans CJK SC'; font-size:11pt; font-weight:400; font-style:normal;">
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html>]]></projectnotes>
<timeline lpstate="0" lp0pos="0" lp1pos="192"/>
<controllers/>
</song>
</lmms-project>
Binary file added resources/sounds/wood.mp3
Binary file not shown.
13 changes: 13 additions & 0 deletions src/pref-window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,17 @@ PreferenceWindow::PreferenceWindow(QWidget *parent) : QMainWindow(parent) {
flashForLabel->setText(QString("%1 sec").arg(value));
});

QLabel *bellLabel = new QLabel("Sound Effect after break");
QHBoxLayout *bellLayout = new QHBoxLayout();
bellLayout->addWidget(bellLabel);
bellSoundSelect = new QComboBox();
bellSoundSelect->setEditable(true);
bellSoundSelect->addItem("");
bellSoundSelect->addItem("qrc:/sounds/wood.mp3");
bellSoundSelect->addItem("qrc:/sounds/bell.mp3");
bellLayout->addWidget(bellSoundSelect);
layout->addLayout(bellLayout);

layout->addWidget(new QLabel("<h3>Pausing</h3>"));

QGridLayout *pauseForm = new QGridLayout();
Expand Down Expand Up @@ -265,6 +276,7 @@ void PreferenceWindow::loadSettings() {
flashForSlider->setValue(SanePreferences::flashFor->get());
pauseOnIdleSlider->setValue(SanePreferences::pauseOnIdleFor->get() / 60);
pauseOnBatteryCheck->setChecked(SanePreferences::pauseOnBattery->get());
bellSoundSelect->setEditText(SanePreferences::bellSound->get());
}

void PreferenceWindow::saveSettings() {
Expand All @@ -275,6 +287,7 @@ void PreferenceWindow::saveSettings() {
SanePreferences::flashFor->set(flashForSlider->value());
SanePreferences::pauseOnIdleFor->set(pauseOnIdleSlider->value() * 60);
SanePreferences::pauseOnBattery->set(pauseOnBatteryCheck->isChecked());
SanePreferences::bellSound->set(bellSoundSelect->currentText());
}

void PreferenceWindow::closeEvent(QCloseEvent *event) {
Expand Down
2 changes: 2 additions & 0 deletions src/pref-window.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define SANE_PREFERENCES_WINDOW_H

#include <QCheckBox>
#include <QComboBox>
#include <QLabel>
#include <QMainWindow>
#include <QMouseEvent>
Expand Down Expand Up @@ -42,5 +43,6 @@ class PreferenceWindow : public QMainWindow {
SteppedSlider *flashForSlider;
SteppedSlider *pauseOnIdleSlider;
QCheckBox *pauseOnBatteryCheck;
QComboBox *bellSoundSelect;
};
#endif // SANE_PREFERENCES_WINDOW_H
1 change: 1 addition & 0 deletions src/preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ Setting<int>* SanePreferences::pauseOnIdleFor =
new Setting<int>("pause/on-idle-for", 180);
Setting<bool>* SanePreferences::pauseOnBattery =
new Setting<bool>("pause/on-battery", false);
Setting<QString>* SanePreferences::bellSound = new Setting<QString>("bell/sound", "");
1 change: 1 addition & 0 deletions src/preferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class SanePreferences : public QObject {
static Setting<int> *flashFor;
static Setting<int> *pauseOnIdleFor;
static Setting<bool> *pauseOnBattery;
static Setting<QString> *bellSound;
};

#endif // SANE_PREFERENCES_H
19 changes: 18 additions & 1 deletion src/window-manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
#include "macos/workspace.h"
#endif
#include <QApplication>
#include <QAudioOutput>
#include <QList>
#include <QMediaPlayer>
#include <QObject>
#include <QScreen>
#include <QSettings>
Expand All @@ -40,6 +42,14 @@ BreakWindowManager::BreakWindowManager() : QObject() {
connect(idleTimer, &SystemIdleTime::idleStart, this,
&BreakWindowManager::onIdleStart);
connect(idleTimer, &SystemIdleTime::idleEnd, this, &BreakWindowManager::onIdleEnd);

soundPlayer = new QMediaPlayer(this);
audioOutput = new QAudioOutput();
soundPlayer->setAudioOutput(audioOutput);
audioOutput->setVolume(100);
setSound();
connect(SanePreferences::bellSound, &SettingWithSignal::changed, this,
&BreakWindowManager::setSound);
#ifdef LayerShellQt_FOUND
if (QGuiApplication::platformName() == "wayland")
LayerShellQt::Shell::useLayerShell();
Expand Down Expand Up @@ -111,14 +121,21 @@ void BreakWindowManager::tick() {
remainingTime--;
for (auto w : std::as_const(windows)) w->setTime(remainingTime);
}
if (remainingTime <= 0) return close();
if (remainingTime <= 0) {
soundPlayer->play();
close();
}
}

void BreakWindowManager::forceBreak() {
isForceBreak = true;
for (auto w : std::as_const(windows)) w->setFullScreen();
}

void BreakWindowManager::setSound() {
soundPlayer->setSource(QUrl(SanePreferences::bellSound->get()));
}

void BreakWindowManager::onIdleStart() {
if (isForceBreak || remainingTime <= 0) return;
for (auto w : std::as_const(windows)) {
Expand Down
5 changes: 5 additions & 0 deletions src/window-manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
#ifndef SANE_BREAK_WINDOW_MANAGER_H
#define SANE_BREAK_WINDOW_MANAGER_H

#include <QAudioOutput>
#include <QList>
#include <QMediaPlayer>
#include <QObject>

#include "break-window.h"
Expand All @@ -32,10 +34,13 @@ class BreakWindowManager : public QObject {
QList<BreakWindow *> windows;
QTimer *countdownTimer;
QTimer *forceBreakTimer;
QMediaPlayer *soundPlayer;
QAudioOutput *audioOutput;
SystemIdleTime *idleTimer;
void createWindows(BreakType type);
void tick();
void forceBreak();
void setSound();
void onIdleStart();
void onIdleEnd();
};
Expand Down

0 comments on commit 4e9d70c

Please sign in to comment.