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.

181 lines
4.2KB

  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 "Tempo_Point.H"
  19. #include "Tempo_Sequence.H"
  20. #include "Timeline.H" // for timeline->tempo_track
  21. Tempo_Point::Tempo_Point ( )
  22. {
  23. timeline->tempo_track->add( this );
  24. }
  25. Tempo_Point::Tempo_Point ( nframes_t when, float bpm )
  26. {
  27. _tempo = bpm;
  28. _make_label();
  29. timeline->tempo_track->add( this );
  30. start( when );
  31. log_create();
  32. }
  33. Tempo_Point::~Tempo_Point ( )
  34. {
  35. timeline->tempo_track->remove( this );
  36. log_destroy();
  37. }
  38. void
  39. Tempo_Point::get ( Log_Entry &e ) const
  40. {
  41. // Sequence_Point::get( e );
  42. e.add( ":start", start() );
  43. e.add( ":tempo", _tempo );
  44. }
  45. void
  46. Tempo_Point::set ( Log_Entry &e )
  47. {
  48. Sequence_Point::set( e );
  49. for ( int i = 0; i < e.size(); ++i )
  50. {
  51. const char *s, *v;
  52. e.get( i, &s, &v );
  53. if ( ! strcmp( s, ":tempo" ) )
  54. _tempo = atof( v );
  55. /* /\* FIXME: we need to add this to the time track on creation!!! *\/ */
  56. /* timeline->tempo_track->add( this ); */
  57. }
  58. sequence()->handle_widget_change( start(), length() );
  59. _make_label();
  60. }
  61. void
  62. Tempo_Point::log_children ( void ) const
  63. {
  64. log_create();
  65. }
  66. int
  67. Tempo_Point::handle ( int m )
  68. {
  69. Logger log( this );
  70. if ( m == FL_PUSH && Fl::event_button3() && ! ( Fl::event_state() & ( FL_ALT | FL_CTRL | FL_SHIFT ) ) )
  71. {
  72. float t = _tempo;
  73. edit( &t );
  74. tempo( t );
  75. return 0;
  76. }
  77. return Sequence_Point::handle( m );
  78. }
  79. #include <FL/Fl_Float_Input.H>
  80. #include <FL/Fl_Menu_Window.H>
  81. class Tempo_Point_Editor : public Fl_Menu_Window
  82. {
  83. /* not permitted */
  84. Tempo_Point_Editor ( const Tempo_Point_Editor &rhs );
  85. Tempo_Point_Editor & operator = ( const Tempo_Point_Editor &rhs );
  86. float *_tempo;
  87. Fl_Float_Input *_fi;
  88. bool _sucess;
  89. public:
  90. Tempo_Point_Editor ( float *tempo ) : Fl_Menu_Window( 75, 58, "Edit Tempo" )
  91. {
  92. _sucess = false;
  93. _tempo = tempo;
  94. set_modal();
  95. Fl_Float_Input *fi = _fi = new Fl_Float_Input( 12, 0 + 24, 50, 24, "Tempo:" );
  96. fi->align( FL_ALIGN_TOP );
  97. fi->when( FL_WHEN_NOT_CHANGED | FL_WHEN_ENTER_KEY );
  98. fi->callback( &Tempo_Point_Editor::enter_cb, (void*)this );
  99. char pat[10];
  100. snprintf( pat, sizeof( pat ), "%.1f", *tempo );
  101. fi->value( pat );
  102. end();
  103. show();
  104. while ( shown() )
  105. Fl::wait();
  106. }
  107. static void
  108. enter_cb ( Fl_Widget *, void *v )
  109. {
  110. ((Tempo_Point_Editor*)v)->enter_cb();
  111. }
  112. void
  113. enter_cb ( void )
  114. {
  115. sscanf( _fi->value(), "%f", _tempo );
  116. _sucess = true;
  117. hide();
  118. }
  119. bool
  120. sucess ( void )
  121. {
  122. return _sucess;
  123. }
  124. };
  125. bool
  126. Tempo_Point::edit ( float *tempo )
  127. {
  128. Tempo_Point_Editor ti( tempo );
  129. return ti.sucess();
  130. }