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.

177 lines
4.9KB

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