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.

106 lines
2.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. #include "Audio_File.H"
  19. #include "Audio_File_SF.H"
  20. #include "Audio_File_Dummy.H"
  21. #include "debug.h"
  22. std::map <std::string, Audio_File*> Audio_File::_open_files;
  23. Audio_File::~Audio_File ( )
  24. {
  25. _open_files[ std::string( _filename ) ] = NULL;
  26. if ( _filename )
  27. free( _filename );
  28. }
  29. void
  30. Audio_File::all_supported_formats ( std::list <const char *> &formats )
  31. {
  32. const format_desc *fd;
  33. fd = Audio_File_SF::supported_formats;
  34. for ( ; fd->name; ++fd )
  35. formats.push_back( fd->name );
  36. }
  37. /** attmpet to open any supported filetype */
  38. Audio_File *
  39. Audio_File::from_file ( const char * filename )
  40. {
  41. Audio_File *a;
  42. if ( ( a = _open_files[ std::string( filename ) ] ) )
  43. return a;
  44. if ( ( a = Audio_File_SF::from_file( filename ) ) )
  45. goto done;
  46. // TODO: other formats
  47. DWARNING( "creating dummy source for \"%s\"", filename );
  48. /* FIXME: wrong place for this? */
  49. if ( ( a = Audio_File_Dummy::from_file( filename ) ) )
  50. goto done;
  51. return NULL;
  52. done:
  53. _open_files[ std::string( filename ) ] = a;
  54. return a;
  55. }
  56. bool
  57. Audio_File::read_peaks( float fpp, nframes_t start, nframes_t end, int *peaks, Peak **pbuf, int *channels )
  58. {
  59. // Peaks pk;
  60. if ( dummy() )
  61. {
  62. *peaks = (end - start) / fpp;
  63. *channels = 0;
  64. *pbuf = NULL;
  65. return false;
  66. }
  67. else
  68. {
  69. *peaks = 0;
  70. *channels = 0;
  71. *pbuf = NULL;
  72. *peaks = _peaks.fill_buffer( fpp, start, end );
  73. *channels = this->channels();
  74. *pbuf = _peaks.peakbuf();
  75. return true;
  76. }
  77. }