@@ -457,6 +457,17 @@ namespace {
457
457
{
458
458
return numSamples > wxLL (9223372036854775807 );
459
459
}
460
+
461
+ BlockFilePtr NewSimpleBlockFile ( DirManager &dm,
462
+ samplePtr sampleData, size_t sampleLen,
463
+ sampleFormat format,
464
+ bool allowDeferredWrite = false )
465
+ {
466
+ return dm.NewBlockFile ( [&]( wxFileNameWrapper filePath ) {
467
+ return make_blockfile<SimpleBlockFile>(
468
+ std::move (filePath), sampleData, sampleLen, format, allowDeferredWrite);
469
+ } );
470
+ }
460
471
}
461
472
462
473
void Sequence::Paste (sampleCount s, const Sequence *src)
@@ -549,7 +560,7 @@ void Sequence::Paste(sampleCount s, const Sequence *src)
549
560
splitPoint, length - splitPoint, true );
550
561
551
562
auto file =
552
- mDirManager -> NewSimpleBlockFile (
563
+ NewSimpleBlockFile ( * mDirManager ,
553
564
// largerBlockLen is not more than mMaxSamples...
554
565
buffer.ptr (), largerBlockLen.as_size_t (), mSampleFormat );
555
566
@@ -709,41 +720,6 @@ void Sequence::InsertSilence(sampleCount s0, sampleCount len)
709
720
Paste (s0, &sTrack );
710
721
}
711
722
712
- void Sequence::AppendAlias (const FilePath &fullPath,
713
- sampleCount start,
714
- size_t len, int channel, bool useOD)
715
- // STRONG-GUARANTEE
716
- {
717
- // Quick check to make sure that it doesn't overflow
718
- if (Overflows ((mNumSamples .as_double ()) + ((double )len)))
719
- THROW_INCONSISTENCY_EXCEPTION;
720
-
721
- SeqBlock newBlock (
722
- useOD?
723
- mDirManager ->NewODAliasBlockFile (fullPath, start, len, channel):
724
- mDirManager ->NewAliasBlockFile (fullPath, start, len, channel),
725
- mNumSamples
726
- );
727
- mBlock .push_back (newBlock);
728
- mNumSamples += len;
729
- }
730
-
731
- void Sequence::AppendCoded (const FilePath &fName , sampleCount start,
732
- size_t len, int channel, int decodeType)
733
- // STRONG-GUARANTEE
734
- {
735
- // Quick check to make sure that it doesn't overflow
736
- if (Overflows ((mNumSamples .as_double ()) + ((double )len)))
737
- THROW_INCONSISTENCY_EXCEPTION;
738
-
739
- SeqBlock newBlock (
740
- mDirManager ->NewODDecodeBlockFile (fName , start, len, channel, decodeType),
741
- mNumSamples
742
- );
743
- mBlock .push_back (newBlock);
744
- mNumSamples += len;
745
- }
746
-
747
723
void Sequence::AppendBlock
748
724
(DirManager &mDirManager ,
749
725
BlockArray &mBlock , sampleCount &mNumSamples , const SeqBlock &b)
@@ -1267,13 +1243,13 @@ void Sequence::SetSamples(samplePtr buffer, sampleFormat format,
1267
1243
else
1268
1244
ClearSamples (scratch.ptr (), mSampleFormat , bstart, blen);
1269
1245
1270
- block.f = mDirManager -> NewSimpleBlockFile (
1246
+ block.f = NewSimpleBlockFile ( * mDirManager ,
1271
1247
scratch.ptr (), fileLength, mSampleFormat );
1272
1248
}
1273
1249
else {
1274
1250
// Avoid reading the disk when the replacement is total
1275
1251
if (useBuffer)
1276
- block.f = mDirManager -> NewSimpleBlockFile (
1252
+ block.f = NewSimpleBlockFile ( * mDirManager ,
1277
1253
useBuffer, fileLength, mSampleFormat );
1278
1254
else
1279
1255
block.f = make_blockfile<SilentBlockFile>(fileLength);
@@ -1599,7 +1575,7 @@ void Sequence::Append(samplePtr buffer, sampleFormat format,
1599
1575
const auto newLastBlockLen = length + addLen;
1600
1576
1601
1577
SeqBlock newLastBlock (
1602
- mDirManager -> NewSimpleBlockFile (
1578
+ NewSimpleBlockFile ( * mDirManager ,
1603
1579
buffer2.ptr (), newLastBlockLen, mSampleFormat ,
1604
1580
blockFileLog != NULL
1605
1581
),
@@ -1625,12 +1601,12 @@ void Sequence::Append(samplePtr buffer, sampleFormat format,
1625
1601
const auto addedLen = std::min (idealSamples, len);
1626
1602
BlockFilePtr pFile;
1627
1603
if (format == mSampleFormat ) {
1628
- pFile = mDirManager -> NewSimpleBlockFile (
1604
+ pFile = NewSimpleBlockFile ( * mDirManager ,
1629
1605
buffer, addedLen, mSampleFormat , blockFileLog != NULL );
1630
1606
}
1631
1607
else {
1632
1608
CopySamples (buffer, format, buffer2.ptr (), mSampleFormat , addedLen);
1633
- pFile = mDirManager -> NewSimpleBlockFile (
1609
+ pFile = NewSimpleBlockFile ( * mDirManager ,
1634
1610
buffer2.ptr (), addedLen, mSampleFormat , blockFileLog != NULL );
1635
1611
}
1636
1612
@@ -1673,7 +1649,7 @@ void Sequence::Blockify
1673
1649
int newLen = ((i + 1 ) * len / num) - offset;
1674
1650
samplePtr bufStart = buffer + (offset * SAMPLE_SIZE (mSampleFormat ));
1675
1651
1676
- b.f = mDirManager . NewSimpleBlockFile (bufStart, newLen, mSampleFormat );
1652
+ b.f = NewSimpleBlockFile ( mDirManager , bufStart, newLen, mSampleFormat );
1677
1653
1678
1654
list.push_back (b);
1679
1655
}
@@ -1735,7 +1711,7 @@ void Sequence::Delete(sampleCount start, sampleCount len)
1735
1711
( pos + len ).as_size_t (), newLen - pos, true );
1736
1712
1737
1713
auto newFile =
1738
- mDirManager -> NewSimpleBlockFile (scratch.ptr (), newLen, mSampleFormat );
1714
+ NewSimpleBlockFile ( * mDirManager , scratch.ptr (), newLen, mSampleFormat );
1739
1715
1740
1716
// Don't make a duplicate array. We can still give STRONG-GUARANTEE
1741
1717
// if we modify only one block in place.
@@ -1779,7 +1755,7 @@ void Sequence::Delete(sampleCount start, sampleCount len)
1779
1755
ensureSampleBufferSize (scratch, mSampleFormat , scratchSize, preBufferLen);
1780
1756
Read (scratch.ptr (), mSampleFormat , preBlock, 0 , preBufferLen, true );
1781
1757
auto pFile =
1782
- mDirManager -> NewSimpleBlockFile (scratch.ptr (), preBufferLen, mSampleFormat );
1758
+ NewSimpleBlockFile ( * mDirManager , scratch.ptr (), preBufferLen, mSampleFormat );
1783
1759
1784
1760
newBlock.push_back (SeqBlock (pFile, preBlock.start ));
1785
1761
} else {
@@ -1825,7 +1801,7 @@ void Sequence::Delete(sampleCount start, sampleCount len)
1825
1801
auto pos = (start + len - postBlock.start ).as_size_t ();
1826
1802
Read (scratch.ptr (), mSampleFormat , postBlock, pos, postBufferLen, true );
1827
1803
auto file =
1828
- mDirManager -> NewSimpleBlockFile (scratch.ptr (), postBufferLen, mSampleFormat );
1804
+ NewSimpleBlockFile ( * mDirManager , scratch.ptr (), postBufferLen, mSampleFormat );
1829
1805
1830
1806
newBlock.push_back (SeqBlock (file, start));
1831
1807
} else {
@@ -2016,6 +1992,23 @@ size_t Sequence::GetMaxDiskBlockSize()
2016
1992
return sMaxDiskBlockSize ;
2017
1993
}
2018
1994
1995
+ void Sequence::AppendBlockFile ( const BlockFileFactory &factory, size_t len )
1996
+ // STRONG-GUARANTEE
1997
+ {
1998
+ // Quick check to make sure that it doesn't overflow
1999
+ if (Overflows ((mNumSamples .as_double ()) + ((double )len)))
2000
+ THROW_INCONSISTENCY_EXCEPTION;
2001
+
2002
+ SeqBlock newBlock (
2003
+ mDirManager ->NewBlockFile ( [&]( wxFileNameWrapper filePath ){
2004
+ return factory ( std::move ( filePath ), len );
2005
+ } ),
2006
+ mNumSamples
2007
+ );
2008
+ mBlock .push_back (newBlock);
2009
+ mNumSamples += len;
2010
+ }
2011
+
2019
2012
void Sequence::AppendBlockFile (const BlockFilePtr &blockFile)
2020
2013
{
2021
2014
// We assume blockFile has the correct ref count already
0 commit comments