Assists music production by grouping standalone programs into sessions. Community version of "Non Session Manager".
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

145 lines
3.1KB

  1. /*******************************************************************************/
  2. /* Copyright (C) 2007-2008 Jonathan Moore Liles */
  3. /* */
  4. /* This program is free software; you can redistribute it and/or modify it */
  5. /* under the terms of the GNU General Public License as published by the */
  6. /* Free Software Foundation; either version 2 of the License, or (at your */
  7. /* option) any later version. */
  8. /* */
  9. /* This program is distributed in the hope that it will be useful, but WITHOUT */
  10. /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
  11. /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for */
  12. /* more details. */
  13. /* */
  14. /* You should have received a copy of the GNU General Public License along */
  15. /* with This program; see the file COPYING. If not,write to the Free Software */
  16. /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  17. /*******************************************************************************/
  18. /* Higher level event interface, supporting doublely-linked list,
  19. marking, selection, and linking of note pairs. */
  20. #include "event.H"
  21. #include <stdio.h>
  22. #include <string.h>
  23. void
  24. event::_init ( void )
  25. {
  26. _link = _next = _prev = NULL;
  27. _selected = 0;
  28. }
  29. event::event ( void )
  30. {
  31. _init();
  32. }
  33. event::~event ( void )
  34. {
  35. _link = _next = _prev = NULL;
  36. }
  37. /* copy constructor */
  38. event::event ( const event &e )
  39. {
  40. *this = e;
  41. _link = _next = _prev = NULL;
  42. }
  43. event::event ( const midievent &e ) : midievent( e )
  44. {
  45. _init();
  46. }
  47. void
  48. event::link ( event *event )
  49. {
  50. if ( event == NULL )
  51. {
  52. if ( _link )
  53. {
  54. _link->_link = NULL;
  55. _link = NULL;
  56. }
  57. return;
  58. }
  59. _link = event;
  60. _link->_link = this;
  61. }
  62. event *
  63. event::link ( void ) const
  64. {
  65. return _link;
  66. }
  67. bool
  68. event::linked ( void ) const
  69. {
  70. return _link != NULL;
  71. }
  72. void
  73. event::select ( void )
  74. {
  75. _selected = 1;
  76. if ( _link )
  77. _link->_selected = 1;
  78. }
  79. void
  80. event::deselect ( void )
  81. {
  82. _selected = 0;
  83. if ( _link )
  84. _link->_selected = 0;
  85. }
  86. bool
  87. event::selected ( int n ) const
  88. {
  89. return _selected == n;
  90. }
  91. bool
  92. event::selected ( void ) const
  93. {
  94. return _selected == 1;
  95. }
  96. /* override this so we can update linked event */
  97. void
  98. event::note ( char note )
  99. {
  100. midievent::note( note );
  101. if ( _link )
  102. _link->midievent::note( note );
  103. }
  104. /* stupid C++ makes us override the all polymorphic functions... */
  105. unsigned char
  106. event::note ( void ) const
  107. {
  108. return midievent::note();
  109. }
  110. tick_t
  111. event::note_duration ( void ) const
  112. {
  113. return _link ? _link->timestamp() - timestamp() : 0;
  114. }
  115. void
  116. event::note_duration ( tick_t l )
  117. {
  118. if ( _link )
  119. _link->timestamp( timestamp() + l );
  120. }