summaryrefslogtreecommitdiff
path: root/gtk2_ardour/canvas-midi-event.cc
blob: 823b1a718ba23e56c13f9c68217cbdf0d0da8e6c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
    Copyright (C) 2007 Paul Davis 
    Author: Dave Robillard

    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; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#include <iostream>
#include "canvas-midi-event.h"
#include "midi_region_view.h"
#include "public_editor.h"
#include "editing_syms.h"
#include "keyboard.h"

using namespace std;

namespace Gnome {
namespace Canvas {


CanvasMidiEvent::CanvasMidiEvent(MidiRegionView& region, Item* item)
	: _region(region)
	, _item(item)
	, _state(None)
{	
}


bool
CanvasMidiEvent::on_event(GdkEvent* ev)
{
	static double last_x, last_y;
	double event_x, event_y;

	if (_region.get_time_axis_view().editor.current_mouse_mode() != Editing::MouseNote)
		return false;

	switch (ev->type) {
	case GDK_ENTER_NOTIFY:
		cerr << "ENTERED: " << ev->crossing.state << endl;
		Keyboard::magic_widget_grab_focus();
		_item->grab_focus();
		/*if ( (ev->crossing.state & GDK_BUTTON2_MASK) ) {

		}*/
		break;

	case GDK_LEAVE_NOTIFY:
		cerr << "LEAVE: " << ev->crossing.state << endl;
		Keyboard::magic_widget_drop_focus();
		//_item->drop_focus();
		break;
	
	case GDK_KEY_PRESS:
		cerr << "EVENT KEY PRESS\n"; // doesn't work :/
		break;

	case GDK_BUTTON_PRESS:
		_state = Pressed;
		return true;

	case GDK_MOTION_NOTIFY:
		event_x = ev->motion.x;
		event_y = ev->motion.y;
		_item->property_parent().get_value()->w2i(event_x, event_y);

		switch (_state) {
		case Pressed:
			_item->grab(GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK,
					Gdk::Cursor(Gdk::FLEUR), ev->motion.time);
			_state = Dragging;
			last_x = event_x;
			last_y = event_y;
			return true;
		case Dragging:
			if (ev->motion.is_hint) {
				int t_x;
				int t_y;
				GdkModifierType state;
				gdk_window_get_pointer(ev->motion.window, &t_x, &t_y, &state);
				event_x = t_x;
				event_y = t_y;
			}

			_item->move(event_x - last_x, event_y - last_y);

			last_x = event_x;
			last_y = event_y;

			return true;
		default:
			break;
		}
		break;
	
	case GDK_BUTTON_RELEASE:
		switch (_state) {
		case Pressed: // Clicked
			_state = None;
			return true;
		case Dragging: // Dropped
			_item->ungrab(ev->button.time);
			_state = None;
			return true;
		default:
			break;
		}

	default:
		break;
	}

	return false;
}

} // namespace Canvas
} // namespace Gnome