-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 87abfd6
Showing
16 changed files
with
1,133 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.DS_Store | ||
/bin/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>ex27-music-starting</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package music; | ||
|
||
/** | ||
* Concat represents two pieces of music played one after the other. | ||
*/ | ||
public class Concat implements Music { | ||
|
||
private final Music first; | ||
private final Music second; | ||
|
||
private void checkRep() { | ||
assert first != null; | ||
assert second != null; | ||
} | ||
|
||
/** | ||
* Make a Music sequence that plays m1 followed by m2. | ||
* @param m1 music to play first | ||
* @param m2 music to play second | ||
*/ | ||
public Concat(Music m1, Music m2) { | ||
this.first = m1; | ||
this.second = m2; | ||
checkRep(); | ||
} | ||
|
||
/** | ||
* @return first piece in this concatenation | ||
*/ | ||
public Music first() { | ||
return first; | ||
} | ||
|
||
/** | ||
* @return second piece in this concatenation | ||
*/ | ||
public Music second() { | ||
return second; | ||
} | ||
|
||
/** | ||
* @return duration of this concatenation | ||
*/ | ||
@Override | ||
public double duration() { | ||
return first.duration() + second.duration(); | ||
} | ||
|
||
/** | ||
* Play this concatenation. | ||
*/ | ||
@Override | ||
public void play(SequencePlayer player, double atBeat) { | ||
first.play(player, atBeat); | ||
second.play(player, atBeat + first.duration()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
final int prime = 31; | ||
return first.hashCode() + prime * second.hashCode(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) return true; | ||
if (obj == null) return false; | ||
if (getClass() != obj.getClass()) return false; | ||
|
||
final Concat other = (Concat) obj; | ||
return first.equals(other.first) && second.equals(other.second); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return first + " " + second; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
package music; | ||
|
||
/** | ||
* Instrument represents a musical instrument. | ||
* | ||
* These instruments are the 128 standard General MIDI Level 1 instruments. | ||
* See: http://www.midi.org/about-midi/gm/gm1sound.shtml | ||
*/ | ||
public enum Instrument { | ||
// Order is important in this enumeration because an instrument's | ||
// position must correspond to its MIDI program number. | ||
|
||
PIANO, | ||
BRIGHT_PIANO, | ||
ELECTRIC_GRAND, | ||
HONKY_TONK_PIANO, | ||
ELECTRIC_PIANO_1, | ||
ELECTRIC_PIANO_2, | ||
HARPSICHORD, | ||
CLAVINET, | ||
|
||
CELESTA, | ||
GLOCKENSPIEL, | ||
MUSIC_BOX, | ||
VIBRAPHONE, | ||
MARIMBA, | ||
XYLOPHONE, | ||
TUBULAR_BELL, | ||
DULCIMER, | ||
|
||
HAMMOND_ORGAN, | ||
PERC_ORGAN, | ||
ROCK_ORGAN, | ||
CHURCH_ORGAN, | ||
REED_ORGAN, | ||
ACCORDION, | ||
HARMONICA, | ||
TANGO_ACCORDION, | ||
|
||
NYLON_STR_GUITAR, | ||
STEEL_STRING_GUITAR, | ||
JAZZ_ELECTRIC_GTR, | ||
CLEAN_GUITAR, | ||
MUTED_GUITAR, | ||
OVERDRIVE_GUITAR, | ||
DISTORTION_GUITAR, | ||
GUITAR_HARMONICS, | ||
|
||
ACOUSTIC_BASS, | ||
FINGERED_BASS, | ||
PICKED_BASS, | ||
FRETLESS_BASS, | ||
SLAP_BASS_1, | ||
SLAP_BASS_2, | ||
SYN_BASS_1, | ||
SYN_BASS_2, | ||
|
||
VIOLIN, | ||
VIOLA, | ||
CELLO, | ||
CONTRABASS, | ||
TREMOLO_STRINGS, | ||
PIZZICATO_STRINGS, | ||
ORCHESTRAL_HARP, | ||
TIMPANI, | ||
|
||
ENSEMBLE_STRINGS, | ||
SLOW_STRINGS, | ||
SYNTH_STRINGS_1, | ||
SYNTH_STRINGS_2, | ||
CHOIR_AAHS, | ||
VOICE_OOHS, | ||
SYN_CHOIR, | ||
ORCHESTRA_HIT, | ||
|
||
TRUMPET, | ||
TROMBONE, | ||
TUBA, | ||
MUTED_TRUMPET, | ||
FRENCH_HORN, | ||
BRASS_ENSEMBLE, | ||
SYN_BRASS_1, | ||
SYN_BRASS_2, | ||
|
||
SOPRANO_SAX, | ||
ALTO_SAX, | ||
TENOR_SAX, | ||
BARITONE_SAX, | ||
OBOE, | ||
ENGLISH_HORN, | ||
BASSOON, | ||
CLARINET, | ||
|
||
PICCOLO, | ||
FLUTE, | ||
RECORDER, | ||
PAN_FLUTE, | ||
BOTTLE_BLOW, | ||
SHAKUHACHI, | ||
WHISTLE, | ||
OCARINA, | ||
|
||
SYN_SQUARE_WAVE, | ||
SYN_SAW_WAVE, | ||
SYN_CALLIOPE, | ||
SYN_CHIFF, | ||
SYN_CHARANG, | ||
SYN_VOICE, | ||
SYN_FIFTHS_SAW, | ||
SYN_BRASS_AND_LEAD, | ||
|
||
FANTASIA, | ||
WARM_PAD, | ||
POLYSYNTH, | ||
SPACE_VOX, | ||
BOWED_GLASS, | ||
METAL_PAD, | ||
HALO_PAD, | ||
SWEEP_PAD, | ||
|
||
ICE_RAIN, | ||
SOUNDTRACK, | ||
CRYSTAL, | ||
ATMOSPHERE, | ||
BRIGHTNESS, | ||
GOBLINS, | ||
ECHO_DROPS, | ||
SCI_FI, | ||
|
||
SITAR, | ||
BANJO, | ||
SHAMISEN, | ||
KOTO, | ||
KALIMBA, | ||
BAG_PIPE, | ||
FIDDLE, | ||
SHANAI, | ||
|
||
TINKLE_BELL, | ||
AGOGO, | ||
STEEL_DRUMS, | ||
WOODBLOCK, | ||
TAIKO_DRUM, | ||
MELODIC_TOM, | ||
SYN_DRUM, | ||
REVERSE_CYMBAL, | ||
|
||
GUITAR_FRET_NOISE, | ||
BREATH_NOISE, | ||
SEASHORE, | ||
BIRD, | ||
TELEPHONE, | ||
HELICOPTER, | ||
APPLAUSE, | ||
GUNSHOT, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package music; | ||
|
||
/** | ||
* Music represents a piece of music played by multiple instruments. | ||
*/ | ||
public interface Music { | ||
|
||
/** | ||
* @return total duration of this piece in beats | ||
*/ | ||
double duration(); | ||
|
||
/** | ||
* Play this piece. | ||
* @param player player to play on | ||
* @param atBeat when to play | ||
*/ | ||
void play(SequencePlayer player, double atBeat); | ||
|
||
} |
Oops, something went wrong.