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.

210 lines
5.1KB

  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. #include "Time_Point.H"
  19. #include "Time_Sequence.H"
  20. #include "Timeline.H" // for timeline->time_track
  21. Time_Point::Time_Point ( ) : _time( 4, 4 )
  22. {
  23. timeline->time_track->add( this );
  24. }
  25. Time_Point::Time_Point ( nframes_t when, int bpb, int note ) : _time( bpb, note )
  26. {
  27. _make_label();
  28. timeline->time_track->add( this );
  29. start( when );
  30. log_create();
  31. }
  32. Time_Point::Time_Point ( const Time_Point &rhs ) : Sequence_Point( rhs )
  33. {
  34. _time = rhs._time;
  35. log_create();
  36. }
  37. Time_Point::~Time_Point ( )
  38. {
  39. timeline->time_track->remove( this );
  40. log_destroy();
  41. }
  42. void
  43. Time_Point::get ( Log_Entry &e ) const
  44. {
  45. // Sequence_Point::get( e );
  46. e.add( ":start", start() );
  47. e.add( ":beats_per_bar", _time.beats_per_bar );
  48. e.add( ":beat_type", _time.beat_type );
  49. }
  50. void
  51. Time_Point::set ( Log_Entry &e )
  52. {
  53. Sequence_Point::set( e );
  54. for ( int i = 0; i < e.size(); ++i )
  55. {
  56. const char *s, *v;
  57. e.get( i, &s, &v );
  58. if ( ! strcmp( s, ":beats_per_bar" ) )
  59. _time.beats_per_bar = atoi( v );
  60. else if ( ! strcmp( s, ":beat_type" ) )
  61. _time.beat_type = atoi( v );
  62. /* /\* FIXME: we need to add this to the time track on creation!!! *\/ */
  63. /* timeline->time_track->add( this ); */
  64. }
  65. sequence()->handle_widget_change( start(), length() );
  66. _make_label();
  67. }
  68. void
  69. Time_Point::log_children ( void ) const
  70. {
  71. log_create();
  72. }
  73. int
  74. Time_Point::handle ( int m )
  75. {
  76. Logger log( this );
  77. if ( m == FL_PUSH && Fl::event_button3() && ! ( Fl::event_state() & ( FL_ALT | FL_CTRL | FL_SHIFT ) ) )
  78. {
  79. time_sig t = _time;
  80. edit( &t );
  81. time( t.beats_per_bar, t.beat_type );
  82. return 0;
  83. }
  84. return Sequence_Point::handle( m );
  85. }
  86. #include <FL/Fl_Int_Input.H>
  87. #include <FL/Fl_Menu_Window.H>
  88. class Time_Point_Editor : public Fl_Menu_Window
  89. {
  90. /* not permitted */
  91. Time_Point_Editor ( const Time_Point_Editor &rhs );
  92. Time_Point_Editor & operator = ( const Time_Point_Editor &rhs );
  93. time_sig *_sig;
  94. Fl_Int_Input *_beats;
  95. Fl_Int_Input *_beat_type;
  96. bool _sucess;
  97. public:
  98. Time_Point_Editor ( time_sig *sig )
  99. : Fl_Menu_Window( 150, 110, "Edit Time" )
  100. {
  101. _sig = sig;
  102. set_modal();
  103. {
  104. Fl_Int_Input *o = _beats = new Fl_Int_Input( 50, 0 + 24, 50, 24, "Beats Per Bar:" );
  105. o->align( FL_ALIGN_TOP );
  106. o->when( FL_WHEN_NOT_CHANGED | FL_WHEN_ENTER_KEY );
  107. o->callback( &Time_Point_Editor::enter_cb, (void*)this );
  108. }
  109. {
  110. Fl_Int_Input *o = _beat_type = new Fl_Int_Input( 50, 0 + 75, 50, 24, "Beat Type:" );
  111. o->align( FL_ALIGN_TOP );
  112. o->when( FL_WHEN_NOT_CHANGED | FL_WHEN_ENTER_KEY );
  113. o->callback( &Time_Point_Editor::enter_cb, (void*)this );
  114. }
  115. char pat[10];
  116. snprintf( pat, sizeof( pat ), "%d", _sig->beats_per_bar );
  117. _beats->value( pat );
  118. snprintf( pat, sizeof( pat ), "%d", _sig->beat_type );
  119. _beat_type->value( pat );
  120. end();
  121. show();
  122. while ( shown() )
  123. Fl::wait();
  124. }
  125. static void
  126. enter_cb ( Fl_Widget *, void *v )
  127. {
  128. ((Time_Point_Editor*)v)->enter_cb();
  129. }
  130. void
  131. enter_cb ( void )
  132. {
  133. _sig->beats_per_bar = atoi( _beats->value() );
  134. _sig->beat_type = atoi( _beat_type->value() );
  135. _sucess = true;
  136. hide();
  137. }
  138. bool
  139. sucess ( void )
  140. {
  141. return _sucess;
  142. }
  143. };
  144. bool
  145. Time_Point::edit ( time_sig *sig )
  146. {
  147. Time_Point_Editor ti( sig );
  148. return ti.sucess();
  149. }