tonic 0.2.3

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 87

Dart #

Build Status

Tonic is a Dart package that models components of music theory.

It also computes chord diagrams; this functionality is in progress. (I'm porting it from schoen.)

Installing via Pub #

The current version of this package requires Dart 2.0. Use version 0.1.1 with Dart 1.x.

Add the following to your pubspec.yaml, and run pub get.

dependencies:
  tonic: any

Example Usage #

  import 'package:tonic/tonic.dart';

  main() {
    // Hemholtz and Scientific pitch notation
    print(Pitch.parse('C4'));
    print(Pitch.parse('C♯4'));
    print(Pitch.parse('C♭4'));

    // Unicode and ASCII sharps and flats
    print(Pitch.parse('C#4') == Pitch.parse('C#4')); // => true
    print(Pitch.parse('Cb4') == Pitch.parse('Cb4')); // => true

    // Enharmonic equivalents
    print(Pitch.parse('E♯4').midiNumber == Pitch.parse('F4').midiNumber); // => true
    print(Pitch.parse('E4').midiNumber == Pitch.parse('F♭4').midiNumber); // => true
    print(Pitch.parse('E♯4') == Pitch.parse('F4')); // => false
    print(Pitch.parse('E4') == Pitch.parse('F♭4')); // => false

    print(Pitch.parse('C4').octave); // => 5
    print(Pitch.parse('C4').midiNumber); // => 60
    print(new Pitch.fromMidiNumber(60)); // => C4

    // Intervals
    print(Interval.M3);
    print(Interval.parse('M3'));
    print(Interval.m3.semitones); // => 3
    print(Interval.M3.semitones); // => 4
    print(Interval.A3.semitones); // => 5
    print(Interval.d4.semitones); // => 4
    print(Interval.P4.semitones); // => 5
    print(Interval.A4.semitones); // => 6
    print(Interval.M3.number); // => 3
    print(Interval.M3.qualityName); // => "M"

    // Interval arithmetic
    print(Interval.M3 + Interval.m3); // => P5
    print(Interval.m3 + Interval.M3); // => P5
    print(Interval.m3 + Interval.m3); // => d5
    print(Interval.M3 + Interval.M3); // => A5

    print(Pitch.parse('C4') + Interval.M3); // => E4
    print(Pitch.parse('C4') + Interval.A3); // => E♯4
    print(Pitch.parse('C4') + Interval.d4); // => F♭4
    print(Pitch.parse('C4') + Interval.P4); // => F4

    print(Pitch.parse('C4') - Pitch.parse('C4'));   // => P1
    print(Pitch.parse('D4') - Pitch.parse('C4'));   // => M2
    print(Pitch.parse('E4') - Pitch.parse('C4'));   // => M3
    print(Pitch.parse('E♯4') - Pitch.parse('C4')); // => A3
    print(Pitch.parse('F♭4') - Pitch.parse('C4')); // => d4
    print(Pitch.parse('F4') - Pitch.parse('C4'));  // => P4

    // Chords
    print(Chord.parse('E Major'));
    print(ChordPattern.parse('Dominant 7th')); // => Dom 7th
    print(ChordPattern.fromIntervals([Interval.P1, Interval.M3, Interval.P5])); // => Major
    print(ChordPattern.fromIntervals([Interval.P1, Interval.m3, Interval.P5])); // => Minor
    print(ChordPattern.fromIntervals([Interval.P1, Interval.m3, Interval.P5, Interval.m7])); // => Min 7th

    // Scales
    final scalePattern = ScalePattern.findByName('Diatonic Major');
    print(scalePattern.intervals); // => [P1, M2, M3, P4, P5, M6, M7]
    print(scalePattern.modes);
    print(scalePattern.modes['Dorian'].intervals); // => [P1, M2, m3, P4, P5, M6, m7]

    final scale = scalePattern.at(Pitch.parse('E4'));
    print(scale.intervals); // => [P1, M2, M3, P4, P5, M6, M7]
    print(scale.pitchClasses); // => [E4, F♯4, G♯4, A4, B4, C♯5, D♯5]

    // Instruments and fret fingerings
    final chord = Chord.parse('E Major');
    final instrument = Instrument.Guitar;
    print(bestFrettingFor(chord, instrument)); // => 022100
  }

More examples can be found in the tests in test/*_test.dart.

License #

MIT

[0.0.2] - Dart 2 / Flutter compatibility

  • Updated for Flutter and Dart 2 compatibility.

[0.0.1] - Initial release

  • Initial release.

example/tonic_example.dart

import 'package:tonic/tonic.dart';

main() {
  banner("Hemholtz and Scientific pitch notation");
  print(Pitch.parse('C4'));
  print(Pitch.parse('C♯4'));
  print(Pitch.parse('C♭4'));

  banner("Unicode and ASCII sharps and flats");
  print(Pitch.parse('C#4') == Pitch.parse('C#4')); // => true
  print(Pitch.parse('Cb4') == Pitch.parse('Cb4')); // => true

  banner("Enharmonic equivalents");
  print(
      Pitch.parse('E♯4').midiNumber == Pitch.parse('F4').midiNumber); // => true
  print(
      Pitch.parse('E4').midiNumber == Pitch.parse('F♭4').midiNumber); // => true
  print(Pitch.parse('E♯4') == Pitch.parse('F4')); // => false
  print(Pitch.parse('E4') == Pitch.parse('F♭4')); // => false

  print(Pitch.parse('C4').octave); // => 5
  print(Pitch.parse('C4').midiNumber); // => 60
  print(new Pitch.fromMidiNumber(60)); // => C4

  banner("Intervals");
  print(Interval.M3);
  print(Interval.parse('M3'));
  print(Interval.m3.semitones); // => 3
  print(Interval.M3.semitones); // => 4
  print(Interval.A3.semitones); // => 5
  print(Interval.d4.semitones); // => 4
  print(Interval.P4.semitones); // => 5
  print(Interval.A4.semitones); // => 6
  print(Interval.M3.number); // => 3
  print(Interval.M3.qualityName); // => "M"

  banner("Interval arithmetic");
  print(Interval.M3 + Interval.m3); // => P5
  print(Interval.m3 + Interval.M3); // => P5
  print(Interval.m3 + Interval.m3); // => d5
  print(Interval.M3 + Interval.M3); // => A5

  print(Pitch.parse('C4') + Interval.M3); // => E4
  print(Pitch.parse('C4') + Interval.A3); // => E♯4
  print(Pitch.parse('C4') + Interval.d4); // => F♭4
  print(Pitch.parse('C4') + Interval.P4); // => F4

  print(Pitch.parse('C4') - Pitch.parse('C4')); // => P1
  print(Pitch.parse('D4') - Pitch.parse('C4')); // => M2
  print(Pitch.parse('E4') - Pitch.parse('C4')); // => M3
  print(Pitch.parse('E♯4') - Pitch.parse('C4')); // => A3
  print(Pitch.parse('F♭4') - Pitch.parse('C4')); // => d4
  print(Pitch.parse('F4') - Pitch.parse('C4')); // => P4

  banner("Chords");
  print(Chord.parse('E Major'));
  print(ChordPattern.parse('Dominant 7th')); // => Dom 7th
  print(ChordPattern.fromIntervals(
      [Interval.P1, Interval.M3, Interval.P5])); // => Major
  print(ChordPattern.fromIntervals(
      [Interval.P1, Interval.m3, Interval.P5])); // => Minor
  print(ChordPattern.fromIntervals(
      [Interval.P1, Interval.m3, Interval.P5, Interval.m7])); // => Min 7th

  banner("Scales");
  final scalePattern = ScalePattern.findByName('Diatonic Major');
  print(scalePattern.intervals); // => [P1, M2, M3, P4, P5, M6, M7]
  print(scalePattern.modes);
  print(scalePattern
      .modes['Dorian'].intervals); // => [P1, M2, m3, P4, P5, M6, m7]

  final scale = scalePattern.at(PitchClass.parse('E4'));
  print(scale.intervals); // => [P1, M2, M3, P4, P5, M6, M7]
  print(scale.pitchClasses); // => [E4, F♯4, G♯4, A4, B4, C♯5, D♯5]

  final chord = Chord.parse('E Major');
  final instrument = Instrument.guitar;
  print(bestFrettingFor(chord, instrument)); // => 022100
}

void banner(msg) => print("\n" + msg + ":");

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  tonic: ^0.2.3

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:tonic/tonic.dart';
  
Version Uploaded Documentation Archive
0.2.3 Aug 2, 2018 Go to the documentation of tonic 0.2.3 Download tonic 0.2.3 archive
0.2.2 Aug 1, 2018 Go to the documentation of tonic 0.2.2 Download tonic 0.2.2 archive
0.2.1 Aug 1, 2018 Go to the documentation of tonic 0.2.1 Download tonic 0.2.1 archive
0.2.0 Aug 1, 2018 Go to the documentation of tonic 0.2.0 Download tonic 0.2.0 archive
0.0.1 Feb 27, 2014 Go to the documentation of tonic 0.0.1 Download tonic 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
80
Health:
Code health derived from static analysis. [more]
94
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
95
Overall:
Weighted score of the above. [more]
87
Learn more about scoring.

We analyzed this package on Apr 17, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.2.0
  • pana: 0.12.14

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:tonic/tonic.dart.

Health suggestions

Fix lib/pitch.dart. (-1.99 points)

Analysis of lib/pitch.dart reported 4 hints:

line 128 col 51: Use = to separate a named parameter from its default value.

line 128 col 66: Use = to separate a named parameter from its default value.

line 144 col 52: Use = to separate a named parameter from its default value.

line 144 col 67: Use = to separate a named parameter from its default value.

Fix lib/pitch_class.dart. (-1.49 points)

Analysis of lib/pitch_class.dart reported 3 hints:

line 7 col 48: Use = to separate a named parameter from its default value.

line 7 col 67: Use = to separate a named parameter from its default value.

line 36 col 28: Use = to separate a named parameter from its default value.

Fix lib/fretting.dart. (-1 points)

Analysis of lib/fretting.dart reported 2 hints:

line 188 col 17: Use = to separate a named parameter from its default value.

line 365 col 57: Use = to separate a named parameter from its default value.

Fix lib/interval.dart. (-1 points)

Analysis of lib/interval.dart reported 2 hints:

line 58 col 47: Use contains instead of indexOf

line 102 col 9: Use contains instead of indexOf

Fix lib/src/utils.dart. (-0.50 points)

Analysis of lib/src/utils.dart reported 1 hint:

line 17 col 18: Use = to separate a named parameter from its default value.

Maintenance suggestions

Homepage URL is insecure. (-5 points)

Update the homepage field and use a secure (https) URL.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.69.5 <3.0.0
collection ^1.14.0 1.14.11
Dev dependencies
test ^1.3.0