BRAMP - SETUP
=============

Bramp plays the music you own. It has three parts, and you can use any of them:

  * The SERVER runs on a computer that has your music (it can stay on all the time).
    It lets your phone, and other computers, play that music.
  * The ANDROID APP plays the server's music on your phone (and in the car, with
    Android Auto).
  * The DESKTOP APP plays music on Windows, from folders on the PC or from the
    server. It doesn't need the server: if you only want music on one PC, install
    Bramp-Setup and skip to section 7.

Bramp only ever reads your music. It never changes, moves or deletes your files.

What's in this folder:

  SETUP.txt                  this guide
  Bramp Guide.txt            how to use the desktop app, and its keyboard shortcuts
  Bramp-x.y.z.apk            the Android app
  Bramp-Setup-x.y.z.exe      the Windows desktop app
  server\                    the server


1. WHAT YOU NEED
----------------

  * A computer for the server, with your music on it or on a drive it can reach:
    Windows 10 or 11, a Mac, or a Linux PC (64-bit Intel or AMD). Raspberry Pi and
    other ARM computers don't work yet. On Macs with Apple chips (M1 and later)
    it runs through Docker's Intel emulation, which is slower.
  * Docker, a free program that runs the server (step 2).
  * An Android phone with Android 9 or later.
  * At home, the phone and the server on the same Wi-Fi. For away from home, see
    section 6.


2. INSTALL DOCKER (once)
------------------------

  Windows or Mac: install "Docker Desktop" from https://www.docker.com/
                  Start it once and let it finish starting (the whale icon stops
                  moving). Docker Desktop must be running for the server to run.
                  In its Settings, turn on "Start Docker Desktop when you sign in".

  Linux:          Install Docker and its compose plugin from your distribution.
                  Debian / Ubuntu / Mint:
                      sudo apt install docker.io docker-compose-v2
                      sudo usermod -aG docker "$USER"
                  WARNING: "sudo" changes your system. The first line installs
                  packages. The second lets your user run Docker, and that access
                  is as powerful as the administrator's. Then log out and back in.

  Check it works: open a terminal (Windows: PowerShell; Mac: Terminal) and type
      docker compose version
  You should see a version number.


3. SET UP THE SERVER (once)
---------------------------

  a) Unzip this folder somewhere it can stay, e.g. your Documents folder.
     The server keeps its own files in server\data, so don't delete it later.

  b) In the server folder, open the file named .env with Notepad (or any text
     editor). On a Mac or Linux it's hidden: press Cmd+Shift+. (Mac) or Ctrl+H
     (Linux) to see it.

     Change the MUSIC_DIR line to your music folder, with forward slashes (/):
         MUSIC_DIR=C:/Users/Pat/Music          (Windows)
         MUSIC_DIR=/Users/pat/Music            (Mac)
         MUSIC_DIR=/home/pat/Music             (Linux)
     Linux only: also set BRAMP_UID and BRAMP_GID to the numbers the commands
     id -u  and  id -g  show (often both 1000, which is already filled in).
     Save the file.

  c) Open a terminal in the server folder.
         Windows: open the server folder, click the address bar, type
                  powershell  and press Enter.
         Mac / Linux: open a terminal, type  cd  and a space, drag the server folder
                  into the window, then press Enter.

  d) Load the server into Docker (type the start of the name and press Tab to
     fill in the rest):
         docker load -i bramp-server-x.y.z.tar.gz

  e) Start it:
         docker compose up -d

     The server now runs in the background, and starts again on its own after a
     restart (once Docker is running). The first time, it reads your whole
     collection; a big one takes a few minutes. Watch it with:
         docker compose logs -f
     (Ctrl+C stops watching; the server keeps running.) After it has read the
     collection, it also listens to every song once for "song radio". That can take
     an hour or more for a big collection. Music plays while it does this.

     Windows: if a Firewall window asks about Docker, allow "Private networks".


4. MAKE A KEY FOR EACH DEVICE
-----------------------------

Each phone or computer signs in with its own key. To make one, type this in the
server folder:

    docker compose exec bramp bramp user key add me "My phone" --config /config/server.toml

It shows a key that starts with bk_. It's shown ONCE only. Copy it somewhere safe
until you've entered it in the app. Make another key, with another name, for each
device. Treat keys like passwords.

  See your keys:   docker compose exec bramp bramp user key list me --config /config/server.toml
  Stop one:        docker compose exec bramp bramp user key revoke me <number> --config /config/server.toml
                   (the number comes from the list)

Limits: they stop one account being shared with lots of people. Each person can play
on 2 devices at once and have 10 keys, and a server can have at most 10 people. A
third device gets "Already playing on ...". It can play once one of the others has
been quiet for about a minute after its song. You can lower these limits in
config\server.toml, but not raise them.

The server's ADDRESS is http://<the server computer's address>:4747
  Find the computer's address:
    Windows: in PowerShell type  ipconfig  and use the "IPv4 Address",
             e.g. 192.168.1.20
    Mac:     System Settings > Wi-Fi (or Network) > Details > IP address
    Linux:   hostname -I  (the first number)
  So the address is something like  http://192.168.1.20:4747

  Tip: your router can give the server computer the same address every time
  (look for "DHCP reservation" or "static lease" in its settings). Otherwise the
  address can change, and the apps would need the new one.


5. INSTALL THE ANDROID APP
--------------------------

  a) Copy Bramp-x.y.z.apk to the phone (USB cable, Google Drive, or email it to
     yourself), then tap it on the phone (in Files or Downloads).
  b) Android asks to allow installing apps from that source (Files, Drive or
     Chrome): allow it, then tap Install. You can turn that permission off again
     afterwards.
     If Play Protect warns that the app is unknown, choose "Install anyway". The
     app isn't in the Play Store, so Google doesn't recognise it.
  c) Open Bramp and fill in:
         Name:        anything, e.g. Home
         Address:     the server's address from step 4, e.g. http://192.168.1.20:4747
         Device key:  the bk_ key you made for this phone
     Tap Connect. Your artists, albums and playlists appear.

  Android Auto: Bramp shows up in the car's app list. Android Auto may hide apps
  that aren't from the Play Store. If it does: in Android Auto's settings, tap
  "Version" about 10 times to unlock developer settings, open the menu (three dots)
  > Developer settings, and turn on "Unknown sources".

  Updating: install the new .apk the same way. Your settings stay.


6. AWAY FROM HOME (optional)
----------------------------

Out of the box, the server is only reachable on your home network. To use it
anywhere, without opening your router to the internet, use Tailscale (free for
personal use, https://tailscale.com):

  * Install Tailscale on the server computer and on the phone, and sign in to both
    with the same account.
  * In the Bramp app, use the server computer's Tailscale address instead: it
    starts with 100. (shown in the Tailscale app), e.g. http://100.101.102.103:4747
    This address works at home and away. Tailscale encrypts the connection.

Don't forward port 4747 on your router: it would put the server on the open
internet.


7. THE WINDOWS DESKTOP APP
--------------------------

  * Run Bramp-Setup-x.y.z.exe. It installs for your user only and doesn't need an
    administrator. Windows may say "Windows protected your PC" because the
    installer isn't signed: click "More info" > "Run anyway".
  * On the last page you can choose Bramp as your default music player.
  * The first time it starts, Bramp asks where your music is. Pick your music
    folder.
  * To play the server's music too: Settings tab > Server, the server's address and
    a key made for this PC (step 4).
  * "Bramp Guide" in the Start menu explains the rest, including the keyboard
    shortcuts.


8. EVERYDAY
-----------

Run these in the server folder:

  Is it running?          docker compose ps
  What is it doing?       docker compose logs -f
  Stop / start            docker compose stop   /   docker compose start
  New music               nothing to do: it checks for new songs every hour
                          (and when it starts)
  Change settings         edit config\server.toml (comments in the file explain
                          each setting); most changes apply within seconds

  Updating the server (when you get a new zip): copy the new
  bramp-server-x.y.z.tar.gz into your server folder, then:
      docker load -i bramp-server-x.y.z.tar.gz
      docker compose up -d
  Keep your existing .env, config and data. Your keys, stars and playlists stay.

  Backups: every day the server saves its own data (keys, stars, play counts,
  playlists) in server\data\backups. Copy that folder somewhere else now and then.
  Your music isn't in it. Back up your music separately, as you always have.


9. WHEN SOMETHING IS WRONG
--------------------------

  "set MUSIC_DIR in .env"        The .env file is missing or has no MUSIC_DIR line
                                 (step 3b). It must be named exactly .env (not
                                 .env.txt) and be in the server folder.

  The app says it can't connect  Is the server running (docker compose ps)? Is the
                                 phone on the same Wi-Fi? Is the address right, with
                                 http:// and :4747? Has the server computer's
                                 address changed (step 4)? On Windows, check the
                                 Firewall allows Docker on private networks.

  The app says the key is wrong  Make a new key (step 4) and enter it exactly,
                                 starting with bk_.

  The library is empty           MUSIC_DIR doesn't point at your music, or the drive
                                 wasn't connected when the server started. Fix it,
                                 then:  docker compose up -d   and   docker compose
                                 restart

  "permission denied" in the logs (Linux) BRAMP_UID / BRAMP_GID in .env aren't
                                 your numbers, or the data folder belongs to another
                                 user. Check with:  ls -ld data

  Radio plays random songs       The server is still listening to your songs
                                 (step 3e). Radio picks songs that sound alike once
                                 it has finished.
