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.

94 lines
2.6KB

  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. std::map <std::string, Audio_File*> Audio_File::_open_files;
  21. Audio_File::~Audio_File ( )
  22. {
  23. _open_files[ std::string( _filename ) ] = NULL;
  24. }
  25. void
  26. Audio_File::all_supported_formats ( std::list <const char *> &formats )
  27. {
  28. const format_desc *fd;
  29. fd = Audio_File_SF::supported_formats;
  30. for ( ; fd->name; ++fd )
  31. formats.push_back( fd->name );
  32. }
  33. /** attmpet to open any supported filetype */
  34. Audio_File *
  35. Audio_File::from_file ( const char * filename )
  36. {
  37. Audio_File *a;
  38. if ( ( a = _open_files[ std::string( filename ) ] ) )
  39. return a;
  40. if ( ( a = Audio_File_SF::from_file( filename ) ) )
  41. goto done;
  42. // TODO: other formats
  43. return NULL;
  44. done:
  45. /* a->_peaks = new Peaks; */
  46. /* a->_peaks->clip( a ); */
  47. /* a->_peaks->open(); */
  48. _open_files[ std::string( filename ) ] = a;
  49. return a;
  50. }
  51. bool
  52. Audio_File::read_peaks( float fpp, nframes_t start, nframes_t end, int *peaks, Peak **pbuf, int *channels )
  53. {
  54. Peaks pk;
  55. *peaks = 0;
  56. *channels = 0;
  57. *pbuf = NULL;
  58. pk.clip( this );
  59. if ( ! pk.open() )
  60. return false;
  61. *peaks = pk.fill_buffer( fpp, start, end );
  62. *channels = this->channels();
  63. *pbuf = pk.peakbuf();
  64. return true;
  65. }