videoeditorengine/audioeditorengine/src/AudClip.cpp
changeset 0 951a5db380a0
equal deleted inserted replaced
-1:000000000000 0:951a5db380a0
       
     1 /*
       
     2 * Copyright (c) 2010 Ixonos Plc.
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - Initial contribution
       
    11 *
       
    12 * Contributors:
       
    13 * Ixonos Plc
       
    14 *
       
    15 * Description:  
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 /* Copyright (c) 2003 Nokia. All rights reserved. */
       
    21 
       
    22 #include "AudClip.h"
       
    23 #include "AudPanic.h"
       
    24 
       
    25 #include "AudClipInfo.h"
       
    26 #include "AudSong.h"
       
    27 #include "ProcTools.h"
       
    28 
       
    29     
       
    30 CAudClip* CAudClip::NewL(CAudSong* aSong, const TDesC& aFileName,
       
    31         TTimeIntervalMicroSeconds aStartTime,                            
       
    32         MAudClipInfoObserver& aObserver, TInt aTrackIndex) 
       
    33     {
       
    34     
       
    35     CAudClip* self = new (ELeave) CAudClip(aSong);
       
    36     CleanupStack::PushL(self);
       
    37     self->ConstructL(aFileName, aStartTime, aObserver, aTrackIndex);
       
    38     CleanupStack::Pop(self);
       
    39     return self;
       
    40     
       
    41     }
       
    42     
       
    43 CAudClip* CAudClip::NewL(CAudSong* aSong, RFile* aFileHandle,
       
    44         TTimeIntervalMicroSeconds aStartTime,                            
       
    45         MAudClipInfoObserver& aObserver, TInt aTrackIndex) 
       
    46     {
       
    47     
       
    48     CAudClip* self = new (ELeave) CAudClip(aSong);
       
    49     CleanupStack::PushL(self);
       
    50     self->ConstructL(aFileHandle, aStartTime, aObserver, aTrackIndex);
       
    51     CleanupStack::Pop(self);
       
    52     return self;
       
    53     
       
    54     }
       
    55 
       
    56 
       
    57 CAudClip::CAudClip(CAudSong* aSong) : iSong(aSong), iMute(EFalse), iNormalize(EFalse), 
       
    58 iPriority(KAudClipPriorityNormal) 
       
    59     {
       
    60     
       
    61     }
       
    62 
       
    63 EXPORT_C CAudClipInfo* CAudClip::Info() const 
       
    64     {
       
    65 
       
    66     return iInfo;
       
    67     }
       
    68 
       
    69 EXPORT_C TBool CAudClip::Normalizing() const 
       
    70     {
       
    71 
       
    72     return iNormalize;
       
    73     }
       
    74 
       
    75 EXPORT_C TAudDynamicLevelMark CAudClip::DynamicLevelMark(TInt aIndex) const 
       
    76     {
       
    77 
       
    78     return *iDynamicLevelMarkArray[aIndex];
       
    79     }
       
    80     
       
    81 EXPORT_C TInt CAudClip::DynamicLevelMarkCount() const 
       
    82     {
       
    83 
       
    84     return iDynamicLevelMarkArray.Count();
       
    85     }
       
    86 EXPORT_C TBool CAudClip::Muting() const
       
    87     {
       
    88     return iMute;
       
    89     }
       
    90 
       
    91 EXPORT_C void CAudClip::SetStartTime(TTimeIntervalMicroSeconds aStartTime) 
       
    92     {
       
    93 
       
    94     if (iStartTime.Int64() != aStartTime.Int64()-iCutInTime.Int64()) 
       
    95         {
       
    96         iStartTime = aStartTime.Int64()-iCutInTime.Int64();
       
    97         }
       
    98         
       
    99 
       
   100     TInt clipIndexOnSong = iSong->FindClipIndexOnSong(this);
       
   101     TInt newIndex = 0;
       
   102     TBool found = EFalse;
       
   103     for (newIndex = 0 ; newIndex < iSong->ClipCount(KAllTrackIndices); newIndex++) 
       
   104         {
       
   105         if (iSong->iClipArray[newIndex]->StartTime() > aStartTime) 
       
   106             {
       
   107             found = ETrue;
       
   108             break;
       
   109             }
       
   110         }
       
   111     if (!found) 
       
   112         {
       
   113         newIndex = iSong->ClipCount(KAllTrackIndices);
       
   114         }
       
   115 
       
   116     // the order is the same
       
   117     if (newIndex == clipIndexOnSong || newIndex == clipIndexOnSong+1) 
       
   118         {
       
   119         
       
   120         iSong->FireClipTimingsChanged(iSong, this);
       
   121         }
       
   122     else 
       
   123         {
       
   124 
       
   125 
       
   126         TInt oldIndexOnTrack = iIndex;
       
   127         iSong->UpdateClipArray();
       
   128         iSong->UpdateClipIndexes();
       
   129         TInt newIndexOnTrack = iIndex;
       
   130 
       
   131         if (oldIndexOnTrack != newIndexOnTrack) 
       
   132             {
       
   133             iSong->FireClipIndicesChanged(iSong, oldIndexOnTrack, newIndexOnTrack, iTrackIndex);
       
   134             }
       
   135         else 
       
   136             {
       
   137             iSong->FireClipTimingsChanged(iSong, this);
       
   138             }
       
   139 
       
   140         }
       
   141 
       
   142     }
       
   143 
       
   144 
       
   145 
       
   146 
       
   147 EXPORT_C TTimeIntervalMicroSeconds CAudClip::StartTime() const 
       
   148     {
       
   149 
       
   150     return iStartTime.Int64()+iCutInTime.Int64();
       
   151     }
       
   152 
       
   153 
       
   154 
       
   155 TInt32 CAudClip::StartTimeMilliSeconds() const 
       
   156     {
       
   157 
       
   158     return ProcTools::MilliSeconds(iStartTime);
       
   159     
       
   160     }
       
   161 
       
   162 EXPORT_C TTimeIntervalMicroSeconds CAudClip::EndTime() const
       
   163     {
       
   164     return TTimeIntervalMicroSeconds(iStartTime.Int64()+iCutOutTime.Int64());
       
   165 
       
   166     }
       
   167 
       
   168 
       
   169 EXPORT_C TTimeIntervalMicroSeconds CAudClip::EditedDuration() const
       
   170     {
       
   171     TTimeIntervalMicroSeconds edDur(iCutOutTime.Int64()-iCutInTime.Int64());
       
   172     return edDur;
       
   173 
       
   174     }
       
   175 
       
   176 EXPORT_C TInt CAudClip::Priority() const
       
   177     {
       
   178     return iPriority;
       
   179     
       
   180     }
       
   181 
       
   182 
       
   183 EXPORT_C TInt CAudClip::IndexOnTrack() const 
       
   184     {
       
   185 
       
   186     return iIndex;
       
   187     }
       
   188 
       
   189 
       
   190 
       
   191 EXPORT_C TInt CAudClip::TrackIndex() const 
       
   192     {
       
   193 
       
   194     return iTrackIndex;
       
   195     }
       
   196 
       
   197 
       
   198 EXPORT_C TTimeIntervalMicroSeconds CAudClip::CutInTime() const 
       
   199     {
       
   200     
       
   201     return iCutInTime;
       
   202     }
       
   203     
       
   204 
       
   205 TInt32 CAudClip::CutInTimeMilliSeconds() const 
       
   206     {
       
   207 
       
   208     return ProcTools::MilliSeconds(iCutInTime);
       
   209     
       
   210     }
       
   211 
       
   212 EXPORT_C void CAudClip::SetCutInTime(TTimeIntervalMicroSeconds aCutInTime) 
       
   213     {
       
   214 
       
   215     TInt64 oldCutIn = iCutInTime.Int64();
       
   216     TInt64 cutDif = aCutInTime.Int64() - oldCutIn;  
       
   217 
       
   218     iCutInTime = aCutInTime;
       
   219     iStartTime = (TTimeIntervalMicroSeconds)(iStartTime.Int64()-cutDif);
       
   220     iSong->FireClipTimingsChanged(iSong, this);
       
   221     }
       
   222     
       
   223 EXPORT_C TTimeIntervalMicroSeconds CAudClip::CutOutTime() const 
       
   224     {
       
   225 
       
   226     return iCutOutTime;
       
   227     }
       
   228 
       
   229 TInt32 CAudClip::CutOutTimeMilliSeconds() const 
       
   230     {
       
   231 
       
   232     return ProcTools::MilliSeconds(iCutOutTime);
       
   233     
       
   234 
       
   235     }
       
   236     
       
   237 EXPORT_C void CAudClip::SetCutOutTime(TTimeIntervalMicroSeconds aCutOutTime) 
       
   238     {
       
   239 
       
   240     iCutOutTime = aCutOutTime;
       
   241     iSong->FireClipTimingsChanged(iSong, this);
       
   242     }
       
   243 
       
   244 
       
   245 
       
   246 
       
   247 EXPORT_C TBool CAudClip::SetPriority(TInt aPriority)
       
   248 
       
   249     {
       
   250     if (aPriority < 0) return EFalse;
       
   251 
       
   252     iPriority = aPriority;
       
   253     return ETrue;
       
   254 
       
   255     }
       
   256 
       
   257 
       
   258 EXPORT_C TInt CAudClip::InsertDynamicLevelMarkL(const TAudDynamicLevelMark& aMark) 
       
   259     {
       
   260 
       
   261     if (aMark.iTime < TTimeIntervalMicroSeconds(0)) 
       
   262         {
       
   263         TAudPanic::Panic(TAudPanic::EIllegalDynamicLevelMark);
       
   264         }
       
   265 
       
   266     TAudDynamicLevelMark* newMark = new (ELeave) TAudDynamicLevelMark(aMark);
       
   267     
       
   268     TBool added = EFalse;
       
   269     TInt err = KErrNone;
       
   270 
       
   271     // insert marks so that they are always sorted by time
       
   272     TInt index = 0;
       
   273     for (index = 0 ; index < iDynamicLevelMarkArray.Count() ; index++) 
       
   274         {
       
   275         if (iDynamicLevelMarkArray[index]->iTime == newMark->iTime) 
       
   276             {
       
   277             // replace the level
       
   278             TAudDynamicLevelMark* oldMark = iDynamicLevelMarkArray[index];
       
   279             iDynamicLevelMarkArray.Remove(index);
       
   280             delete oldMark;
       
   281             err = iDynamicLevelMarkArray.Insert(newMark, index);
       
   282             added = ETrue;
       
   283             break;
       
   284             }
       
   285         else if (iDynamicLevelMarkArray[index]->iTime > newMark->iTime) 
       
   286             {
       
   287             err = iDynamicLevelMarkArray.Insert(newMark, index);
       
   288             added = ETrue;
       
   289             break;
       
   290             }
       
   291         }
       
   292     if (!added) 
       
   293         {
       
   294         index = iDynamicLevelMarkArray.Count();
       
   295         err = iDynamicLevelMarkArray.Insert(newMark, index);
       
   296         }
       
   297     if (err != KErrNone) 
       
   298         {
       
   299         User::Leave(err);
       
   300         }
       
   301 
       
   302     iSong->FireDynamicLevelMarkInserted(*this, *newMark, index);
       
   303     return index;
       
   304 
       
   305 
       
   306     }
       
   307     
       
   308 EXPORT_C TBool CAudClip::RemoveDynamicLevelMark(TInt aIndex) 
       
   309     {
       
   310 
       
   311     if (aIndex > iDynamicLevelMarkArray.Count() || aIndex < 0) 
       
   312         {
       
   313         TAudPanic::Panic(TAudPanic::EAudioClipIllegalIndex);
       
   314         }
       
   315     
       
   316     TAudDynamicLevelMark* mark = iDynamicLevelMarkArray[aIndex];
       
   317     
       
   318     iDynamicLevelMarkArray.Remove(aIndex);
       
   319     delete mark;
       
   320     
       
   321     iSong->FireDynamicLevelMarkRemoved(*this, aIndex);
       
   322     return ETrue;
       
   323     }
       
   324     
       
   325 EXPORT_C void CAudClip::SetMuting(TBool aMuted)
       
   326     {
       
   327     
       
   328     iMute = aMuted;
       
   329     
       
   330     }
       
   331 
       
   332 EXPORT_C void CAudClip::SetNormalizing(TBool aNormalizing) 
       
   333     {
       
   334     
       
   335     iNormalize = aNormalizing;    
       
   336 
       
   337     }
       
   338 
       
   339 EXPORT_C void CAudClip::Reset(TBool aNotify) 
       
   340     {
       
   341 
       
   342     TInt a = 0;
       
   343 
       
   344     for (a = 0 ; a < iDynamicLevelMarkArray.Count() ; a++) 
       
   345         {
       
   346         delete iDynamicLevelMarkArray[a];
       
   347         }
       
   348     iDynamicLevelMarkArray.Reset();
       
   349     iCutInTime = 0;
       
   350     
       
   351     if (iInfo != 0)
       
   352         {
       
   353         iCutOutTime = iInfo->Properties().iDuration;
       
   354         }
       
   355 
       
   356     if (aNotify) 
       
   357         {
       
   358         iSong->FireClipReseted(*this);
       
   359         }
       
   360 
       
   361     }
       
   362 
       
   363 
       
   364 EXPORT_C void CAudClip::SetVolumeGain(TInt aVolumeGain)
       
   365     {
       
   366     iVolumeGain = aVolumeGain;
       
   367     }
       
   368 
       
   369 EXPORT_C TInt CAudClip::GetVolumeGain()
       
   370     {
       
   371     return iVolumeGain;
       
   372     }
       
   373 
       
   374 /*
       
   375 EXPORT_C TBool CAudClip::operator<(const CAudClip &c2) const {
       
   376 
       
   377     return (this->iStartTime < c2.StartTime());
       
   378 
       
   379 }
       
   380 
       
   381 
       
   382 EXPORT_C TBool CAudClip::operator>(const CAudClip &c2) const {
       
   383 
       
   384     return (this->iStartTime > c2.StartTime());
       
   385 
       
   386 }
       
   387 
       
   388 EXPORT_C TBool CAudClip::operator==(const CAudClip &c2) const {
       
   389 
       
   390     return (this->iStartTime == c2.StartTime());
       
   391 
       
   392 }
       
   393 */
       
   394 TInt CAudClip::Compare(const CAudClip& c1, const CAudClip& c2) 
       
   395     {
       
   396 
       
   397     if (c1.iStartTime > c2.iStartTime) 
       
   398         {
       
   399         return 1;
       
   400         }
       
   401     else if (c1.iStartTime < c2.iStartTime) 
       
   402         {
       
   403         return -1;
       
   404         }
       
   405     else 
       
   406         {
       
   407         return 0;
       
   408         }
       
   409     }
       
   410 
       
   411 
       
   412 
       
   413 void CAudClip::ConstructL(const TDesC& aFileName,
       
   414                           TTimeIntervalMicroSeconds aStartTime,
       
   415                           MAudClipInfoObserver& aObserver, TInt aTrackIndex) 
       
   416     {
       
   417     
       
   418     __ASSERT_ALWAYS(aStartTime >= TInt64(0), 
       
   419         TAudPanic::Panic(TAudPanic::EAudioClipIllegalStartTime));
       
   420     iStartTime = aStartTime;
       
   421     iTrackIndex = aTrackIndex;
       
   422     
       
   423     iInfo = CAudClipInfo::NewL(aFileName, aObserver);
       
   424     
       
   425     }
       
   426     
       
   427 void CAudClip::ConstructL(RFile* aFileHandle,
       
   428                           TTimeIntervalMicroSeconds aStartTime,
       
   429                           MAudClipInfoObserver& aObserver, TInt aTrackIndex) 
       
   430     {
       
   431     
       
   432     __ASSERT_ALWAYS(aStartTime >= TInt64(0), 
       
   433         TAudPanic::Panic(TAudPanic::EAudioClipIllegalStartTime));
       
   434     iStartTime = aStartTime;
       
   435     iTrackIndex = aTrackIndex;
       
   436     
       
   437     iInfo = CAudClipInfo::NewL(aFileHandle, aObserver);
       
   438     
       
   439     }
       
   440 
       
   441 
       
   442 CAudClip::~CAudClip() 
       
   443     {
       
   444 
       
   445     Reset(EFalse);
       
   446     if (iInfo != 0)
       
   447         {
       
   448         delete iInfo;
       
   449         iInfo = 0;
       
   450         }
       
   451     
       
   452     }
       
   453