chords
An easily customizable Kotlin multi-platform View to display guitar (and other stringed instrument) chords. Simple to use and beautifully designed.
Building the library
The library is provided through Bintray. Checkout the releases page to get the latest version.
Repository
Dependencies
Core Kotlin Common:
Core Kotlin JVM:
Core Kotlin JS:
Android Library:
Using the library
There are a few main components to using the library:
ChordWidget
is theChordView
implementation that displays the chord.ChordChart
is a class that represents information about the chord chart that will be displayed.Chord
is a class that represents the markers on a chord that will be displayed.
Creating an instance of ChordWidget
Android:
Kotlin JS:
Assigning a ChordChart
to a ChordWidget
Creating a Chord using the DSL
Assigning a Chord
to a ChordWidget
Note: This library doesn't try to coerce values to fit into a chart or exclude values that exceed the chart bounds. If the ChordChart
and Chord
have inconsistent values, the ChordWidget
may look peculiar.
It's important for the user of the library to properly handle coordinating the different components.
Parsing Chords from other formats
The ChordParser
interface takes in an input type and outputs a ChordParseResult
. This interface can be implemented for different format input types. There are a couple provided ChordParser
implementations.
AsciiChordParser:
AsciiChordParser
parses a String
input of an ASCII Chord Diagram and outputs a ChordParseResult
containing a Chord
.
ChordProParser:
ChordProParser
parses a String
input of a Chord Pro (Chord or Define) Directive and outputs a ChordParseResult
containing a Chord
.
Customizing the appearance
ChordWidget
implements the ChordView
interface which contains properties to alter the appearance of the view.
ChordView:
Updating properties directly on ChordWidget:
Note: That in Kotlin JS, you have to explicitly call the render()
function after updating properties on the ChordWidget
.
Updating properties using a ViewModel and Binder:
Note: That in Kotlin JS, there is a convenience function ChordViewBinder.bindAndRender()
which will bind the properties from the ChordViewModel
to the ChordWidget
and call render()
.
Updating properties in Android XML:
Available Android XML Attributes:
Selectable Chord names in Text using Android Spans
The library comes with a ChordSpan
which allows the pairing of text with a Chord
. And when the ChordSpan
is selected, a listener is alerted with the Chord
.
Adding a ChordSpan
to a TextView
:
Using DSL functions to add a ChordSpan
to a TextView
:
Listening to Chord
selected events:
Customizing the ChordSpan
appearance:
ChordSpan
extends from TouchableSpan
which inherits from TouchableSpanView
and has the following customizable properties:
These properties can be changed on the span:
Passing Chords between Android components
The model classes are not Parcelable
because they are in a Kotlin multi-platform module and don't have access to Android Framework classes. But the Android library module does have wrapper classes that handle the serialization and de-serialization of the Chord
and ChordChart
models.
These classes are ParcelableChordWrapper
and ParcelableChartWrapper
. To pass Chord
and ChordChart
between components, such as, in a Bundle, just wrap them with their respective wrapper models.
Then retrieve the wrappers just as you would with any other Parcelable object.
For convenience, there are extension functions on the Bundle
and Intent
objects which handle the wrapping and unwrapping of the Chord
and ChordChart
objects.
Bundle:
Intent:
There is also a convenience ChordAndChart
class (with similar Parcelable extension functions) for when both a Chord
and a ChordChart
need to be passed between Android components together.
Samples
Checkout the sample modules for examples on using the library.