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.

171 lines
4.6KB

  1. /*******************************************************************************/
  2. /* Copyright (C) 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. #pragma once
  19. #include "Track_Point.H"
  20. #include "Loggable.H"
  21. struct time_sig
  22. {
  23. int beats_per_bar;
  24. int beat_type;
  25. time_sig ( int bpb, int note )
  26. {
  27. beats_per_bar = bpb;
  28. beat_type = note;
  29. }
  30. };
  31. #define __CLASS__ "Time_Point"
  32. class Time_Point : public Track_Point
  33. {
  34. time_sig _time;
  35. void
  36. _make_label ( void )
  37. {
  38. if ( ! _label )
  39. _label = new char[40];
  40. snprintf( _label, 40, "%d/%d", _time.beats_per_bar, _time.beat_type );
  41. }
  42. Time_Point ( ) : _time( 4, 4 )
  43. {
  44. }
  45. protected:
  46. const char *class_name ( void ) { return "Time_Point"; }
  47. char ** get ( void )
  48. {
  49. char **sa = (char**)malloc( sizeof( char* ) * 5 );
  50. int i = 0;
  51. asprintf( &sa[i++], ":track 0x%X", _track ? _track->id() : 0 );
  52. asprintf( &sa[i++], ":x %lu", _offset );
  53. asprintf( &sa[i++], ":beats_per_bar %d", _time.beats_per_bar );
  54. asprintf( &sa[i++], ":beat_type %d", _time.beat_type );
  55. sa[i] = NULL;
  56. return sa;
  57. }
  58. void
  59. set ( char **sa )
  60. {
  61. for ( int i = 0; sa[i]; ++i )
  62. {
  63. char *s = sa[i];
  64. strtok( s, " " );
  65. char *v = s + strlen( s ) + 1;
  66. if ( ! strcmp( s, ":x" ) )
  67. _offset = atol( v );
  68. else
  69. if ( ! strcmp( s, ":beats_per_bar" ) )
  70. _time.beats_per_bar = atoi( v );
  71. else
  72. if ( ! strcmp( s, ":beat_type" ) )
  73. _time.beat_type = atoi( v );
  74. else
  75. if ( ! strcmp( s, ":track" ) )
  76. {
  77. int i;
  78. sscanf( v, "%X", &i );
  79. Track *t = (Track*)Loggable::find( i );
  80. assert( t );
  81. t->add( this );
  82. }
  83. free( s );
  84. }
  85. free( sa );
  86. timeline->redraw();
  87. _make_label();
  88. }
  89. public:
  90. /* for loggable */
  91. static Loggable *
  92. create ( char **sa )
  93. {
  94. Time_Point *r = new Time_Point;
  95. r->set( sa );
  96. return (Loggable *)r;
  97. }
  98. Time_Point ( nframes_t when, int bpb, int note ) : _time( bpb, note )
  99. {
  100. _offset = when;
  101. _make_label();
  102. log_create();
  103. }
  104. ~Time_Point ( )
  105. {
  106. if ( _label ) delete[] _label;
  107. log_destroy();
  108. }
  109. /* beats_per_bar ( void ) const { return _time.beats_per_bar; } */
  110. /* beat_type ( void ) const { return _beat_type; } */
  111. void time ( int bpb, int note ) { _time.beats_per_bar = bpb; _time.beat_type = note; }
  112. time_sig time ( void ) const { return _time; }
  113. int
  114. handle ( int m )
  115. {
  116. int r = Track_Widget::handle( m );
  117. if ( m == FL_RELEASE )
  118. {
  119. _track->sort();
  120. timeline->redraw();
  121. }
  122. return r;
  123. }
  124. };
  125. #undef __CLASS__