Skip to content

Commit

Permalink
fix linter warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
xaviergodart committed Aug 9, 2024
1 parent 2a01e84 commit d2e0b22
Show file tree
Hide file tree
Showing 15 changed files with 80 additions and 57 deletions.
4 changes: 4 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ linters:
- unparam
- revive

linters-settings:
gofumpt:
module-path: sektron

# it weirdly fails when running in github actions on interface composition.
issues:
exclude-rules:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ $(BIN):
mkdir -p $(BIN)

$(GOLANG_LINT): $(BIN)
GOBIN=$$(pwd)/$(BIN) go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.51.2
GOBIN=$$(pwd)/$(BIN) go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.59.1

build: $(BIN)
$(GOLANG_BUILD_OPTS) $(GOLANG_BIN) build -o $(BIN)/$(BIN_NAME)
Expand Down
2 changes: 1 addition & 1 deletion filesystem/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type Configuration struct {
}

// NewConfiguration returns a new default configuration.
func NewConfiguration(filename string, keyboard string) Configuration {
func NewConfiguration(filename, keyboard string) Configuration {
config := Configuration{
KeyMap: NewDefaultQwertyKeyMap(),
filename: filename,
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"log"
"os"

"sektron/filesystem"
"sektron/midi"
"sektron/sequencer"
Expand Down
16 changes: 8 additions & 8 deletions midi/midi.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ const (
// Midi provides a way to interct with midi devices.
type Midi interface {
Devices() gomidi.OutPorts
NoteOn(device int, channel uint8, note uint8, velocity uint8)
NoteOff(device int, channel uint8, note uint8)
NoteOn(device int, channel, note, velocity uint8)
NoteOff(device int, channel, note uint8)
Silence(device int, channel uint8)
ControlChange(device int, channel, controller, value uint8)
ProgramChange(device int, channel uint8, value uint8)
ProgramChange(device int, channel, value uint8)
Pitchbend(device int, channel uint8, value int16)
AfterTouch(device int, channel uint8, value uint8)
AfterTouch(device int, channel, value uint8)
SendClock(devices []int)
Close()
}
Expand Down Expand Up @@ -112,12 +112,12 @@ func (m *midi) Devices() gomidi.OutPorts {
}

// NoteOn sends a Note On midi meessage to the given device.
func (m *midi) NoteOn(device int, channel uint8, note uint8, velocity uint8) {
func (m *midi) NoteOn(device int, channel, note, velocity uint8) {
m.outputs[device] <- gomidi.NoteOn(channel, note, velocity)
}

// NoteOff sends a Note Off midi meessage to the given device.
func (m *midi) NoteOff(device int, channel uint8, note uint8) {
func (m *midi) NoteOff(device int, channel, note uint8) {
m.outputs[device] <- gomidi.NoteOff(channel, note)
}

Expand All @@ -134,7 +134,7 @@ func (m *midi) ControlChange(device int, channel, controller, value uint8) {
}

// ProgramChange sends a Program Change messages to the given device.
func (m *midi) ProgramChange(device int, channel uint8, value uint8) {
func (m *midi) ProgramChange(device int, channel, value uint8) {
m.outputs[device] <- gomidi.ProgramChange(channel, value)
}

Expand All @@ -144,7 +144,7 @@ func (m *midi) Pitchbend(device int, channel uint8, value int16) {
}

// AfterTouch sends a After Touch messages to the given device.
func (m *midi) AfterTouch(device int, channel uint8, value uint8) {
func (m *midi) AfterTouch(device int, channel, value uint8) {
m.outputs[device] <- gomidi.AfterTouch(channel, value)
}

Expand Down
3 changes: 2 additions & 1 deletion sequencer/parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package sequencer

import (
"fmt"
"sektron/midi"
"strconv"

"sektron/midi"
)

const (
Expand Down
12 changes: 8 additions & 4 deletions sequencer/sequencer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ package sequencer

import (
"math/rand"
"time"

"sektron/filesystem"
"sektron/midi"
"time"
)

const (
Expand Down Expand Up @@ -49,7 +50,7 @@ type Sequencer interface {
ToggleTrack(track int)
AddStep(track int)
RemoveStep(track int)
ToggleStep(track int, step int)
ToggleStep(track, step int)
Tempo() float64
SetTempo(tempo float64)
Reset()
Expand All @@ -60,6 +61,8 @@ type sequencer struct {
bank filesystem.Bank
chain []int

randomizer *rand.Rand

tracks []*track
clock *clock

Expand All @@ -76,11 +79,12 @@ type sequencer struct {
func New(midi midi.Midi, bank filesystem.Bank) Sequencer {
// The randomizer will be used for step trigger probability.
// Check step.go.
rand.Seed(time.Now().UnixNano())
r := rand.New(rand.NewSource(time.Now().UnixNano()))

seq := &sequencer{
midi: midi,
bank: bank,
randomizer: r,
clockSend: []int{defaultDevice},
isPlaying: false,
isFirstTick: false,
Expand Down Expand Up @@ -233,7 +237,7 @@ func (s *sequencer) ToggleTrack(track int) {
}

// ToggleStep activates or desactivates a specific step of a given track.
func (s *sequencer) ToggleStep(track int, step int) {
func (s *sequencer) ToggleStep(track, step int) {
if len(s.tracks[track].steps) <= step {
return
}
Expand Down
3 changes: 1 addition & 2 deletions sequencer/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package sequencer

import (
"fmt"
"math/rand"
"time"

"sektron/midi"
Expand Down Expand Up @@ -261,7 +260,7 @@ func (s step) sendControls() {
}

func (s step) skip() bool {
return s.Probability() < 100 && rand.Intn(100) > s.Probability()
return s.Probability() < 100 && s.track.seq.randomizer.Intn(100) > s.Probability()
}

func (s step) startingPulse() int {
Expand Down
3 changes: 2 additions & 1 deletion sequencer/track.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package sequencer

import (
"fmt"
"sektron/midi"
"time"

"sektron/midi"
)

// Track contains a track state.
Expand Down
3 changes: 2 additions & 1 deletion ui/keymap.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package ui

import (
"sektron/filesystem"
"strings"

"sektron/filesystem"

"github.com/charmbracelet/bubbles/key"
)

Expand Down
41 changes: 26 additions & 15 deletions ui/parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var (
Bold(true).
BorderStyle(lipgloss.HiddenBorder())

paramStepTitleStyle = paramTrackTitleStyle.Copy().
paramStepTitleStyle = paramTrackTitleStyle.
BorderStyle(lipgloss.DoubleBorder()).
BorderForeground(primaryColor)

Expand Down Expand Up @@ -66,7 +66,7 @@ func (p parameters) getParamIndex(nb int) int {
type parameter[t sequencer.Parametrable] struct {
value func(item t) int
string func(item t) string
set func(item t, value int, add int)
set func(item t, value, add int)
active func(item t) bool
}

Expand All @@ -83,7 +83,7 @@ func newMidiParameter[t sequencer.Parametrable](nb int) parameter[t] {
item.Control(nb).Name(),
)
},
set: func(item t, value int, add int) {
set: func(item t, value, add int) {
item.SetControl(nb, int16(value+add))
},
active: func(item t) bool {
Expand Down Expand Up @@ -112,11 +112,12 @@ func (m *mainModel) initParameters() {
"note",
)
},
set: func(item sequencer.Track, value int, add int) {
set: func(item sequencer.Track, value, add int) {
item.SetChord([]uint8{
uint8(value + add),
})
},
//nolint:revive
active: func(item sequencer.Track) bool {
return true
},
Expand All @@ -133,9 +134,10 @@ func (m *mainModel) initParameters() {
"length",
)
},
set: func(item sequencer.Track, value int, add int) {
set: func(item sequencer.Track, value, add int) {
setLengthParam(item, value, add)
},
//nolint:revive
active: func(item sequencer.Track) bool {
return true
},
Expand All @@ -152,9 +154,10 @@ func (m *mainModel) initParameters() {
"velocity",
)
},
set: func(item sequencer.Track, value int, add int) {
set: func(item sequencer.Track, value, add int) {
item.SetVelocity(uint8(value + add))
},
//nolint:revive
active: func(item sequencer.Track) bool {
return true
},
Expand All @@ -171,9 +174,10 @@ func (m *mainModel) initParameters() {
"probability",
)
},
set: func(item sequencer.Track, value int, add int) {
set: func(item sequencer.Track, value, add int) {
item.SetProbability(value + add)
},
//nolint:revive
active: func(item sequencer.Track) bool {
return true
},
Expand All @@ -195,9 +199,10 @@ func (m *mainModel) initParameters() {
"device",
)
},
set: func(item sequencer.Track, value int, add int) {
set: func(item sequencer.Track, value, add int) {
item.SetDevice(value + add)
},
//nolint:revive
active: func(item sequencer.Track) bool {
return true
},
Expand All @@ -214,9 +219,10 @@ func (m *mainModel) initParameters() {
"channel",
)
},
set: func(item sequencer.Track, value int, add int) {
set: func(item sequencer.Track, value, add int) {
item.SetChannel(uint8(value + add))
},
//nolint:revive
active: func(item sequencer.Track) bool {
return true
},
Expand All @@ -242,11 +248,12 @@ func (m *mainModel) initParameters() {
"note",
)
},
set: func(item sequencer.Step, value int, add int) {
set: func(item sequencer.Step, value, add int) {
item.SetChord([]uint8{
uint8(value + add),
})
},
//nolint:revive
active: func(item sequencer.Step) bool {
return true
},
Expand All @@ -263,9 +270,10 @@ func (m *mainModel) initParameters() {
"length",
)
},
set: func(item sequencer.Step, value int, add int) {
set: func(item sequencer.Step, value, add int) {
setLengthParam(item, value, add)
},
//nolint:revive
active: func(item sequencer.Step) bool {
return true
},
Expand All @@ -282,9 +290,10 @@ func (m *mainModel) initParameters() {
"velocity",
)
},
set: func(item sequencer.Step, value int, add int) {
set: func(item sequencer.Step, value, add int) {
item.SetVelocity(uint8(value + add))
},
//nolint:revive
active: func(item sequencer.Step) bool {
return true
},
Expand All @@ -301,9 +310,10 @@ func (m *mainModel) initParameters() {
"probability",
)
},
set: func(item sequencer.Step, value int, add int) {
set: func(item sequencer.Step, value, add int) {
item.SetProbability(value + add)
},
//nolint:revive
active: func(item sequencer.Step) bool {
return true
},
Expand All @@ -320,9 +330,10 @@ func (m *mainModel) initParameters() {
"offset",
)
},
set: func(item sequencer.Step, value int, add int) {
set: func(item sequencer.Step, value, add int) {
item.SetOffset(value + add)
},
//nolint:revive
active: func(item sequencer.Step) bool {
return true
},
Expand Down Expand Up @@ -459,7 +470,7 @@ func (m *mainModel) updateParams() {
Render(m.paramCarousel.View())
}

func setLengthParam(item sequencer.Parametrable, value int, add int) {
func setLengthParam(item sequencer.Parametrable, value, add int) {
switch {
case value < pulsesPerStep*4:
item.SetLength(value + add)
Expand Down
17 changes: 8 additions & 9 deletions ui/pattern.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,15 @@ func (m mainModel) renderPattern(pattern int) string {
textStyle.Background(activeColor).Render(content),
lipgloss.WithWhitespaceBackground(activeColor),
))
} else {
return stepStyle.Render(lipgloss.Place(
width,
height,
lipgloss.Left,
lipgloss.Top,
textStyle.Background(inactiveColor).Render(number),
lipgloss.WithWhitespaceBackground(inactiveColor),
))
}
return stepStyle.Render(lipgloss.Place(
width,
height,
lipgloss.Left,
lipgloss.Top,
textStyle.Background(inactiveColor).Render(number),
lipgloss.WithWhitespaceBackground(inactiveColor),
))
}

func (m mainModel) renderChain() string {
Expand Down
Loading

0 comments on commit d2e0b22

Please sign in to comment.