Class Phrase
- All Implemented Interfaces:
Serializable,Iterable<NoteEvent>,Collection<NoteEvent>,NavigableSet<NoteEvent>,Set<NoteEvent>,SortedSet<NoteEvent>
- Direct Known Subclasses:
SizedPhrase,SourcePhrase
Fire change events when modified, see the PROP_* values. Fire undoable events.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringNoteEvent client property set when new NoteEvents are created from existing ones.static final StringnewValue=collection of added NoteEvents.static final StringSame as PROP_NOTES_ADDED except this notifies an intermediate operation: a final non-adjusting operation will occur later.static final StringnewValue=a map with keys=OldNoteEvents and values=NewNoteEventsstatic final StringSame as PROP_NOTES_MOVED except this notifies an intermediate operation: a final non-adjusting operation will occur later.static final StringnewValue=collection of removed NoteEvents.static final StringSame as PROP_NOTES_REMOVED except this notifies an intermediate operation: a final non-adjusting operation will occur later.static final StringFired when a new NoteEvent replaced another one.static final StringSame as PROP_NOTES_REPLACED except this notifies an intermediate operation: a final non-adjusting operation will occur later. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdd a NoteEvent.booleanAdd a NoteEvent.voidClone NoteEvents from the specified Phrase and add them to this Phrase.voidAdd a Phrase from the specified Phrase.booleanaddAll(Collection<? extends NoteEvent> collection) Add several NoteEvents.booleanaddAll(Collection<? extends NoteEvent> collection, boolean isAdjusting) Add several NoteEvents.voidvoidvoidclear()clone()A deep clone: returned phrase contains clones of the original NoteEvents.Comparator<? super NoteEvent>booleanbooleancontainsAll(Collection<?> c) voiddump()booleanequalsNearPosition(Phrase p, float nearWindow) Compare the notes (pitch, velocity), but tolerate slight differences in position and duration.first()Get the beat range from start of first note to end of last note.static NoteEventgetCeilNote(float pos) Create a NoteEvent limit to be used as a ceil/max position as per NoteEvent.compareTo().intstatic NoteEventgetFloorNote(float pos) Create a NoteEvent limit to be used as a floor/min position as per NoteEvent.compareTo().floatgetNotes()getNotes(Predicate<NoteEvent> tester, FloatRange range, boolean excludeUpperBound) Get the NoteEvents which match the tester and whose start position is in the [posFrom:posTo] or [posFrom:posTo[ range.Get a new Phrase with only filtered notes processed by the specified mapper.Get a new phrase with all notes changed.Get a new phrase with notes velocity changed.static booleanisAdjustingEvent(String propertyName) Check if propertyName corresponds to one of the adjusting events PROP_NOTES_ADDED_ADJUSTING, PROP_NOTES_REMOVED_ADJUSTING etc.booleanisDrums()Check if the phrase is for non-melodic instruments.booleanisEmpty()iterator()last()static PhraseCreate a Phrase from the specified string.Move a NoteEvent.Move a NoteEvent.Move NoteEvents.pollLast()voidTransform the notes which satisfy the specified tester.voidChange the pitch of all notes of this Phrase.voidChange the velocity of all notes of this Phrase.booleanRemove a NoteEvent.booleanRemove a NoteEvent.booleanremoveAll(Collection<?> collection) Remove elements.booleanremoveAll(Collection<?> collection, boolean isAdjusting) voidvoidvoidReplace a NoteEvent by another one.voidReplace a NoteEvent by another one.voidreplaceAll(Map<NoteEvent, NoteEvent> mapOldNew, boolean isAdjusting) Replace NoteEvents.booleanretainAll(Collection<?> c) static StringSave the specified Phrase as a string.voidshiftAllEvents(float shiftInBeats) Shift all events.intsize()subSet(FloatRange range, boolean excludeUpperBound) A subset of all notes in the specified range.Object[]toArray()<T> T[]toArray(T[] a) toString()Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.SortedSet
spliterator
-
Field Details
-
PROP_NOTES_ADDED
newValue=collection of added NoteEvents.- See Also:
-
PROP_NOTES_ADDED_ADJUSTING
Same as PROP_NOTES_ADDED except this notifies an intermediate operation: a final non-adjusting operation will occur later.- See Also:
-
PROP_NOTES_REMOVED
newValue=collection of removed NoteEvents.- See Also:
-
PROP_NOTES_REMOVED_ADJUSTING
Same as PROP_NOTES_REMOVED except this notifies an intermediate operation: a final non-adjusting operation will occur later.- See Also:
-
PROP_NOTES_MOVED
newValue=a map with keys=OldNoteEvents and values=NewNoteEvents- See Also:
-
PROP_NOTES_MOVED_ADJUSTING
Same as PROP_NOTES_MOVED except this notifies an intermediate operation: a final non-adjusting operation will occur later.- See Also:
-
PROP_NOTES_REPLACED
Fired when a new NoteEvent replaced another one.newValue=a map with keys=OldNoteEvents and values=NewNoteEvents
- See Also:
-
PROP_NOTES_REPLACED_ADJUSTING
Same as PROP_NOTES_REPLACED except this notifies an intermediate operation: a final non-adjusting operation will occur later.- See Also:
-
PARENT_NOTE
NoteEvent client property set when new NoteEvents are created from existing ones.- See Also:
-
-
Constructor Details
-
Phrase
public Phrase(int channel) Construct a new melodic phrase.- Parameters:
channel-
-
Phrase
public Phrase(int channel, boolean isDrums) Construct a new melodic or drums phrase.- Parameters:
channel-isDrums-
-
-
Method Details
-
isDrums
public boolean isDrums()Check if the phrase is for non-melodic instruments.- Returns:
-
replace
Replace a NoteEvent by another one.Same as removing old + adding new, except it only fires a PROP_NOTES_REPLACED change event.
- Parameters:
oldNe-newNe-
-
replace
Replace a NoteEvent by another one.Same as removing old + adding new, except it only fires a PROP_NOTES_REPLACED or PROP_NOTES_REPLACED_ADJUSTING change event.
- Parameters:
oldNe-newNe-isAdjusting- If true fire a PROP_NOTES_REPLACED_ADJUSTING instead of PROP_NOTES_REPLACED
-
replaceAll
Replace NoteEvents.Same as removing old + adding new, except it only fires a PROP_NOTES_REPLACED or PROP_NOTES_REPLACED_ADJUSTING change event.
- Parameters:
mapOldNew- A map where keys=oldNoteEvents and values=newNoteEventsisAdjusting- If true fire a PROP_NOTES_REPLACED_ADJUSTING instead of PROP_NOTES_REPLACED
-
move
Move a NoteEvent.Same as removing the old one + adding copy at new position , except it only fires a PROP_NOTES_MOVED.
- Parameters:
ne- Must belong to this phrasenewPos-- Returns:
- The new NoteEvent at newPos. Return ne if position unchanged.
-
move
Move a NoteEvent.Same as removing the old one + adding copy at new position , except it only fires a PROP_NOTES_MOVED or PROP_NOTES_MOVED_ADJUSTING
- Parameters:
ne- Must belong to this phrasenewPos-isAdjusting- If true fire a PROP_NOTES_MOVED_ADJUSTING instead of PROP_NOTES_MOVED- Returns:
- The new NoteEvent at newPos. Return ne if position unchanged.
-
moveAll
Move NoteEvents.Same as removing the old one + adding copy at new position , except it only fires a PROP_NOTES_MOVED or PROP_NOTES_MOVED_ADJUSTING change event.
- Parameters:
mapNoteNewPos- A map where keys=NoteEvents and values=new positionsisAdjusting- If true fire a PROP_NOTES_MOVED_ADJUSTING instead of PROP_NOTES_MOVED- Returns:
- The created NoteEvents at new positions.
-
add
Clone NoteEvents from the specified Phrase and add them to this Phrase.- Parameters:
p-
-
add
Add a Phrase from the specified Phrase.- Parameters:
p-doNotCloneNotes- If true directly add the NoteEvents without cloning them -so client properties might be changed.
-
clone
A deep clone: returned phrase contains clones of the original NoteEvents.- Returns:
-
equalsNearPosition
Compare the notes (pitch, velocity), but tolerate slight differences in position and duration.- Parameters:
p-nearWindow- Used to compare NoteEvents position and duration.- Returns:
- See Also:
-
NoteEvent#equalsNearPosition(org.jjazz.phrase.api.NoteEvent, float)
-
getChannel
public int getChannel()- Returns:
- 1-16
-
getNotes
-
getNotes
public List<NoteEvent> getNotes(Predicate<NoteEvent> tester, FloatRange range, boolean excludeUpperBound) Get the NoteEvents which match the tester and whose start position is in the [posFrom:posTo] or [posFrom:posTo[ range.- Parameters:
tester-range-excludeUpperBound-- Returns:
-
getBeatRange
Get the beat range from start of first note to end of last note.- Returns:
- FloatRange.EMPTY_FLOAT_RANGE if phrase is empty.
-
getProcessedPhrase
Get a new Phrase with only filtered notes processed by the specified mapper.Notes of the returned phrase will have their PARENT_NOTE client property set to:
- source note's PARENT_NOTE client property if this property is not null, or
- the source note from this phrase.- Parameters:
tester-mapper-- Returns:
-
processNotes
Transform the notes which satisfy the specified tester.Once the mapper has produced a new NoteEvent, the old one is removed and the new one is added. Fire the PROP_NOTES_REPLACED change event.
- Parameters:
tester- Process the NoteEvent which satisfy this tester.mapper- Transform each NoteEvent.
-
getProcessedPhraseVelocity
Get a new phrase with notes velocity changed.Velocity is always maintained between 0 and 127. Notes of the returned phrase will have their PARENT_NOTE client property set to:
- source note's PARENT_NOTE client property if this property is not null, or
- the source note from this phrase- Parameters:
f- A function modifying the velocity.- Returns:
- A new phrase
-
processVelocity
Change the velocity of all notes of this Phrase.Velocity is always maintained between 0 and 127. Fire the PROP_NOTES_REPLACED change event.
- Parameters:
f- A function modifying the velocity.
-
getProcessedPhrasePitch
Get a new phrase with all notes changed.Pitch is always maintained between 0 and 127. Notes of the returned phrase will have their PARENT_NOTE client property set to:
- source note's PARENT_NOTE client property if this property is not null, or
- the source note from this phrase- Parameters:
f- A function modifying the pitch.- Returns:
- A new phrase
-
processPitch
Change the pitch of all notes of this Phrase.Pitch is always maintained between 0 and 127. Fire the PROP_NOTES_REPLACED change event.
- Parameters:
f- A function modifying the pitch.
-
getLastEventPosition
public float getLastEventPosition()- Returns:
- 0 If phrase is empty.
-
toString
-
dump
public void dump() -
isAdjustingEvent
Check if propertyName corresponds to one of the adjusting events PROP_NOTES_ADDED_ADJUSTING, PROP_NOTES_REMOVED_ADJUSTING etc.- Parameters:
propertyName-- Returns:
-
add
Add a NoteEvent.Fire a PROP_NOTES_ADDED event.
-
add
Add a NoteEvent.Fire a PROP_NOTES_ADDED or PROP_NOTES_ADDED_ADJUSTING event.
- Parameters:
ne-isAdjusting-- Returns:
-
addAll
Add several NoteEvents.Fire a PROP_NOTES_ADDED_ADJUSTING or PROP_NOTES_ADDED change event.
- Parameters:
collection-isAdjusting-- Returns:
-
addAll
Add several NoteEvents.Fire a PROP_NOTES_ADDED event.
-
remove
Remove a NoteEvent.Fire a PROP_NOTES_REMOVED event
-
remove
Remove a NoteEvent.Fire a PROP_NOTES_REMOVED or PROP_NOTES_REMOVED_ADJUSTING event.
- Parameters:
o-isAdjusting-- Returns:
-
clear
public void clear() -
removeAll
Remove elements.Fire a PROP_NOTES_REMOVED change event.
-
removeAll
-
size
public int size() -
isEmpty
public boolean isEmpty() -
contains
-
iterator
-
toArray
-
toArray
public <T> T[] toArray(T[] a) -
containsAll
- Specified by:
containsAllin interfaceCollection<NoteEvent>- Specified by:
containsAllin interfaceSet<NoteEvent>
-
retainAll
-
shiftAllEvents
public void shiftAllEvents(float shiftInBeats) Shift all events.- Parameters:
shiftInBeats- The value added to each event's position.- Throws:
IllegalArgumentException- If an event's position become negative.
-
comparator
- Specified by:
comparatorin interfaceSortedSet<NoteEvent>
-
subSet
-
headSet
-
tailSet
-
first
-
last
-
lower
- Specified by:
lowerin interfaceNavigableSet<NoteEvent>
-
floor
- Specified by:
floorin interfaceNavigableSet<NoteEvent>
-
ceiling
- Specified by:
ceilingin interfaceNavigableSet<NoteEvent>
-
higher
- Specified by:
higherin interfaceNavigableSet<NoteEvent>
-
pollFirst
- Specified by:
pollFirstin interfaceNavigableSet<NoteEvent>
-
pollLast
- Specified by:
pollLastin interfaceNavigableSet<NoteEvent>
-
descendingSet
- Specified by:
descendingSetin interfaceNavigableSet<NoteEvent>- Returns:
- Return value is unmodifiable.
-
descendingIterator
- Specified by:
descendingIteratorin interfaceNavigableSet<NoteEvent>- Returns:
- Return value is unmodifiable.
-
subSet
public NavigableSet<NoteEvent> subSet(NoteEvent fromElement, boolean fromInclusive, NoteEvent toElement, boolean toInclusive) - Specified by:
subSetin interfaceNavigableSet<NoteEvent>- Returns:
- Return value is unmodifiable.
-
subSet
A subset of all notes in the specified range.- Parameters:
range-excludeUpperBound-- Returns:
- Return value is unmodifiable.
-
headSet
- Specified by:
headSetin interfaceNavigableSet<NoteEvent>- Returns:
- Return value is unmodifiable.
-
tailSet
- Specified by:
tailSetin interfaceNavigableSet<NoteEvent>- Returns:
- Return value is unmodifiable.
-
saveAsString
Save the specified Phrase as a string.Examples:
- "[8|NoteEventStr0|NoteEventStr1]" means a meodic Phrase for channel 8 with 2 NoteEvents
- "[drums_9|NoteEventStr0]" means a drums Phrase for channel 9 with 1 NoteEvent
- "[0]" empty phrase on channel 0- Parameters:
p-- Returns:
- See Also:
-
loadAsString
Create a Phrase from the specified string.Example: "[8|NoteEventStr0|NoteEventStr1]" means a meodic Phrase for channel 8 with 2 NoteEvents.
Example: "[drums_8|NoteEventStr0|NoteEventStr1]" means a drums Phrase for channel 8 with 2 NoteEvents.- Parameters:
s-- Returns:
- Throws:
ParseException- If s is not a valid string.- See Also:
-
getFloorNote
Create a NoteEvent limit to be used as a floor/min position as per NoteEvent.compareTo().For use with the subSet(), tailSet() etc. methods.
- Parameters:
pos-- Returns:
-
getCeilNote
Create a NoteEvent limit to be used as a ceil/max position as per NoteEvent.compareTo().For use with the subSet(), tailSet() etc. methods.
- Parameters:
pos-- Returns:
-
addPropertyChangeListener
-
removePropertyChangeListener
-
addUndoableEditListener
-
removeUndoableEditListener
-