Skip to content

Commit

Permalink
add: Makefile, workflow; fix: README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
vasilymilovidov committed Oct 15, 2023
1 parent d098517 commit 07c7e44
Show file tree
Hide file tree
Showing 10 changed files with 153 additions and 385 deletions.
92 changes: 92 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: Release Binaries

on:
release:
types: [created]

jobs:
build:
strategy:
matrix:
include:
- os: ubuntu-latest
goos: linux
goarch: amd64
rust_target: x86_64-unknown-linux-gnu
- os: windows-latest
goos: windows
goarch: amd64
rust_target: x86_64-pc-windows-msvc
- os: macOS-latest
goos: darwin
goarch: amd64
rust_target: x86_64-apple-darwin
- os: macOS-latest
goos: darwin
goarch: arm64
rust_target: aarch64-apple-darwin

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2

- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.20

- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: ${{ matrix.rust_target }}
override: true

- name: Run Makefile
env:
GO111MODULE: on
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
TARGET: ${{ matrix.rust_target }}
EXTENSION: ${{ matrix.goos == 'windows' && '.exe' || '' }}
run: make -f Makefile.ci all

- name: Archive executables
shell: bash
run: |
if [[ "${{ matrix.goos }}" == "windows" ]]; then
7z a doughscraper_${{ matrix.goos }}_${{ matrix.goarch }}.zip doughscraper.exe
7z a pitchdetector_${{ matrix.goos }}_${{ matrix.goarch }}.zip pitchdetector.exe
else
tar czvf doughscraper_${{ matrix.goos }}_${{ matrix.goarch }}.tar.gz doughscraper
tar czvf pitchdetector_${{ matrix.goos }}_${{ matrix.goarch }}.tar.gz pitchdetector
fi
- name: Upload binaries
uses: actions/upload-artifact@v2
with:
name: binaries-${{ matrix.goos }}-${{ matrix.goarch }}
path: |
doughscraper_${{ matrix.goos }}_${{ matrix.goarch }}.tar.gz
pitchdetector_${{ matrix.goos }}-${{ matrix.goarch }}.tar.gz
- name: Upload Release Asset (doughscraper)
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./doughscraper_${{ matrix.goos }}_${{ matrix.goarch }}${{ matrix.goos == 'windows' && '.zip' || '.tar.gz' }}
asset_name: doughscraper_${{ matrix.goos }}_${{ matrix.goarch }}${{ matrix.goos == 'windows' && '.zip' || '.tar.gz' }}
asset_content_type: application/gzip

- name: Upload Release Asset (pitchdetector)
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./pitchdetector_${{ matrix.goos }}_${{ matrix.goarch }}${{ matrix.goos == 'windows' && '.zip' || '.tar.gz' }}
asset_name: pitchdetector_${{ matrix.goos }}_${{ matrix.goarch }}${{ matrix.goos == 'windows' && '.zip' || '.tar.gz' }}
asset_content_type: application/gzip
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
*.dll
*.so
*.dylib
pitchdetector
doughscraper

# Test binary, built with `go test -c`
*.test
Expand Down
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.PHONY: build_go build_rust

BINARY_GO := doughscraper
BINARY_RUST := pitchdetector
INSTALL_PATH := /usr/local/bin/

build_go:
@echo "Building Go binary"
@cd go && go build -o ../$(BINARY_GO)

build_rust:
@echo "Building Rust binary"
@cd rust/pitchdetector && cargo build --release
@cp rust/pitchdetector/target/release/$(BINARY_RUST) .

all: build_go build_rust
16 changes: 16 additions & 0 deletions Makefile.ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.PHONY: build_go build_rust install

BINARY_GO := doughscraper
BINARY_RUST := pitchdetector

build_go:
@echo "Building Go binary"
cd go && GOOS=$(GOOS) GOARCH=$(GOARCH) go build -o ../$(BINARY_GO)$(EXTENSION)

build_rust:
@echo "Building Rust binary"
cd rust/pitchdetector && cargo build --release --target $(TARGET)
cp rust/pitchdetector/target/$(TARGET)/release/$(BINARY_RUST)$(EXTENSION) $(BINARY_RUST)$(EXTENSION)


all: build_go build_rust
24 changes: 14 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
# Doughscraper
## Doughscraper

Doughscraper is a CLI tool for preparing samples for [`tidalcycles/strudel`](https://github.com/tidalcycles/strudel). It has two modes:
- Detect files with note/octave pairs in their names and rename them, removing everything else. This mode is primarily designed to prepare samples generated by Logic Pro's 'Auto Sampler'.
- Take a folder of samples, detect subfolders with pitched samples using their filenames, detect subfolders with one-shot samples, and generate a JSON file for use with strudel.
Doughscraper is a CLI tool for preparing samples for [`tidalcycles/strudel`](https://github.com/tidalcycles/strudel).

#### Usage

The first mode requires a path to the local folder with pitched samples:
(e.g., 'Users/username/samples/piano').
### Usage
Download the latest release for your OS from the release page and put `doughscraper` and `pitchdetector` binaries in your PATH.

The second mode requires a path to the root of the local samples folder (e.g., 'Users/username/samples') and a path to a remote folder where you will upload your samples (e.g., 'https://raw.githubusercontent.com/vasilymilovidov/samples/main').
#### Modes:
- **Rename pitched files**
identifies files with note/octave pairs in their names and renames them by removing everything else. It requires the path to the local folder containing the pitched samples, for example, `Users/username/samples/piano`.
- **Generate JSON** — takes a folder containing samples, identifies subfolders with pitched and oneshot samples based on their filenames. It then generates a JSON file that can be used with strudel. You need to provide the path to the root of the local samples folder (e.g., `'Users/username/samples'`) and the path to a remote folder where you will upload your samples (e.g., `'https://raw.githubusercontent.com/vasilymilovidov/samples/main'`).
- **Detect pitch and rename** — identifies the pitch of the samples and renames them accordingly. It requires the path to the local folder containing the pitched samples, for example, ``Users/username/samples/piano``. Note that this script keeps the original filenames and adds the note/octave pairs to them. So, if you want to properly add these samples to the strudel.json file, run the **Rename pitched files** script first.

Do not include the closing backslash in the paths.

#### Build
### Build
To build, you need to have Go and Rust installed.

Clone the repo and run:
```go
go build
make all
```
Then copy both generated binaries (`doughscraper` and `pitchdetector`) to your PATH.

Binary file added doughscraper.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 13 additions & 5 deletions go/main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package main

import (
"errors"
"fmt"
"os/exec"

tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/muesli/reflow/indent"
Expand All @@ -11,7 +13,11 @@ import (
type pitchDetectorFinishedMsg struct{err error}

func PitchDetectAndRenameFiles(path string) tea.Cmd {
c := exec.Command("pitch_detector", path)
// pitchdetector, err := exec.LookPath("pitchdetector")
c := exec.Command("pitchdetector", path)
if errors.Is(c.Err, exec.ErrDot) {
c.Err = nil
}
return tea.ExecProcess(c, func(err error) tea.Msg {
return pitchDetectorFinishedMsg{err}
})
Expand Down Expand Up @@ -42,6 +48,7 @@ func main() {
newLocalFolder("Local folder path"),
newLocalRoot("Local root path"),
newRemoteFolder("Remote root folder path"),
newLocalFolder("Local folder path"),
}
styles := DefaultStyles()
initialModel := model{
Expand Down Expand Up @@ -238,7 +245,7 @@ func updateRename(msg tea.Msg, m model) (tea.Model, tea.Cmd) {
}

func PitchDetectAndRename(m model) string {
current := m.paths[0]
current := m.paths[3]
return lipgloss.Place(
m.width,
m.height,
Expand All @@ -254,7 +261,7 @@ func PitchDetectAndRename(m model) string {
}

func updatePitchDetectAndRename(msg tea.Msg, m model) (tea.Model, tea.Cmd) {
current := &m.paths[0]
current := &m.paths[3]
var cmd tea.Cmd
switch msg := msg.(type) {
case tea.WindowSizeMsg:
Expand Down Expand Up @@ -314,7 +321,7 @@ func updateCreateJson(msg tea.Msg, m model) (tea.Model, tea.Cmd) {
return m, tea.Quit
case "enter":
current.answer = current.input.Value()
if m.index == len(m.paths)-1 {
if m.index == len(m.paths)-2 {
err := GenerateJson(m.paths[1].answer, m.paths[2].answer)
if err != nil {
fmt.Printf("Error: %s", err.Error())
Expand All @@ -323,7 +330,8 @@ func updateCreateJson(msg tea.Msg, m model) (tea.Model, tea.Cmd) {
m.doneMessage = fmt.Sprintf("Generated JSON in %s", m.paths[1].answer)
m.CreateJsonMenu = false
}
m.Next()
m.Next()

return m, current.input.Blur()
}
}
Expand Down
Loading

0 comments on commit 07c7e44

Please sign in to comment.