2013-04-05 17:16:33 -04:00
|
|
|
/*
|
2019-08-02 17:26:43 -04:00
|
|
|
* Copyright (C) 2013-2017 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
* Copyright (C) 2014 David Robillard <d@drobilla.net>
|
|
|
|
*
|
|
|
|
* 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.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2013-04-05 17:16:33 -04:00
|
|
|
|
2017-09-24 12:03:54 -04:00
|
|
|
#include "temporal/beats.h"
|
2017-09-24 12:57:27 -04:00
|
|
|
|
2019-10-25 15:13:51 -04:00
|
|
|
#include "evoral/Note.h"
|
2014-03-06 13:26:36 -05:00
|
|
|
|
2013-04-05 17:16:33 -04:00
|
|
|
#include "canvas/polygon.h"
|
2014-03-06 13:26:36 -05:00
|
|
|
#include "canvas/debug.h"
|
|
|
|
|
2013-04-05 17:16:33 -04:00
|
|
|
#include "hit.h"
|
|
|
|
|
|
|
|
using namespace ARDOUR;
|
|
|
|
using namespace ArdourCanvas;
|
|
|
|
|
2024-01-04 21:07:52 -05:00
|
|
|
Hit::Hit (MidiView& region, Item* parent, double size, const std::shared_ptr<NoteType> note, bool with_events)
|
2013-04-05 17:16:33 -04:00
|
|
|
: NoteBase (region, with_events, note)
|
|
|
|
{
|
2014-06-21 11:44:22 -04:00
|
|
|
_polygon = new ArdourCanvas::Polygon (parent);
|
2014-03-06 13:26:36 -05:00
|
|
|
CANVAS_DEBUG_NAME (_polygon, "note");
|
2013-04-05 17:16:33 -04:00
|
|
|
set_item (_polygon);
|
2014-03-06 13:26:36 -05:00
|
|
|
set_height (size);
|
2013-04-05 17:16:33 -04:00
|
|
|
}
|
|
|
|
|
2014-03-06 23:17:04 -05:00
|
|
|
Hit::~Hit ()
|
|
|
|
{
|
|
|
|
delete _polygon;
|
|
|
|
}
|
|
|
|
|
2013-04-05 17:16:33 -04:00
|
|
|
void
|
|
|
|
Hit::move_event (double dx, double dy)
|
|
|
|
{
|
2014-03-13 11:02:06 -04:00
|
|
|
Points points = _polygon->get();
|
|
|
|
Points moved;
|
|
|
|
for (Points::iterator p = points.begin(); p != points.end(); ++p) {
|
|
|
|
moved.push_back ((*p).translate (ArdourCanvas::Duple (dx, dy)));
|
|
|
|
}
|
|
|
|
_polygon->set (moved);
|
2013-04-05 17:16:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Hit::set_outline_color (uint32_t color)
|
|
|
|
{
|
|
|
|
_polygon->set_outline_color (color);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Hit::set_fill_color (uint32_t color)
|
|
|
|
{
|
|
|
|
_polygon->set_fill_color (color);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Hit::show ()
|
|
|
|
{
|
|
|
|
_polygon->show ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Hit::hide ()
|
|
|
|
{
|
|
|
|
_polygon->hide ();
|
|
|
|
}
|
|
|
|
|
2014-12-28 21:31:33 -05:00
|
|
|
Points
|
|
|
|
Hit::points(Distance height)
|
2013-04-05 17:16:33 -04:00
|
|
|
{
|
2014-03-06 13:26:36 -05:00
|
|
|
/* draw a diamond */
|
|
|
|
|
|
|
|
Points p;
|
|
|
|
|
|
|
|
const double half_height = height/2.0;
|
|
|
|
p.push_back (Duple (-half_height, 0)); // left, middle
|
|
|
|
p.push_back (Duple (0, -half_height)); // top
|
|
|
|
p.push_back (Duple (+half_height, 0)); // right, middle
|
|
|
|
p.push_back (Duple (0, +half_height)); // bottom
|
|
|
|
|
2014-12-28 21:31:33 -05:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Hit::set_height (Distance height)
|
|
|
|
{
|
|
|
|
_polygon->set (points(height));
|
|
|
|
}
|
|
|
|
|
|
|
|
Duple
|
|
|
|
Hit::position ()
|
|
|
|
{
|
|
|
|
return _polygon->position ();
|
2013-04-05 17:16:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Hit::set_position (Duple position)
|
|
|
|
{
|
|
|
|
_polygon->set_position (position);
|
|
|
|
}
|
2014-03-06 13:26:36 -05:00
|
|
|
|
|
|
|
Coord
|
|
|
|
Hit::x0 () const
|
|
|
|
{
|
|
|
|
/* left vertex */
|
2014-12-28 20:03:38 -05:00
|
|
|
return _polygon->position().x + _polygon->get()[0].x;
|
2014-03-06 13:26:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
Coord
|
|
|
|
Hit::x1 () const
|
|
|
|
{
|
|
|
|
/* right vertex */
|
2014-12-28 20:03:38 -05:00
|
|
|
return _polygon->position().x + _polygon->get()[2].x;
|
2014-03-06 13:26:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
Coord
|
|
|
|
Hit::y0 () const
|
|
|
|
{
|
|
|
|
/* top vertex */
|
2014-12-28 20:03:38 -05:00
|
|
|
return _polygon->position().y + _polygon->get()[1].y;
|
2014-03-06 13:26:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
Coord
|
|
|
|
Hit::y1 () const
|
|
|
|
{
|
|
|
|
/* bottom vertex */
|
2014-12-28 20:03:38 -05:00
|
|
|
return _polygon->position().y + _polygon->get()[3].y;
|
2014-03-06 13:26:36 -05:00
|
|
|
}
|
2014-12-28 20:23:52 -05:00
|
|
|
|
|
|
|
void
|
|
|
|
Hit::set_ignore_events (bool ignore)
|
|
|
|
{
|
|
|
|
_polygon->set_ignore_events (ignore);
|
|
|
|
}
|
2023-06-20 16:42:43 -04:00
|
|
|
|
|
|
|
double
|
|
|
|
Hit::visual_velocity() const
|
|
|
|
{
|
|
|
|
/* We don't display velocity in any explicit way */
|
|
|
|
return 0.0;
|
|
|
|
}
|