Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Investigate making Scale and Chord generic over their note type #11

Open
fwcd opened this issue Aug 28, 2022 · 0 comments
Open

Investigate making Scale and Chord generic over their note type #11

fwcd opened this issue Aug 28, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@fwcd
Copy link
Owner

fwcd commented Aug 28, 2022

This would e.g. enable forming scales and chords over both Note and NoteClasses. Perhaps we could do this using a new protocol:

protocol DiatonicIntervalArithmetic {
  static func +(lhs: Self, rhs: DiatonicInterval) -> Self

  static func -(lhs: Self, rhs: DiatonicInterval) -> Self

  static func +=(lhs: inout Self, rhs: DiatonicInterval) -> Self

  static func -=(lhs: inout Self, rhs: DiatonicInterval) -> Self
}

extension Note: DiatonicIntervalArithmetic {}

extension NoteClass: DiatonicIntervalArithmetic {}

and then rewrite the protocols e.g. as follows

protocol Scale {
  associatedtype Note: DiatonicIntervalArithmetic

  var notes: [Note] { get }
}

protocol Chord {
  associatedtype Note: DiatonicIntervalArithmetic

  var notes: [Note] { get }
}

(though we may want to name the associated types differently to avoid confusion with the Note struct).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant