Git Product home page Git Product logo

swiftyguitarchords's Introduction

Swifty Chords

banner

This is a Swift library that can generate CAShapeLayers for any chord within it's database. All you need to do is supply a Key (C, C#, etc) and a suffix (Major, Minor, sus4, etc) to find the appropriate chord. Each chord comes with a few variants.

The database is pulled from another project I found a while ago, but cannot remember where that was. Please do not rely 100% on this data, as I have found that a few chords are incorrect. If you find any of your own, please open a PR correcting these.

This library is currently in Beta. Everything works, and the drawing speeds are fine, but there is lots of room for improvement.

I am using this library in my music study app "Mustud" with no problems at all.

Requirements

  • iOS 13+
  • macOS 10.12+ -> It works, but you'll need to flip the results since it uses iOS drawing coordinates.
  • Xcode 11+

Installation

Only supports Swift Package Manager at this time.

Usage

Setup

import SwiftyChords

Search

Get all Chords

Chords.guitar

Filter by Key

Returns all chords based on C#

Chords.guitar.matching(key: .cSharp)

Filter by Suffix

Returns all major seventh chords in the database across all keys.

Chords.guitar.matching(suffix: .majorSeven)

Filter by Key and Suffix

Returns all C Major chords. These will be in order of position on the fretboard, starting at the nut.

Chords.guitar.matching(key: .c).matching(suffix: .major)

Filter by Suffix Group

Returns all suspended chords in the database along with their variants such as sus2, sus4

Chords.guitar.matching(group: .suspended)

Display

Swifty Chords suports a number of alternative texts you can use in your UI including an accessibility text-to-speech friendly variant. Display texts from both Key and Suffix properties can be combined to complete the chord name.

let cMajSevenFlatFive = Chords.guitar.matching(key: .c).matching(suffix: .majorSevenFlatFive)
print(cMajSevenFlatFive.suffix.display.accessible) // " major seven flat five"
print(cMajSevenFlatFive.suffix.display.short)      // "Maj7b5"
print(cMajSevenFlatFive.suffix.display.symbolized) // "Maj⁷♭⁵" 
print(cMajSevenFlatFive.suffix.display.altSymbol)  // "M⁷♭⁵"

Drawing

There are a number of ways to use the CAShapeLayer. You can add it directly to a view, or convert it to an Image.

To use it, we just need a chord!

let chordPosition = Chords.guitar.matching(key: .c).matching(suffix: .major).first!
let frame = CGRect(x: 0, y: 0, width: 100, height: 150) // I find these sizes to be good.
let layer = chordPosition.chordLayer(rect: frame, chordName: .init(show: true, key: .symbol, suffix: .symbolized))
imageView.image = layer.image() // might be expensive. Use Layers when possible while drawing to a view. Images are better if you plan to send them outside the app.

Arguments

rect: The area for which the chord will be drawn to. This determines it's size. Chords have a set aspect ratio, and so the size of the chord will be based on the shortest side of the rect.

showFingers: Determines if the finger numbers should be drawn on top of the dots. Default true.

showChordName Determines if the chord name should be drawn above the chord. Choosing this option will reduce the size of the chord chart slightly to account for the text. Default true. The display mode can be set for Key and Suffix. Default rawValue

forPrint: If set to true the diagram will be colored Black, ignoring the users device settings. If set to false, the color of the diagram will match the system label color. Dark text for light mode, and Light text for dark mode. Default false.

mirror: For left-handed users. This will flip the chord along its y axis. Default false.

swiftyguitarchords's People

Contributors

beaunouvelle avatar desbeers avatar wacumov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

swiftyguitarchords's Issues

Populating json file

Hi BeauNouvelle,
This is a great resource! I'm going to use it in one of my apps for learning chords. What did you use to populate the json file for the chords?
Regards Gerard

Data Clean

At the moment all chords are kept within a single file. This requires all of them to be initialized at once, and searching through this list can be slow on older hardware.

Ideally the data would be categorized into separate areas, or perhaps managed in an actual database.
Until then, we can split the data into sections as follows:

Instrument > Key > Suffix

The reason for why this wasn't done before is that some users of the library may want to search based on a suffix, rather than the instrument. This definitely needs to be considered.

Ability to specify Chord Name display type in the drawing function

Currently the library uses the RawValue of the Key and Suffix properties on a chord for the name drawn above the chord diagram.

The library now supports other naming variants, so it makes sense to give developers the option to choose from these variants.

This will need to remain backwards compatible. I suggest adding this to the parameters of the current drawing functions, hardcode (and deprecate) the proxy functions to pass in RawValue, and create a new public function that accepts a new enum for these titles.

Another option is to allow developers to add any text they like to the chord names. Discussion?

Add Support for Ukulele

Currently the drawing system is coded for 6 strings, but I think it would make this library far more useful if it could also support Ukulele chords too!

Localization

Support for Solfege perhaps?
Not a necessity, but could be a nice option for folks who are more used to scales pronounced in this way.

I understand that in MOST languages with musical terms they tend to still use the Arabic numbers and major/minor style of writing.

If I'm wrong on this, please let me know and add examples in the comments.

Update chord charts remotely

Add a new function that fetches the latest chord list from this repository. This can be optionally called by consumers of the library.

Fetching and caching the latest chord list could be helpful for apps that don't update dependencies as often and allows library maintainers to fix issues with incorrect chords or add new ones quickly.

Checks for Sharp/Flats/Maj/Min etc

Adding a new property for isMajor, isMinor, etc, to the Suffix enum.
These could then be used for filtering based on grouped attributes.
i.e. maj, maj7 etc, could be grouped together under isMajor.

Devs could then create NEW filters for chord search.

Different Tunings

Add support for a number of different tunings.

Would this require a new chord database for each, or could we recalculate each chord at runtime?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.