1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
/**********************************************************************
Audacity: A Digital Audio Editor
Import.cpp
Dominic Mazzoni
This file contains a general function which will import almost
any type of sampled audio file (i.e. anything except MIDI)
and return the tracks that were imported. This function just
figures out which one to call; the actual importers are in
ImportPCM, ImportMP3, ImportOGG, and ImportRawData.
**********************************************************************/
#include "Audacity.h"
#include <wx/msgdlg.h>
#include <wx/string.h>
#include "ImportPCM.h"
#include "ImportMP3.h"
#include "ImportOGG.h"
#include "ImportRaw.h"
#include "Project.h"
// General purpose function used by importers
wxString TrackNameFromFileName(wxString fName)
{
return fName.AfterLast(wxFILE_SEP_PATH).BeforeFirst('.');
}
// returns number of tracks imported
int Import(AudacityProject *project,
wxString fName,
WaveTrack *** tracks)
{
bool success;
int numTracks = 0;
DirManager *dirManager = project->GetDirManager();
wxWindow *parent = project;
if (!fName.Right(3).CmpNoCase("aup")) {
wxMessageBox("Audacity does not support importing Audacity Projects.\n"
"Please use the Open command instead of Import.",
"Import audio file", wxOK | wxCENTRE, parent);
return 0;
}
if (!fName.Right(3).CmpNoCase("mid") ||
!fName.Right(3).CmpNoCase("midi")) {
wxMessageBox("Please use the Import MIDI command instead.",
"Import audio file", wxOK | wxCENTRE, parent);
return 0;
}
if (!fName.Right(3).CmpNoCase("mp3")) {
#ifdef MP3SUPPORT
*tracks = new WaveTrack *[2];
success =::ImportMP3(project, fName,
&(*tracks)[0], &(*tracks)[1]);
if (!success)
return 0;
numTracks = 1;
if ((*tracks)[1] != NULL)
numTracks = 2;
return numTracks;
#else
wxMessageBox("This version of Audacity was not compiled "
"with MP3 support.");
return 0;
#endif
}
if (!fName.Right(3).CmpNoCase("ogg")) {
#ifdef USE_LIBVORBIS
success =::ImportOGG(parent, fName, tracks, &numTracks, dirManager);
if (!success)
return 0;
return numTracks;
#else
wxMessageBox("This version of Audacity was not compiled "
"with Ogg Vorbis support.", "Import Ogg Vorbis",
wxOK | wxCENTRE, parent);
return 0;
#endif
}
if (::IsPCM(fName)) {
*tracks = new WaveTrack *[2];
success =::ImportPCM(parent, fName,
&(*tracks)[0], &(*tracks)[1], dirManager);
if (!success)
return 0;
numTracks = 1;
if ((*tracks)[1] != NULL)
numTracks = 2;
return numTracks;
}
int action = wxMessageBox("Audacity did not recognize the type "
"of this file.\n"
"Would you like to try to import it as "
"raw PCM audio data?",
"Unknown file type",
wxYES_NO | wxICON_EXCLAMATION,
parent);
if (action == wxYES) {
*tracks = new WaveTrack *[2];
success =::ImportRaw(parent, fName,
&(*tracks)[0], &(*tracks)[1], dirManager);
if (!success)
return 0;
numTracks = 1;
if ((*tracks)[1] != NULL)
numTracks = 2;
return numTracks;
}
return 0;
}
|