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.

176 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. void
  22. Tempo_Point::get ( Log_Entry &e ) const
  23. {
  24. // Sequence_Point::get( e );
  25. e.add( ":start", start() );
  26. e.add( ":tempo", _tempo );
  27. }
  28. void
  29. Tempo_Point::set ( Log_Entry &e )
  30. {
  31. Sequence_Point::set( e );
  32. for ( int i = 0; i < e.size(); ++i )
  33. {
  34. const char *s, *v;
  35. e.get( i, &s, &v );
  36. if ( ! strcmp( s, ":tempo" ) )
  37. _tempo = atof( v );
  38. /* /\* FIXME: we need to add this to the time track on creation!!! *\/ */
  39. /* timeline->tempo_track->add( this ); */
  40. }
  41. sequence()->handle_widget_change( start(), length() );
  42. _make_label();
  43. }
  44. Tempo_Point::Tempo_Point ( )
  45. {
  46. timeline->tempo_track->add( this );
  47. }
  48. Tempo_Point::Tempo_Point ( nframes_t when, float bpm )
  49. {
  50. _tempo = bpm;
  51. _make_label();
  52. timeline->tempo_track->add( this );
  53. start( when );
  54. log_create();
  55. }
  56. Tempo_Point::~Tempo_Point ( )
  57. {
  58. timeline->tempo_track->remove( this );
  59. log_destroy();
  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. }