2007-12-18 05:09:02 +01:00
|
|
|
|
|
|
|
/*******************************************************************************/
|
|
|
|
/* Copyright (C) 2007-2008 Jonathan Moore Liles */
|
|
|
|
/* */
|
|
|
|
/* This program is free software; you can redistribute it and/or modify it */
|
|
|
|
/* under the terms of the GNU General Public License as published by the */
|
|
|
|
/* Free Software Foundation; either version 2 of the License, or (at your */
|
|
|
|
/* option) any later version. */
|
|
|
|
/* */
|
|
|
|
/* This program is distributed in the hope that it will be useful, but WITHOUT */
|
|
|
|
/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
|
|
|
|
/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for */
|
|
|
|
/* more details. */
|
|
|
|
/* */
|
|
|
|
/* You should have received a copy of the GNU General Public License along */
|
|
|
|
/* with This program; see the file COPYING. If not,write to the Free Software */
|
|
|
|
/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
|
|
|
/*******************************************************************************/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "grid.H"
|
|
|
|
#include "gui/draw.H"
|
|
|
|
|
|
|
|
#include <sigc++/sigc++.h>
|
|
|
|
using namespace sigc;
|
|
|
|
|
|
|
|
class Mapping;
|
|
|
|
|
|
|
|
struct cell_t {
|
2012-03-01 05:46:57 +01:00
|
|
|
unsigned char color : 8;
|
2007-12-18 05:09:02 +01:00
|
|
|
unsigned char state : 4;
|
|
|
|
unsigned char flags : 4;
|
|
|
|
|
|
|
|
bool
|
|
|
|
operator!= ( const cell_t &rhs )
|
|
|
|
{
|
2012-03-01 05:46:57 +01:00
|
|
|
return color != rhs.color || state != rhs.state || flags != rhs.flags;
|
2007-12-18 05:09:02 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
enum { LEFT, RIGHT, UP, DOWN, TO_PLAYHEAD, TO_NEXT_NOTE, TO_PREV_NOTE };
|
|
|
|
|
|
|
|
|
|
|
|
class Canvas : public trackable
|
|
|
|
{
|
|
|
|
|
|
|
|
struct {
|
|
|
|
int origin_x, origin_y;
|
|
|
|
int width, height;
|
|
|
|
|
|
|
|
int margin_left, margin_top;
|
|
|
|
int div_w, div_h;
|
|
|
|
|
|
|
|
int old_div_w, old_div_h;
|
|
|
|
|
|
|
|
int maxh;
|
|
|
|
|
|
|
|
bool ruler_drawn;
|
|
|
|
bool mapping_drawn;
|
|
|
|
|
|
|
|
bool grid_drawn;
|
|
|
|
|
|
|
|
int playhead; /* where the playhead is for this canvas. only used for display. */
|
|
|
|
|
|
|
|
enum { PATTERN, SEQUENCE } mode;
|
|
|
|
|
|
|
|
Grid *grid; /* grid currently connected to this canvas */
|
|
|
|
|
|
|
|
size_t size;
|
|
|
|
cell_t **current, **previous;
|
|
|
|
|
|
|
|
bool draw; /* really drawing, or just checking size? */
|
|
|
|
|
|
|
|
int rule;
|
|
|
|
|
2008-02-15 05:20:04 +01:00
|
|
|
bool row_compact; /* use row-compaction? */
|
2007-12-18 05:09:02 +01:00
|
|
|
|
|
|
|
/* tables used for row-compaction */
|
|
|
|
int rtn[128]; /* row-to-note */
|
|
|
|
int ntr[128]; /* note-to-row */
|
|
|
|
|
|
|
|
int shape;
|
|
|
|
|
|
|
|
Viewport *vp;
|
|
|
|
int w, h;
|
|
|
|
|
2008-02-15 05:20:04 +01:00
|
|
|
uint p1, p2; /* range cursors */
|
|
|
|
uint p3, p4; /* row cursors */
|
2007-12-18 05:09:02 +01:00
|
|
|
} m;
|
|
|
|
|
2008-02-11 23:59:54 +01:00
|
|
|
int rtn ( int r ) const;
|
|
|
|
int ntr ( int n ) const;
|
2007-12-18 05:09:02 +01:00
|
|
|
|
|
|
|
void _update_row_mapping ( void );
|
|
|
|
cell_t ** _alloc_array ( void );
|
|
|
|
|
|
|
|
void redraw_ruler ( void );
|
|
|
|
void redraw_mapping ( void );
|
|
|
|
void draw_mapping ( void );
|
|
|
|
void draw_ruler ( void );
|
|
|
|
|
|
|
|
void _reset ( void );
|
|
|
|
void _lr ( void );
|
|
|
|
|
|
|
|
bool viewable_x ( int x );
|
|
|
|
void draw_line ( int x, int flags );
|
|
|
|
|
2008-06-15 19:45:57 +02:00
|
|
|
void update_mapping ( void );
|
|
|
|
|
2007-12-18 05:09:02 +01:00
|
|
|
public:
|
|
|
|
|
|
|
|
enum { OFF, ON, TOGGLE };
|
|
|
|
|
|
|
|
signal <void> signal_settings_change;
|
|
|
|
signal <void> signal_draw;
|
|
|
|
signal <void> signal_resize;
|
2012-03-01 08:00:38 +01:00
|
|
|
signal <void> signal_pan;
|
2007-12-18 05:09:02 +01:00
|
|
|
|
|
|
|
Canvas ( );
|
|
|
|
|
|
|
|
void handle_event_change ( void );
|
|
|
|
void set ( int x, int y );
|
2008-02-11 06:20:39 +01:00
|
|
|
void grid ( Grid *g );
|
2007-12-18 05:09:02 +01:00
|
|
|
void changed_mapping ( void );
|
|
|
|
Grid * grid ( void );
|
|
|
|
void resize ( void );
|
|
|
|
void resize_grid ( void );
|
|
|
|
void resize ( int x, int y, int w, int h );
|
|
|
|
void copy ( void );
|
|
|
|
void clear ( void );
|
|
|
|
void flip ( void );
|
|
|
|
void draw_row_name ( int y, const char *name, int color );
|
|
|
|
void draw_shape ( int x, int y, int shape, int state, int color, bool selected );
|
|
|
|
void draw_dash ( int x, int y, int l, int shape, int color, bool selected );
|
|
|
|
int draw_playhead ( void );
|
|
|
|
void draw ( void );
|
|
|
|
void redraw ( void );
|
2008-02-11 23:59:54 +01:00
|
|
|
bool grid_pos ( int *x, int *y ) const;
|
|
|
|
int is_row_name ( int x, int y );
|
2007-12-18 05:09:02 +01:00
|
|
|
void unset ( int x, int y );
|
|
|
|
void adj_color ( int x, int y, int n );
|
|
|
|
void adj_length ( int x, int y, int n );
|
|
|
|
void select ( int x, int y );
|
|
|
|
void select_range ( void );
|
2008-02-15 05:20:04 +01:00
|
|
|
void invert_selection ( void );
|
2007-12-18 05:09:02 +01:00
|
|
|
void duplicate_range ( void );
|
|
|
|
void crop ( void );
|
|
|
|
void row_compact ( int n );
|
|
|
|
void pan ( int dir, int n );
|
2012-03-01 08:00:38 +01:00
|
|
|
void can_scroll ( int *left, int *right, int *up, int *down );
|
2007-12-18 05:09:02 +01:00
|
|
|
void h_zoom ( float n );
|
|
|
|
void v_zoom ( float n );
|
2008-02-13 00:04:38 +01:00
|
|
|
void v_zoom_fit ( void );
|
2007-12-18 05:09:02 +01:00
|
|
|
void notes ( char *s );
|
|
|
|
char * notes ( void );
|
|
|
|
void randomize_row ( int y );
|
2012-03-14 03:50:17 +01:00
|
|
|
int playhead_moved ( void );
|
2007-12-18 05:09:02 +01:00
|
|
|
|
2008-02-15 05:20:04 +01:00
|
|
|
void start_cursor ( int x, int y );
|
|
|
|
void end_cursor ( int x, int y );
|
|
|
|
|
2007-12-18 05:09:02 +01:00
|
|
|
void delete_time ( void );
|
|
|
|
void insert_time ( void );
|
|
|
|
|
|
|
|
void move_selected ( int dir, int n );
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
inline int
|
2008-02-11 23:59:54 +01:00
|
|
|
Canvas::rtn ( int r ) const
|
2007-12-18 05:09:02 +01:00
|
|
|
{
|
|
|
|
return m.row_compact ? m.rtn[ r ] : r;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline int
|
2008-02-11 23:59:54 +01:00
|
|
|
Canvas::ntr ( int n ) const
|
2007-12-18 05:09:02 +01:00
|
|
|
{
|
|
|
|
return m.row_compact ? m.ntr[ n ] : n;
|
|
|
|
}
|