Class PianoRollEditor

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

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

It can edit whole or part of a Phrase.

Its Lookup must contain :
- editor's ActionMap
- editor's 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 changeds, newValue=selected state
      See Also:
    • PROP_ACTIVE_TOOL

      public static final String PROP_ACTIVE_TOOL
      oldValue=old tool, newValue=new tool
      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:
  • Constructor Details

    • PianoRollEditor

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

    • setSong

      public void setSong(Song song)
      Associate an optional song to the editor.

      Put the song in the editor's lookup. Song undo manager is used. The ruler can show the chord symbols and listen to chord symbols changes.

      This method can be called only once.

      Parameters:
      song - Can't be null
    • getSong

      public Song getSong()
    • 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:
      • #setModel(int, org.jjazz.util.api.FloatRange, org.jjazz.phrase.api.Phrase, int, java.util.NavigableMap, org.jjazz.midi.api.DrumKit.KeyMap)
    • getEditTools

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

      public void setGhostPhases(Map<Integer,Phrase> mapChannelPhrases)
      Optional view-only phrases shown faded in the background of the editor.

      The specified phrases are shown faded in the background in order to facilite the editing of the Phrase model. E.g. if the edited phrase is a bass line, you can use this method to make the corresponding drums phrase also visible.

      Parameters:
      mapChannelPhrases - A name associated to a Phrase.
    • getGhostPhrases

      public Map<Integer,Phrase> getGhostPhrases()
      Get the optional view-only phrases shown faded in the background of the editor.
      Returns:
      Can be empty
    • getModel

      public Phrase getModel()
      Get the Phrase edited by this editor.
      Returns:
    • setModel

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

      Fire a PROP_MODEL_PHRASE change event if p is different from existing model.

      Parameters:
      p - The phrase model
      beatRange - The edited part of the phrase model
      phraseStartBar - The start bar corresponding to beatRange.from
      rulerStartBar - The start bar displayed on the ruler corresponding to beatRange.from. Usually it has the same value than phraseStartBar, but it can be different to make the edited range appear at a different bar range.
      channel - The Midi channel of the edited Phrase (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:
    • 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()
    • getPhraseStartBar

      public int getPhraseStartBar()
      Get the bar index corresponding to getPhraseBeatRange().from.
      Returns:
    • getPhraseBarRange

      public IntRange getPhraseBarRange()
    • 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.

    • setZoom

      public void setZoom(ZoomValue zoom)
      Set the editor zoom value.
      Parameters:
      zoom -
    • 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 associated to the specified NoteEvent.
      Parameters:
      ne -
      Returns:
      Can be null
    • getNoteViews

      public List<NoteView> getNoteViews()
      Get all the NoteViews 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:
    • 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)
    • 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 editorPoint)
      Return the phrase position in beats that corresponds to a graphical point in the editor.

      Parameters:
      editorPoint - A point in the editor's coordinates. -1 if point is not valid.
      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:
    • toPosition

      public Position toPosition(float posInBeats)
      Convert a phrase position in beats into a Position.
      Parameters:
      posInBeats - Must be in the beat range.
      Returns:
      See Also:
    • 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 notes which are currently visible.
      Returns:
    • 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:
    • 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
    • propertyChange

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