mirror of
https://github.com/vsariola/sointu.git
synced 2025-07-25 16:34:45 -04:00
feat: UI work to facilitate future improvements in midi-into-track-input
This commit is contained in:
47
tracker/types/optional.go
Normal file
47
tracker/types/optional.go
Normal file
@ -0,0 +1,47 @@
|
||||
package types
|
||||
|
||||
type (
|
||||
// OptionalInteger is the simple struct, not to be confused with tracker.OptionalInt.
|
||||
// It implements the tracker.optionalIntData interface, without needing to know so.
|
||||
OptionalInteger struct {
|
||||
value int
|
||||
exists bool
|
||||
}
|
||||
)
|
||||
|
||||
func NewOptionalInteger(value int, exists bool) OptionalInteger {
|
||||
return OptionalInteger{value, exists}
|
||||
}
|
||||
|
||||
func NewOptionalIntegerOf(value int) OptionalInteger {
|
||||
return OptionalInteger{
|
||||
value: value,
|
||||
exists: true,
|
||||
}
|
||||
}
|
||||
|
||||
func NewEmptyOptionalInteger() OptionalInteger {
|
||||
// could also just use OptionalInteger{}
|
||||
return OptionalInteger{
|
||||
exists: false,
|
||||
}
|
||||
}
|
||||
|
||||
func (i OptionalInteger) Unpack() (int, bool) {
|
||||
return i.value, i.exists
|
||||
}
|
||||
|
||||
func (i OptionalInteger) Value() int {
|
||||
if !i.exists {
|
||||
panic("Access value of empty OptionalInteger")
|
||||
}
|
||||
return i.value
|
||||
}
|
||||
|
||||
func (i OptionalInteger) Empty() bool {
|
||||
return !i.exists
|
||||
}
|
||||
|
||||
func (i OptionalInteger) Equals(value int) bool {
|
||||
return i.exists && i.value == value
|
||||
}
|
Reference in New Issue
Block a user