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.

118 lines
3.2KB

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