Skip to content

Commit

Permalink
Added handling of fraction tempos
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianrudnik committed Oct 29, 2023
1 parent b6c5990 commit d977065
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
4 changes: 2 additions & 2 deletions service/internal/indexer/mapping_live_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ type LiveSetDocument struct {
ScaleName string `json:"scaleName,omitempty"`
ScaleRootNote string `json:"scaleRootNote,omitempty"`

InKey bool `json:"inKey,omitempty"`
Tempo float64 `json:"tempo,omitempty"`
InKey bool `json:"inKey,omitempty"`
Tempo int64 `json:"tempo,omitempty"`

ScaleInformation string ``
}
Expand Down
13 changes: 11 additions & 2 deletions service/internal/parser/ablv5parser/parse_live_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/adrianrudnik/ablegram/internal/util"
"github.com/djherbis/times"
"github.com/duaneking/gozodiacs"
"math"
"path/filepath"
"strings"
)
Expand Down Expand Up @@ -64,7 +65,15 @@ func ParseLiveSet(m *stats.Metrics, path string, data *ablv5schema.Ableton) *pip
}

if data.LiveSet.MasterTrack.DeviceChain.Mixer.Tempo.Manual.Value > 0 {
tags.AddSystemTag(fmt.Sprintf("live-set:tempo:%d", data.LiveSet.MasterTrack.DeviceChain.Mixer.Tempo.Manual.Value))
// If we have a rounded tempo, we just need to add one tag
if math.Trunc(data.LiveSet.MasterTrack.DeviceChain.Mixer.Tempo.Manual.Value) == data.LiveSet.MasterTrack.DeviceChain.Mixer.Tempo.Manual.Value {
tags.AddSystemTag(fmt.Sprintf("live-set:tempo:%d", int(math.Round(data.LiveSet.MasterTrack.DeviceChain.Mixer.Tempo.Manual.Value))))
} else {
// Otherwise it's a weird file where the tempo is a fraction, like in some Ableton delivered ALS files.
// We just add both rounded values to the tags
tags.AddSystemTag(fmt.Sprintf("live-set:tempo:%d", int(math.Floor(data.LiveSet.MasterTrack.DeviceChain.Mixer.Tempo.Manual.Value))))
tags.AddSystemTag(fmt.Sprintf("live-set:tempo:%d", int(math.Ceil(data.LiveSet.MasterTrack.DeviceChain.Mixer.Tempo.Manual.Value))))
}
}

// Extract some details about the file itself
Expand Down Expand Up @@ -124,7 +133,7 @@ func ParseLiveSet(m *stats.Metrics, path string, data *ablv5schema.Ableton) *pip
liveSet.ScaleName = data.LiveSet.ScaleInformation.Name.Value
liveSet.Scale = fmt.Sprintf("%s %s", liveSet.ScaleRootNote, liveSet.ScaleName)
liveSet.InKey = data.LiveSet.InKey.Value
liveSet.Tempo = data.LiveSet.MasterTrack.DeviceChain.Mixer.Tempo.Manual.Value
liveSet.Tempo = int64(math.Round(data.LiveSet.MasterTrack.DeviceChain.Mixer.Tempo.Manual.Value))

m.AddLiveSet()

Expand Down

0 comments on commit d977065

Please sign in to comment.