Skip to content

Commit

Permalink
keep the last used channel for new nodes (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
xaviergodart committed Nov 17, 2024
1 parent 333129d commit 53f1640
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion core/music/note.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ const (
maxProbability uint8 = 100
)

var (
lastUsedChannel uint8 = defaultChannel
)

// Note represents a midi note.
type Note struct {
midi midi.Midi
Expand All @@ -45,7 +49,7 @@ func NewNote(midi midi.Midi) *Note {
midi: midi,
rand: rand.New(source),
Key: NewKeyValue(defaultKey),
Channel: common.NewControlValue[uint8](defaultChannel, 0, maxChannel),
Channel: common.NewControlValue[uint8](lastUsedChannel, 0, maxChannel),
Velocity: common.NewControlValue[uint8](defaultVelocity, 0, maxVelocity),
Length: common.NewControlValue[uint8](defaultLength, minLength, maxLength),
Probability: maxProbability,
Expand Down Expand Up @@ -164,6 +168,7 @@ func (n *Note) SetLength(length uint8) {
// SetChannel updates the MIDI channel of the note.
func (n *Note) SetChannel(channel uint8) {
n.Channel.Set(channel)
lastUsedChannel = channel
}

// ClockDivision returns the pulses per step and steps per quarter note,
Expand Down

0 comments on commit 53f1640

Please sign in to comment.