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.

179 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. if ( m == FL_PUSH && Fl::event_button3() && ! ( Fl::event_state() & ( FL_ALT | FL_CTRL | FL_SHIFT ) ) )
  70. {
  71. float t = _tempo;
  72. edit( &t );
  73. tempo( t );
  74. return 0;
  75. }
  76. return Sequence_Point::handle( m );
  77. }
  78. #include <FL/Fl_Float_Input.H>
  79. #include <FL/Fl_Menu_Window.H>
  80. class Tempo_Point_Editor : public Fl_Menu_Window
  81. {
  82. /* not permitted */
  83. Tempo_Point_Editor ( const Tempo_Point_Editor &rhs );
  84. Tempo_Point_Editor & operator = ( const Tempo_Point_Editor &rhs );
  85. float *_tempo;
  86. Fl_Float_Input *_fi;
  87. bool _sucess;
  88. public:
  89. Tempo_Point_Editor ( float *tempo ) : Fl_Menu_Window( 75, 58, "Edit Tempo" )
  90. {
  91. _sucess = false;
  92. _tempo = tempo;
  93. set_modal();
  94. Fl_Float_Input *fi = _fi = new Fl_Float_Input( 12, 0 + 24, 50, 24, "Tempo:" );
  95. fi->align( FL_ALIGN_TOP );
  96. fi->when( FL_WHEN_NOT_CHANGED | FL_WHEN_ENTER_KEY );
  97. fi->callback( &Tempo_Point_Editor::enter_cb, (void*)this );
  98. char pat[10];
  99. snprintf( pat, sizeof( pat ), "%.1f", *tempo );
  100. fi->value( pat );
  101. end();
  102. show();
  103. while ( shown() )
  104. Fl::wait();
  105. }
  106. static void
  107. enter_cb ( Fl_Widget *, void *v )
  108. {
  109. ((Tempo_Point_Editor*)v)->enter_cb();
  110. }
  111. void
  112. enter_cb ( void )
  113. {
  114. sscanf( _fi->value(), "%f", _tempo );
  115. _sucess = true;
  116. hide();
  117. }
  118. bool
  119. sucess ( void )
  120. {
  121. return _sucess;
  122. }
  123. };
  124. bool
  125. Tempo_Point::edit ( float *tempo )
  126. {
  127. Tempo_Point_Editor ti( tempo );
  128. return ti.sucess();
  129. }