Rewrite the code comments for consistent tone and accuracy
Comments only: the tokens of every Go file are unchanged. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
+34
-15
@@ -16,8 +16,12 @@ type ValueType int
|
||||
const (
|
||||
// TypeUnspecified is for an opcode whose value the format doesn't describe.
|
||||
TypeUnspecified ValueType = iota
|
||||
// TypeString is for a value that is text, which may have a fixed set of
|
||||
// options.
|
||||
TypeString
|
||||
// TypeInteger is for a whole number, which may also be a note name.
|
||||
TypeInteger
|
||||
// TypeFloat is for a number that may have a fraction.
|
||||
TypeFloat
|
||||
)
|
||||
|
||||
@@ -40,8 +44,10 @@ type HeaderInfo struct {
|
||||
Name string
|
||||
// Version is the first SFZ version or player that has it: "SFZ v1", "SFZ v2",
|
||||
// "ARIA", and so on.
|
||||
Version string
|
||||
Deprecated bool
|
||||
Version string
|
||||
// Deprecated is whether the format has dropped the header.
|
||||
Deprecated bool
|
||||
// Description is what the format says about the header.
|
||||
Description string
|
||||
}
|
||||
|
||||
@@ -55,12 +61,14 @@ type OpcodeInfo struct {
|
||||
Aliases []string
|
||||
// Version is the first SFZ version or player that has it: "SFZ v1", "SFZ
|
||||
// v2", "ARIA", "sfizz", "Calfbox" or "LinuxSampler".
|
||||
Version string
|
||||
Version string
|
||||
// Deprecated is whether the format has dropped the opcode.
|
||||
Deprecated bool
|
||||
// Category is where the format lists it, such as "Performance Parameters /
|
||||
// Amplifier".
|
||||
Category string
|
||||
Type ValueType
|
||||
// Type is the kind of value the opcode takes.
|
||||
Type ValueType
|
||||
// Min and Max bound a numeric value, or are nil where the format gives no
|
||||
// bound it can state as a number.
|
||||
Min, Max *float64
|
||||
@@ -72,20 +80,27 @@ type OpcodeInfo struct {
|
||||
// Options are the values a string opcode may take, if it has a fixed set.
|
||||
Options []string
|
||||
// Note is whether an integer opcode also takes a note name, such as c4.
|
||||
Note bool
|
||||
Note bool
|
||||
// Description is what the format says about the opcode.
|
||||
Description string
|
||||
}
|
||||
|
||||
// matcher finds the registry entry for an opcode name.
|
||||
// matcher finds the registry entry for the names of an opcode family.
|
||||
type matcher struct {
|
||||
// re matches the names that the family's name stands for.
|
||||
re *regexp.Regexp
|
||||
info *OpcodeInfo
|
||||
}
|
||||
|
||||
var (
|
||||
// registryOnce makes the lookup tables below on the first lookup.
|
||||
registryOnce sync.Once
|
||||
byName map[string]*OpcodeInfo
|
||||
patterns []matcher
|
||||
// byName holds the opcodes that aren't families, by each of their names.
|
||||
byName map[string]*OpcodeInfo
|
||||
// patterns holds the opcode families, with those whose names have a * last
|
||||
// so that a more exact family is found first.
|
||||
patterns []matcher
|
||||
// headerByName holds the headers, by lowercase name.
|
||||
headerByName map[string]*HeaderInfo
|
||||
)
|
||||
|
||||
@@ -116,6 +131,7 @@ func pattern(name string) *regexp.Regexp {
|
||||
return regexp.MustCompile(b.String())
|
||||
}
|
||||
|
||||
// loadRegistry makes the lookup tables from the generated data, once.
|
||||
func loadRegistry() {
|
||||
registryOnce.Do(func() {
|
||||
byName = map[string]*OpcodeInfo{}
|
||||
@@ -142,9 +158,10 @@ func loadRegistry() {
|
||||
})
|
||||
}
|
||||
|
||||
// Lookup returns what the format says about an opcode, found by its name or
|
||||
// one of its aliases. The info is the same for each name of the opcode, and
|
||||
// its Name is the opcode's own.
|
||||
// Lookup returns what the format says about an opcode, and whether it knows
|
||||
// the opcode. The opcode is found by its name or one of its aliases, and by the
|
||||
// name of a family it is in, such as locc64 in loccN. The info is the same for
|
||||
// each name of the opcode, and its Name is the opcode's own.
|
||||
func Lookup(name string) (OpcodeInfo, bool) {
|
||||
loadRegistry()
|
||||
if info, ok := byName[name]; ok {
|
||||
@@ -158,7 +175,8 @@ func Lookup(name string) (OpcodeInfo, bool) {
|
||||
return OpcodeInfo{}, false
|
||||
}
|
||||
|
||||
// KnownOpcodes returns every opcode of the format, in the order of its listing.
|
||||
// KnownOpcodes returns every opcode of the format, in the order the format
|
||||
// lists them.
|
||||
func KnownOpcodes() iter.Seq[OpcodeInfo] {
|
||||
return func(yield func(OpcodeInfo) bool) {
|
||||
for _, info := range opcodeData {
|
||||
@@ -169,7 +187,8 @@ func KnownOpcodes() iter.Seq[OpcodeInfo] {
|
||||
}
|
||||
}
|
||||
|
||||
// KnownHeaders returns every header of the format.
|
||||
// KnownHeaders returns every header of the format, in the order the format
|
||||
// lists them.
|
||||
func KnownHeaders() iter.Seq[HeaderInfo] {
|
||||
return func(yield func(HeaderInfo) bool) {
|
||||
for _, h := range headerData {
|
||||
@@ -180,8 +199,8 @@ func KnownHeaders() iter.Seq[HeaderInfo] {
|
||||
}
|
||||
}
|
||||
|
||||
// LookupHeader returns what the format says about a header, given its name
|
||||
// without brackets, in any case.
|
||||
// LookupHeader returns what the format says about a header, and whether it
|
||||
// knows the header. The name is given without brackets, in any case.
|
||||
func LookupHeader(name string) (HeaderInfo, bool) {
|
||||
loadRegistry()
|
||||
h, ok := headerByName[strings.ToLower(name)]
|
||||
|
||||
Reference in New Issue
Block a user