Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: CI

on:
push:
branches: [main]
pull_request:

permissions:
contents: read

jobs:
linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Install ALSA and X11 headers
run: |
sudo apt-get update
sudo apt-get install -y libasound2-dev libgl1-mesa-dev libxrandr-dev \
libxcursor-dev libxinerama-dev libxi-dev libxxf86vm-dev
- name: gofmt
run: |
unformatted=$(gofmt -l .)
if [ -n "$unformatted" ]; then
echo "Run gofmt on:"; echo "$unformatted"; exit 1
fi
- run: go vet ./...
- run: go test -race ./...
- name: Cross-build for Windows
run: GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build ./...

macos:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- run: go vet ./...
- run: go test -race ./...
- name: Build xWinAmp.app
run: scripts/build-app.sh
- uses: actions/upload-artifact@v4
with:
name: xWinAmp-app
path: dist/xWinAmp-macos.zip
retention-days: 7
66 changes: 66 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Release

on:
push:
tags: ["v*"]

permissions:
contents: read

jobs:
macos:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Build xWinAmp.app
run: VERSION=${{ github.ref_name }} scripts/build-app.sh
- uses: actions/upload-artifact@v4
with:
name: macos
path: dist/xWinAmp-macos.zip

linux-windows:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Install ALSA and X11 headers
run: |
sudo apt-get update
sudo apt-get install -y libasound2-dev libgl1-mesa-dev libxrandr-dev \
libxcursor-dev libxinerama-dev libxi-dev libxxf86vm-dev
- name: Build
run: |
mkdir -p dist
go build -trimpath -ldflags "-s -w" -o dist/xwinamp ./cmd/xwinamp
tar -czf dist/xwinamp-linux-amd64.tar.gz -C dist xwinamp
# -H=windowsgui: no console window behind the player.
GOOS=windows GOARCH=amd64 CGO_ENABLED=0 \
go build -trimpath -ldflags "-s -w -H=windowsgui" -o dist/xwinamp.exe ./cmd/xwinamp
(cd dist && zip -q xwinamp-windows-amd64.zip xwinamp.exe)
- uses: actions/upload-artifact@v4
with:
name: linux-windows
path: |
dist/xwinamp-linux-amd64.tar.gz
dist/xwinamp-windows-amd64.zip

release:
needs: [macos, linux-windows]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/download-artifact@v4
with:
path: dist
merge-multiple: true
- uses: softprops/action-gh-release@v2
with:
files: dist/*
generate_release_notes: true
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

A Winamp-style audio player written in Go. macOS first, Linux and Windows later.

Status: step 3 of 4. Player window with a playlist; CI and macOS app packaging come next.
Status: player window with a playlist, CI and release builds (steps 1-4 of the initial plan).

![xWinAmp main window](docs/screenshot.png)

Expand All @@ -13,6 +13,8 @@ Status: step 3 of 4. Player window with a playlist; CI and macOS app packaging c
- `playlist/` - track list, next/prev, repeat/shuffle, M3U. No UI code.
- `cmd/xwinamp/` - the desktop player; saves the playlist and settings between runs.
- `cmd/xwinamp-cli/` - terminal player built on `player`.
- `tools/mkicon/` - draws the app icon.
- `scripts/build-app.sh` - builds `dist/xWinAmp.app` on macOS.

Supported formats: MP3, WAV, FLAC, OGG Vorbis.

Expand Down Expand Up @@ -57,6 +59,24 @@ While playing, type a command and press Enter: `p` pause/resume, `s` stop,
`sudo apt install libasound2-dev libgl1-mesa-dev libxrandr-dev libxcursor-dev libxinerama-dev libxi-dev libxxf86vm-dev`.
File dialogs need `zenity` or `kdialog` installed.

## macOS app

```sh
scripts/build-app.sh # dist/xWinAmp.app and dist/xWinAmp-macos.zip
VERSION=1.0.0 scripts/build-app.sh
```

The app is a universal binary (Apple Silicon and Intel). It is ad-hoc signed,
not signed with a Developer ID, so on first launch open it with right click →
Open.

## Releases

Pushing a tag like `v0.1.0` runs `.github/workflows/release.yml`, which builds
the macOS app, a Linux binary and a Windows `.exe` and attaches them to a
GitHub Release. `.github/workflows/ci.yml` checks formatting, vet and tests on
Linux and macOS for every pull request.

## Tests

```sh
Expand Down
73 changes: 73 additions & 0 deletions scripts/build-app.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/usr/bin/env bash
# Builds dist/xWinAmp.app (universal arm64 + amd64) and dist/xWinAmp-macos.zip.
# Runs on macOS only: it needs lipo, sips, iconutil and ditto.
#
# VERSION=1.2.3 scripts/build-app.sh
set -euo pipefail

cd "$(dirname "$0")/.."

VERSION="${VERSION:-0.0.0-dev}"
VERSION="${VERSION#v}"
APP=dist/xWinAmp.app
WORK=$(mktemp -d)
trap 'rm -rf "$WORK"' EXIT

rm -rf "$APP" dist/xWinAmp-macos.zip
mkdir -p "$APP/Contents/MacOS" "$APP/Contents/Resources"

echo "Building binaries..."
for arch in arm64 amd64; do
GOOS=darwin GOARCH=$arch CGO_ENABLED=1 \
go build -trimpath -ldflags "-s -w" -o "$WORK/xwinamp-$arch" ./cmd/xwinamp
done
lipo -create -output "$APP/Contents/MacOS/xwinamp" "$WORK/xwinamp-arm64" "$WORK/xwinamp-amd64"

echo "Building icon..."
go run ./tools/mkicon -size 1024 -o "$WORK/icon.png"
ICONSET="$WORK/xwinamp.iconset"
mkdir "$ICONSET"
for size in 16 32 128 256 512; do
sips -z $size $size "$WORK/icon.png" --out "$ICONSET/icon_${size}x${size}.png" >/dev/null
sips -z $((size * 2)) $((size * 2)) "$WORK/icon.png" --out "$ICONSET/icon_${size}x${size}@2x.png" >/dev/null
done
iconutil -c icns -o "$APP/Contents/Resources/xwinamp.icns" "$ICONSET"

cat >"$APP/Contents/Info.plist" <<PLIST
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleName</key>
<string>xWinAmp</string>
<key>CFBundleDisplayName</key>
<string>xWinAmp</string>
<key>CFBundleIdentifier</key>
<string>io.github.rooty.xwinamp</string>
<key>CFBundleExecutable</key>
<string>xwinamp</string>
<key>CFBundleIconFile</key>
<string>xwinamp</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>${VERSION}</string>
<key>CFBundleVersion</key>
<string>${VERSION}</string>
<key>LSMinimumSystemVersion</key>
<string>11.0</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.music</string>
<key>NSHighResolutionCapable</key>
<true/>
</dict>
</plist>
PLIST
plutil -lint "$APP/Contents/Info.plist" >/dev/null

# Ad-hoc signature: required for arm64 binaries; not a Developer ID signature,
# so Gatekeeper still asks on first launch (right click -> Open).
codesign --force --deep --sign - "$APP"

ditto -c -k --keepParent "$APP" dist/xWinAmp-macos.zip
echo "Built $APP ($VERSION) and dist/xWinAmp-macos.zip"
111 changes: 111 additions & 0 deletions tools/mkicon/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// Command mkicon draws the xWinAmp app icon and writes it as a PNG.
//
// go run ./tools/mkicon -size 1024 -o icon.png
package main

import (
"flag"
"image"
"image/color"
"image/png"
"log"
"math"
"os"
)

var (
colBg = color.RGBA{0x2a, 0x2a, 0x3a, 0xff}
colBorder = color.RGBA{0x5a, 0x5a, 0x78, 0xff}
colScreen = color.RGBA{0x00, 0x00, 0x00, 0xff}
colLCD = color.RGBA{0x00, 0xe0, 0x00, 0xff}
)

func main() {
size := flag.Int("size", 1024, "icon size in pixels")
out := flag.String("o", "icon.png", "output PNG file")
flag.Parse()

f, err := os.Create(*out)
if err != nil {
log.Fatal(err)
}
if err := png.Encode(f, draw(*size)); err != nil {
log.Fatal(err)
}
if err := f.Close(); err != nil {
log.Fatal(err)
}
}

// draw renders the icon: a rounded dark body like the player window with a
// black screen and a green play triangle, in the macOS icon grid (the body
// covers about 80% of the canvas).
func draw(size int) *image.RGBA {
img := image.NewRGBA(image.Rect(0, 0, size, size))
s := float64(size)
margin := s * 0.1
body := rect{margin, margin, s - margin, s - margin}
screen := body.inset(s * 0.09)
tri := screen.inset(s * 0.14)

for y := range size {
for x := range size {
// Sample at the pixel centre with 4x4 supersampling for smooth edges.
var r, g, b, a float64
for sy := range 4 {
for sx := range 4 {
px := float64(x) + (float64(sx)+0.5)/4
py := float64(y) + (float64(sy)+0.5)/4
c, ok := sample(px, py, s, body, screen, tri)
if ok {
r += float64(c.R)
g += float64(c.G)
b += float64(c.B)
a += 255
}
}
}
if a > 0 {
// Premultiplied: colours are summed only where covered.
img.SetRGBA(x, y, color.RGBA{uint8(r / 16), uint8(g / 16), uint8(b / 16), uint8(a / 16)})
}
}
}
return img
}

func sample(x, y, s float64, body, screen, tri rect) (color.RGBA, bool) {
radius := s * 0.18
if !body.containsRounded(x, y, radius) {
return color.RGBA{}, false
}
if !body.inset(s*0.02).containsRounded(x, y, radius*0.9) {
return colBorder, true
}
if !screen.containsRounded(x, y, s*0.04) {
return colBg, true
}
// Play triangle pointing right, centred in the screen.
t := tri
if x >= t.x0+t.w()*0.08 && math.Abs(y-t.cy())*2 <= t.h()*(1-(x-t.x0-t.w()*0.08)/(t.w()*0.84)) {
return colLCD, true
}
return colScreen, true
}

type rect struct{ x0, y0, x1, y1 float64 }

func (r rect) w() float64 { return r.x1 - r.x0 }
func (r rect) h() float64 { return r.y1 - r.y0 }
func (r rect) cy() float64 { return (r.y0 + r.y1) / 2 }

func (r rect) inset(d float64) rect { return rect{r.x0 + d, r.y0 + d, r.x1 - d, r.y1 - d} }

func (r rect) containsRounded(x, y, rad float64) bool {
if x < r.x0 || x > r.x1 || y < r.y0 || y > r.y1 {
return false
}
cx := math.Max(r.x0+rad, math.Min(x, r.x1-rad))
cy := math.Max(r.y0+rad, math.Min(y, r.y1-rad))
return math.Hypot(x-cx, y-cy) <= rad
}
Loading