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
Modifier and TypeFieldDescriptionstatic final String
NoteEvent client property set when new NoteEvents are created from existing ones.static final String
newValue=collection of added NoteEvents.static final String
Same as PROP_NOTES_ADDED except this notifies an intermediate operation: a final non-adjusting operation will occur later.static final String
newValue=a map with keys=OldNoteEvents and values=NewNoteEventsstatic final String
Same as PROP_NOTES_MOVED except this notifies an intermediate operation: a final non-adjusting operation will occur later.static final String
newValue=collection of removed NoteEvents.static final String
Same as PROP_NOTES_REMOVED except this notifies an intermediate operation: a final non-adjusting operation will occur later.static final String
Fired when a new NoteEvent replaced another one.static final String
Same as PROP_NOTES_REPLACED except this notifies an intermediate operation: a final non-adjusting operation will occur later. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Add a NoteEvent.boolean
Add a NoteEvent.void
Clone NoteEvents from the specified Phrase and add them to this Phrase.void
Add a Phrase from the specified Phrase.boolean
addAll
(Collection<? extends NoteEvent> collection) Add several NoteEvents.boolean
addAll
(Collection<? extends NoteEvent> collection, boolean isAdjusting) Add several NoteEvents.void
void
void
clear()
clone()
A deep clone: returned phrase contains clones of the original NoteEvents.Comparator<? super NoteEvent>
boolean
boolean
containsAll
(Collection<?> c) void
dump()
boolean
equalsNearPosition
(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 NoteEvent
getCeilNote
(float pos) Create a NoteEvent limit to be used as a ceil/max position as per NoteEvent.compareTo().int
static NoteEvent
getFloorNote
(float pos) Create a NoteEvent limit to be used as a floor/min position as per NoteEvent.compareTo().float
getNotes()
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 boolean
isAdjustingEvent
(String propertyName) Check if propertyName corresponds to one of the adjusting events PROP_NOTES_ADDED_ADJUSTING, PROP_NOTES_REMOVED_ADJUSTING etc.boolean
isDrums()
Check if the phrase is for non-melodic instruments.boolean
isEmpty()
iterator()
last()
static Phrase
Create a Phrase from the specified string.Move a NoteEvent.Move a NoteEvent.Move NoteEvents.pollLast()
void
Transform the notes which satisfy the specified tester.void
Change the pitch of all notes of this Phrase.void
Change the velocity of all notes of this Phrase.boolean
Remove a NoteEvent.boolean
Remove a NoteEvent.boolean
removeAll
(Collection<?> collection) Remove elements.boolean
removeAll
(Collection<?> collection, boolean isAdjusting) void
void
void
Replace a NoteEvent by another one.void
Replace a NoteEvent by another one.void
replaceAll
(Map<NoteEvent, NoteEvent> mapOldNew, boolean isAdjusting) Replace NoteEvents.boolean
retainAll
(Collection<?> c) static String
Save the specified Phrase as a string.void
shiftAllEvents
(float shiftInBeats) Shift all events.int
size()
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, wait
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
Methods 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:
containsAll
in interfaceCollection<NoteEvent>
- Specified by:
containsAll
in 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:
comparator
in interfaceSortedSet<NoteEvent>
-
subSet
-
headSet
-
tailSet
-
first
-
last
-
lower
- Specified by:
lower
in interfaceNavigableSet<NoteEvent>
-
floor
- Specified by:
floor
in interfaceNavigableSet<NoteEvent>
-
ceiling
- Specified by:
ceiling
in interfaceNavigableSet<NoteEvent>
-
higher
- Specified by:
higher
in interfaceNavigableSet<NoteEvent>
-
pollFirst
- Specified by:
pollFirst
in interfaceNavigableSet<NoteEvent>
-
pollLast
- Specified by:
pollLast
in interfaceNavigableSet<NoteEvent>
-
descendingSet
- Specified by:
descendingSet
in interfaceNavigableSet<NoteEvent>
- Returns:
- Return value is unmodifiable.
-
descendingIterator
- Specified by:
descendingIterator
in interfaceNavigableSet<NoteEvent>
- Returns:
- Return value is unmodifiable.
-
subSet
public NavigableSet<NoteEvent> subSet(NoteEvent fromElement, boolean fromInclusive, NoteEvent toElement, boolean toInclusive) - Specified by:
subSet
in 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:
headSet
in interfaceNavigableSet<NoteEvent>
- Returns:
- Return value is unmodifiable.
-
tailSet
- Specified by:
tailSet
in 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
-