|
@@ -151,7 +151,7 @@ func (p *Project) AssignSample(slot int, src string) error {
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return err
|
|
return err
|
|
|
}
|
|
}
|
|
|
- var e edit
|
|
|
|
|
|
|
+ var e setter
|
|
|
e.set(pad, "tempo", xpj.NewFloat(padTempo))
|
|
e.set(pad, "tempo", xpj.NewFloat(padTempo))
|
|
|
e.set(l, "sampleName", xpj.NewString(stem(newFile)))
|
|
e.set(l, "sampleName", xpj.NewString(stem(newFile)))
|
|
|
e.set(l, "sampleFile", xpj.NewString(newFile))
|
|
e.set(l, "sampleFile", xpj.NewString(newFile))
|
|
@@ -161,7 +161,7 @@ func (p *Project) AssignSample(slot int, src string) error {
|
|
|
return e.err
|
|
return e.err
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // Apply. None of these steps can fail: wrap checked that the pool
|
|
|
|
|
|
|
+ // Apply. None of these steps can fail: fromFile checked that the pool
|
|
|
// and the pads are lists.
|
|
// and the pads are lists.
|
|
|
p.clear(slot, file)
|
|
p.clear(slot, file)
|
|
|
p.pads().Items[slot] = pad
|
|
p.pads().Items[slot] = pad
|
|
@@ -239,19 +239,21 @@ func poolFileName(name string) string {
|
|
|
func stem(file string) string { return strings.TrimSuffix(file, filepath.Ext(file)) }
|
|
func stem(file string) string { return strings.TrimSuffix(file, filepath.Ext(file)) }
|
|
|
|
|
|
|
|
// uniqueFile returns base, or base with a 001, 002 ... suffix before the
|
|
// uniqueFile returns base, or base with a 001, 002 ... suffix before the
|
|
|
-// extension, so that no two pool files share a name. Names are compared
|
|
|
|
|
-// without case, as on Windows, macOS and FAT.
|
|
|
|
|
|
|
+// extension, so that no two pool files share a file name or a sample name
|
|
|
|
|
+// (the file name without its extension). Names are compared without case,
|
|
|
|
|
+// as on Windows, macOS and FAT.
|
|
|
func (p *Project) uniqueFile(base string, freed map[string]bool) string {
|
|
func (p *Project) uniqueFile(base string, freed map[string]bool) string {
|
|
|
- taken := map[string]bool{}
|
|
|
|
|
|
|
+ takenFiles := map[string]bool{}
|
|
|
|
|
+ takenNames := map[string]bool{}
|
|
|
for _, e := range p.pool().Items {
|
|
for _, e := range p.pool().Items {
|
|
|
if freed[text(e.Lookup("path"))] {
|
|
if freed[text(e.Lookup("path"))] {
|
|
|
continue // about to be dropped
|
|
continue // about to be dropped
|
|
|
}
|
|
}
|
|
|
- taken[strings.ToLower(text(e.Lookup("path")))] = true
|
|
|
|
|
- taken[strings.ToLower(text(e.Lookup("name")))+"\x00"] = true
|
|
|
|
|
|
|
+ takenFiles[strings.ToLower(text(e.Lookup("path")))] = true
|
|
|
|
|
+ takenNames[strings.ToLower(text(e.Lookup("name")))] = true
|
|
|
}
|
|
}
|
|
|
free := func(f string) bool {
|
|
free := func(f string) bool {
|
|
|
- return !taken[strings.ToLower(f)] && !taken[strings.ToLower(stem(f))+"\x00"]
|
|
|
|
|
|
|
+ return !takenFiles[strings.ToLower(f)] && !takenNames[strings.ToLower(stem(f))]
|
|
|
}
|
|
}
|
|
|
if free(base) {
|
|
if free(base) {
|
|
|
return base
|
|
return base
|
|
@@ -285,7 +287,7 @@ func poolEntry(file string) *xpj.Node {
|
|
|
return e
|
|
return e
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// addPoolEntry adds file to both pools. Both are lists (checked by wrap),
|
|
|
|
|
|
|
+// addPoolEntry adds file to both pools. Both are lists (checked by fromFile),
|
|
|
// so this cannot fail.
|
|
// so this cannot fail.
|
|
|
func (p *Project) addPoolEntry(file string) {
|
|
func (p *Project) addPoolEntry(file string) {
|
|
|
_ = p.pool().Append(poolEntry(file))
|
|
_ = p.pool().Append(poolEntry(file))
|
|
@@ -393,7 +395,7 @@ func (p *Project) SetTune(slot, coarse, fine int) error {
|
|
|
return fmt.Errorf("project: pad %s layer 1 is %s, not an object", SlotName(slot), l.Kind)
|
|
return fmt.Errorf("project: pad %s layer 1 is %s, not an object", SlotName(slot), l.Kind)
|
|
|
}
|
|
}
|
|
|
// Setting keys on an object cannot fail, so all three are written.
|
|
// Setting keys on an object cannot fail, so all three are written.
|
|
|
- var e edit
|
|
|
|
|
|
|
+ var e setter
|
|
|
e.set(l, "coarseTune", xpj.NewInt(int64(coarse)))
|
|
e.set(l, "coarseTune", xpj.NewInt(int64(coarse)))
|
|
|
e.set(l, "fineTune", xpj.NewInt(int64(fine)))
|
|
e.set(l, "fineTune", xpj.NewInt(int64(fine)))
|
|
|
e.set(l, "pitch", xpj.NewFloat32(float64(coarse)+float64(fine)/100))
|
|
e.set(l, "pitch", xpj.NewFloat32(float64(coarse)+float64(fine)/100))
|