/** * Returns a copy of the Score. * * @return Score a copy of the Score */ public Score copy() { // Trace.log(2, "copying Score of size " + size()); Score newScore = new Score(title, tempo); newScore.setMetre(metre[0], metre[1]); PartList newPartList = new PartList(partList.size()); ListIterator<MelodyPart> i = partList.listIterator(); while (i.hasNext()) newPartList.add(i.next().copy()); newScore.partList = newPartList; newScore.chordProg = chordProg.copy(); newScore.setChordInstrument(getChordInstrument()); newScore.setBassInstrument(getBassInstrument()); newScore.setBassMuted(getBassMuted()); newScore.setDrumMuted(getDrumMuted()); newScore.setChordMuted(getChordMuted()); newScore.setMelodyMuted(getMelodyMuted()); newScore.setMasterVolumeMuted(getMasterVolumeMuted()); newScore.setBassVolume(getBassVolume()); newScore.setDrumVolume(getDrumVolume()); newScore.setChordVolume(getChordVolume()); newScore.setMelodyVolume(getMelodyVolume()); newScore.setMasterVolume(getMasterVolume()); newScore.countInProg = countInProg == null ? null : countInProg.copy(); return newScore; }
/** * Adds the specified number of empty Parts to the Score. * * @param parts the number of Parts to add */ public void addParts(int parts) { // Trace.log(0, "adding " + parts + " new parts to score"); for (int i = 0; i < parts; i++) { MelodyPart mp = new MelodyPart(length); if (partList.size() > 0) { mp.setInstrument(partList.get(0).getInstrument()); } partList.add(mp); } }
/** * Returns the Note at the specified index across all parts * * @param index the index of the Note to get * @return the Note at the specified index */ public Note getNote(int index) { int sizeOfPart = chordProg.size(); int partNum = index / sizeOfPart; int indexWithinPart = index % sizeOfPart; MelodyPart part = partList.get(partNum); return part.getNote(indexWithinPart); }
public void dumpMelody(PrintStream out) { ListIterator<MelodyPart> i = partList.listIterator(); while (i.hasNext()) { i.next().dump(out); out.println(); } }
/** * Adds the specified Part to the Score. * * @param part Part to add */ public void addPart(MelodyPart part) { Trace.log(2, "adding existing melody part to score"); if (length < part.size()) { setLength(part.size()); } partList.add(part); }
/** * Sets the key signature of the Score * * @param keySig the key signature to set the Score to */ public void setKeySignature(int keySig) { Trace.log(2, "setting key signature of score to " + keySig); this.keySig = keySig; chordProg.setKeySignature(keySig); ListIterator<MelodyPart> i = partList.listIterator(); while (i.hasNext()) { i.next().setKeySignature(keySig); } }
/** * Sets the metre of the Score metre is now represented in most places as a 2-elt array, where the * first element is the top of the time signature, and the second element is the bottom. */ public void setMetre(int top, int bottom) { metre[0] = top; metre[1] = bottom; chordProg.setMetre(top, bottom); ListIterator<MelodyPart> i = partList.listIterator(); while (i.hasNext()) { i.next().setMetre(top, bottom); } }
/** * Creates and returns a String representation of the Score. * * @return String the Score as a String */ public String toString() { String scoreData = "Score: " + '\n'; scoreData += "ChordProg: " + '\n' + chordProg.toString() + '\n'; ListIterator<MelodyPart> i = partList.listIterator(); while (i.hasNext()) { scoreData += "Part " + i.nextIndex() + ":" + '\n' + i.next().toString() + '\n'; } return scoreData; }
/** * Writes the Score to the BufferedWriter passed to this method in Leadsheet notation. * * @param out a BufferedWriter to save the score onto */ public void saveLeadsheet(BufferedWriter out) throws IOException { Chord.initSaveToLeadsheet(); chordProg.saveLeadsheet(out, "chords"); out.newLine(); ListIterator<MelodyPart> i = partList.listIterator(); while (i.hasNext()) { ((MelodyPart) i.next()).saveLeadsheet(out, "melody"); out.newLine(); } }
/** Calls makeSwing on each individual Part. */ public void makeSwing() { ListIterator<MelodyPart> i = partList.listIterator(); while (i.hasNext()) { MelodyPart m = i.next(); Style style = chordProg.getStyle(); if (style != null) { m.setSwing(style.getSwing()); } m.makeSwing(chordProg.getSectionInfo()); } }
/** * Return first Note in melody, or null if there is no note * * @return */ public Note getFirstNote() { ListIterator<MelodyPart> i = partList.listIterator(); while (i.hasNext()) { Note note = i.next().getFirstNote(); if (note != null) { return note; } } return null; // TEMP! }
public void checkLength() { int maxLength = length; if (chordProg.size() > maxLength) maxLength = chordProg.size(); ListIterator<MelodyPart> i = partList.listIterator(); while (i.hasNext()) { MelodyPart part = i.next(); if (part.size() > maxLength) maxLength = part.size(); } setLength(maxLength); }
public void setLength(int newLength) { if (newLength == length) { return; // avoid unnecessary setting } Trace.log(3, "setting score length to " + newLength); length = newLength; if (chordProg != null) { chordProg.setSize(length); } Iterator<MelodyPart> i = partList.listIterator(); while (i.hasNext()) { i.next().setSize(length); } }
public int getActiveBarsInChorus() { int activeBars = chordProg.getActiveBars(); ListIterator<MelodyPart> i = partList.listIterator(); while (i.hasNext()) { int barsInChorus = i.next().getActiveBars(); if (barsInChorus > activeBars) { activeBars = barsInChorus; } } // System.out.println("active bars = " + activeBars); return activeBars; // TEMP! }
public void testBuilder() throws Exception { MockRequest request = new MockRequest(); request.setTarget("/path?a=query_A&b=query_B&c=query_C&d=query_D"); request.setContentType("application/x-www-form-urlencoded"); request.setContent("a=post_A&c=post_C&e=post_E"); MockBody body = new MockBody(); MockEntity entity = new MockEntity(body); FormCreator builder = new FormCreator(request, entity); PartList list = body.getParts(); list.add(new MockPart("a", "part_A", false)); list.add(new MockPart("b", "part_B", false)); list.add(new MockPart("c", "part_C", false)); list.add(new MockPart("f", "part_F", true)); list.add(new MockPart("g", "part_G", false)); Form form = builder.getInstance(); assertEquals(form.getAll("a").size(), 3); assertEquals(form.getAll("b").size(), 2); assertEquals(form.getAll("c").size(), 3); assertEquals(form.getAll("e").size(), 1); assertEquals(form.getPart("a").getContent(), "part_A"); assertEquals(form.getPart("b").getContent(), "part_B"); assertEquals(form.getPart("c").getContent(), "part_C"); assertEquals(form.getPart("f").getContent(), "part_F"); assertEquals(form.getPart("g").getContent(), "part_G"); assertEquals(form.get("a"), "query_A"); assertEquals(form.get("b"), "query_B"); assertEquals(form.get("c"), "query_C"); assertEquals(form.get("d"), "query_D"); assertEquals(form.get("e"), "post_E"); assertEquals(form.get("f"), null); assertEquals(form.get("g"), "part_G"); }
/** * Creates and returns a MIDI sequence from the Score. Calls Part.render on each Part and (for * now) creates a new channel for each Part. This means that you can only have 16 Parts, which * should be changed in the future. * * @param ppqn the resolution for the Sequence * @return Sequence the MIDI render */ public Sequence render(short ppqn, int transposition, boolean useDrums, int endLimitIndex) throws InvalidMidiDataException { // to trace sequencing // System.out.println("Score: render, start 0, endLimitIndex = " + endLimitIndex); MidiSequence seq = new MidiSequence(ppqn); long time = 0; if (countInProg != null) { // Handle count-in render int len = getCountInOffset(); if (endLimitIndex != ENDSCORE) { endLimitIndex += len; } time = countInProg.render(seq, time, seq.getChordTrack(), 0, true, endLimitIndex); } // System.out.println("time = " + time); ListIterator<MelodyPart> i = partList.listIterator(); while (i.hasNext() && Style.limitNotReached(time, endLimitIndex)) { // render the chord progression in parallel with each melody chorus long melTime = i.next() .render( seq, ImproVisor.getMelodyChannel(), time, seq.getMelodyTrack(), transposition, endLimitIndex); long chTime = chordProg.render(seq, time, seq.getChordTrack(), transposition, useDrums, endLimitIndex); time = Math.max(melTime, chTime); } // System.out.println("seq = " + seq); // Find the longest track, and put a Stop event at the end of it MidiSynth.endSequence(seq.getSequence()); // Trace.log(0, "done rendering, tickLength = " + seq.getSequence().getTickLength()); // System.out.println("countIn size = " + getCountInOffset()); return seq.getSequence(); }
public int getTotalLength() { return length * partList.size(); }
/** * Deletes the part at the specified index * * @param index the index of the Part to delete */ public void delPart(int index) { if (index >= 0 && index < partList.size()) partList.remove(index); }
/** * Clear all melody parts in the score * * @param index the index of the Part to delete */ public void clearParts() { int numberParts = partList.size(); partList = new PartList(numberParts); addParts(numberParts); }
/** * Moves part from specified index 1 to specified index 2 * * @param index1 the index of the Part to be moved * @param index2 destination of moved Part */ public void movePart(int index1, int index2) { partList.move(index1, index2); }
public int size() { checkLength(); return partList.size(); }
/** * Returns the Part at the specified index. * * @param index the index of the Part to get * @return Part the Part at the specified index */ public MelodyPart getPart(int index) { return partList.get(index); }
/** * Returns a PartListIterator * * @return PartListIterator iterating the parts */ public ListIterator getPartIterator() { return partList.listIterator(); }