The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

793 lines
25KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. BEGIN_JUCE_NAMESPACE
  19. //==============================================================================
  20. struct AudioThumbnail::MinMaxValue
  21. {
  22. MinMaxValue() noexcept
  23. {
  24. values[0] = 0;
  25. values[1] = 0;
  26. }
  27. inline void set (const char newMin, const char newMax) noexcept
  28. {
  29. values[0] = newMin;
  30. values[1] = newMax;
  31. }
  32. inline char getMinValue() const noexcept { return values[0]; }
  33. inline char getMaxValue() const noexcept { return values[1]; }
  34. inline void setFloat (const float newMin, const float newMax) noexcept
  35. {
  36. values[0] = (char) jlimit (-128, 127, roundFloatToInt (newMin * 127.0f));
  37. values[1] = (char) jlimit (-128, 127, roundFloatToInt (newMax * 127.0f));
  38. if (values[0] == values[1])
  39. {
  40. if (values[1] == 127)
  41. values[0]--;
  42. else
  43. values[1]++;
  44. }
  45. }
  46. inline bool isNonZero() const noexcept
  47. {
  48. return values[1] > values[0];
  49. }
  50. inline int getPeak() const noexcept
  51. {
  52. return jmax (std::abs ((int) values[0]),
  53. std::abs ((int) values[1]));
  54. }
  55. inline void read (InputStream& input) { input.read (values, 2); }
  56. inline void write (OutputStream& output) { output.write (values, 2); }
  57. private:
  58. char values[2];
  59. };
  60. //==============================================================================
  61. class AudioThumbnail::LevelDataSource : public TimeSliceClient
  62. {
  63. public:
  64. LevelDataSource (AudioThumbnail& owner_, AudioFormatReader* newReader, int64 hash)
  65. : lengthInSamples (0), numSamplesFinished (0), sampleRate (0), numChannels (0),
  66. hashCode (hash), owner (owner_), reader (newReader)
  67. {
  68. }
  69. LevelDataSource (AudioThumbnail& owner_, InputSource* source_)
  70. : lengthInSamples (0), numSamplesFinished (0), sampleRate (0), numChannels (0),
  71. hashCode (source_->hashCode()), owner (owner_), source (source_)
  72. {
  73. }
  74. ~LevelDataSource()
  75. {
  76. owner.cache.removeTimeSliceClient (this);
  77. }
  78. enum { timeBeforeDeletingReader = 1000 };
  79. void initialise (int64 numSamplesFinished_)
  80. {
  81. const ScopedLock sl (readerLock);
  82. numSamplesFinished = numSamplesFinished_;
  83. createReader();
  84. if (reader != nullptr)
  85. {
  86. lengthInSamples = reader->lengthInSamples;
  87. numChannels = reader->numChannels;
  88. sampleRate = reader->sampleRate;
  89. if (lengthInSamples <= 0 || isFullyLoaded())
  90. reader = nullptr;
  91. else
  92. owner.cache.addTimeSliceClient (this);
  93. }
  94. }
  95. void getLevels (int64 startSample, int numSamples, Array<float>& levels)
  96. {
  97. const ScopedLock sl (readerLock);
  98. if (reader == nullptr)
  99. {
  100. createReader();
  101. if (reader != nullptr)
  102. owner.cache.addTimeSliceClient (this);
  103. }
  104. if (reader != nullptr)
  105. {
  106. float l[4] = { 0 };
  107. reader->readMaxLevels (startSample, numSamples, l[0], l[1], l[2], l[3]);
  108. levels.clearQuick();
  109. levels.addArray ((const float*) l, 4);
  110. }
  111. }
  112. void releaseResources()
  113. {
  114. const ScopedLock sl (readerLock);
  115. reader = nullptr;
  116. }
  117. int useTimeSlice()
  118. {
  119. if (isFullyLoaded())
  120. {
  121. if (reader != nullptr && source != nullptr)
  122. releaseResources();
  123. return -1;
  124. }
  125. bool justFinished = false;
  126. {
  127. const ScopedLock sl (readerLock);
  128. createReader();
  129. if (reader != nullptr)
  130. {
  131. if (! readNextBlock())
  132. return 0;
  133. justFinished = true;
  134. }
  135. }
  136. if (justFinished)
  137. owner.cache.storeThumb (owner, hashCode);
  138. return timeBeforeDeletingReader;
  139. }
  140. bool isFullyLoaded() const noexcept
  141. {
  142. return numSamplesFinished >= lengthInSamples;
  143. }
  144. inline int sampleToThumbSample (const int64 originalSample) const noexcept
  145. {
  146. return (int) (originalSample / owner.samplesPerThumbSample);
  147. }
  148. int64 lengthInSamples, numSamplesFinished;
  149. double sampleRate;
  150. unsigned int numChannels;
  151. int64 hashCode;
  152. private:
  153. AudioThumbnail& owner;
  154. ScopedPointer <InputSource> source;
  155. ScopedPointer <AudioFormatReader> reader;
  156. CriticalSection readerLock;
  157. void createReader()
  158. {
  159. if (reader == nullptr && source != nullptr)
  160. {
  161. InputStream* audioFileStream = source->createInputStream();
  162. if (audioFileStream != nullptr)
  163. reader = owner.formatManagerToUse.createReaderFor (audioFileStream);
  164. }
  165. }
  166. bool readNextBlock()
  167. {
  168. jassert (reader != nullptr);
  169. if (! isFullyLoaded())
  170. {
  171. const int numToDo = (int) jmin (256 * (int64) owner.samplesPerThumbSample, lengthInSamples - numSamplesFinished);
  172. if (numToDo > 0)
  173. {
  174. int64 startSample = numSamplesFinished;
  175. const int firstThumbIndex = sampleToThumbSample (startSample);
  176. const int lastThumbIndex = sampleToThumbSample (startSample + numToDo);
  177. const int numThumbSamps = lastThumbIndex - firstThumbIndex;
  178. HeapBlock<MinMaxValue> levelData ((size_t) numThumbSamps * 2);
  179. MinMaxValue* levels[2] = { levelData, levelData + numThumbSamps };
  180. for (int i = 0; i < numThumbSamps; ++i)
  181. {
  182. float lowestLeft, highestLeft, lowestRight, highestRight;
  183. reader->readMaxLevels ((firstThumbIndex + i) * owner.samplesPerThumbSample, owner.samplesPerThumbSample,
  184. lowestLeft, highestLeft, lowestRight, highestRight);
  185. levels[0][i].setFloat (lowestLeft, highestLeft);
  186. levels[1][i].setFloat (lowestRight, highestRight);
  187. }
  188. {
  189. const ScopedUnlock su (readerLock);
  190. owner.setLevels (levels, firstThumbIndex, 2, numThumbSamps);
  191. }
  192. numSamplesFinished += numToDo;
  193. }
  194. }
  195. return isFullyLoaded();
  196. }
  197. };
  198. //==============================================================================
  199. class AudioThumbnail::ThumbData
  200. {
  201. public:
  202. ThumbData (const int numThumbSamples)
  203. : peakLevel (-1)
  204. {
  205. ensureSize (numThumbSamples);
  206. }
  207. inline MinMaxValue* getData (const int thumbSampleIndex) noexcept
  208. {
  209. jassert (thumbSampleIndex < data.size());
  210. return data.getRawDataPointer() + thumbSampleIndex;
  211. }
  212. int getSize() const noexcept
  213. {
  214. return data.size();
  215. }
  216. void getMinMax (int startSample, int endSample, MinMaxValue& result) const noexcept
  217. {
  218. if (startSample >= 0)
  219. {
  220. endSample = jmin (endSample, data.size() - 1);
  221. char mx = -128;
  222. char mn = 127;
  223. while (startSample <= endSample)
  224. {
  225. const MinMaxValue& v = data.getReference (startSample);
  226. if (v.getMinValue() < mn) mn = v.getMinValue();
  227. if (v.getMaxValue() > mx) mx = v.getMaxValue();
  228. ++startSample;
  229. }
  230. if (mn <= mx)
  231. {
  232. result.set (mn, mx);
  233. return;
  234. }
  235. }
  236. result.set (1, 0);
  237. }
  238. void write (const MinMaxValue* const source, const int startIndex, const int numValues)
  239. {
  240. resetPeak();
  241. if (startIndex + numValues > data.size())
  242. ensureSize (startIndex + numValues);
  243. MinMaxValue* const dest = getData (startIndex);
  244. for (int i = 0; i < numValues; ++i)
  245. dest[i] = source[i];
  246. }
  247. void resetPeak() noexcept
  248. {
  249. peakLevel = -1;
  250. }
  251. int getPeak() noexcept
  252. {
  253. if (peakLevel < 0)
  254. {
  255. for (int i = 0; i < data.size(); ++i)
  256. {
  257. const int peak = data[i].getPeak();
  258. if (peak > peakLevel)
  259. peakLevel = peak;
  260. }
  261. }
  262. return peakLevel;
  263. }
  264. private:
  265. Array <MinMaxValue> data;
  266. int peakLevel;
  267. void ensureSize (const int thumbSamples)
  268. {
  269. const int extraNeeded = thumbSamples - data.size();
  270. if (extraNeeded > 0)
  271. data.insertMultiple (-1, MinMaxValue(), extraNeeded);
  272. }
  273. };
  274. //==============================================================================
  275. class AudioThumbnail::CachedWindow
  276. {
  277. public:
  278. CachedWindow()
  279. : cachedStart (0), cachedTimePerPixel (0),
  280. numChannelsCached (0), numSamplesCached (0),
  281. cacheNeedsRefilling (true)
  282. {
  283. }
  284. void invalidate()
  285. {
  286. cacheNeedsRefilling = true;
  287. }
  288. void drawChannel (Graphics& g, const Rectangle<int>& area,
  289. const double startTime, const double endTime,
  290. const int channelNum, const float verticalZoomFactor,
  291. const double sampleRate, const int numChannels, const int samplesPerThumbSample,
  292. LevelDataSource* levelData, const OwnedArray<ThumbData>& channels)
  293. {
  294. refillCache (area.getWidth(), startTime, endTime, sampleRate,
  295. numChannels, samplesPerThumbSample, levelData, channels);
  296. if (isPositiveAndBelow (channelNum, numChannelsCached))
  297. {
  298. const Rectangle<int> clip (g.getClipBounds().getIntersection (area.withWidth (jmin (numSamplesCached, area.getWidth()))));
  299. if (! clip.isEmpty())
  300. {
  301. const float topY = (float) area.getY();
  302. const float bottomY = (float) area.getBottom();
  303. const float midY = (topY + bottomY) * 0.5f;
  304. const float vscale = verticalZoomFactor * (bottomY - topY) / 256.0f;
  305. const MinMaxValue* cacheData = getData (channelNum, clip.getX() - area.getX());
  306. int x = clip.getX();
  307. for (int w = clip.getWidth(); --w >= 0;)
  308. {
  309. if (cacheData->isNonZero())
  310. g.drawVerticalLine (x, jmax (midY - cacheData->getMaxValue() * vscale - 0.3f, topY),
  311. jmin (midY - cacheData->getMinValue() * vscale + 0.3f, bottomY));
  312. ++x;
  313. ++cacheData;
  314. }
  315. }
  316. }
  317. }
  318. private:
  319. Array <MinMaxValue> data;
  320. double cachedStart, cachedTimePerPixel;
  321. int numChannelsCached, numSamplesCached;
  322. bool cacheNeedsRefilling;
  323. void refillCache (const int numSamples, double startTime, const double endTime,
  324. const double sampleRate, const int numChannels, const int samplesPerThumbSample,
  325. LevelDataSource* levelData, const OwnedArray<ThumbData>& channels)
  326. {
  327. const double timePerPixel = (endTime - startTime) / numSamples;
  328. if (numSamples <= 0 || timePerPixel <= 0.0 || sampleRate <= 0)
  329. {
  330. invalidate();
  331. return;
  332. }
  333. if (numSamples == numSamplesCached
  334. && numChannelsCached == numChannels
  335. && startTime == cachedStart
  336. && timePerPixel == cachedTimePerPixel
  337. && ! cacheNeedsRefilling)
  338. {
  339. return;
  340. }
  341. numSamplesCached = numSamples;
  342. numChannelsCached = numChannels;
  343. cachedStart = startTime;
  344. cachedTimePerPixel = timePerPixel;
  345. cacheNeedsRefilling = false;
  346. ensureSize (numSamples);
  347. if (timePerPixel * sampleRate <= samplesPerThumbSample && levelData != nullptr)
  348. {
  349. int sample = roundToInt (startTime * sampleRate);
  350. Array<float> levels;
  351. int i;
  352. for (i = 0; i < numSamples; ++i)
  353. {
  354. const int nextSample = roundToInt ((startTime + timePerPixel) * sampleRate);
  355. if (sample >= 0)
  356. {
  357. if (sample >= levelData->lengthInSamples)
  358. break;
  359. levelData->getLevels (sample, jmax (1, nextSample - sample), levels);
  360. const int numChans = jmin (levels.size() / 2, numChannelsCached);
  361. for (int chan = 0; chan < numChans; ++chan)
  362. getData (chan, i)->setFloat (levels.getUnchecked (chan * 2),
  363. levels.getUnchecked (chan * 2 + 1));
  364. }
  365. startTime += timePerPixel;
  366. sample = nextSample;
  367. }
  368. numSamplesCached = i;
  369. }
  370. else
  371. {
  372. jassert (channels.size() == numChannelsCached);
  373. for (int channelNum = 0; channelNum < numChannelsCached; ++channelNum)
  374. {
  375. ThumbData* channelData = channels.getUnchecked (channelNum);
  376. MinMaxValue* cacheData = getData (channelNum, 0);
  377. const double timeToThumbSampleFactor = sampleRate / (double) samplesPerThumbSample;
  378. startTime = cachedStart;
  379. int sample = roundToInt (startTime * timeToThumbSampleFactor);
  380. for (int i = numSamples; --i >= 0;)
  381. {
  382. const int nextSample = roundToInt ((startTime + timePerPixel) * timeToThumbSampleFactor);
  383. channelData->getMinMax (sample, nextSample, *cacheData);
  384. ++cacheData;
  385. startTime += timePerPixel;
  386. sample = nextSample;
  387. }
  388. }
  389. }
  390. }
  391. MinMaxValue* getData (const int channelNum, const int cacheIndex) noexcept
  392. {
  393. jassert (isPositiveAndBelow (channelNum, numChannelsCached) && isPositiveAndBelow (cacheIndex, data.size()));
  394. return data.getRawDataPointer() + channelNum * numSamplesCached
  395. + cacheIndex;
  396. }
  397. void ensureSize (const int numSamples)
  398. {
  399. const int itemsRequired = numSamples * numChannelsCached;
  400. if (data.size() < itemsRequired)
  401. data.insertMultiple (-1, MinMaxValue(), itemsRequired - data.size());
  402. }
  403. };
  404. //==============================================================================
  405. AudioThumbnail::AudioThumbnail (const int originalSamplesPerThumbnailSample,
  406. AudioFormatManager& formatManagerToUse_,
  407. AudioThumbnailCache& cacheToUse)
  408. : formatManagerToUse (formatManagerToUse_),
  409. cache (cacheToUse),
  410. window (new CachedWindow()),
  411. samplesPerThumbSample (originalSamplesPerThumbnailSample),
  412. totalSamples (0),
  413. numChannels (0),
  414. sampleRate (0)
  415. {
  416. }
  417. AudioThumbnail::~AudioThumbnail()
  418. {
  419. clear();
  420. }
  421. void AudioThumbnail::clear()
  422. {
  423. source = nullptr;
  424. clearChannelData();
  425. }
  426. void AudioThumbnail::clearChannelData()
  427. {
  428. const ScopedLock sl (lock);
  429. window->invalidate();
  430. channels.clear();
  431. totalSamples = numSamplesFinished = 0;
  432. numChannels = 0;
  433. sampleRate = 0;
  434. sendChangeMessage();
  435. }
  436. void AudioThumbnail::reset (int newNumChannels, double newSampleRate, int64 totalSamplesInSource)
  437. {
  438. clear();
  439. numChannels = newNumChannels;
  440. sampleRate = newSampleRate;
  441. totalSamples = totalSamplesInSource;
  442. createChannels (1 + (int) (totalSamplesInSource / samplesPerThumbSample));
  443. }
  444. void AudioThumbnail::createChannels (const int length)
  445. {
  446. while (channels.size() < numChannels)
  447. channels.add (new ThumbData (length));
  448. }
  449. //==============================================================================
  450. void AudioThumbnail::loadFrom (InputStream& rawInput)
  451. {
  452. clearChannelData();
  453. BufferedInputStream input (rawInput, 4096);
  454. if (input.readByte() != 'j' || input.readByte() != 'a' || input.readByte() != 't' || input.readByte() != 'm')
  455. return;
  456. samplesPerThumbSample = input.readInt();
  457. totalSamples = input.readInt64(); // Total number of source samples.
  458. numSamplesFinished = input.readInt64(); // Number of valid source samples that have been read into the thumbnail.
  459. int32 numThumbnailSamples = input.readInt(); // Number of samples in the thumbnail data.
  460. numChannels = input.readInt(); // Number of audio channels.
  461. sampleRate = input.readInt(); // Source sample rate.
  462. input.skipNextBytes (16); // (reserved)
  463. createChannels (numThumbnailSamples);
  464. for (int i = 0; i < numThumbnailSamples; ++i)
  465. for (int chan = 0; chan < numChannels; ++chan)
  466. channels.getUnchecked(chan)->getData(i)->read (input);
  467. }
  468. void AudioThumbnail::saveTo (OutputStream& output) const
  469. {
  470. const ScopedLock sl (lock);
  471. const int numThumbnailSamples = channels.size() == 0 ? 0 : channels.getUnchecked(0)->getSize();
  472. output.write ("jatm", 4);
  473. output.writeInt (samplesPerThumbSample);
  474. output.writeInt64 (totalSamples);
  475. output.writeInt64 (numSamplesFinished);
  476. output.writeInt (numThumbnailSamples);
  477. output.writeInt (numChannels);
  478. output.writeInt ((int) sampleRate);
  479. output.writeInt64 (0);
  480. output.writeInt64 (0);
  481. for (int i = 0; i < numThumbnailSamples; ++i)
  482. for (int chan = 0; chan < numChannels; ++chan)
  483. channels.getUnchecked(chan)->getData(i)->write (output);
  484. }
  485. //==============================================================================
  486. bool AudioThumbnail::setDataSource (LevelDataSource* newSource)
  487. {
  488. jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  489. numSamplesFinished = 0;
  490. if (cache.loadThumb (*this, newSource->hashCode) && isFullyLoaded())
  491. {
  492. source = newSource; // (make sure this isn't done before loadThumb is called)
  493. source->lengthInSamples = totalSamples;
  494. source->sampleRate = sampleRate;
  495. source->numChannels = (unsigned int) numChannels;
  496. source->numSamplesFinished = numSamplesFinished;
  497. }
  498. else
  499. {
  500. source = newSource; // (make sure this isn't done before loadThumb is called)
  501. const ScopedLock sl (lock);
  502. source->initialise (numSamplesFinished);
  503. totalSamples = source->lengthInSamples;
  504. sampleRate = source->sampleRate;
  505. numChannels = (int32) source->numChannels;
  506. createChannels (1 + (int) (totalSamples / samplesPerThumbSample));
  507. }
  508. return sampleRate > 0 && totalSamples > 0;
  509. }
  510. bool AudioThumbnail::setSource (InputSource* const newSource)
  511. {
  512. clear();
  513. return newSource != nullptr && setDataSource (new LevelDataSource (*this, newSource));
  514. }
  515. void AudioThumbnail::setReader (AudioFormatReader* newReader, int64 hash)
  516. {
  517. clear();
  518. if (newReader != nullptr)
  519. setDataSource (new LevelDataSource (*this, newReader, hash));
  520. }
  521. int64 AudioThumbnail::getHashCode() const
  522. {
  523. return source == nullptr ? 0 : source->hashCode;
  524. }
  525. void AudioThumbnail::addBlock (const int64 startSample, const AudioSampleBuffer& incoming,
  526. int startOffsetInBuffer, int numSamples)
  527. {
  528. jassert (startSample >= 0);
  529. const int firstThumbIndex = (int) (startSample / samplesPerThumbSample);
  530. const int lastThumbIndex = (int) ((startSample + numSamples + (samplesPerThumbSample - 1)) / samplesPerThumbSample);
  531. const int numToDo = lastThumbIndex - firstThumbIndex;
  532. if (numToDo > 0)
  533. {
  534. const int numChans = jmin (channels.size(), incoming.getNumChannels());
  535. const HeapBlock<MinMaxValue> thumbData ((size_t) (numToDo * numChans));
  536. const HeapBlock<MinMaxValue*> thumbChannels ((size_t) numChans);
  537. for (int chan = 0; chan < numChans; ++chan)
  538. {
  539. const float* const sourceData = incoming.getSampleData (chan, startOffsetInBuffer);
  540. MinMaxValue* const dest = thumbData + numToDo * chan;
  541. thumbChannels [chan] = dest;
  542. for (int i = 0; i < numToDo; ++i)
  543. {
  544. float low, high;
  545. const int start = i * samplesPerThumbSample;
  546. findMinAndMax (sourceData + start, jmin (samplesPerThumbSample, numSamples - start), low, high);
  547. dest[i].setFloat (low, high);
  548. }
  549. }
  550. setLevels (thumbChannels, firstThumbIndex, numChans, numToDo);
  551. }
  552. }
  553. void AudioThumbnail::setLevels (const MinMaxValue* const* values, int thumbIndex, int numChans, int numValues)
  554. {
  555. const ScopedLock sl (lock);
  556. for (int i = jmin (numChans, channels.size()); --i >= 0;)
  557. channels.getUnchecked(i)->write (values[i], thumbIndex, numValues);
  558. const int64 start = thumbIndex * (int64) samplesPerThumbSample;
  559. const int64 end = (thumbIndex + numValues) * (int64) samplesPerThumbSample;
  560. if (numSamplesFinished >= start && end > numSamplesFinished)
  561. numSamplesFinished = end;
  562. totalSamples = jmax (numSamplesFinished, totalSamples);
  563. window->invalidate();
  564. sendChangeMessage();
  565. }
  566. //==============================================================================
  567. int AudioThumbnail::getNumChannels() const noexcept
  568. {
  569. return numChannels;
  570. }
  571. double AudioThumbnail::getTotalLength() const noexcept
  572. {
  573. return sampleRate > 0 ? (totalSamples / sampleRate) : 0;
  574. }
  575. bool AudioThumbnail::isFullyLoaded() const noexcept
  576. {
  577. return numSamplesFinished >= totalSamples - samplesPerThumbSample;
  578. }
  579. int64 AudioThumbnail::getNumSamplesFinished() const noexcept
  580. {
  581. return numSamplesFinished;
  582. }
  583. float AudioThumbnail::getApproximatePeak() const
  584. {
  585. int peak = 0;
  586. for (int i = channels.size(); --i >= 0;)
  587. peak = jmax (peak, channels.getUnchecked(i)->getPeak());
  588. return jlimit (0, 127, peak) / 127.0f;
  589. }
  590. void AudioThumbnail::getApproximateMinMax (const double startTime, const double endTime, const int channelIndex,
  591. float& minValue, float& maxValue) const noexcept
  592. {
  593. MinMaxValue result;
  594. const ThumbData* const data = channels [channelIndex];
  595. if (data != nullptr && sampleRate > 0)
  596. {
  597. const int firstThumbIndex = (int) ((startTime * sampleRate) / samplesPerThumbSample);
  598. const int lastThumbIndex = (int) (((endTime * sampleRate) + samplesPerThumbSample - 1) / samplesPerThumbSample);
  599. data->getMinMax (jmax (0, firstThumbIndex), lastThumbIndex, result);
  600. }
  601. minValue = result.getMinValue() / 128.0f;
  602. maxValue = result.getMaxValue() / 128.0f;
  603. }
  604. void AudioThumbnail::drawChannel (Graphics& g, const Rectangle<int>& area, double startTime,
  605. double endTime, int channelNum, float verticalZoomFactor)
  606. {
  607. const ScopedLock sl (lock);
  608. window->drawChannel (g, area, startTime, endTime, channelNum, verticalZoomFactor,
  609. sampleRate, numChannels, samplesPerThumbSample, source, channels);
  610. }
  611. void AudioThumbnail::drawChannels (Graphics& g, const Rectangle<int>& area, double startTimeSeconds,
  612. double endTimeSeconds, float verticalZoomFactor)
  613. {
  614. for (int i = 0; i < numChannels; ++i)
  615. {
  616. const int y1 = roundToInt ((i * area.getHeight()) / numChannels);
  617. const int y2 = roundToInt (((i + 1) * area.getHeight()) / numChannels);
  618. drawChannel (g, Rectangle<int> (area.getX(), area.getY() + y1, area.getWidth(), y2 - y1),
  619. startTimeSeconds, endTimeSeconds, i, verticalZoomFactor);
  620. }
  621. }
  622. END_JUCE_NAMESPACE