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.

187 lines
4.4KB

  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. timeline->update_tempomap();
  42. timeline->redraw();
  43. _make_label();
  44. }
  45. Tempo_Point::Tempo_Point ( )
  46. {
  47. timeline->tempo_track->add( this );
  48. timeline->update_tempomap();
  49. }
  50. Tempo_Point::Tempo_Point ( nframes_t when, float bpm )
  51. {
  52. _tempo = bpm;
  53. _r->start = when;
  54. _make_label();
  55. timeline->tempo_track->add( this );
  56. timeline->update_tempomap();
  57. log_create();
  58. }
  59. Tempo_Point::~Tempo_Point ( )
  60. {
  61. timeline->tempo_track->remove( this );
  62. timeline->update_tempomap();
  63. log_destroy();
  64. }
  65. int
  66. Tempo_Point::handle ( int m )
  67. {
  68. if ( m == FL_PUSH && Fl::event_button3() && ! ( Fl::event_state() & ( FL_ALT | FL_CTRL | FL_SHIFT ) ) )
  69. {
  70. float t = _tempo;
  71. edit( &t );
  72. tempo( t );
  73. return 0;
  74. }
  75. int r = Sequence_Widget::handle( m );
  76. if ( m == FL_RELEASE )
  77. {
  78. sequence()->sort();
  79. timeline->update_tempomap();
  80. timeline->redraw();
  81. }
  82. return r;
  83. }
  84. #include <FL/Fl_Float_Input.H>
  85. #include <FL/Fl_Menu_Window.H>
  86. class Tempo_Point_Editor : public Fl_Menu_Window
  87. {
  88. /* not permitted */
  89. Tempo_Point_Editor ( const Tempo_Point_Editor &rhs );
  90. Tempo_Point_Editor & operator = ( const Tempo_Point_Editor &rhs );
  91. float *_tempo;
  92. Fl_Float_Input *_fi;
  93. bool _sucess;
  94. public:
  95. Tempo_Point_Editor ( float *tempo ) : Fl_Menu_Window( 75, 58, "Edit Tempo" )
  96. {
  97. _sucess = false;
  98. _tempo = tempo;
  99. set_modal();
  100. Fl_Float_Input *fi = _fi = new Fl_Float_Input( 12, 0 + 24, 50, 24, "Tempo:" );
  101. fi->align( FL_ALIGN_TOP );
  102. fi->when( FL_WHEN_NOT_CHANGED | FL_WHEN_ENTER_KEY );
  103. fi->callback( &Tempo_Point_Editor::enter_cb, (void*)this );
  104. char pat[10];
  105. snprintf( pat, sizeof( pat ), "%.1f", *tempo );
  106. fi->value( pat );
  107. end();
  108. show();
  109. while ( shown() )
  110. Fl::wait();
  111. }
  112. static void
  113. enter_cb ( Fl_Widget *w, void *v )
  114. {
  115. ((Tempo_Point_Editor*)v)->enter_cb();
  116. }
  117. void
  118. enter_cb ( void )
  119. {
  120. sscanf( _fi->value(), "%f", _tempo );
  121. _sucess = true;
  122. hide();
  123. }
  124. bool
  125. sucess ( void )
  126. {
  127. return _sucess;
  128. }
  129. };
  130. bool
  131. Tempo_Point::edit ( float *tempo )
  132. {
  133. Tempo_Point_Editor ti( tempo );
  134. return ti.sucess();
  135. }