~ubuntu-branches/ubuntu/gutsy/audacity/gutsy-backports

« back to all changes in this revision

Viewing changes to src/import/Import.cpp

  • Committer: Bazaar Package Importer
  • Author(s): John Dong
  • Date: 2008-02-18 21:58:19 UTC
  • mfrom: (13.1.2 hardy)
  • Revision ID: james.westby@ubuntu.com-20080218215819-tmbcf1rx238r8gdv
Tags: 1.3.4-1.1ubuntu1~gutsy1
Automated backport upload; no source changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
55
55
 
56
56
WX_DEFINE_LIST(ImportPluginList);
57
57
WX_DEFINE_LIST(UnusableImportPluginList);
 
58
WX_DEFINE_LIST(FormatList);
58
59
 
59
60
Importer::Importer()
60
61
{
99
100
int Importer::Import(wxString fName,
100
101
                     TrackFactory *trackFactory,
101
102
                     Track *** tracks,
 
103
                     Tags *tags,
102
104
                     wxString &errorMessage,
103
105
                     progress_callback_t progressCallback,
104
106
                     void *userData)
119
121
         if( mInFile != NULL )
120
122
         {
121
123
            mInFile->SetProgressCallback(progressCallback, userData);
122
 
            if( mInFile->Import(trackFactory, tracks, &numTracks) == true )
 
124
            int res = (mInFile->Import(trackFactory, tracks, &numTracks, tags) == true );
 
125
 
 
126
            delete mInFile;
 
127
 
 
128
            if( res )
123
129
            {
124
130
               // LOF ("list-of-files") has different semantics
125
131
               if (extension.IsSameAs(wxT("lof"), false))
127
133
 
128
134
               if (numTracks > 0) {
129
135
                  // success!
130
 
                  delete mInFile;
131
136
                  return numTracks;
132
137
               }
133
138
            }
134
 
            delete mInFile;
135
 
         }
136
 
      }
137
 
      importPluginNode = importPluginNode->GetNext();
138
 
   }
139
 
 
140
 
   // no importPlugin that recognized the extension succeeded.  However, the
141
 
   // file might be misnamed.  So this time we try all the importPlugins
142
 
   //in order and see if any of them can handle the file
143
 
   importPluginNode = mImportPluginList->GetFirst();
144
 
   while(importPluginNode)
145
 
   {
146
 
      ImportPlugin *plugin = importPluginNode->GetData();
147
 
 
148
 
      mInFile = plugin->Open(fName);
149
 
      if( mInFile != NULL )
150
 
      {
151
 
         mInFile->SetProgressCallback(progressCallback, userData);
152
 
         numTracks = 0;
153
 
         if(mInFile->Import(trackFactory, tracks, &numTracks))
154
 
         {
155
 
            if (numTracks > 0) {
156
 
               // success!
157
 
               delete mInFile;
158
 
               return numTracks;
159
 
            }
160
 
         }
161
 
         delete mInFile;
162
 
 
163
 
         // This will happen if the user cancelled, or if we
164
 
         // tried and got an error partially through.  Either way,
165
 
         // no need to try any other formats at this point!
166
 
         if (numTracks > 0)
167
 
            return 0;
 
139
         }
168
140
      }
169
141
      importPluginNode = importPluginNode->GetNext();
170
142
   }
191
163
 
192
164
   // if someone has sent us a .cda file, send them away
193
165
   if (extension.IsSameAs(wxT("cda"), false)) {
194
 
      errorMessage = wxT("\"") + fName + wxT("\"") + 
195
 
         _(" is an audio CD file. \nAudacity does not open this type of file.\nTry ripping it to a native audio format that Audacity can import.");
 
166
      /* i18n-hint: %s will be the filename */
 
167
      errorMessage.Printf(_("\"%s\" is an audio CD track. \nAudacity cannot open audio CDs directly. \nExtract (rip) the CD tracks to an audio format that \nAudacity can import, such as WAV or AIFF."), fName.c_str());
196
168
      return 0;
197
169
   }
198
170
 
199
171
   // playlist type files
200
172
   if ((extension.IsSameAs(wxT("m3u"), false))||(extension.IsSameAs(wxT("ram"), false))||(extension.IsSameAs(wxT("pls"), false))) {
201
 
      errorMessage = wxT("\"") + fName + wxT("\"") + 
202
 
         _(" is a playlist file.\nAudacity cannot open this file because it only contains links to other files.\nYou may be able to open it in a text editor and download the actual audio files.");
 
173
      errorMessage.Printf(_("\"%s\" is a playlist file. \nAudacity cannot open this file because it only contains links to other files. \nYou may be able to open it in a text editor and download the actual audio files."), fName.c_str());
203
174
      return 0;
204
175
   }
205
176
   //WMA files of various forms
206
177
   if ((extension.IsSameAs(wxT("wmv"), false))||(extension.IsSameAs(wxT("wma"), false))||(extension.IsSameAs(wxT("asf"), false))) {
207
 
      errorMessage = wxT("\"") + fName + wxT("\"") + 
208
 
         _(" is a Windows Media Audio file. \nAudacity cannot open this type of file to due to patent restrictions.\nYou need to convert it to a supported audio format.");
 
178
      errorMessage.Printf(_("\"%s\" is a Windows Media Audio file. \nAudacity cannot open this type of file due to patent restrictions. \nYou need to convert it to a supported audio format, such as WAV or AIFF."), fName.c_str());
209
179
      return 0;
210
180
   }
211
181
   //AAC files of various forms (probably not encrypted)
212
182
   if ((extension.IsSameAs(wxT("aac"), false))||(extension.IsSameAs(wxT("m4a"), false))||(extension.IsSameAs(wxT("mpa"), false))||(extension.IsSameAs(wxT("mp4"), false))) {
213
 
      errorMessage = wxT("\"") + fName + wxT("\"") + 
214
 
         _(" is an Advanced Audio Coding file. \nAudacity cannot open this type of file.\nYou need to convert it to a supported audio format.");
 
183
      errorMessage.Printf(_("\"%s\" is an Advanced Audio Coding file. \nAudacity cannot open this type of file. \nYou need to convert it to a supported audio format, such as WAV or AIFF."), fName.c_str());
215
184
      return 0;
216
185
   }
217
186
   // encrypted itunes files
218
187
   if ((extension.IsSameAs(wxT("m4p"), false))) {
219
 
      errorMessage = wxT("\"") + fName + wxT("\"") + 
220
 
         _(" is an encrypted audio file, typically from an online music store. \nAudacity cannot open this type of file due to the encryption.\nYou need to convert it to a supported, unencrypted audio format.");
 
188
      errorMessage.Printf(_("\"%s\" is an encrypted audio file. These typically are from an online music store. \nAudacity cannot open this type of file due to the encryption. \nTry recording the file into Audacity, or burn it to audio CD then \nextract the CD track to a supported audio format such as WAV or AIFF."), fName.c_str());
221
189
      return 0;
222
190
   }
223
191
   // Real files of various sorts
224
192
   if ((extension.IsSameAs(wxT("ra"), false))||(extension.IsSameAs(wxT("rm"), false))||(extension.IsSameAs(wxT("rpm"), false))||(extension.IsSameAs(wxT("rv"), false))) {
225
 
      errorMessage = wxT("\"") + fName + wxT("\"") + 
226
 
         _(" is a RealPlayer media file. \nAudacity cannot open this proprietary format.\nYou need to convert it to a supported audio format.");
 
193
      errorMessage.Printf(_("\"%s\" is a RealPlayer media file. \nAudacity cannot open this proprietary format. \nYou need to convert it to a supported audio format, such as WAV or AIFF."), fName.c_str());
227
194
      return 0;
228
195
   }
229
196
 
 
197
 
 
198
   // no importPlugin that recognized the extension succeeded.  However, the
 
199
   // file might be misnamed.  So this time we try all the importPlugins
 
200
   //in order and see if any of them can handle the file
 
201
   importPluginNode = mImportPluginList->GetFirst();
 
202
   while(importPluginNode)
 
203
   {
 
204
      ImportPlugin *plugin = importPluginNode->GetData();
 
205
 
 
206
      mInFile = plugin->Open(fName);
 
207
      if( mInFile != NULL )
 
208
      {
 
209
         mInFile->SetProgressCallback(progressCallback, userData);
 
210
         numTracks = 0;
 
211
         if(mInFile->Import(trackFactory, tracks, &numTracks, tags))
 
212
         {
 
213
            if (numTracks > 0) {
 
214
               // success!
 
215
               delete mInFile;
 
216
               errorMessage = _( "Audacity had to make a guess at the type of file.\nThe Audio may be bogus.\n\nIf the audio is bogus, try renaming the file\nso that it has the correct extension before opening it.");
 
217
               return numTracks;
 
218
            }
 
219
         }
 
220
         delete mInFile;
 
221
 
 
222
         // This will happen if the user cancelled, or if we
 
223
         // tried and got an error partially through.  Either way,
 
224
         // no need to try any other formats at this point!
 
225
         if (numTracks > 0)
 
226
            return 0;
 
227
      }
 
228
      importPluginNode = importPluginNode->GetNext();
 
229
   }
 
230
 
230
231
   // we were not able to recognize the file type
231
232
   errorMessage = _("Audacity did not recognize the type of this file.\nIf it is uncompressed, try importing it using \"Import Raw\"" );
232
233
   return 0;