Fix genererally retarded and broken note range / diskstream display / etc. related...
[ardour.git] / gtk2_ardour / midi_region_view.h
index 2220dd93870c105de5ad75a38ee272676c53d8c0..d6a7695997308e030b0678697d093d2744da9a49 100644 (file)
@@ -58,6 +58,8 @@ class AutomationRegionView;
 class MidiRegionView : public RegionView
 {
   public:
+       typedef Evoral::Note<ARDOUR::MidiModel::TimeType> NoteType;
+
        MidiRegionView (ArdourCanvas::Group *,
                        RouteTimeAxisView&,
                        boost::shared_ptr<ARDOUR::MidiRegion>,
@@ -91,7 +93,7 @@ class MidiRegionView : public RegionView
 
        GhostRegion* add_ghost (TimeAxisView&);
 
-       void add_note(const boost::shared_ptr<Evoral::Note> note);
+       void add_note(const boost::shared_ptr<NoteType> note);
        void resolve_note(uint8_t note_num, double end_time);
        
        struct ControlEvent
@@ -148,18 +150,18 @@ class MidiRegionView : public RegionView
        
        /** Displays all program changed events in the region as flags on the canvas.
         */
-       void find_and_insert_program_change_flags();
+       void display_program_change_flags();
 
        void begin_write();
        void end_write();
        void extend_active_notes();
 
-       void create_note_at(double x, double y, double duration);
+       void create_note_at(double x, double y, double length);
 
        void display_model(boost::shared_ptr<ARDOUR::MidiModel> model);
 
        void start_delta_command(string name = "midi edit");
-       void command_add_note(const boost::shared_ptr<Evoral::Note> note, bool selected);
+       void command_add_note(const boost::shared_ptr<NoteType> note, bool selected);
        void command_remove_note(ArdourCanvas::CanvasNoteEvent* ev);
 
        void apply_command();
@@ -173,19 +175,19 @@ class MidiRegionView : public RegionView
        size_t selection_size() { return _selection.size(); }
 
        void move_selection(double dx, double dy);
-       void note_dropped(ArdourCanvas::CanvasNoteEvent* ev, double dt, uint8_t dnote);
+       void note_dropped(ArdourCanvas::CanvasNoteEvent* ev, double d_frames, uint8_t d_note);
 
-       /** Get the region position in pixels.
-        * This function is needed to subtract the region start in pixels
-        * from world coordinates submitted by the mouse
-        */
+       /** Return true iff the note is within the currently visible range */
+       bool note_in_visible_range(const boost::shared_ptr<NoteType> note) const;
+
+       /** Get the region position in pixels relative to session. */
        double get_position_pixels();
 
        /** Begin resizing of some notes.
         * Called by CanvasMidiNote when resizing starts.
         * @param note_end which end of the note, NOTE_ON or NOTE_OFF
         */
-       void  begin_resizing(ArdourCanvas::CanvasNote::NoteEnd note_end);
+       void begin_resizing(ArdourCanvas::CanvasNote::NoteEnd note_end);
 
        /** Update resizing notes while user drags.
         * @param note_end which end of the note, NOTE_ON or NOTE_OFF
@@ -213,7 +215,15 @@ class MidiRegionView : public RegionView
         */
        void change_channel(uint8_t channel);
 
-       enum MouseState { None, Pressed, SelectTouchDragging, SelectRectDragging, AddDragging, EraseTouchDragging };
+       enum MouseState {
+               None,
+               Pressed,
+               SelectTouchDragging,
+               SelectRectDragging,
+               AddDragging,
+               EraseTouchDragging
+       };
+
        MouseState mouse_state() const { return _mouse_state; }
 
        struct NoteResizeData {
@@ -241,8 +251,13 @@ class MidiRegionView : public RegionView
         */
        nframes64_t snap_to_frame(nframes64_t x);
        
+       /** Convert a timestamp in beats to frames (both relative to region start) */
+       nframes64_t beats_to_frames(double beats) const;
+       
+       /** Convert a timestamp in frames to beats (both relative to region start) */
+       double frames_to_beats(nframes64_t beats) const;
+       
   protected:
-
     /** Allows derived types to specify their visibility requirements
      * to the TimeAxisViewItem parent class.
      */
@@ -261,6 +276,15 @@ class MidiRegionView : public RegionView
        void reset_width_dependent_items (double pixel_width);
 
   private:
+       /** Play the NoteOn event of the given note immediately
+        * and schedule the playback of the corresponding NoteOff event.
+        */
+       void play_midi_note(boost::shared_ptr<NoteType> note);
+       
+       /** Play the NoteOff-Event of the given note immediately
+        * (scheduled by @ref play_midi_note()).
+        */
+       bool play_midi_note_off(boost::shared_ptr<NoteType> note);
 
        void clear_events();
        void switch_source(boost::shared_ptr<ARDOUR::Source> src);
@@ -271,7 +295,7 @@ class MidiRegionView : public RegionView
        void midi_channel_mode_changed(ARDOUR::ChannelMode mode, uint16_t mask);
        void midi_patch_settings_changed(std::string model, std::string custom_device_mode);
        
-       void change_note_velocity(ArdourCanvas::CanvasNoteEvent* ev, int8_t velocity, bool relative=false);
+       void change_note_velocity(ArdourCanvas::CanvasNoteEvent* ev, int8_t vel, bool relative=false);
 
        void clear_selection_except(ArdourCanvas::CanvasNoteEvent* ev);
        void clear_selection() { clear_selection_except(NULL); }
@@ -283,7 +307,10 @@ class MidiRegionView : public RegionView
        uint8_t  _current_range_min;
        uint8_t  _current_range_max;
        
+       /// MIDNAM information of the current track: Model name of MIDNAM file
        string   _model_name;
+       
+       /// MIDNAM information of the current track: CustomDeviceMode
        string   _custom_device_mode;   
 
        typedef std::vector<ArdourCanvas::CanvasNoteEvent*> Events;
@@ -305,7 +332,7 @@ class MidiRegionView : public RegionView
 
        /** New notes (created in the current command) which should be selected
         * when they appear after the command is applied. */
-       std::set< boost::shared_ptr<Evoral::Note> > _marked_for_selection;
+       std::set< boost::shared_ptr<NoteType> > _marked_for_selection;
 
        std::vector<NoteResizeData *> _resize_data;
 };