Skip to content

Commit

Permalink
Add PitchBendSemitones setting (v0.5.0)
Browse files Browse the repository at this point in the history
  • Loading branch information
jangler committed Aug 30, 2023
1 parent 6c33eab commit f7577aa
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 35 deletions.
4 changes: 4 additions & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ port is the default.
**OffDivisionAlpha** - The alpha value to use for drawing events that don't
fall on a current division of the beat, range 0 to 255.

**PitchBendSemitones** - The maximum depth of pitch bends, in semitones. Change
this to match your playback synth if it doesn't support the default range of
two octaves.

**ShiftScrollMult** - Multiplier for scroll wheel distance when a Shift key is held.

**UndoBufferSize** - The approximate limit on the size of the undo buffer, in bytes.
Expand Down
1 change: 1 addition & 0 deletions faunatone/config/settings.csv
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ MessageDuration, 3
MidiInPortNumber, -1
MidiOutPortNumber, 0
OffDivisionAlpha, 64
PitchBendSemitones, 24
ShiftScrollMult, 4
UndoBufferSize, 10000000
WindowHeight, 720
Expand Down
23 changes: 12 additions & 11 deletions faunatone/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@ import (
)

const (
appName = "Faunatone"
appVersion = "v0.4.2"
fileExt = ".faun"
defaultFps = 60
bendSemitones = 24
configPath = "config"
assetsPath = "assets"
savesPath = "saves"
exportsPath = "exports"
errorLogFile = "error.txt"
appName = "Faunatone"
appVersion = "v0.5.0"
fileExt = ".faun"
defaultFps = 60
configPath = "config"
assetsPath = "assets"
savesPath = "saves"
exportsPath = "exports"
errorLogFile = "error.txt"
)

//go:embed config/*
var embedFS embed.FS

var (
bendSemitones = 24
colorBeatArray = make([]uint8, 4)
colorBg1Array = make([]uint8, 4)
colorBg2Array = make([]uint8, 4)
Expand All @@ -64,6 +64,7 @@ func must(err error) {

func main() {
settings := loadSettings(func(s string) { println(s) })
bendSemitones = settings.PitchBendSemitones
setColorArray(colorBeatArray, settings.ColorBeat)
setColorArray(colorBg1Array, settings.ColorBg1)
setColorArray(colorBg2Array, settings.ColorBg2)
Expand Down Expand Up @@ -560,7 +561,7 @@ func dialogInsertNote(d *dialog, pe *patternEditor, p *player) {
// assuming a 2-semitone pitch bend range
func pitchToMidi(p float64) (uint8, int16) {
note := uint8(math.Round(math.Max(0, math.Min(127, p))))
bend := int16((p - float64(note)) * 8192.0 / bendSemitones)
bend := int16((p - float64(note)) * 8192.0 / float64(bendSemitones))
return note, bend
}

Expand Down
6 changes: 3 additions & 3 deletions faunatone/patedit.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ const (
defaultController = 1
defaultRefPitch = 60

// widest range achievable with pitch wheel
minPitch = -bendSemitones
maxPitch = 127 + bendSemitones
// widest range achievable without pitch wheel
minPitch = 0
maxPitch = 127
)

func init() {
Expand Down
6 changes: 3 additions & 3 deletions faunatone/playback.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func newPlayer(s *song, wrs []writer.ChannelWriter, realtime bool) *player {

// start signal-handling loop
func (p *player) run() {
p.broadcastPitchBendRPN(bendSemitones, 0)
p.broadcastPitchBendRPN(uint8(bendSemitones), 0)
for sig := range p.signal {
switch sig.typ {
case signalStart:
Expand Down Expand Up @@ -167,7 +167,7 @@ func (p *player) run() {
case signalEvent:
p.playEvent(sig.event)
case signalSendPitchRPN:
p.broadcastPitchBendRPN(bendSemitones, 0)
p.broadcastPitchBendRPN(uint8(bendSemitones), 0)
case signalSendSystemOn:
for _, out := range p.outputs {
writer.SysEx(out.writer, systemOnBytes[p.song.MidiMode])
Expand Down Expand Up @@ -363,7 +363,7 @@ func (p *player) playEvent(te *trackEvent) {
case pitchBendEvent:
if note := t.activeNote; note != byteNil {
p.lastEvtTick = te.Tick
bend := int16((te.FloatData - float64(note)) * 8192.0 / bendSemitones)
bend := int16((te.FloatData - float64(note)) * 8192.0 / float64(bendSemitones))
p.virtChannels[t.Channel].bend = bend
out.writer.SetChannel(t.midiChannel)
writer.Pitchbend(out.writer, bend)
Expand Down
37 changes: 19 additions & 18 deletions faunatone/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,25 @@ var (
)

type settings struct {
ColorBeat uint32
ColorBg1 uint32
ColorBg2 uint32
ColorFg uint32
ColorPlayPos uint32
ColorSelect uint32
DefaultKeymap string
PercussionKeymap string
Font string
FontSize int
MessageDuration int
MidiInPortNumber int
MidiOutPortNumber string
OffDivisionAlpha int
ShiftScrollMult int
UndoBufferSize int
WindowHeight int
WindowWidth int
ColorBeat uint32
ColorBg1 uint32
ColorBg2 uint32
ColorFg uint32
ColorPlayPos uint32
ColorSelect uint32
DefaultKeymap string
PercussionKeymap string
Font string
FontSize int
MessageDuration int
MidiInPortNumber int
MidiOutPortNumber string
OffDivisionAlpha int
PitchBendSemitones int
ShiftScrollMult int
UndoBufferSize int
WindowHeight int
WindowWidth int
}

// load settings from config file
Expand Down

0 comments on commit f7577aa

Please sign in to comment.