Provides type-safe access to localized musical instruments and their tunings.

Overview

InstrumentKit

CI Status Latest Release Swift Compatibility Platform Compatibility License

InstrumentKit provides type-safe access to localized musical instruments and their tunings.

Table of Contents

Work In Progress

⚠️ This package is very much a work in progress. Here are some immediate next steps.

  • For the time being, this package is focused on collecting, validating, and localizing data for string instruments only. Once string instruments feel accurate and stable and the library is extremely tested, the plan will be to add brass, keyboards, percussions, and more.
  • The library currently leverages an internal dependency for musical notation (NoteKit), but should be reaplced by the more accurate and better maintained AudioKit/Tonic as soon as possible. Musical math and theory is difficult, and InstrumentKit doesn't want to be in the business of musical math or theory.
  • Provide system for ensuring paritally localized models provide English values by default. Currently, they fall back on the localizationKey, meaning "Guitar" translated to a partial localization without the "guitar" key will show up as "guitar", not "Guitar".
    • This already works for missing localizations, but doesn't work for partial localizations.
    • This functionality shouldn't be much more work to achieve without increasing performance.

Installation

Swift Package Manager

Swift Package Manager is built into the Swift toolchain and is the preferred way of integrating the SDK.

In addition to being compatible with Apple platforms (iOS, macOS, tvOS, watchOS), the package is also fully compatible with Linux, making it perfect for Server-side Swift projects.

For Swift package projects, simply add the following line to your Package.swift file in the dependencies section, replacing x.x.x with the latest version:

dependencies: [
  .package(url: "https://github.com/bdrelling/InstrumentKit", .from: "x.x.x"),
]

For app projects, simply follow the Apple documentation on adding package dependencies to your app.

Usage

Models

struct StringInstrument {
    let localizationKey: String
    let name: String
    let numberOfStrings: Int
    let numberOfCourses: Int
    let tunings: [Tuning]
}
struct Tuning {
    let localizationKey: String
    let name: String
    let notes: [Note]
}

Examples

Get a specific string instrument.

let guitar: StringInstrument = .guitar
let ukulele: StringInstrument = .ukulele
let irishBouzouki: StringInstrument = .irishBouzouki

Get all string instruments.

let instruments: [StringInstrument] = StringInstrument.allCases
let instruments: [StringInstrument] = .allCases

Collections provide an .allCases convenience extension, so you don't have to write out the name of the element each time.

Get a specific tuning for an instrument.

let guitarStandard: Tuning = Tuning.Guitar.standard.rawValue

Get all tunings for an instrument.

let guitarTunings: [Tuning] = StringInstrument.guitar.tunings
let guitarTunings: [Tuning] = Tuning.Guitar.allTunings

allTunings is provided as a convenience for allCases.map(\.rawValue).

Localization

By default, every StringInstrument and Tuning will be localized to Locale.current. However, you can also localize models on the fly simply by calling .localized(to:) with a Locale, locale identifier (String), or using the SupportedLanguage enum.

Localize a model.

let guitarra: StringInstrument = .guitar.localized(to: "es")
let estandard: Tuning = Tuning.Guitar.standard.localized(to: "es")

Localize a collection of models.

let spanishInstruments: [StringInstrument] = .allCases.localized(to: "es")
let spanishGuitarTunings: [Tuning] = Tuning.Guitar.allTunings.localized(to: "es")

API

Looking for localized instrument and tuning definitions but don't use Swift? No problem!

All instruments and tunings in this package are also available by making API requests to instruments.fyi. You can fetch all instruments, specific instruments, tunings, and more.

For more information, see instruments.fyi or visit instruments.fyi.

Performance

Localization

String localization usage in this module matches standard usage of Bundle.localizedString(forKey:value:table:) and NSLocalizedString. By initializing these strings through localization tables every time, it ensures that anyone consuming the module will get localization out of the box without any additional work, as they will always localize using Locale.current.

String Initialized Tunings

Seeing the following in Tuning+Definitions.swift might make you uncomfortable:

enum Guitar: Tuning, CaseIterable {
    case standard = "standard: E2 A2 D3 G3 B3 E4"
    case dropD = "drop_d: D2 A2 D3 G3 B3 E4"
    case openD = "open_d: D2 A2 D3 F#3 A3 D4"
}

This approach was not taken lightly. Instruments have dozens of commonly applicable tunings, and there are hundreds of instruments. Maintaining a large data set without an easy-to-parse method of analyzing, comparing, and fact-checking that data becomes extremely difficult over time.

String parsing of a Tuning takes place in the special init at the bottom of Tuning+Definitions.swift. By making Tuning conform to ExpressibleByStringLiteral, it allows us to create CaseIterable enums that are easy to validate and provide Tuning collection and organization functionality out of the box.

The logic is simple and very easy to validate: loop through every Tuning in the project and if any of our localization keys in any of our supported languages come back with an error of any sort, numerous unit tests in the project will blow up.

Additionally, these enums are only initialized once, meaning that if you keep accessing one of these enums over and over, you can be sure that it won't be re-parsing the Tuning definition each time.

If you have an alternative to propose, feel free to open an issue or pull request. Several approaches were considered before landing on String-initialized Tunings, but a fresh set of eyes is always helpful. If you have a performant way of defining this data that is type-safe yet provides the same level of convenience and readability (for maintenance and data accuracy), I'm interested!

Contributing

Discussions, issues, and pull requests are more than welcome, for development, corrections, and/or localizations.

If you're providing corrections and/or localizations, please provide as many additional sources as you can for validation in order to help ensure we can get the corrections integrated as quickly as possible.

Credits

Special thanks to AudioKit for all of their expertise and support.

License

This project is released under the MIT license. See LICENSE for details.

You might also like...
An iOS and macOS audio visualization framework built upon Core Audio useful for anyone doing real-time, low-latency audio processing and visualizations.
An iOS and macOS audio visualization framework built upon Core Audio useful for anyone doing real-time, low-latency audio processing and visualizations.

A simple, intuitive audio framework for iOS and OSX. Deprecated EZAudio has recently been deprecated in favor of AudioKit. However, since some people

What is eCortex? A informative tool to manage and organize thoughts and ideas sparked through out the day into custom categories.
What is eCortex? A informative tool to manage and organize thoughts and ideas sparked through out the day into custom categories.

eCortex What is eCortex? A informative tool to manage and organize thoughts and ideas sparked through out the day into custom categories. What problem

Nobetci Eczacim is open-source App Store Application which users can get pharmacy information and location easily and safely.

Pharmacy-On-Duty Nobetci Eczacim Project Description This project designed for make it easier for people to search for a pharmacy on duty. App Store A

AudioPlayer is syntax and feature sugar over AVPlayer. It plays your audio files (local & remote).

AudioPlayer AudioPlayer is a wrapper around AVPlayer. It also offers cool features such as: Quality control based on number of interruption (buffering

AudioPlayer is a simple class for playing audio in iOS, macOS and tvOS apps.
AudioPlayer is a simple class for playing audio in iOS, macOS and tvOS apps.

AudioPlayer AudioPlayer is a simple class for playing audio in iOS, macOS and tvOS apps.

Soundable is a tiny library that uses AVFoundation to manage the playing of sounds in iOS applications in a simple and easy way

Soundable is a tiny library that uses AVFoundation to manage the playing of sounds in iOS applications in a simple and easy way. You can play

Beautiful Music Player app built using SwiftUI to demonstrate Neumorphic design pattern and MVVM architecture.
Beautiful Music Player app built using SwiftUI to demonstrate Neumorphic design pattern and MVVM architecture.

Beautiful Music Player app built using SwiftUI to demonstrate Neumorphic design pattern 🎨 and MVVM architecture 🏗 . Made with love ❤️ by Sameer Nawaz

Swift audio synthesis, processing, & analysis platform for iOS, macOS and tvOS
Swift audio synthesis, processing, & analysis platform for iOS, macOS and tvOS

AudioKit AudioKit is an audio synthesis, processing, and analysis platform for iOS, macOS (including Catalyst), and tvOS. Installation To add AudioKit

The DoubanFM for iPhone,using AFN and MPMoviePlayer
The DoubanFM for iPhone,using AFN and MPMoviePlayer

DoubanFM github:@XVXVXXX csdn:@XVXVXXX please open DoubanFM.xcworkspace The DoubanFM for iPhone,using MPMoviePlayer &AFNetworking@AFNetworking/AFNetwo

Owner
Brian Drelling
I make apps, games, and music. The trick is never sleeping. He/Him.
Brian Drelling
Project by Group 6 - Good Morning | An assortment of musical theory tools

MusicalRooms Ever find yourself staring at theory books, unsure of when the obscure music terms will ever become second nature? Are you on your way to

Swift Innovators Network 7 Nov 4, 2022
MusicalInstrument - Play musical instrument in just few lines of swift code

MusicalInstrument Play musical instrument in just few lines of swift code. Requi

null 2 Feb 3, 2022
MusicTheoryKit: a swift module that provides an easy-to-use API for most commonly used music terms

MusicTheoryKit Introduction MusicTheoryKit is a Swift framework that provides an easy-to-use API for most commonly used music terms. Create notes, ass

Jin Zhang 4 Feb 8, 2022
Swift-music - swift-music is a swift package that provides an easy-to-use API for music related developments.

?? swift-music Introduction swift-music is a swift package that provides an easy-to-use API for music related developments. Currently available module

Jin Zhang 4 Feb 8, 2022
OSCKit - The OSCKit package provides the classes needed for your apps to communicate among computers, sound synthesizers

OSCKit The OSCKit package provides the classes needed for your apps to communica

Sammy Smallman 23 Nov 27, 2022
An iOS app that visually clones Spotify's app and consumes the official Spotify's Web API to show(and play) songs, podcasts, artists and more.

SpotifyClone An iOS app that visually clones Spotify's app and consumes the official Spotify's Web API to show(and play) songs, podcasts, artists and

null 104 Jan 7, 2023
AudioKit is an audio synthesis, processing, and analysis platform for iOS, macOS, and tvOS.

AudioKit is an audio synthesis, processing, and analysis platform for iOS, macOS (including Catalyst), and tvOS. Installation To add AudioKit

AudioKit 9.5k Dec 31, 2022
MusicKit is a framework and DSL for creating, analyzing, and transforming music in Swift.

MusicKit MusicKit is a framework and DSL for creating, analyzing, and transforming music in Swift. Examples Functional harmony let C5 = Pitch(midi: 72

Ben Guo 591 Oct 18, 2022
Voice Memos is an audio recorder App for iPhone and iPad that covers some of the new technologies and APIs introduced in iOS 8 written in Swift.

VoiceMemos Voice Memos is a voice recorder App for iPhone and iPad that covers some of the new technologies and APIs introduced in iOS 8 written in Sw

Zhouqi Mo 322 Aug 4, 2022
Extensions and classes in Swift that make it easy to get an iOS device reading and processing MIDI data

MorkAndMIDI A really thin Swift layer on top of CoreMIDI that opens a virtual MIDI destination and port and connects to any MIDI endpoints that appear

Brad Howes 11 Nov 5, 2022