Metadata-Version: 2.4
Name: mocassino
Version: 0.0.10
Summary: Lightweight audio player based on MOC for Raspberry Pi devices with Pimoroni Pirate Audio hats
Author-email: Alberto Pettarin <alberto@albertopettarin.it>
Maintainer-email: Alberto Pettarin <alberto@albertopettarin.it>
License-Expression: GPL-3.0-or-later
Project-URL: Documentation, https://www.albertopettarin.it/mocassino/docs/
Project-URL: Download, https://github.com/pettarin/mocassino#installation
Project-URL: Homepage, https://github.com/pettarin/mocassino
Project-URL: Release Notes, https://github.com/pettarin/mocassino/blob/main/docs/CHANGELOG.md
Project-URL: Source, https://github.com/pettarin/mocassino
Project-URL: Tracker, https://github.com/pettarin/mocassino/issues
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Multimedia :: Sound/Audio
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.13
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: click>=8.1.0
Requires-Dist: colorzero>=2.0
Requires-Dist: gpiod>=2.6.0
Requires-Dist: gpiodevice>=0.1.0
Requires-Dist: gpiozero>=2.0.1.post3
Requires-Dist: lgpio>=0.2.2.0; platform_machine == "aarch64" or platform_machine == "armv7l" or platform_machine == "armv6l"
Requires-Dist: pillow>=13.0.0
Requires-Dist: PyYAML>=6.0
Requires-Dist: spidev>=3.8
Requires-Dist: st7789>=1.0.1
Provides-Extra: dev
Requires-Dist: build>=1.3.0; extra == "dev"
Requires-Dist: coverage>=7.0.0; extra == "dev"
Requires-Dist: lucio>=0.0.9; extra == "dev"
Requires-Dist: mypy>=2.3.0; extra == "dev"
Requires-Dist: pytest-asyncio>=0.24.0; extra == "dev"
Requires-Dist: pytest-cov>=6.0.0; extra == "dev"
Requires-Dist: pytest-mock>=3.14.0; extra == "dev"
Requires-Dist: pytest>=9.1.0; extra == "dev"
Requires-Dist: ruff>=0.16.0; extra == "dev"
Requires-Dist: setuptools>=80.9.0; extra == "dev"
Requires-Dist: wheel>=0.45.1; extra == "dev"
Dynamic: license-file

# mocassino

Lightweight audio player based on MOC
for Raspberry Pi devices with Pimoroni Pirate Audio hats


## Overview

`mocassino` is a service turning a
[Raspberry Pi](https://www.raspberrypi.com/)
device with a
[Pimoroni](https://shop.pimoroni.com/)
Pirate Audio hat into a standalone audio player
for local audio files that can be used even when fully offline.

The service handles the four buttons of the hat,
pilots its display, and delegates the playback to
[MOC](https://moc.daper.net/) (music on console),
which it controls by running `mocp` commands.

![Mocassino running on a Raspberry Pi Zero 2 with Pimoroni Pirate Audio Headphone Amp in a Flirc case](imgs/device_rotation_180.jpg)

The supported
[Pimoroni](https://shop.pimoroni.com/)
Pirate Audio hats are those featuring
the 1.3" IPS color LCD display (240x240 px, ST7789 driver)
with four tactile buttons and a DAC:

- [Pirate Audio: 3W Stereo Amp](https://shop.pimoroni.com/en-eu/products/pirate-audio-3w-stereo-amp?variant=31189753233491)
- [Pirate Audio: Headphone Amp](https://shop.pimoroni.com/en-eu/products/pirate-audio-headphone-amp?variant=31189750480979)
- [Pirate Audio: Line-out](https://shop.pimoroni.com/en-eu/products/pirate-audio-line-out?variant=31189750546515)
- [Pirate Audio: Speaker](https://shop.pimoroni.com/en-eu/products/pirate-audio-mini-speaker?variant=31189753692243)

## Features

- Playback control with the buttons of the hat:
  play/pause, previous/next track,
  seek backward/forward, volume down/up
- Playback information rendered on the display of the hat:
  artist, title, and album of the current track,
  playback progress, volume, etc.
- Adjustable screen brightness and timeout
- Configurable, minimal UI (elements, colors, etc.)
- Music library directory browser: select a directory
  or a single audio file to play
- Menu to change most of the settings of the running service
- Settings stored in a YAML configuration file
- Save the playback state and volume on exit,
  and restore them on the next boot
- Configurable behavior on boot and on exit
- To develop/debug on a PC without the hardware:
  built-in Tk-based simulator for the display and the buttons


## Requirements

- One of the supported Raspberry Pi devices: 3, 4, 5, Zero, Zero 2
- One of the supported Pimoroni Pirate Audio hats listed above
- An SD card or SSD with a (64-bit) OS based on Debian 13 (trixie) installed
  (e.g., Raspberry Pi OS Full or Lite, DietPi, etc.)
- Some local audio files (FLAC, MP3, OGG, WAV)  to play

Make sure your `/boot/firmware/config.txt` has the following entries:

```
# enable SPI
dtparam=spi=on

# prevent pin GPIO 9 to be claimed for MISO,
# as it is needed to drive the hat display
dtoverlay=spi0-2cs,no_miso

# enable the DAC
dtoverlay=hifiberry-dac
gpio=25=op,dh
```


## Installation

### Using The Installer Script (Recommended)

Download the install script:

```bash
cd /tmp
curl -kO https://raw.githubusercontent.com/pettarin/mocassino/refs/heads/main/install.sh
```

Inspect all the available options by issuing the `--help` option:

```bash
bash install.sh --help
Usage: bash install.sh [options]

Options:
  --alsa-card-number NUMBER             Use the ALSA card NUMBER for the software volume control (default: '0')
  --display-orientation [0|90|180|270]  Configure the specified display orientation (default: '0')
  --library-directory-path PATH         Configure the specified PATH as the root directory for the library (default: '/')
  --no-install-apt-dependencies         Do not install the required APT packages (alsa-utils build-essential liblgpio-dev moc python3-dev python3-pip python3-venv swig)
  --no-install-sudoers                  Do not install the sudoers file
  --no-install-systemd                  Do not install the systemd service
  --no-install-venv                     Do not install the virtual environment
  --no-uninstall-first                  Do not remove a previous installation before installing
  --no-write-alsa-configuration         Do not write the ALSA configuration to file
  --no-write-configuration              Do not write the configuration to file
  --run-arguments STRING                Use the provided STRING as argument to the ExecStart command line of the systemd service (default: 'run --foreground')
  --run-as-group STRING                 Use the provided STRING as group for the service (default: 'audio')
  --run-as-user STRING                  Use the provided STRING as user for the service, creating it if it does not exist (default: 'mocassino')
  --uninstall                           Remove a previous installation and exit
  --uninstall-user                      When removing a previous installation, also remove the user created by this script

Note: this script must be executed as root, for instance with sudo
```

> [!WARNING]
> The following commands to install and uninstall the service
> require privilege elevation, for instance with `sudo` as illustrated below.

To install the service with the default options,
which should be fine for most users,
simply execute the script without arguments nor options:

```bash
sudo bash install.sh
[INFO] Running installation as:   '0' (root)
[INFO] Systemd service to run as:
[INFO]   group: 'audio'
[INFO]    user: 'mocassino'
...
    The installation takes between 1 and 5 minutes,
    depending on the device and your connection.
...
[INFO] Installation of mocassino complete
```

The last steps of the installation script
start the service (you should see the application GUI drawn
on the display, similar to the screenshots shown below),
and then print its status:

```bash
...
[INFO] Installing systemd service ...
Created symlink '/etc/systemd/system/multi-user.target.wants/mocassino.service' → '/usr/lib/systemd/system/mocassino.service'.
● mocassino.service - Lightweight audio player based on MOC for Raspberry Pi devices with Pimoroni Pirate Audio hats
     Loaded: loaded (/usr/lib/systemd/system/mocassino.service; enabled; preset: enabled)
     Active: active (running) since Sat 2026-11-28 22:34:55 CET; 1s ago
 Invocation: cefe7dfa63c84cda8cb2c782972b8d68
       Docs: https://github.com/pettarin/mocassino
    Process: 1431 ExecStartPre=/usr/bin/aplay -D default -f cd -d 1 /dev/zero (code=exited, status=0/SUCCESS)
   Main PID: 1433 (mocassino)
      Tasks: 1 (limit: 448)
        CPU: 1.161s
     CGroup: /system.slice/mocassino.service
             └─1433 /opt/mocassino/venv/bin/python3 /opt/mocassino/venv/bin/mocassino run --foreground

Nov 28 22:34:54 zephyr systemd[1]: Starting mocassino.service - Lightweight audio player based on MOC for Raspberry Pi devices with Pimoroni Pirate Audio hats...
Nov 28 22:34:54 zephyr aplay[1431]: Playing raw data '/dev/zero' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
Nov 28 22:34:55 zephyr systemd[1]: Started mocassino.service - Lightweight audio player based on MOC for Raspberry Pi devices with Pimoroni Pirate Audio hats.
[INFO] Installing systemd service ... done
[INFO] Installation of mocassino complete
```

Some application settings can be specified at install time,
so that they are applied out-of-the-box
instead of requiring the user to change them via the application GUI
or editing the configuration file.
For example, to rotate the display by 180 degrees
(which is useful when using a
[Flirc case for a Raspberry Pi Zero 2](https://flirc.tv/products/flirc-raspberrypizero?variant=43085036519656)
) and to set the root directory of the music library at `/music`
(make sure that user `mocassino` and/or group `audio`
can read and traverse it!)
instead of the default `/`:

```bash
sudo bash install.sh --display-orientation 180 --library-directory-path /music
[INFO] Running installation as:   '0' (root)
[INFO] Systemd service to run as:
[INFO]   group: 'audio'
[INFO]    user: 'mocassino'
...
[INFO] Configuration arguments:
[INFO]      --display-orientation '180'
[INFO]   --library-directory-path '/music'
...
```

To uninstall the service and remove all the files created by it:

```bash
sudo bash install.sh --uninstall
[INFO] Running installation as:   '0' (root)
...
[INFO] Uninstalling service mocassino ...
...
[INFO] Uninstalling service mocassino ... done
[INFO] Option --uninstall specified: exit without installing service mocassino
```

### Manual Installation (Developers And Advanced Users)

`mocassino` is published on PyPI as the same-name package
[mocassino](https://pypi.org/project/mocassino/).

Developers and advanced users might want to setup a development environment
instead of relying on the installation script described above.
See the
[DEVELOPMENT](https://github.com/pettarin/mocassino/blob/main/docs/DEVELOPMENT.md)
documentation for the details.


## GUI Usage

> [!TIP]
> This section summarizes the main points of the full
> [GUI Usage](https://github.com/pettarin/mocassino/blob/main/docs/gui/INDEX.md)
> guide: please refer to the latter for a more comprehensive description
> of the GUI of `mocassino`.

The installation script installs `mocassino` as a `systemd` service,
which is started automatically when the device boots up
(and immediately after its installation).

The MOC server is started automatically by `mocassino`,
if it is not already running.

### Buttons

With the default display orientation `0`,
the four buttons are located as described in the following table:

| Button Label | Location     |
|--------------|--------------|
| `A`          | Top Left     |
| `B`          | Bottom Left  |
| `X`          | Top Right    |
| `Y`          | Bottom Right |

![Mocassino with display with rotation 0 (audio jack on the left)](imgs/device_rotation_0.jpg)

When a different orientation is selected, the actions
are attached to the location of the button with respect to the display.
For instance, when orientation `180` is selected,
the following mapping takes place:

| Button Label | Location     | Acts As Button ... In Orientation `0` |
|--------------|--------------|---------------------------------------|
| `Y`          | Top Left     | `A`                                   |
| `X`          | Bottom Left  | `B`                                   |
| `B`          | Top Right    | `X`                                   |
| `A`          | Bottom Right | `Y`                                   |

![Mocassino with display with rotation 180 (audio jack on the right)](imgs/device_rotation_180.jpg)

Similarly for orientations `90` and `270`.

### Playback Screen

The first time the service runs, immediately after its installation,
it shows the following "Playback Screen":

![Playback screen after setup](imgs/playback_screen_after_setup.png)

After selecting a directory or file to play
(see Section "Library Menu" below for the details),
the "Playback Screen" will be similar to the following:

![Playback screen after open](imgs/playback_screen_after_open.png)

In the `Settings > Display > UI Elements` menu
it is possible to select what UI elements are shown or hidden.
For example, the side icons at the corners, the playlist progress bar
on the left, and the volume bar on the right can be hidden:

![Playback screen without side icons](imgs/playback_screen_no_side_icons.png)

#### Buttons

The default actions for the four buttons of the hat
while the "Playback Screen" is displayed are:

| Button Location | Short Press  | Long/Hold Press |
|-----------------|--------------|-----------------|
| Top left        | Play/pause   | Open the menu   |
| Bottom left     | Next track   | Previous track  |
| Top right       | Volume up    | Seek forward    |
| Bottom right    | Volume down  | Seek backward   |

### Menu Screen

The "Main" menu screen is as shown by the next screenshot:

![Main menu](imgs/main_menu.png)

Pressing the Top Left button will go back to the "Playback Screen".
In general, the Top Left button acts
as a "back one level" or "cancel" button,
no matter the nesting level of the menu currently displayed.

Pressing the Top or Bottom Right buttons will cycle through
the various menu items upwards or downwards
(with wrap-around at top and bottom),
highlighting the current item.

Menu items with a `>` on the right can be highlighted
(with Top/Bottom Right buttons, as explained in the previous paragraph)
and then selected by pressing the Bottom Left button:
the corresponding submenu or choices will be displayed.

Menu items with a square box on the right represent a boolean value
(`■` for `true`, `☐` for `false`):
highlighting it (Top/Bottom Right buttons)
and selecting it (Bottom Left button)
will toggle the corresponding boolean value.

### Library Menu

Selecting the "Library" submenu in the "Main" menu enters
the browser of the music library directory,
showing all directories and files that are direct children
of the it:

![Library menu 1](imgs/library_menu_1.png)

A directory can be highlighted and selected to enter it:

![Library menu 2](imgs/library_menu_2.png)
![Library menu 3](imgs/library_menu_3.png)
![Library menu 4](imgs/library_menu_4.png)

Selecting the "Play this folder" item
(or a selecting a single file)
regenerates the current playlist, adding the appropriate file(s),
possibly recursively inspecting subdirectories of the selected directory,
and returns to the "Playback Screen" view, starting the playback.

The above screenshots show a music library organized
in a hierarchical tree by author (`Francesco_De_Gregori`) and album (`Titanic`).

### Settings Menu

![Settings menu](imgs/settings_menu.png)

Submenus (first level only; to see a screenshot of all the submenus,
consult the detailed
[GUI Usage](https://github.com/pettarin/mocassino/blob/main/docs/gui/INDEX.md)
documentation):

![Settings > Display menu](imgs/display_menu.png)
![Settings > Playback menu](imgs/playback_menu.png)
![Settings > Run menu](imgs/run_menu.png)
![Settings > Startup menu](imgs/startup_menu.png)
![Settings > Reset all settings menu](imgs/reset_all_settings_menu_confirmation.png)

Examples of different UI elements shown/hidden:

![Settings > Display > UI elements menu with all elements shown](imgs/ui_elements_menu_all.png)
![Settings > Display > UI elements menu with all elements shown, corresponding screen](imgs/ui_elements_menu_all_screen.png)

![Settings > Display > UI elements menu with no side bars shown](imgs/ui_elements_menu_no_side_bars.png)
![Settings > Display > UI elements menu with no side bars shown, corresponding screen](imgs/ui_elements_menu_no_side_bars_screen.png)

![Settings > Display > UI elements menu with no side bars nor timers shown](imgs/ui_elements_menu_no_side_bars_no_timers.png)
![Settings > Display > UI elements menu with no side bars nor timers shown, corresponding screen](imgs/ui_elements_menu_no_side_bars_no_timers_screen.png)

![Settings > Display > UI elements menu with only timers shown](imgs/ui_elements_menu_only_timers.png)
![Settings > Display > UI elements menu with only timers shown, corresponding screen](imgs/ui_elements_menu_only_timers_screen.png)

#### System Menu

![System menu](imgs/system_menu.png)

Submenus:

![System > Restart service menu](imgs/restart_service_menu_confirmation.png)
![System > Reboot menu](imgs/reboot_menu_confirmation.png)
![System > Shutdown menu](imgs/shutdown_menu_confirmation.png)

#### About Mocassino Menu

![About mocassino menu](imgs/about_mocassino_menu.png)

Submenus:

![About mocassino > Host menu](imgs/host_menu.png)
![About mocassino > OS menu](imgs/os_menu.png)
![About mocassino > Python menu](imgs/python_menu.png)

#### Buttons

The default actions for the four buttons of the hat
while the "Menu Screen" is displayed are:

| Button Location | Short Press    | Long/Hold Press |
|-----------------|----------------|-----------------|
| Top left        | Back one level | (None)          |
| Bottom left     | Select         | (None)          |
| Top right       | Up             | Select          |
| Bottom right    | Down           | Select          |


## Configuration Files

The permanent settings are stored in the file located at
`/opt/mocassino/run/.config/mocassino/configuration.yaml`,
an example of which can be found at
[res/configuration/configuration.yaml](https://github.com/pettarin/mocassino/blob/main/res/configuration/configuration.yaml).
Most of the settings can be changed directly through the service menus,
thus not requiring a local or SSH connection to the device running `mocassino`.

The state of the player is stored in the file located at
`/opt/mocassino/run/.config/mocassino/state.yaml` file,
an example of which can be found at
[res/configuration/state.yaml](https://github.com/pettarin/mocassino/blob/main/res/configuration/state.yaml).
Regular users do not need to alter this file.


## CLI Usage

The
[CLI Usage](https://github.com/pettarin/mocassino/blob/main/docs/cli/INDEX.md)
guide describes all the commands, subcommands, and most of the options
of the CLI tool `mocassino`.


## Releases And Changelog

The list of releases and their changes is contained
in the
[CHANGELOG](https://github.com/pettarin/mocassino/blob/main/docs/CHANGELOG.md)
document.


## Development

Consult the
[DEVELOPMENT](https://github.com/pettarin/mocassino/blob/main/docs/DEVELOPMENT.md)
document to learn how to set up a development environment,
run the tests, and browse the project structure.

The
[CONTRIBUTING](https://github.com/pettarin/mocassino/blob/main/docs/CONTRIBUTING.md)
document explains how to report issues and propose changes.


## License

This project is licensed under
the GNU General Public License v3.0 or later (GPLv3+).

See the
[LICENSE](https://github.com/pettarin/mocassino/blob/main/LICENSE)
file for details.

The bundled Roboto Regular font is licensed under
the SIL Open Font License 1.1, see the
[OFL.txt](https://github.com/pettarin/mocassino/blob/main/src/mocassino/res/font/OFL.txt)
file for details.


## Authors

- Alberto Pettarin ([Web](https://www.albertopettarin.it))

