Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Universal music theory library for iOS, iPadOS, macOS, tvOS and watchOS in Swift

License

NotificationsYou must be signed in to change notification settings

cemolcay/MusicTheory

Repository files navigation

A music theory library withKey,Pitch,Interval,Scale andChord representations in swift enums.

Requirements

  • Swift 4.0+
  • iOS 8.0+
  • macOS 10.9+
  • tvOS 9.0+
  • watchOS 2.0+

Install

CocoaPods

pod 'MusicTheorySwift'

Swift Package Manager

letpackage=Package(  name:...  dependencies:[.package(url:"https://github.com/cemolcay/MusicTheory.git")],  targets:...)

Usage

MusicTheory adds a bunch of basic enums and structs that you can define pretty much any music related data. Most importants arePitch,Key,Scale andChord.

All data types conformsCodable,CustomStringConvertable.
Pitch, andAccident structs areRawPresentable withInt as well asExpressibleByIntegerLiteral that you can represent them directly withInts.

Pitch andKey

  • All keys can be defined withKey struct.
  • It has aKeyType where you can set the base key like C, D, A, G, and anAccidental where it can be.natural,.flat,sharp or more specific like.sharps(amount: 3).
  • You can createPitches with aKey and octave.
  • Also, you can createPitches with MIDI note number.rawValue of a pitch is its MIDI note number.
  • Pitch,Key,Accidental structs are equatable,+ and- custom operators defined for making calculations easier.
  • Also, there are other helper functions or properties like frequency of a note.
  • You can define them with directly string representations as well.
letdFlat=Key(type: d, accidental:.flat)letc4=Pitch(key:Key(type:.c), octave:4)letaSharp:Key="a#" // Key(type: .a, accidental: .sharp)letgFlat3:Pitch="gb3" // or "g♭3" or "Gb3" is Pitch(key: (type: .g, accidental: .flat), octave: 3)

Interval

  • Intervals are halfsteps between pitches.
  • They areIntegerLiteral and you can make add/substract them between themselves, notes or note types.
  • You can build up a custom interval with its quality, degree and semitone properties.
  • You can build scales or chords from intervals.
  • Minor, major, perfect, augmented and diminished intervals up to 2 octaves are predefined.

ScaleType andScale

  • ScaleType enum defines a lot of readymade scales.
  • Also, you can create a custom scale type byScaleType.custom(intervals: [Interval], description: String)
  • Scale defines a scale with a scale type and root key.
  • You can generate notes of scale in an octave range.
  • Also you can generateHarmonicField of a scale.
  • Harmonic field is all possible triad, tetrad or extended chords in a scale.
letc=Key(type:.c)letmaj:ScaleType=.majorletcMaj=Scale(type: maj, key: c)

ChordType andChord

  • ChordType is a struct withChordParts which are building blocks of chords.
  • You can define any chord existing withChordType.
  • Thirds, fifths, sixths, sevenths and extensions are parts of theChordType.
  • Each of them also structs which conformsChordPart protocol.
  • Chord defines chords with type and a root key.
  • You can generate notes of chord in any octave range.
  • You can generate inversions of any chord.
letm13=ChordType(  third:.minor,  seventh:.dominant,  extensions:[ChordExtensionType(type:.thirteenth)])letcm13=Chord(type: m13, key:Key(type:.c))
  • You can generate chord progressions withChordProgression enum.
  • For any scale, in any harmonic field, for any inversion.
letprogression=ChordProgression.i_ii_vi_ivletcSharpHarmonicMinorTriadsProgression= progression.chords(  for: cSharpHarmonicMinor,  harmonicField:.triad,  inversion:0)

Tempo andTimeSignature

  • Tempo is a helper struct to define timings in your music app.
  • TimeSignature is number of beats in per measure andNoteValue of each beat.
  • You can calculate notes duration in any tempo by therNoteValue.
  • Note value defines the note's duration in a beat. It could be whole note, half note, quarter note, 8th, 16th or 32nd note.

HarmonicFunctions

  • Harmonic functions is a utility for finding related notes or chords in a scale when composing.
  • You can create recommendation engines or chord generators with that.

Playgrounds

  • You can experiment with the library right away in the Xcode Playgrounds!
  • After cloning the project, build it for the Mac target,
  • Go to playground page in the project,
  • Make sure the macOS platform is selected,
  • And make sure the "Build Active Scheme" option is selected in the playground settings.
  • There are some recipes ready in the playground page, you can just run them right away.

Documentation

Full documentation is here

Unit Tests

You can find unit tests inMusicTheoryTests target.
Press⌘+U for running tests.

AppStore

This library battle tested in my apps for iOS, macOS, watchOS and tvOS, check them out!
KeyBud (iOS, watchOS, tvOS, macOS)
FretBud (iOS, watchOS, tvOS)
ChordBud (iOS)
ArpBud (iOS)
ScaleBud (iOS, AUv3, M1)
StepBud (iOS, AUv3, M1)
RhythmBud (iOS, AUv3, M1)
ArpBud 2 (iOS, AUv3, M1)
ChordBud 2 (iOS, AUv3, M1)
LoopBud (iOS, AUv3, M1)
Euclid Goes to Party (iOS, AUv3, M1)
SnakeBud (iOS, AUv3, M1)
MelodyBud (iOS, AUv3, M1)
ScaleBud 2 (iOS, AUv3, M1)
ShiftBud (iOS, AUv3, M1)
PolyBud (iOS, AUv3, M1)
PatternBud (iOS, AUv3, M1)
MIDI Motion (iOS, watchOS)
Textquencer (iOS, AUv3, M1)
In Theory (iOS, AUv3, M1)
BrainBud (iOS, AUv3, M1)
Binarhythmic (iOS, AUv3, M1)
Auto Bass (iOS, AUv3, M1)
BounceBud (iOS, AUv3, M1)
MuseBud (iOS, AUv3, M1)
Auto Fills (iOS, AUv3, M1)
Kebarp (iOS, AUv3, M1)
FuncBud (iOS, AUv3, M1)
Note to Be (iOS, AUv3, M1)
Harmonicc (iOS, AUv3, M1)

About

Universal music theory library for iOS, iPadOS, macOS, tvOS and watchOS in Swift

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp