public static void midi(Phrase paramPhrase, String paramString) { Part localPart = new Part(); localPart.addPhrase(paramPhrase); Score localScore = new Score("Score of " + paramPhrase.getTitle()); localScore.addPart(localPart); midi(localScore, paramString); }
public static void midi(CPhrase paramCPhrase) { Part localPart = new Part(); localPart.addCPhrase(paramCPhrase); Score localScore = new Score("Score of " + paramCPhrase.getTitle()); localScore.addPart(localPart); midi(localScore, paramCPhrase.getTitle() + ".mid"); }
public static void main(String[] args) { Phrase phr = new Phrase(); // create a random walk int pitch = 60; for (int i = 0; i < 12; i++) { Note n = new Note(pitch += (int) (Math.random() * 8 - 4), SQ * (int) (Math.random() * 2 + 1)); phr.addNote(n); } // repeat the whole thing three times Mod.repeat(phr, 3); // see the result at this stage View.show(phr); // repeat beats 2 - 4 three times Mod.repeat(phr, 3, 2.0, 4.0); // see the result of this change View.show(phr, 50, 50); // hear the result Part p = new Part(); Score s = new Score(); p.addPhrase(phr); s.addPart(p); s.setTempo(140.0); Play.midi(s, false); // false so that it doesn't close everything, the view.show() window // in particular Write.midi(s, "Repeat.mid"); }
public static void au(CPhrase paramCPhrase, Instrument[] paramArrayOfInstrument) { Part localPart = new Part(); localPart.addCPhrase(paramCPhrase); Score localScore = new Score("Score of " + paramCPhrase.getTitle()); localScore.addPart(localPart); au(localScore, paramCPhrase.getTitle() + ".au", paramArrayOfInstrument); }
public static void xml(Phrase paramPhrase) { Part localPart = new Part(); localPart.addPhrase(paramPhrase); Score localScore = new Score("Score of " + paramPhrase.getTitle()); localScore.addPart(localPart); xml(localScore, paramPhrase.getTitle() + ".xml"); }
public static void au(Phrase paramPhrase, String paramString, Instrument paramInstrument) { Part localPart = new Part(); localPart.addPhrase(paramPhrase); Score localScore = new Score("Score of " + paramPhrase.getTitle()); localScore.addPart(localPart); Instrument[] arrayOfInstrument = {paramInstrument}; au(localScore, paramString, arrayOfInstrument); }
public void transform() { // Bird for (int i = 0; i < bird_num; i++) { note = new Note( bird_jnote[i].pitch, (double) bird_jnote[i].duration / 120, bird_jnote[i].velocity); bird_phrase.addNote(note); } bird_phrase.setStartTime(start_time * 4.0); bird_part.empty(); bird_part.addPhrase(bird_phrase); }
/** Convert a SMF into the jMusic data type */ @SuppressWarnings("rawtypes") public static void SMFToScore(Score score, SMFTools smf) { Enumeration<Track> en = smf.getTrackList().elements(); // Go through tracks while (en.hasMoreElements()) { Part part = new Part(); Track smfTrack = en.nextElement(); Vector evtList = smfTrack.getEvtList(); Vector phrVct = new Vector(); sortEvents(evtList, phrVct, smf, part); for (int i = 0; i < phrVct.size(); i++) { part.addPhrase((Phrase) phrVct.elementAt(i)); } score.addPart(part); score.clean(); } }
private static Score adjustTempo(Score paramScore) { Enumeration localEnumeration1 = paramScore.getPartList().elements(); double d1 = 60.0D / paramScore.getTempo(); while (localEnumeration1.hasMoreElements()) { Part localPart = (Part) localEnumeration1.nextElement(); double d2 = d1; if (localPart.getTempo() != 0.0D) { d2 = 60.0D / localPart.getTempo(); } Enumeration localEnumeration2 = localPart.getPhraseList().elements(); while (localEnumeration2.hasMoreElements()) { Phrase localPhrase = (Phrase) localEnumeration2.nextElement(); Enumeration localEnumeration3 = localPhrase.getNoteList().elements(); while (localEnumeration3.hasMoreElements()) { Note localNote = (Note) localEnumeration3.nextElement(); localNote.setRhythmValue(localNote.getRhythmValue() * d2); localNote.setDuration(localNote.getDuration() * d2); } } } return paramScore; }
@SuppressWarnings("rawtypes") private static void sortEvents(Vector evtList, Vector phrVct, SMFTools smf, Part part) { double startTime = 0.0; double[] currentLength = new double[100]; Note[] curNote = new Note[100]; int phrIndex = 0; // Go through evts for (int i = 0; i < evtList.size(); i++) { Event evt = (Event) evtList.elementAt(i); startTime += (double) evt.getTime() / (double) smf.getPPQN(); if (evt.getID() == 007) { PChange pchg = (PChange) evt; part.setInstrument(pchg.getValue()); // if this event is a NoteOn event go on } else if (evt.getID() == 005) { NoteOn noteOn = (NoteOn) evt; part.setChannel(noteOn.getMidiChannel()); short pitch = noteOn.getPitch(); int dynamic = noteOn.getVelocity(); short midiChannel = noteOn.getMidiChannel(); // if you're a true NoteOn if (dynamic > 0) { noteOn( phrIndex, curNote, smf, i, currentLength, startTime, phrVct, midiChannel, pitch, dynamic, evtList); } } } }
@Override public void handleScore(Score score, ScoreContext ctx) { Part part = ctx.getParts().get(PartType.ARPEGGIO); if (part == null) { return; } Part mainPart = ctx.getParts().get(PartType.MAIN); double currentMeasureSize = 0; double normalizedMeasureSize = ctx.getNormalizedMeasureSize(); SpecialNoteType specialNoteType = null; for (Phrase phrase : mainPart.getPhraseArray()) { if (Chance.test(20)) { // change the special note type if (Chance.test(60)) { // to a new value specialNoteType = SpecialNoteType.values()[random.nextInt(SpecialNoteType.values().length)]; } else { // reset specialNoteType = null; } } Phrase arpeggioPhrase = new Phrase(); arpeggioPhrase.setTitle("Arpeggio phrase"); Scale currentScale = ((ExtendedPhrase) phrase).getScale(); // get copies of the static ones, so that we can shuffle them without affecting the original List<Chord> scaleChords = new ArrayList<Chord>(ChordUtils.chords.get(currentScale)); Collections.shuffle(scaleChords, random); Note[] notes = phrase.getNoteArray(); List<ToneType> firstToneTypes = new ArrayList<>(); int measures = 0; Note[] currentNotes = null; boolean useTwoNoteChords = Chance.test(14); Chord chord = null; for (int i = 0; i < notes.length; i++) { Note currentNote = notes[i]; if (currentNote.getRhythmValue() == 0) { continue; // rhythm value is 0 for the first notes of a (main-part) chord. So progress to // the next } boolean lastMeasure = measures == ctx.getMeasures() - 1; if (currentMeasureSize == 0 && !currentNote.isRest() && !lastMeasure) { boolean preferStable = ToneResolver.needsContrastingChord(firstToneTypes, ToneGroups.UNSTABLE); boolean preferUnstable = ToneResolver.needsContrastingChord(firstToneTypes, ToneGroups.STABLE); // change the chord only in 1/4 of the cases if (currentNotes == null || Chance.test(25)) { // no alternatives for now - only 3-note chords Chord previous = chord; chord = ChordUtils.getChord( ctx, currentNote.getPitch(), previous, scaleChords, scaleChords, scaleChords, preferStable, preferUnstable); if (chord != null) { int[] pitches = chord.getPitches(); // remove the middle note in some cases (but make it possible to have three-note // chords in a generally two-note phrase) if (pitches.length == 3 && useTwoNoteChords && Chance.test(90)) { pitches = ArrayUtils.remove(pitches, 1); } int count = Chance.test(90) ? (Chance.test(80) ? 4 : 2) : (Chance.test(80) ? 3 : 5); currentNotes = new Note[count]; double length = normalizedMeasureSize / count; for (int k = 0; k < count; k++) { Note note = NoteFactory.createNote(pitches[random.nextInt(pitches.length)], length); note.setDynamic( InstrumentGroups.getInstrumentSpecificDynamics( 65 + random.nextInt(10), part.getInstrument())); if (specialNoteType != null) { note.setDuration(note.getRhythmValue() * specialNoteType.getValue()); } currentNotes[k] = note; } } } if (Chance.test(85) && currentNotes != null) { for (Note note : currentNotes) { arpeggioPhrase.addNote(note); } } else { arpeggioPhrase.addRest(new Rest(normalizedMeasureSize)); } } else if (currentMeasureSize == 0 && (currentNote.isRest() || lastMeasure)) { arpeggioPhrase.addRest(new Rest(normalizedMeasureSize)); } currentMeasureSize += currentNote.getRhythmValue(); if (currentMeasureSize >= normalizedMeasureSize) { currentMeasureSize = 0; measures++; } } part.add(arpeggioPhrase); } }
public ParseMidiSmart() { FileDialog fd; Frame f = new Frame(); // open a MIDI file fd = new FileDialog(f, "Open MIDI file or choose cancel to" + " finish.", FileDialog.LOAD); fd.show(); // break out when user presses cancel if (fd.getFile() == null) return; // SMF smf = new SMF(); // try { // smf.read(new FileInputStream(new File(fd.getDirectory()+fd.getFile()))); // } catch (IOException e) { // e.printStackTrace(); // } // Vector vector = smf.getTrackList(); // for (int i = 0; i < vector.size(); i++) { // Score score = new Score(); // MidiParser.SMFToScore(score, smf); // System.out.println(); // } Read.midi(s, fd.getDirectory() + fd.getFile()); s.setTitle(fd.getFile()); // try { // System.out.println(MidiSystem.getMidiFileFormat(fd.getFiles()[0])); // } catch (InvalidMidiDataException e) { // e.printStackTrace(); // } catch (IOException e) { // e.printStackTrace(); // } Score scoreToWrite = null; for (int i = 0; i < s.getSize(); i++) { scoreToWrite = new Score(); scoreToWrite.add(s.getPart(i)); scoreToWrite.setTempo(200); Write.midi(scoreToWrite, String.format(fd.getFile() + "%d.mid", i)); Part part = s.getPart(i); for (int j = 0; j < part.getSize(); j++) { Phrase phrase = part.getPhrase(j); for (int ii = 0; ii < phrase.getSize(); ii++) { System.out.println(phrase.getNote(ii).getNote()); } } } // //keep track of the number of scores analysed // scoreCount++; // //reset melody length // int tempLength = 0; // // iterate through each note // //find the highest and lowest notes // Enumeration enum1 = s.getPartList().elements(); // while(enum1.hasMoreElements()){ // Part nextPt = (Part)enum1.nextElement(); // Enumeration enum2 = // nextPt.getPhraseList().elements(); // while(enum2.hasMoreElements()){ // Phrase nextPhr = // (Phrase)enum2.nextElement(); // Enumeration enum3 = // nextPhr.getNoteList().elements(); // while(enum3.hasMoreElements()){ // Note nextNote = // (Note)enum3.nextElement(); // int pitch = nextNote.getPitch(); // //check range // pitchRange(pitch); // double rv = // nextNote.getRhythmValue(); // //check rhythmic values // rhythmRange(rv); // //check meldoy length // tempLength++; // //check direction // upOrDown(pitch); // } // } // } // update length extremes // musicLength(tempLength); // //output the current stats // System.out.print(PRE_TEXT); // System.out.println("STATS after "+scoreCount+ // " files. Last score called "+ // s.getTitle()); // System.out.print(PRE_TEXT); // System.out.println("Lowest note is "+lowNote); // System.out.println("Highest note is "+highNote); // System.out.println("---------------------------------"); // System.out.println("Shortest note is "+shortestRhythm); // System.out.println("Longest note is "+longestRhythm); // System.out.println("---------------------------------"); // System.out.println("Smallest score contains "+ // shortLength+" notes"); // System.out.println("Largest score contains "+longLength+ // " notes"); // System.out.println("---------------------------------"); // System.out.println("Upward movements were "+ascending); // System.out.println("Downward movements were "+ // descending); // System.out.println("---------------------------------"); }
public static void jm(Part paramPart) { Score localScore = new Score("Score of " + paramPart.getTitle()); localScore.addPart(paramPart); jm(localScore, paramPart.getTitle() + ".jm"); }
public static void au(Part paramPart, String paramString, Instrument[] paramArrayOfInstrument) { Score localScore = new Score("Score of " + paramPart.getTitle()); localScore.addPart(paramPart); au(localScore, paramString, paramArrayOfInstrument); }
public static void midi(Part paramPart, String paramString) { Score localScore = new Score("Score of " + paramPart.getTitle()); localScore.addPart(paramPart); midi(localScore, paramString); }
public void play() { bird_part.setTempo(120); // Default: 60 Play.midi(bird_part); }
public static void xml(Part paramPart) { Score localScore = new Score("Score of " + paramPart.getTitle()); localScore.addPart(paramPart); xml(localScore, paramPart.getTitle() + ".xml"); }