Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions format.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package playback
import (
"io"

"github.com/gotracker/playback/settings"
"github.com/gotracker/playback/player/feature"
)

// Format is an interface to a music file format loader
type Format[TChannelData any] interface {
Load(filename string, s *settings.Settings) (Playback, error)
LoadFromReader(r io.Reader, s *settings.Settings) (Playback, error)
Load(filename string, features []feature.Feature) (Playback, error)
LoadFromReader(r io.Reader, features []feature.Feature) (Playback, error)
}
8 changes: 4 additions & 4 deletions format/common/loadformat.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ package common
import (
"io"

"github.com/gotracker/playback/settings"
"github.com/gotracker/playback/player/feature"
)

type ReaderFunc[TSong any] func(r io.Reader, s *settings.Settings) (*TSong, error)
type ReaderFunc[TSong any] func(r io.Reader, features []feature.Feature) (*TSong, error)

type ManagerFactory[TSong, TManager any] func(*TSong) (*TManager, error)

func Load[TSong, TManager any](r io.Reader, reader ReaderFunc[TSong], factory ManagerFactory[TSong, TManager], s *settings.Settings) (*TManager, error) {
song, err := reader(r, s)
func Load[TSong, TManager any](r io.Reader, reader ReaderFunc[TSong], factory ManagerFactory[TSong, TManager], features []feature.Feature) (*TManager, error) {
song, err := reader(r, features)
if err != nil {
return nil, err
}
Expand Down
26 changes: 6 additions & 20 deletions format/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/gotracker/playback/format/mod"
"github.com/gotracker/playback/format/s3m"
"github.com/gotracker/playback/format/xm"
"github.com/gotracker/playback/settings"
"github.com/gotracker/playback/player/feature"
"github.com/gotracker/playback/song"
)

Expand All @@ -19,16 +19,9 @@ var (
)

// Load loads the a file into a playback manager
func Load(filename string, options ...settings.OptionFunc) (playback.Playback, playback.Format[song.ChannelData], error) {
s := &settings.Settings{}
for _, opt := range options {
if err := opt(s); err != nil {
return nil, nil, err
}
}

func Load(filename string, features ...feature.Feature) (playback.Playback, playback.Format[song.ChannelData], error) {
for _, f := range supportedFormats {
if pb, err := f.Load(filename, s); err == nil {
if pb, err := f.Load(filename, features); err == nil {
return pb, f, nil
} else if os.IsNotExist(err) {
return nil, nil, err
Expand All @@ -38,29 +31,22 @@ func Load(filename string, options ...settings.OptionFunc) (playback.Playback, p
}

// LoadFromReader loads a song file on a reader into a playback manager
func LoadFromReader(format string, r io.Reader, options ...settings.OptionFunc) (playback.Playback, playback.Format[song.ChannelData], error) {
s := &settings.Settings{}
for _, opt := range options {
if err := opt(s); err != nil {
return nil, nil, err
}
}

func LoadFromReader(format string, r io.Reader, features ...feature.Feature) (playback.Playback, playback.Format[song.ChannelData], error) {
if format != "" {
f, ok := supportedFormats[format]
if !ok {
return nil, nil, errors.New("unsupported format")
}

if pb, err := f.LoadFromReader(r, s); err == nil {
if pb, err := f.LoadFromReader(r, features); err == nil {
return pb, f, nil
} else {
return nil, nil, err
}
}

for _, f := range supportedFormats {
if pb, err := f.LoadFromReader(r, s); err == nil {
if pb, err := f.LoadFromReader(r, features); err == nil {
return pb, f, nil
} else if os.IsNotExist(err) {
return nil, nil, err
Expand Down
24 changes: 13 additions & 11 deletions format/it/channel/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ import (

const MaxTotalChannels = 64

type Command uint8

func (c Command) ToRune() rune {
switch {
case c > 0 && c <= 26:
return '@' + rune(c)
default:
panic("effect out of range")
}
}

// DataEffect is the type of a channel's EffectParameter value
type DataEffect uint8

Expand All @@ -24,7 +35,7 @@ type Data struct {
Note itfile.Note
Instrument uint8
VolPan uint8
Effect uint8
Effect Command
EffectParameter DataEffect
}

Expand Down Expand Up @@ -104,15 +115,6 @@ func (Data) getNoteString(n note.Note) string {
}
}

func (Data) getCommandString(cmd uint8) rune {
switch {
case cmd > 0 && cmd <= 26:
return '@' + rune(cmd)
default:
panic("effect out of range")
}
}

func (d Data) String() string {
pieces := []string{
"...", // note
Expand All @@ -130,7 +132,7 @@ func (d Data) String() string {
pieces[2] = fmt.Sprintf("%02X", d.VolPan)
}
if d.HasCommand() && d.Effect != 0 {
pieces[3] = fmt.Sprintf("%c%02X", d.getCommandString(d.Effect), d.EffectParameter)
pieces[3] = fmt.Sprintf("%c%02X", d.Effect.ToRune(), d.EffectParameter)
}
return strings.Join(pieces, " ")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/gotracker/playback"
"github.com/gotracker/playback/format/it/channel"
effectIntf "github.com/gotracker/playback/format/it/playback/effect/intf"
effectIntf "github.com/gotracker/playback/format/it/effect/intf"
)

// FinePatternDelay defines an fine pattern delay effect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/gotracker/playback"
"github.com/gotracker/playback/format/it/channel"
effectIntf "github.com/gotracker/playback/format/it/playback/effect/intf"
effectIntf "github.com/gotracker/playback/format/it/effect/intf"
)

// GlobalVolumeSlide defines a global volume slide effect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/gotracker/playback"
"github.com/gotracker/playback/format/it/channel"
effectIntf "github.com/gotracker/playback/format/it/playback/effect/intf"
effectIntf "github.com/gotracker/playback/format/it/effect/intf"
)

// PatternDelay defines a pattern delay effect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type PortaVolumeSlide struct { // 'L'
}

// NewPortaVolumeSlide creates a new PortaVolumeSlide object
func NewPortaVolumeSlide(mem *channel.Memory, cd uint8, val channel.DataEffect) PortaVolumeSlide {
func NewPortaVolumeSlide(mem *channel.Memory, cd channel.Command, val channel.DataEffect) PortaVolumeSlide {
pvs := PortaVolumeSlide{}
vs := volumeSlideFactory(mem, cd, val)
pvs.Effects = append(pvs.Effects, vs, PortaToNote(0x00))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/gotracker/playback"
"github.com/gotracker/playback/format/it/channel"
effectIntf "github.com/gotracker/playback/format/it/playback/effect/intf"
effectIntf "github.com/gotracker/playback/format/it/effect/intf"
)

// SetSpeed defines a set speed effect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/gotracker/playback"
"github.com/gotracker/playback/format/it/channel"
effectIntf "github.com/gotracker/playback/format/it/playback/effect/intf"
effectIntf "github.com/gotracker/playback/format/it/effect/intf"
)

// SetTempo defines a set tempo effect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type VibratoVolumeSlide struct { // 'K'
}

// NewVibratoVolumeSlide creates a new VibratoVolumeSlide object
func NewVibratoVolumeSlide(mem *channel.Memory, cd uint8, val channel.DataEffect) VibratoVolumeSlide {
func NewVibratoVolumeSlide(mem *channel.Memory, cd channel.Command, val channel.DataEffect) VibratoVolumeSlide {
vvs := VibratoVolumeSlide{}
vs := volumeSlideFactory(mem, cd, val)
vvs.Effects = append(vvs.Effects, vs, Vibrato(0x00))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func specialNoteEffects(data *channel.Data) EffectIT {
return UnhandledCommand{Command: data.Effect, Info: data.EffectParameter}
}

func volumeSlideFactory(mem *channel.Memory, cd uint8, ce channel.DataEffect) EffectIT {
func volumeSlideFactory(mem *channel.Memory, cd channel.Command, ce channel.DataEffect) EffectIT {
x, y := mem.VolumeSlide(channel.DataEffect(ce))
switch {
case x == 0:
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import (

"github.com/gotracker/playback"
"github.com/gotracker/playback/format/it/channel"
effectIntf "github.com/gotracker/playback/format/it/playback/effect/intf"
effectIntf "github.com/gotracker/playback/format/it/effect/intf"
)

// UnhandledCommand is an unhandled command
type UnhandledCommand struct {
Command uint8
Command channel.Command
Info channel.DataEffect
}

Expand All @@ -23,14 +23,7 @@ func (e UnhandledCommand) PreStart(cs playback.Channel[channel.Memory, channel.D
}

func (e UnhandledCommand) String() string {
switch {
case e.Command <= 0x09:
return fmt.Sprintf("%c%0.2x", e.Command+'0', e.Info)
case e.Command >= 0x0A && e.Command <= 0x23:
return fmt.Sprintf("%c%0.2x", e.Command+'A', e.Info)
default:
return fmt.Sprintf("?%0.2x%0.2x?", e.Command, e.Info)
}
return fmt.Sprintf("%c%0.2x", e.Command.ToRune(), e.Info)
}

// UnhandledVolCommand is an unhandled volume command
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/gotracker/playback"
"github.com/gotracker/playback/format/it/channel"
effectIntf "github.com/gotracker/playback/format/it/playback/effect/intf"
effectIntf "github.com/gotracker/playback/format/it/effect/intf"
itVolume "github.com/gotracker/playback/format/it/volume"
"github.com/gotracker/playback/note"
"github.com/heucuva/comparison"
Expand Down
5 changes: 5 additions & 0 deletions format/it/feature/longchanneloutput.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package feature

type LongChannelOutput struct {
Enabled bool
}
5 changes: 5 additions & 0 deletions format/it/feature/newnoteactions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package feature

type NewNoteActions struct {
Enabled bool
}
10 changes: 5 additions & 5 deletions format/it/it.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/gotracker/playback"
"github.com/gotracker/playback/format/it/load"
"github.com/gotracker/playback/settings"
"github.com/gotracker/playback/player/feature"
"github.com/gotracker/playback/util"
)

Expand All @@ -18,16 +18,16 @@ var (
)

// Load loads an IT file into a playback system
func (f format) Load(filename string, s *settings.Settings) (playback.Playback, error) {
func (f format) Load(filename string, features []feature.Feature) (playback.Playback, error) {
r, err := util.ReadFile(filename)
if err != nil {
return nil, err
}

return f.LoadFromReader(r, s)
return f.LoadFromReader(r, features)
}

// LoadFromReader loads an IT file on a reader into a playback system
func (f format) LoadFromReader(r io.Reader, s *settings.Settings) (playback.Playback, error) {
return load.IT(r, s)
func (f format) LoadFromReader(r io.Reader, features []feature.Feature) (playback.Playback, error) {
return load.IT(r, features)
}
16 changes: 8 additions & 8 deletions format/it/load/instrument.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/gotracker/gomixing/panning"
"github.com/gotracker/gomixing/volume"
"github.com/gotracker/playback/period"
"github.com/gotracker/playback/player/feature"
"github.com/gotracker/playback/voice"
"github.com/gotracker/playback/voice/envelope"
"github.com/gotracker/playback/voice/fadeout"
Expand All @@ -19,12 +20,11 @@ import (
"github.com/gotracker/playback/voice/pcm"

"github.com/gotracker/playback/filter"
itfilter "github.com/gotracker/playback/format/it/filter"
itNote "github.com/gotracker/playback/format/it/note"
itfilter "github.com/gotracker/playback/format/it/playback/filter"
"github.com/gotracker/playback/instrument"
"github.com/gotracker/playback/note"
oscillatorImpl "github.com/gotracker/playback/oscillator"
"github.com/gotracker/playback/settings"
)

type convInst struct {
Expand All @@ -38,7 +38,7 @@ type convertITInstrumentSettings struct {
useHighPassFilter bool
}

func convertITInstrumentOldToInstrument(inst *itfile.IMPIInstrumentOld, sampData []itfile.FullSample, convSettings convertITInstrumentSettings, s *settings.Settings) (map[int]*convInst, error) {
func convertITInstrumentOldToInstrument(inst *itfile.IMPIInstrumentOld, sampData []itfile.FullSample, convSettings convertITInstrumentSettings, features []feature.Feature) (map[int]*convInst, error) {
outInsts := make(map[int]*convInst)

if err := buildNoteSampleKeyboard(outInsts, inst.NoteSampleKeyboard[:]); err != nil {
Expand Down Expand Up @@ -87,7 +87,7 @@ func convertITInstrumentOldToInstrument(inst *itfile.IMPIInstrumentOld, sampData
}

ci.Inst = &ii
if err := addSampleInfoToConvertedInstrument(ci.Inst, &id, &sampData[i], volume.Volume(1), convSettings, s); err != nil {
if err := addSampleInfoToConvertedInstrument(ci.Inst, &id, &sampData[i], volume.Volume(1), convSettings, features); err != nil {
return nil, err
}

Expand Down Expand Up @@ -132,7 +132,7 @@ func convertITInstrumentOldToInstrument(inst *itfile.IMPIInstrumentOld, sampData
return outInsts, nil
}

func convertITInstrumentToInstrument(inst *itfile.IMPIInstrument, sampData []itfile.FullSample, convSettings convertITInstrumentSettings, pluginFilters map[int]filter.Factory, s *settings.Settings) (map[int]*convInst, error) {
func convertITInstrumentToInstrument(inst *itfile.IMPIInstrument, sampData []itfile.FullSample, convSettings convertITInstrumentSettings, pluginFilters map[int]filter.Factory, features []feature.Feature) (map[int]*convInst, error) {
outInsts := make(map[int]*convInst)

if err := buildNoteSampleKeyboard(outInsts, inst.NoteSampleKeyboard[:]); err != nil {
Expand Down Expand Up @@ -188,7 +188,7 @@ func convertITInstrumentToInstrument(inst *itfile.IMPIInstrument, sampData []itf
mixVol := volume.Volume(inst.GlobalVolume.Value())

ci.Inst = &ii
if err := addSampleInfoToConvertedInstrument(ci.Inst, &id, &sampData[i], mixVol, convSettings, s); err != nil {
if err := addSampleInfoToConvertedInstrument(ci.Inst, &id, &sampData[i], mixVol, convSettings, features); err != nil {
return nil, err
}

Expand Down Expand Up @@ -337,7 +337,7 @@ func itAutoVibratoWSToProtrackerWS(vibtype uint8) uint8 {
}
}

func addSampleInfoToConvertedInstrument(ii *instrument.Instrument, id *instrument.PCM, si *itfile.FullSample, instVol volume.Volume, convSettings convertITInstrumentSettings, s *settings.Settings) error {
func addSampleInfoToConvertedInstrument(ii *instrument.Instrument, id *instrument.PCM, si *itfile.FullSample, instVol volume.Volume, convSettings convertITInstrumentSettings, features []feature.Feature) error {
instLen := int(si.Header.Length)
numChannels := 1

Expand Down Expand Up @@ -434,7 +434,7 @@ func addSampleInfoToConvertedInstrument(ii *instrument.Instrument, id *instrumen
data = buf.Bytes()
}

samp, err := instrument.NewSample(data, instLen, numChannels, format, s)
samp, err := instrument.NewSample(data, instLen, numChannels, format, features)
if err != nil {
return err
}
Expand Down
Loading