Package music.lib.instruments

Source Code of music.lib.instruments.Piano

/*
*    Musical Skill Coach - An interactive midi device friendly program to help music students improve their skills
*    Copyright (C) 2011  Paul-Emile Gaudet
*
*    This program is free software: you can redistribute it and/or modify
*    it under the terms of the GNU General Public License as published by
*    the Free Software Foundation, either version 3 of the License, or
*    (at your option) any later version.
*
*    This program is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU General Public License for more details.
*
*    You should have received a copy of the GNU General Public License
*    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

package music.lib.instruments;

import java.util.ArrayList;

import music.lib.LabeledInteger;
import music.lib.MusicScoreNote;

public class Piano implements Instrument
{
  protected static final String [][] KEYS =
  {
  { "C", "0" },
  { "C# / Db", "1" },
  { "D", "2" },
  { "D# / Eb", "3" },
  { "E", "4" },
  { "F / E#", "5" },
  { "F# / Gb", "6" },
  { "G", "7" },
  { "G# / Ab", "8" },
  { "A", "9" },
  { "A# / Bb", "10" },
  { "B / Cb", "11" } };

  protected static final String [][] CHORDS =
  {
  { "Major", "4,7" },
  { "Minor", "3,7" },
  { "5", "7" },
  { "Dominant 7th", "4,7,10" },
  { "Major 7th", "4,7,11" },
  { "Minor 7th", "3,7,10" },
  { "Minor Major 7th", "3,7,11" },
  { "Sus 4", "5,7" },
  { "Sus 2", "2,7" },
  { "6", "4,7,9" },
  { "Minor 6", "3,7,9" },
  { "9", "4,7,10" },
  { "Minor 9", "3,7,10" },
  { "Major 9", "4,7,11" },
  { "Minor Major 9", "2,3,7,11" },
  { "11", "2,4,5,7,10" },
  { "Minor 11", "2,3,5,7,10" },
  { "Major 11", "2,4,5,7,11" },
  { "Minor Major 11", "2,3,5,7,11" },
  { "13", "2,4,7,9,10" },
  { "Minor 13", "2,3,7,9,10" },
  { "Major 13", "2,4,7,9,11" },
  { "Minor Major 13", "2,3,7,9,11" },
  { "add 9", "2,4,7" },
  { "Minor add 9", "2,3,7" },
  { "6 add 9", "2,4,7,9" },
  { "Minor 6 add 9", "2,3,7,9" },
  { "Dominant 7th add 11", "4,5,7,10" },
  { "Major 7th add 11", "4,5,7,11" },
  { "Minor 7th add 11", "3,5,7,10" },
  { "Minor Major 7th add 11", "3,5,7,11" },
  { "Dominant 7th add 13", "4,7,9,10" },
  { "Major 7th add 13", "4,7,9,11" },
  { "Minor 7th add 13", "3,7,9,10" },
  { "Minor Major 7th add 13", "3,7,9,11" },
  { "7b5", "4,6,10" },
  { "7#5", "4,8,10" },
  { "7b9", "1,4,7,10" },
  { "7#9", "3,4,7,10" },
  { "7#5b9", "1,4,8,10" },
  { "m7b5", "3,6,10" },
  { "m7#5", "3,8,10" },
  { "m7b9", "1,3,7,10" },
  { "9#11", "2,4,6,7,10" },
  { "9b13", "2,4,7,8,10" },
  { "6sus4", "5,7,9" },
  { "7sus4", "5,7,10" },
  { "Major 7th Sus4", "5,7,11" },
  { "9sus4", "2,5,7,10" },
  { "Major 9 Sus4", "2,5,7,11" } };

  protected static final String [][] SCALES =
  {
  { "Major", "2212221" },
  { "Minor", "2122221" },
  { "Harmonic Minor", "2122131" },
  { "Melodic Minor", "2122221" },
  { "Pentatonic Major", "23223" },
  { "Pentatonic Minor", "32232" },
  { "Pentatonic Blues", "32113" },
  { "Pentatonic Neutral", "2323" },
  { "Ionian", "2212221" },
  { "Aeolian", "32122122" },
  { "Dorian", "2122212" },
  { "Mixolydian", "2212212" },
  { "Phrygian", "1222122" },
  { "Lydian", "2221221" },
  { "Locrian", "1221222" },
  { "Dim half", "1212121" },
  { "Dim whole", "2121212" },
  { "Whole", "22222" },
  { "Augmented", "31313" },
  { "Chromatic", "111111111111" },
  { "Roumanian Minor", "2131212" },
  { "Spanish Gypsy", "1312122" },
  { "Blues", "321132" },
  { "Diatonic", "22323" },
  { "Double Harmonic", "1312131" },
  { "Eight Tone Spanish", "12111222" },
  { "Enigmatic", "1322211" },
  { "Leading Whole Tone", "222211" },
  { "Lydian Augmented", "2222121" },
  { "Neoploitan Major", "1222221" },
  { "Neopolitan Minor", "1222122" },
  { "Pelog", "12341" },
  { "Prometheus", "222312" },
  { "Prometheus Neopolitan", "132312" },
  { "Six Tone Symmetrical", "131313" },
  { "Super Locrian", "1212222" },
  { "Lydian Minor", "2221122" },
  { "Lydian Diminished", "2131122" },
  { "Nine Tone Scale", "211211121" },
  { "Auxiliary Diminished", "21212121" },
  { "Auxiliary Augmented", "222222" },
  { "Auxiliary Diminished Blues", "12121212" },
  { "Major Locrian", "2211222" },
  { "Overtone", "2221212" },
  { "Diminished Whole Tone", "1212222" },
  { "Pure Minor", "2122122" },
  { "Dominant 7th", "232212" } };
 
  protected LabeledInteger keyLabel;
  protected LabeledInteger chordLabel;
  protected LabeledInteger scaleLabel;

  @Override
  public ArrayList<LabeledInteger> getKeyLabels()
  {
    ArrayList<LabeledInteger> labels = new ArrayList<LabeledInteger>();
    LabeledInteger labeledInteger;

    for (int i = 0;i < KEYS.length;i ++)
    {
      labeledInteger = new LabeledInteger();
      labeledInteger.setLabel(KEYS[i][0]);
      labeledInteger.setIntValue(i);
      labels.add(labeledInteger);
    }
   
    return labels;
  }

  @Override
  public ArrayList<LabeledInteger> getChordLabels()
  {
    ArrayList<LabeledInteger> labels = new ArrayList<LabeledInteger>();
    LabeledInteger labeledInteger;

    for (int i = 0;i < CHORDS.length;i ++)
    {
      labeledInteger = new LabeledInteger();
      labeledInteger.setLabel(CHORDS[i][0]);
      labeledInteger.setIntValue(i);
      labels.add(labeledInteger);
    }
   
    return labels;
  }

  @Override
  public ArrayList<LabeledInteger> getScaleLabels()
  {
    ArrayList<LabeledInteger> labels = new ArrayList<LabeledInteger>();
    LabeledInteger labeledInteger;

    for (int i = 0;i < SCALES.length;i ++)
    {
      labeledInteger = new LabeledInteger();
      labeledInteger.setLabel(SCALES[i][0]);
      labeledInteger.setIntValue(i);
      labels.add(labeledInteger);
    }
   
    return labels;
  }

  @Override
  public void setKey(LabeledInteger keyLabel)
  {
    this.keyLabel = keyLabel;
  }

  @Override
  public void setChord(LabeledInteger chordLabel)
  {
    this.chordLabel = chordLabel;
  }
 
  @Override
  public void setScale(LabeledInteger scaleLabel)
  {
    this.scaleLabel = scaleLabel;
  }

  @Override
  public ArrayList<MusicScoreNote> getChord(int octave)
  {
    return new ArrayList<MusicScoreNote>();
  }

  @Override
  public ArrayList<MusicScoreNote> getScales(int octave)
  {
   
    ArrayList<MusicScoreNote> scales = new ArrayList<MusicScoreNote>();
   
    if ((keyLabel != null) && (keyLabel.getIntValue() >= 0) && (keyLabel.getIntValue() < KEYS.length) &&
      (scaleLabel != null) && (scaleLabel.getIntValue() >= 0) && (scaleLabel.getIntValue() < SCALES.length))
    {
      int keyIndex = keyLabel.getIntValue();
      int scaleIndex = scaleLabel.getIntValue();
      int note = 12 * octave;
     
      try
      {
        Integer i = new Integer(KEYS[keyIndex][1]);
        note += i.intValue();
      }
      catch (Exception e)
      {
        return scales;
      }
     
      byte [] offsets = SCALES[scaleIndex][1].getBytes();
     
      ArrayList<Integer> al = new ArrayList<Integer>();
     
      for (int i = 0;i < offsets.length;i ++)
      {
        if ((offsets[i] > '0') && (offsets[i] <= '9'))
        {
          MusicScoreNote msn = new MusicScoreNote();
          msn.setBeamToNextNote(0);
          msn.setChannel(1);
          msn.setDotted(0);
          msn.setFinger(0);
          msn.setMeasure(1);
          msn.setMeasureLength(1);
          msn.setMeasureSignature(1);
          msn.setMidiNote(note);
          msn.setStaff(1);
          msn.setVelocity(80);
         
          al.add(new Integer(note));
         
          note += ((int)offsets[i] - (int)'0');
         
          scales.add(msn);
        }
      }
     
      if (al.size() > 0)
        al.remove(al.size() - 1);
      while (al.size() > 1)
      {
        Integer i = al.remove(al.size() - 1);
       
        MusicScoreNote msn = new MusicScoreNote();
        msn.setBeamToNextNote(0);
        msn.setChannel(1);
        msn.setDotted(0);
        msn.setFinger(0);
        msn.setMeasure(1);
        msn.setMeasureLength(1);
        msn.setMeasureSignature(1);
        msn.setMidiNote(i.intValue());
        msn.setStaff(1);
        msn.setVelocity(80);
       
        scales.add(msn);
      }
    }
   
    return scales;
  }

}
TOP

Related Classes of music.lib.instruments.Piano

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.