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.

92 lines
2.7KB

  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 "Peak_Server.H"
  19. #include <stdio.h>
  20. #include <string.h>
  21. #include <sys/socket.h>
  22. /* Peak Server
  23. The peak server streams peak data to any timeline editors or other clients that ask for it.
  24. Peak request looks like:
  25. > read_peaks "foo.wav" fpp start end
  26. Response looks like (in binary floats):
  27. > channels length min max min max min max
  28. length ...
  29. */
  30. #include "Audio_File.H"
  31. #include "Peaks.H"
  32. typedef unsigned long tick_t;
  33. #define PEAK_PORT 6100
  34. void
  35. Peak_Server::handle_new ( int s )
  36. {
  37. printf( "new connection\n" );
  38. }
  39. void
  40. Peak_Server::handle_hang_up ( int s )
  41. {
  42. printf( "hangup\n" );
  43. }
  44. void
  45. Peak_Server::handle_request ( int s, const char *buf, int l )
  46. {
  47. printf( "request: %s", buf );
  48. char source[512];
  49. float fpp;
  50. tick_t start, end;
  51. if ( 4 != sscanf( buf, "read_peaks \"%[^\"]\" %f %lu %lu", source, &fpp, &start, &end ) )
  52. fprintf( stderr, "error: malformed peak request!\n" );
  53. Audio_File *af = Audio_File::from_file( source );
  54. int channels = af->channels();
  55. send( s, &channels, sizeof( int ), 0 );
  56. for ( int i = 0; i < af->channels(); ++i )
  57. {
  58. const Peaks *pk = af->peaks( i );
  59. int peaks = pk->fill_buffer( fpp, start, end );
  60. send( s, &peaks, sizeof( int ), 0 );
  61. send( s, pk->peakbuf(), peaks * sizeof( Peak ), 0 );
  62. }
  63. delete af;
  64. }