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.

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