Skip to content

Commit

Permalink
Add Shuffle (#12)
Browse files Browse the repository at this point in the history
* add shuffle

* small tweak

* ui tweak
  • Loading branch information
dhulihan authored Aug 13, 2022
1 parent d74c517 commit 2c958b3
Show file tree
Hide file tree
Showing 10 changed files with 130 additions and 83 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
dist/
/grump
/grump.log
*.prof
27 changes: 24 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/dhulihan/grump

go 1.14
go 1.19

require (
github.com/bogem/id3v2 v1.2.0
Expand All @@ -10,7 +10,28 @@ require (
github.com/rivo/tview v0.0.0-20200404204604-ca37f83cb2e7
github.com/sirupsen/logrus v1.5.0
github.com/stretchr/testify v1.4.0
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae // indirect
golang.org/x/text v0.3.3 // indirect
gopkg.in/yaml.v2 v2.3.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gdamore/encoding v1.0.0 // indirect
github.com/hajimehoshi/go-mp3 v0.3.0 // indirect
github.com/hajimehoshi/oto v0.6.1 // indirect
github.com/icza/bitio v1.0.0 // indirect
github.com/jfreymuth/oggvorbis v1.0.1 // indirect
github.com/jfreymuth/vorbis v1.0.0 // indirect
github.com/konsorten/go-windows-terminal-sequences v1.0.1 // indirect
github.com/lucasb-eyer/go-colorful v1.0.3 // indirect
github.com/mattn/go-runewidth v0.0.8 // indirect
github.com/mewkiz/flac v1.0.6 // indirect
github.com/mewkiz/pkg v0.0.0-20190919212034-518ade7978e2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.1.0 // indirect
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8 // indirect
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067 // indirect
golang.org/x/mobile v0.0.0-20190415191353-3e0bab5405d6 // indirect
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab // indirect
golang.org/x/text v0.3.3 // indirect
)
10 changes: 2 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,16 @@ github.com/jfreymuth/vorbis v1.0.0 h1:SmDf783s82lIjGZi8EGUUaS7YxPHgRj4ZXW/h7rUi7
github.com/jfreymuth/vorbis v1.0.0/go.mod h1:8zy3lUAm9K/rJJk223RKy6vjCZTWC61NA2QD06bfOE0=
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/lucasb-eyer/go-colorful v1.0.2 h1:mCMFu6PgSozg9tDNMMK3g18oJBX7oYGrC09mS6CXfO4=
github.com/lucasb-eyer/go-colorful v1.0.2/go.mod h1:0MS4r+7BZKSJ5mw4/S5MPN+qHFF1fYclkSPilDOKW0s=
github.com/lucasb-eyer/go-colorful v1.0.3 h1:QIbQXiugsb+q10B+MI+7DI1oQLdmnep86tWFlaaUAac=
github.com/lucasb-eyer/go-colorful v1.0.3/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y=
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mattn/go-runewidth v0.0.8 h1:3tS41NlGYSmhhe/8fhGRzc+z3AYCw1Fe1WAyLuujKs0=
github.com/mattn/go-runewidth v0.0.8/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mewkiz/flac v1.0.6 h1:OnMwCWZPAnjDndjEzLynOZ71Y2U+/QYHoVI4JEKgKkk=
github.com/mewkiz/flac v1.0.6/go.mod h1:yU74UH277dBUpqxPouHSQIar3G1X/QIclVbFahSd1pU=
github.com/mewkiz/pkg v0.0.0-20190919212034-518ade7978e2 h1:EyTNMdePWaoWsRSGQnXiSoQu0r6RS1eA557AwJhlzHU=
github.com/mewkiz/pkg v0.0.0-20190919212034-518ade7978e2/go.mod h1:3E2FUC/qYUfM8+r9zAwpeHJzqRVVMIYnpzD/clwWxyA=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand All @@ -55,7 +52,6 @@ github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJ
github.com/sirupsen/logrus v1.5.0 h1:1N5EYkVAPEywqZRJd7cwnRtCb6xJx7NH3T3WUTF980Q=
github.com/sirupsen/logrus v1.5.0/go.mod h1:+F7Ogzej0PZc/94MaYx/nvG9jOFMD2osvC3s+Squfpo=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
Expand All @@ -71,12 +67,10 @@ golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190429190828-d89cdac9e872/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4 h1:sfkvUWPNGwSV+8/fNqctR5lS2AqCSqYwXdrjCxp/dXo=
golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae h1:/WDfKMnPU+m5M4xB+6x4kaepxRw6jWvR5iDRdvjHgy8=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab h1:2QkjZIsXupsJbJIdSjjUOgWK3aEtzyuh2mPt3l/CkeU=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
Expand Down
3 changes: 1 addition & 2 deletions library/audio.go → library/audio_shelf.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ import (
type AudioShelf interface {
Tracks() []Track

// LoadTracks searches for new files to add to the library
// LoadTracks fills the shelf with tracks
LoadTracks() (count uint64, err error)

LoadTrack(ctx context.Context, location string) (*Track, error)
SaveTrack(ctx context.Context, prev, track *Track) (*Track, error)
DeleteTrack(ctx context.Context, track *Track) error
Expand Down
2 changes: 1 addition & 1 deletion player/audio.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type AudioPlayer interface {
type AudioController interface {
Paused() bool
PauseToggle() bool
Progress() (PlayState, error)
PlayState() (PlayState, error)
SeekForward() error
SeekBackward() error
SpeedUp()
Expand Down
4 changes: 2 additions & 2 deletions player/beep.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ func (c *BeepController) Done() chan (bool) {
return c.done
}

// Progress returns the current state of playing audio.
func (c *BeepController) Progress() (PlayState, error) {
// PlayState returns the current state of playing audio.
func (c *BeepController) PlayState() (PlayState, error) {
speaker.Lock()
p := c.audioPanel.streamer.Position()
position := c.audioPanel.sampleRate.D(p)
Expand Down
22 changes: 11 additions & 11 deletions player/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ func NewMockAudioPlayer() *MockAudioPlayer {
}

// Play a track and return a controller that lets you perform changes to a running track.
func (bmp *MockAudioPlayer) Play(track library.Track, repeat bool) (AudioController, error) {
func (bmp *MockAudioPlayer) Play(track library.Track, repeat bool) (*MockAudioController, error) {
return &MockAudioController{}, nil
}

type MockAudioController struct{}

func (p *MockAudioController) Paused() bool { return false }
func (p *MockAudioController) PauseToggle() bool { return true }
func (p *MockAudioController) Progress() (PlayState, error) { return PlayState{}, nil }
func (p *MockAudioController) SeekForward() error { return nil }
func (p *MockAudioController) SeekBackward() error { return nil }
func (p *MockAudioController) SpeedUp() {}
func (p *MockAudioController) SpeedDown() {}
func (p *MockAudioController) Stop() {}
func (p *MockAudioController) VolumeUp() {}
func (p *MockAudioController) VolumeDown() {}
func (p *MockAudioController) Paused() bool { return false }
func (p *MockAudioController) PauseToggle() bool { return true }
func (p *MockAudioController) PlayState() (PlayState, error) { return PlayState{}, nil }
func (p *MockAudioController) SeekForward() error { return nil }
func (p *MockAudioController) SeekBackward() error { return nil }
func (p *MockAudioController) SpeedUp() {}
func (p *MockAudioController) SpeedDown() {}
func (p *MockAudioController) Stop() {}
func (p *MockAudioController) VolumeUp() {}
func (p *MockAudioController) VolumeDown() {}
1 change: 1 addition & 0 deletions ui/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func NewHelpPage(ctx context.Context) *HelpPage {
KeyboardShortcut{"[", "play previous track"},
KeyboardShortcut{"=", "volume up"},
KeyboardShortcut{"-", "volume down"},
KeyboardShortcut{"S", "toggle shuffle"},
KeyboardShortcut{"+", "speed up"},
KeyboardShortcut{"_", "speed down"},
KeyboardShortcut{"q", "quit"},
Expand Down
10 changes: 10 additions & 0 deletions ui/icons.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package ui

const (
trackIconEmptyText = " "
trackIconPlayingText = "🔈"
trackIconPausedText = "🔇"

shuffleIconOff = " "
shuffleIconOn = "🔀"
)
Loading

0 comments on commit 2c958b3

Please sign in to comment.