Class PianoRollEditor

All Implemented Interfaces:
ImageObserver, MenuContainer, PropertyChangeListener, Serializable, EventListener, Accessible, ClsChangeListener

public class PianoRollEditor extends JPanel implements PropertyChangeListener, ClsChangeListener
A piano roll editor of a musical phrase.

Optional view-only "ghost phrases" can be shown faded in the background of the editor, based on the ghostPhrasesModel state.

Editor's lookup must contain :
- its ActionMap instance
- a Zoomable instance

See Also:
  • Field Details

    • PROP_EDITOR_ALIVE

      public static final String PROP_EDITOR_ALIVE
      newValue=false. This property change event is fired ONLY once, when the editor is destroyed (cleanup() is called).
      See Also:
    • PROP_MODEL_PHRASE

      public static final String PROP_MODEL_PHRASE
      oldValue=old phrase model, newValue=new Phrase model.
      See Also:
    • PROP_MODEL_CHANNEL

      public static final String PROP_MODEL_CHANNEL
      oldValue=old channel, newValue=new channel model.
      See Also:
    • PROP_SELECTED_NOTE_VIEWS

      public static final String PROP_SELECTED_NOTE_VIEWS
      oldValue=sorted list of NoteViews whose state has changed, newValue=selected state
      See Also:
    • PROP_ACTIVE_TOOL

      public static final String PROP_ACTIVE_TOOL
      oldValue=old tool, newValue=new tool
      See Also:
    • PROP_LOOP_ZONE

      public static final String PROP_LOOP_ZONE
      oldValue=old loop zone, newValue=new loop zone
      See Also:
    • PROP_SNAP_ENABLED

      public static final String PROP_SNAP_ENABLED
      newValue=boolean
      See Also:
    • PROP_QUANTIZATION

      public static final String PROP_QUANTIZATION
      oldValue=old quantization value, newValue=new quantization value
      See Also:
    • PROP_PLAYBACK_POINT_POSITION

      public static final String PROP_PLAYBACK_POINT_POSITION
      newValue=playback point position in beats
      See Also:
    • PROP_CHORD_SEQUENCE

      public static final String PROP_CHORD_SEQUENCE
      oldValue=old ChordSequence newValue=new ChordSequence
      See Also:
  • Constructor Details

    • PianoRollEditor

      public PianoRollEditor(PianoRollEditorSettings settings, GhostPhrasesModel ghostPhrasesModel)
      Create a piano roll editor for a dummy phrase model.
      Parameters:
      settings - Can't be null
      ghostPhrasesModel - Can't be null
  • Method Details

    • getKeyboard

      public KeyboardComponent getKeyboard()
    • setSong

      public void setSong(Song song)
      Associate an optional song to the editor -this method can be called only once.

      - Song isput in the editor's lookup
      - Song undo manager is used for undo/redo
      - Song can be used by subpanels to show e.g. chord symbols.
      - The Chord sequence associated to the edited phrase is kept uptodate.

      Parameters:
      song - Can't be null
      See Also:
    • getSong

      public Song getSong()
      Get the song the edited phrase belongs to.
      Returns:
      Might be null.
      See Also:
    • getGhostPhrasesModel

      public GhostPhrasesModel getGhostPhrasesModel()
    • getChannel

      public int getChannel()
      Get the channel of the editor.

      The channel is used e.g. when "hear preview" or "solo mode" is activated, or when notes are imported from a dragged Midi file.

      Returns:
      See Also:
    • getEditTools

      public List<EditTool> getEditTools()
      The available EditTools.
      Returns:
    • getModel

      public Phrase getModel()
      Get the Phrase edited by this editor.
      Returns:
      Can not be null but can be empty. Starts at bar/beat=0.
    • setModel

      public void setModel(Phrase p, FloatRange beatRange, int rulerStartBar, int channel, NavigableMap<Float,TimeSignature> mapPosTs, DrumKit.KeyMap kMap)
      Set the phrase model.

      Can fire PROP_MODEL_PHRASE and PROP_MODEL_CHANNEL change events.

      Parameters:
      p - The phrase model. Must start at bar/beat 0.
      beatRange - The beat range of the phrase model to edit. It must start at beat 0. It might be only a part of the phrase model or be longer.
      rulerStartBar - The start bar displayed on the ruler. Might be > 0, e.g. for a custom phrase of a song part in the middle of the song.
      channel - The Midi channel of the phrase model (p.getChannel() is ignored).
      mapPosTs - The position of each time signature. Must have at least 1 entry at beatRange.from position or before.
      kMap - If null means it's a melodic phrase
    • getRulerStartBar

      public int getRulerStartBar()
      Get the bar index displayed on the ruler corresponding to getBeatRange().from.

      Usually identical to getPhraseStartBar(), but it can be different to make the edited range appear at a different bar in the ruler.

      Returns:
    • getRulerBarRange

      public IntRange getRulerBarRange()
      Get the ruler bar range.

      An IntRange starting at getRulerStartbar() with size equals to getPhraseBarRange().

      Returns:
    • getChordSequence

      public ChordSequence getChordSequence()
      The chord sequence associated to the edited phrase.

      Important: Chord sequence first bar is equals to getRulerStartBar().

      Returns:
      Can be null if song is not set.
      See Also:
    • toPhraseRelativeBeatPosition

      public float toPhraseRelativeBeatPosition(CLI_ChordSymbol cliCs)
      Compute the phrase-based beat position of a CLI_ChordSymbol obtained via getChordSequence().
      Parameters:
      cliCs -
      Returns:
      See Also:
    • getTimeSignature

      public TimeSignature getTimeSignature(float posInBeats)
      The time signature at the specified beat position.
      Parameters:
      posInBeats - Must be in the beat range
      Returns:
      Can't be null
    • getTimeSignatures

      public NavigableMap<Float,TimeSignature> getTimeSignatures()
      Get all the time signatures with their position.
      Returns:
      Can't be empty.
    • getPhraseBeatRange

      public FloatRange getPhraseBeatRange()
      Get the phase beat range of the edited phrase.
      Returns:
      A FloatRange with from=0.
    • getPhraseBarRange

      public IntRange getPhraseBarRange()
      Get the bar range of the edited phrase.
      Returns:
      An IntRange with from=0.
    • getLookup

      public org.openide.util.Lookup getLookup()
      Get the lookup of this editor.

      Lookup contains

      Returns:
    • isDrums

      public boolean isDrums()
      Convenience method which returns true if getDrumKeyMap() is non null.
      Returns:
    • getDrumKeyMap

      public DrumKit.KeyMap getDrumKeyMap()
      The drum key map used by the edited phrase.
      Returns:
      Null if it's a melodic phrase.
    • getSettings

      public PianoRollEditorSettings getSettings()
      Get the graphical settings of this editor.
      Returns:
    • cleanup

      public void cleanup()
      Clean up everything so component can be garbaged.

      Fire a PROP_EDITOR_ALIVE with value=false.

    • getZoom

      public ZoomValue getZoom()
      Get the editor zoom value.
      Returns:
    • setQuantization

      public void setQuantization(Quantization q)
      Set the display quantization.

      Fire a PROP_QUANTIZATION change event.

      Parameters:
      q - Accepted values are BEAT, HALF_BEAT, ONE_THIRD_BEAT, ONE_QUARTER_BEAT, ONE_SIXTH_BEAT.
    • getQuantization

      public Quantization getQuantization()
      Get the display quantization.
      Returns:
      Can't be null
    • isNoteSelected

      public boolean isNoteSelected(NoteEvent ne)
    • selectNote

      public void selectNote(NoteEvent ne, boolean b)
    • selectNotes

      public void selectNotes(Collection<NoteEvent> notes, boolean b)
      Select or unselect NoteViews.

      Fire a PROP_SELECTED_NOTE_VIEWS change event.

      Parameters:
      notes -
      b -
    • setSnapEnabled

      public void setSnapEnabled(boolean b)
      Enable or disable the snap to quantization feature.

      Fire a PROP_SNAP_ENABLED change event.

      Parameters:
      b -
    • isSnapEnabled

      public boolean isSnapEnabled()
      Check if the snap to quantization feature is enabled.
      Returns:
    • getNoteView

      public NoteView getNoteView(NoteEvent ne)
      Get the NoteView from the main EditorPanel associated to the specified NoteEvent.
      Parameters:
      ne -
      Returns:
      Can be null
    • getNoteViews

      public List<NoteView> getNoteViews()
      Get all the NoteViews from the main EditorPanel sorted by NoteEvent natural order.

      Returns:
    • unselectAll

      public void unselectAll()
      Unselect all notes.
    • getSelectedNoteViews

      public List<NoteView> getSelectedNoteViews()
      Get the currently selected NoteViews sorted by NoteEvent natural order.
      Returns:
      Unmodifiable list
    • getSelectedNoteEvents

      public List<NoteEvent> getSelectedNoteEvents()
      Get the currently selected NoteEvents sorted by NoteEvent natural order.
      Returns:
      Unmodifiable list
    • setActiveTool

      public void setActiveTool(EditTool tool)
      Set the active EditTool.

      Fire a PROP_ACTIVE_TOOL change event.

      Parameters:
      tool -
    • getActiveTool

      public EditTool getActiveTool()
      Get the actived EditTool.
      Returns:
      Can't be null
    • isPlaybackAutoScrollEnabled

      public boolean isPlaybackAutoScrollEnabled()
    • setPlaybackAutoScrollEnabled

      public void setPlaybackAutoScrollEnabled(boolean playbackAutoScrollEnabled)
    • setLoopZone

      public void setLoopZone(IntRange barRange)
      Set the loop zone.
      Parameters:
      barRange - If null there is no loop zone. If not null must be contained in the phrase bar range.
    • getLoopZone

      public IntRange getLoopZone()
      Get the loop zone.
      Returns:
      Can be null if no loop zone is set
    • showPlaybackPoint

      public void showPlaybackPoint(float pos)
      Show (or hide) a playback point in the editor at specified phrase position.

      If pos is < 0 or out of the editor bounds, nothing is shown. Fire a PROP_PLAYBACK_POINT_POSITION change event.

      Parameters:
      pos - The phrase position in beats.
    • getPlaybackPointPosition

      public float getPlaybackPointPosition()
      Get the playback point position.
      Returns:
      If < 0 no playback point is shown.
    • getPositionFromPoint

      public float getPositionFromPoint(Point notesPanelPoint)
      Return the phrase position in beats that corresponds to a graphical point in the NotesPanel.

      Parameters:
      notesPanelPoint - A point in NotesPanel's coordinates. -1 if point is not valid.
      Returns:
      See Also:
    • toNotesPanelPoint

      public Point toNotesPanelPoint(Point editorPoint)
      Convert a point in this editor coordinates into NotesPanel's coordinates.
      Parameters:
      editorPoint -
      Returns:
    • getXFromPosition

      public int getXFromPosition(float pos)
      Return the X editor position that corresponds to a beat position of the Phrase model.
      Parameters:
      pos -
      Returns:
      -1 If pos is outside the Phrase
    • toPositionInBeats

      public float toPositionInBeats(Position pos)
      Convert a phrase Position into a phrase position in beats.
      Parameters:
      pos - Must be in the bar range.
      Returns:
      A beat positino relative to the edited phrase (starts at beat 0)
    • toPosition

      public Position toPosition(float posInBeats)
      Convert a phrase position in beats into a Position.
      Parameters:
      posInBeats - Must be in the beat range.
      Returns:
      A position relative to the edited phrase (starts at bar 0)
    • getPitchFromPoint

      public int getPitchFromPoint(Point notesPanelPoint)
      Return the pitch that correspond to a graphical point in the editor.
      Parameters:
      notesPanelPoint - A point in the editor's coordinates. -1 if point is not valid.
      Returns:
    • scrollToCenter

      public void scrollToCenter(int pitch)
      Scroll so that specified pitch is shown in the center of the editor, if possible.
      Parameters:
      pitch -
    • scrollToCenter

      public void scrollToCenter(float posInBeats)
      Scroll so that specified position is shown in the center of the editor, if possible.
      Parameters:
      posInBeats -
    • getVisiblePitchRange

      public IntRange getVisiblePitchRange()
      Get the min/max phrase notes which are currently visible.
      Returns:
      Might be empty
    • getVisibleBeatRange

      public FloatRange getVisibleBeatRange()
      Get the min/max beat positions which are visible.
      Returns:
      Can be EMPTY_FLOAT_RANGE
    • isReady

      public boolean isReady()
      Check is editor is ready, ie painted and layouted at the correct size, so all editor methods can be called.
      Returns:
    • getVisibleBarRange

      public IntRange getVisibleBarRange()
      Get the min/max bar indexes which are visible.
      Returns:
      Can be IntRange.EMPTY_RANGE
    • getUndoManager

      public JJazzUndoManager getUndoManager()
      Returns:
      The UndoManager used by this editor.
    • setUndoManager

      public final void setUndoManager(JJazzUndoManager um)
      Set the UndoManager used by this editor.
      Parameters:
      um -
    • toString

      public String toString()
      Overrides:
      toString in class Component
    • chordLeadSheetChanged

      public void chordLeadSheetChanged(ClsChangeEvent e) throws UnsupportedEditException
      Description copied from interface: ClsChangeListener
      Process the change.

      Note that this method might be called outside of the EDT.

      Specified by:
      chordLeadSheetChanged in interface ClsChangeListener
      Parameters:
      e -
      Throws:
      UnsupportedEditException - If a ClsVetoableChangeEvent is not authorized by a listener.
    • propertyChange

      public void propertyChange(PropertyChangeEvent evt)
      Specified by:
      propertyChange in interface PropertyChangeListener