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.

152 lines
4.0KB

  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. void
  21. Track::draw ( void )
  22. {
  23. for ( list <Region *>::iterator r = _regions.begin(); r != _regions.end(); r++ )
  24. {
  25. (*r)->draw( x(), y(), w(), h() );
  26. }
  27. }
  28. void
  29. Track::remove_region ( Region *r )
  30. {
  31. _regions.remove( r );
  32. }
  33. void
  34. Track::add ( Region *r )
  35. {
  36. if ( r->track() )
  37. {
  38. r->track()->remove_region( r );
  39. r->track()->redraw();
  40. }
  41. _regions.push_back( r );
  42. r->track( this );
  43. // Fl_Group::add( r );
  44. // add( r );
  45. // r->position( r->x(), y() );
  46. // r->redraw();
  47. }
  48. /** snap /r/ to nearest edge */
  49. /* void */
  50. /* Track::snap ( Region *r ) */
  51. /* { */
  52. /* const int snap_pixels = 10; */
  53. /* int rx1 = r->x(); */
  54. /* int rx2 = r->x() + r->w(); */
  55. /* for ( int i = children(); i-- ; ) */
  56. /* { */
  57. /* const Region *w = (Region*)child( i ); */
  58. /* if ( w == r ) */
  59. /* continue; */
  60. /* int wx1 = w->x(); */
  61. /* int wx2 = w->x() + w->w(); */
  62. /* if ( abs( rx1 - wx2 ) < snap_pixels ) */
  63. /* { */
  64. /* r->offset( w->offset() + w->length() + 1 ); */
  65. /* printf( "snap: %lu | %lu\n", w->offset() + w->length(), r->offset() ); */
  66. /* goto done; */
  67. /* } */
  68. /* if ( abs( rx2 - wx1 ) < snap_pixels ) */
  69. /* { */
  70. /* r->offset( ( w->offset() - r->length() ) - 1 ); */
  71. /* printf( "snap: %lu | %lu\n", r->offset() + r->length(), w->offset() ); */
  72. /* goto done; */
  73. /* } */
  74. /* } */
  75. /* r->offset( timeline.x_to_ts( r->x() ) ); */
  76. /* done: */
  77. /* r->resize(); */
  78. /* // r->position( rx1, y() ); */
  79. /* } */
  80. int
  81. Track::handle ( int m )
  82. {
  83. switch ( m )
  84. {
  85. case FL_DND_DRAG:
  86. case FL_DND_ENTER:
  87. case FL_ENTER:
  88. return 1;
  89. case FL_DND_LEAVE:
  90. case FL_DND_RELEASE:
  91. return 1;
  92. case FL_PASTE:
  93. {
  94. const char *text = Fl::event_text();
  95. char *file;
  96. if ( ! sscanf( text, "file://%a[^\r\n]\n", &file ) )
  97. {
  98. printf( "invalid drop \"%s\"\n", text );
  99. return 0;
  100. }
  101. printf( "pasted file \"%s\"\n", file );
  102. Clip *c = Clip::from_file( file );
  103. if ( ! c )
  104. {
  105. free( file );
  106. return 0;
  107. }
  108. Region *r = new Region( c );
  109. r->offset( timeline.x_to_ts( Fl::event_x() ) );
  110. // r->position( Fl::event_x(), r->y() );
  111. this->add( r );
  112. return 1;
  113. }
  114. default:
  115. return Fl_Group::handle( m );
  116. }
  117. }