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.

197 lines
5.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 "Track.H"
  19. #include "Timeline.H"
  20. #include "Region.H"
  21. void
  22. Track::draw ( void )
  23. {
  24. Fl_Group::draw();
  25. for ( list <Region *>::iterator r = _regions.begin(); r != _regions.end(); r++ )
  26. {
  27. (*r)->draw( timeline.xoffset + x(), y(), w(), h() );
  28. }
  29. }
  30. void
  31. Track::remove_region ( Region *r )
  32. {
  33. _regions.remove( r );
  34. }
  35. Region *
  36. Track::event_region ( void )
  37. {
  38. // FIXME: doesn't handle overlap!
  39. for ( list <Region *>::iterator r = _regions.begin(); r != _regions.end(); r++ )
  40. {
  41. int X = timeline.ts_to_x( (*r)->offset() ) - timeline.xoffset;
  42. int W = timeline.ts_to_x( (*r)->length() );
  43. if ( Fl::event_x() > X && Fl::event_x() < X + W )
  44. return (*r);
  45. }
  46. return NULL;
  47. }
  48. void
  49. Track::add ( Region *r )
  50. {
  51. if ( r->track() )
  52. {
  53. r->track()->remove_region( r );
  54. r->track()->redraw();
  55. }
  56. _regions.push_back( r );
  57. r->track( this );
  58. // Fl_Group::add( r );
  59. // add( r );
  60. // r->position( r->x(), y() );
  61. // r->redraw();
  62. }
  63. /** snap /r/ to nearest edge */
  64. /* void */
  65. /* Track::snap ( Region *r ) */
  66. /* { */
  67. /* const int snap_pixels = 10; */
  68. /* int rx1 = r->x(); */
  69. /* int rx2 = r->x() + r->w(); */
  70. /* for ( int i = children(); i-- ; ) */
  71. /* { */
  72. /* const Region *w = (Region*)child( i ); */
  73. /* if ( w == r ) */
  74. /* continue; */
  75. /* int wx1 = w->x(); */
  76. /* int wx2 = w->x() + w->w(); */
  77. /* if ( abs( rx1 - wx2 ) < snap_pixels ) */
  78. /* { */
  79. /* r->offset( w->offset() + w->length() + 1 ); */
  80. /* printf( "snap: %lu | %lu\n", w->offset() + w->length(), r->offset() ); */
  81. /* goto done; */
  82. /* } */
  83. /* if ( abs( rx2 - wx1 ) < snap_pixels ) */
  84. /* { */
  85. /* r->offset( ( w->offset() - r->length() ) - 1 ); */
  86. /* printf( "snap: %lu | %lu\n", r->offset() + r->length(), w->offset() ); */
  87. /* goto done; */
  88. /* } */
  89. /* } */
  90. /* r->offset( timeline.x_to_ts( r->x() ) ); */
  91. /* done: */
  92. /* r->resize(); */
  93. /* // r->position( rx1, y() ); */
  94. /* } */
  95. int
  96. Track::handle ( int m )
  97. {
  98. static Region *current_region;
  99. switch ( m )
  100. {
  101. case FL_DND_DRAG:
  102. case FL_DND_ENTER:
  103. case FL_ENTER:
  104. return 1;
  105. case FL_DND_LEAVE:
  106. case FL_DND_RELEASE:
  107. return 1;
  108. case FL_PASTE:
  109. {
  110. const char *text = Fl::event_text();
  111. char *file;
  112. if ( ! sscanf( text, "file://%a[^\r\n]\n", &file ) )
  113. {
  114. printf( "invalid drop \"%s\"\n", text );
  115. return 0;
  116. }
  117. printf( "pasted file \"%s\"\n", file );
  118. Clip *c = Clip::from_file( file );
  119. if ( ! c )
  120. {
  121. free( file );
  122. return 0;
  123. }
  124. Region *r = new Region( c );
  125. r->offset( timeline.x_to_ts( Fl::event_x() ) );
  126. // r->position( Fl::event_x(), r->y() );
  127. this->add( r );
  128. return 1;
  129. }
  130. case FL_MOVE:
  131. /* these aren't used, so don't bother doing lookups for them */
  132. return 1;
  133. default:
  134. {
  135. Region *r = event_region();
  136. if ( current_region )
  137. r = current_region;
  138. if ( r )
  139. {
  140. int retval = r->handle( m );
  141. if ( retval && m == FL_PUSH )
  142. current_region = r;
  143. if ( retval && m == FL_RELEASE )
  144. current_region = NULL;
  145. return retval;
  146. }
  147. else
  148. return Fl_Group::handle( m );
  149. }
  150. }
  151. }