//=============================================================================
// model view control piano roll
//=============================================================================
// Author  : Adrian Meyer
// Version : 0.2.1
// Log     :
//=============================================================================
// 14.09.2000 building class
// 15.09.2000 adding pitch display
// 16.09.2000 adding note display with selection and cursors
// 18.09.2000 added deleting and draging notes
// 19.09.2000 adding rubber bending for changing pitch
//             drawing routine for changing event changed (tripple buffer ;) )
// 20.09.2000 corrected y scaling to even pix/note
// 13.11.2000 adding offset change
// 24.11.2000 add duration change operation
// 13.02.2001 change window to velocity edit style
//            change main scroll bar to Gtk[HV]Scrollbar
// 14.02.2001 checking window size change on expose events. works very nice!
// 18.02.2001 reset the scale zoom added (incl. center scale)
// 19.02.2001 adding mouse entry in velocity window
// 20.02.2001 redraw entry line and apply velocity changes after mouse up
// 21.02.2001 add user snap based on TMidiSequence->GetGrid()
// 01.03.2001 add controler expose
// 10.04.2001 adding language file for snap property dialog
//============================================================================
// to do   :
//=============================================================================
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <stdio.h>

#include "glade_interface.h"
#include "glade_support.h"

#include <mvcBase.h>
#include <mvcHeader.h>
#include <mcSequence.h>
#include <mcEvent.h>
#include <mcStatics.h>
#include <mvcUserSnapProperties.h>

struct sPianoRollEventList                            // list of displayed events
{
  TMidiEvent* Event;
  long x1;
  long y1;
  long x2;
  long y2;
  long Offset;
  short Pitch;
  long Duration;
};

struct sPianoRollControllerList                       // list of displayed controllers
{
  TMidiEvent* Event;
  long x;
  long y;
  long Offset;
  short Value;
};

struct sVelocityDrawPointList                         // list of drawing points
{
  long x;
  long y;
  sVelocityDrawPointList* Next;
};

typedef enum                                          // operation in main window
{
  PR_NONE,
  PR_CHANGE_OFFSET,
  PR_CHANGE_PITCH,
  PR_CHANGE_DURATION,
  PR_CHANGE_SELECTION,
  PR_DELETE_EVENT
} ePRSelectionOperation;


class TMvcPianoRoll: public TMvcBase
{
  private:
    GtkWidget* fWidget;                               // main widget
    TMidiSequence* fSequence;                         // last displayed sequence
    TMvcHeader* fHeader;                              // header of view
    GtkWidget* drwPianoRollMain;											// very much used widgets
    TMvcUserSnapProperties* fUserSnapProperties;      // user snap properties

    int fWidth;                                       // width of drawing area
    int fHeight;                                      // height of drawing area
    int fWindowWidth;                                 // width of window
    int fWindowHeight;                                // height of window
    int fWindowVelocityHeight;                        // height of velocity window

    double fTicksPerPix;                              // midi ticks per pixel on screen
    double fPixPerNote;                               // pix per note
    double fPixPerValue;                              // pix per value
    long fMeasureCount;                               // measure count for x-axis

    ePRSelectionOperation fSelectionOperation;        // operation of selection
    sVelocityDrawPointList* fVelocityDrawPointList;   // list of points to draw velocity
    sVelocityDrawPointList* fVelocityDisplayList;     // list of points displayed
    sPianoRollEventList* fSelectedEvent;              // selected event
    bool fMouseDownVelocity;													// mouse down in velocity window

    GList* fEventList;     		                        // list with displayed midi events
    GList* fControllerList;                           // list with displayed controllers
    GList* fControllerNames;                          // controller name list

    GdkColor* colBackground;                          // background color
    GdkColor* colGrid;                                // color of grid
    GdkColor* colSubGrid;                             // color of subgrid
    GdkColor* colMidi;                                // midi event color
    GdkColor* colSelection;                           // selection color
    GdkColor* colEventSelection;                      // color selected event
    GdkColor* colHint;                                // color hint box

    GdkPixmap* fBufferPianoRoll;                      // pixmap buffer for main view
    GdkPixmap* fBufferPianoRollScale;                 // pixmap buffer for scale view
    GdkPixmap* fBufferPianoRollVelocity;              // pixmap buffer for velocity
    GdkPixmap* fBufferPianoRollController;            // pixmap buffer for controller
    GdkPixmap* fBufferPianoRollVelocityLabel;         // pixmap buffer for velocity label

    GdkCursor* fPitchCursor;                          // pitch cursor
    GdkCursor* fMeasureCursor;                        // measure cursor
    GdkCursor* fEditCursor;                           // edit cursor
    GdkCursor* fDeleteCursor;                         // delete cursor
    GdkCursor* fDrawCursor;                           // draw cursor

    GtkAdjustment* fXAdjustment;                      // adjustment x axis
    GtkAdjustment* fYAdjustment;                      // adjustment y axis

    void BuildEventList( void );                      // build list with midi events
                                                      // read offset on grid
    long GetOffsetOnGrid( long aOffset, bool aRoundDown );

    void AddVelocityDrawPoint( long x, long y );      // add point to velocity draw
    void ClearVelocityDrawPointList( void );          // clear list of points
    void DrawVelocityChange( void );                  // draw velocity change line
    void ApplyVelocityChange( void );                 // apply changes on velocity

  public:
                                                      // constructor
    TMvcPianoRoll( GtkWidget* aWidget, TMidiSequence* aSequence );                 
    GtkWidget* GetWidget( void );                     // read widget

    void Resize( void );                              // set new with and height
    void Scroll( void );                              // scroll piano roll
                                                      // draw in main area
    bool PianoRollExpose( GtkWidget* aWidget, GdkEventExpose* aEvent );
                                                      // draw in scale area
    bool PianoRollScaleExpose( GtkWidget* aWidget, GdkEventExpose* aEvent );
																											// draw velocity
		bool PianoRollVelocityExpose( GtkWidget* aWidget, GdkEventExpose* aEvent );
																											// draw controller
		bool PianoRollControllerExpose( GtkWidget* aWidget, GdkEventExpose* aEvent );
																											// draw velocity label
		bool PianoRollVelocityLabelExpose( GtkWidget* aWidget, GdkEventExpose* aEvent );

                                                      // draw header area
    void MCMessage( TMidiBase* aMidiBase, sMCMessage* aMCMessage );                                                

    void MouseDown( long x, long y );                 // mouse events
    void MouseUp( long x, long y );
    void MouseMove( long x, long y );

    void VelocityMouseDown( long x, long y );         // mouse events velocity
    void VelocityMouseUp( long x, long y );
    void VelocityMouseMove( long x, long y );

    void StartOperationPosition( long x, long y );    // starts an operation at the given position
                                                      // gives the event the mouse is over
    sPianoRollEventList* MouseOverEvent( long x, long y );
                                                      // draw selected note in piano roll
    void DrawSelectedEvent( sPianoRollEventList* aEvent, long x1, long y1, long x2, long y2 );
                                                      // draw the change of the note
    void DrawChangeFrame( sPianoRollEventList* aEvent,  long x1, long y1, long x2, long y2, long newx, long newy );
    void SetCursor( long x, long y );
    void ResetZoom();																	// reset the scale zoom

    void ShowUserSnapProperties();										// display user snap dialog
};


Documentation generated by kingadi@ameyer on Thu Apr 19 23:14:22 EDT 2001