non/sequencer/src/event.C

145 lines
3.1 KiB
C++
Raw Normal View History

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. */
/*******************************************************************************/
/* Higher level event interface, supporting doublely-linked list,
marking, selection, and linking of note pairs. */
#include "event.H"
#include <stdio.h>
#include <string.h>
void
event::_init ( void )
{
_link = _next = _prev = NULL;
_selected = 0;
}
event::event ( void )
{
_init();
}
event::~event ( void )
{
_link = _next = _prev = NULL;
}
/* copy constructor */
2008-05-20 07:18:10 +02:00
event::event ( const event &e ) : midievent( e )
2007-12-18 05:09:02 +01:00
{
_link = _next = _prev = NULL;
_selected = e._selected;
2007-12-18 05:09:02 +01:00
}
event::event ( const midievent &e ) : midievent( e )
{
_init();
}
void
event::link ( event *event )
{
if ( event == NULL )
{
if ( _link )
{
_link->_link = NULL;
_link = NULL;
}
return;
}
_link = event;
_link->_link = this;
}
event *
event::link ( void ) const
{
return _link;
}
bool
event::linked ( void ) const
{
return _link != NULL;
}
void
event::select ( void )
{
_selected = 1;
if ( _link )
_link->_selected = 1;
}
void
event::deselect ( void )
{
_selected = 0;
if ( _link )
_link->_selected = 0;
}
bool
event::selected ( int n ) const
{
return _selected == n;
}
bool
event::selected ( void ) const
{
return _selected == 1;
}
/* override this so we can update linked event */
void
event::note ( char note )
{
midievent::note( note );
if ( _link )
_link->midievent::note( note );
}
/* stupid C++ makes us override the all polymorphic functions... */
unsigned char
event::note ( void ) const
{
return midievent::note();
}
tick_t
event::note_duration ( void ) const
{
return _link ? _link->timestamp() - timestamp() : 0;
}
void
event::note_duration ( tick_t l )
{
if ( _link )
_link->timestamp( timestamp() + l );
}