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.

144 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 ) : midievent( e )
  39. {
  40. _link = _next = _prev = NULL;
  41. }
  42. event::event ( const midievent &e ) : midievent( e )
  43. {
  44. _init();
  45. }
  46. void
  47. event::link ( event *event )
  48. {
  49. if ( event == NULL )
  50. {
  51. if ( _link )
  52. {
  53. _link->_link = NULL;
  54. _link = NULL;
  55. }
  56. return;
  57. }
  58. _link = event;
  59. _link->_link = this;
  60. }
  61. event *
  62. event::link ( void ) const
  63. {
  64. return _link;
  65. }
  66. bool
  67. event::linked ( void ) const
  68. {
  69. return _link != NULL;
  70. }
  71. void
  72. event::select ( void )
  73. {
  74. _selected = 1;
  75. if ( _link )
  76. _link->_selected = 1;
  77. }
  78. void
  79. event::deselect ( void )
  80. {
  81. _selected = 0;
  82. if ( _link )
  83. _link->_selected = 0;
  84. }
  85. bool
  86. event::selected ( int n ) const
  87. {
  88. return _selected == n;
  89. }
  90. bool
  91. event::selected ( void ) const
  92. {
  93. return _selected == 1;
  94. }
  95. /* override this so we can update linked event */
  96. void
  97. event::note ( char note )
  98. {
  99. midievent::note( note );
  100. if ( _link )
  101. _link->midievent::note( note );
  102. }
  103. /* stupid C++ makes us override the all polymorphic functions... */
  104. unsigned char
  105. event::note ( void ) const
  106. {
  107. return midievent::note();
  108. }
  109. tick_t
  110. event::note_duration ( void ) const
  111. {
  112. return _link ? _link->timestamp() - timestamp() : 0;
  113. }
  114. void
  115. event::note_duration ( tick_t l )
  116. {
  117. if ( _link )
  118. _link->timestamp( timestamp() + l );
  119. }