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.

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