JUCE  v6.1.6 (6.0.8-1114)
JUCE API
Looking for a senior C++ dev?
I'm looking for work. Hire me!
juce::AudioThumbnailBase Class Referenceabstract

Provides a base for classes that can store and draw scaled views of an audio waveform. More...

#include <juce_AudioThumbnailBase.h>

Inheritance diagram for juce::AudioThumbnailBase:
Collaboration diagram for juce::AudioThumbnailBase:

Public Member Functions

 AudioThumbnailBase ()=default
 
 ~AudioThumbnailBase () override=default
 
virtual void addBlock (int64 sampleNumberInSource, const AudioBuffer< float > &newData, int startOffsetInBuffer, int numSamples)=0
 
void addChangeListener (ChangeListener *listener)
 Registers a listener to receive change callbacks from this broadcaster. More...
 
virtual void clear ()=0
 Clears and resets the thumbnail. More...
 
void dispatchPendingMessages ()
 If a change message has been sent but not yet dispatched, this will call sendSynchronousChangeMessage() to make the callback immediately. More...
 
virtual void drawChannel (Graphics &g, const Rectangle< int > &area, double startTimeSeconds, double endTimeSeconds, int channelNum, float verticalZoomFactor)=0
 Draws the waveform for a channel. More...
 
virtual void drawChannels (Graphics &g, const Rectangle< int > &area, double startTimeSeconds, double endTimeSeconds, float verticalZoomFactor)=0
 Draws the waveforms for all channels in the thumbnail. More...
 
virtual void getApproximateMinMax (double startTime, double endTime, int channelIndex, float &minValue, float &maxValue) const noexcept=0
 Reads the approximate min and max levels from a section of the thumbnail. More...
 
virtual float getApproximatePeak () const =0
 Returns the highest level in the thumbnail. More...
 
virtual int64 getHashCode () const =0
 Returns the hash code that was set by setSource() or setReader(). More...
 
virtual int getNumChannels () const noexcept=0
 Returns the number of channels in the file. More...
 
virtual int64 getNumSamplesFinished () const noexcept=0
 Returns the number of samples that have been set in the thumbnail. More...
 
virtual double getTotalLength () const noexcept=0
 Returns the length of the audio file, in seconds. More...
 
virtual bool isFullyLoaded () const noexcept=0
 Returns true if the low res preview is fully generated. More...
 
virtual bool loadFrom (InputStream &input)=0
 Reloads the low res thumbnail data from an input stream. More...
 
void removeAllChangeListeners ()
 Removes all listeners from the list. More...
 
void removeChangeListener (ChangeListener *listener)
 Unregisters a listener from the list. More...
 
virtual void reset (int numChannels, double sampleRate, int64 totalSamplesInSource)=0
 
virtual void saveTo (OutputStream &output) const =0
 Saves the low res thumbnail data to an output stream. More...
 
void sendChangeMessage ()
 Causes an asynchronous change message to be sent to all the registered listeners. More...
 
void sendSynchronousChangeMessage ()
 Sends a synchronous change message to all the registered listeners. More...
 
virtual void setReader (AudioFormatReader *newReader, int64 hashCode)=0
 Gives the thumbnail an AudioFormatReader to use directly. More...
 
virtual bool setSource (InputSource *newSource)=0
 Specifies the file or stream that contains the audio file. More...
 

Private Member Functions

void callListeners ()
 

Private Attributes

std::atomic< boolanyListeners { false }
 
ChangeBroadcasterCallback broadcastCallback
 
ListenerList< ChangeListenerchangeListeners
 

Detailed Description

Provides a base for classes that can store and draw scaled views of an audio waveform.

Typically, you'll want to use the derived class AudioThumbnail, which provides a concrete implementation.

See also
AudioThumbnail, AudioThumbnailCache

@tags{Audio}

Constructor & Destructor Documentation

◆ AudioThumbnailBase()

juce::AudioThumbnailBase::AudioThumbnailBase ( )
default

◆ ~AudioThumbnailBase()

juce::AudioThumbnailBase::~AudioThumbnailBase ( )
overridedefault

Member Function Documentation

◆ addBlock()

virtual void juce::AudioFormatWriter::ThreadedWriter::IncomingDataReceiver::addBlock ( int64  sampleNumberInSource,
const AudioBuffer< float > &  newData,
int  startOffsetInBuffer,
int  numSamples 
)
pure virtualinherited

Implemented in juce::AudioThumbnail.

◆ addChangeListener()

void juce::ChangeBroadcaster::addChangeListener ( ChangeListener listener)
inherited

Registers a listener to receive change callbacks from this broadcaster.

Trying to add a listener that's already on the list will have no effect.

◆ callListeners()

void juce::ChangeBroadcaster::callListeners ( )
privateinherited

◆ clear()

virtual void juce::AudioThumbnailBase::clear ( )
pure virtual

Clears and resets the thumbnail.

Implemented in juce::AudioThumbnail.

◆ dispatchPendingMessages()

void juce::ChangeBroadcaster::dispatchPendingMessages ( )
inherited

If a change message has been sent but not yet dispatched, this will call sendSynchronousChangeMessage() to make the callback immediately.

For thread-safety reasons, you must only call this method on the main message thread.

◆ drawChannel()

virtual void juce::AudioThumbnailBase::drawChannel ( Graphics g,
const Rectangle< int > &  area,
double  startTimeSeconds,
double  endTimeSeconds,
int  channelNum,
float  verticalZoomFactor 
)
pure virtual

Draws the waveform for a channel.

The waveform will be drawn within the specified rectangle, where startTime and endTime specify the times within the audio file that should be positioned at the left and right edges of the rectangle.

The waveform will be scaled vertically so that a full-volume sample will fill the rectangle vertically, but you can also specify an extra vertical scale factor with the verticalZoomFactor parameter.

Implemented in juce::AudioThumbnail.

◆ drawChannels()

virtual void juce::AudioThumbnailBase::drawChannels ( Graphics g,
const Rectangle< int > &  area,
double  startTimeSeconds,
double  endTimeSeconds,
float  verticalZoomFactor 
)
pure virtual

Draws the waveforms for all channels in the thumbnail.

This will call drawChannel() to render each of the thumbnail's channels, stacked above each other within the specified area.

See also
drawChannel

Implemented in juce::AudioThumbnail.

◆ getApproximateMinMax()

virtual void juce::AudioThumbnailBase::getApproximateMinMax ( double  startTime,
double  endTime,
int  channelIndex,
float minValue,
float maxValue 
) const
pure virtualnoexcept

Reads the approximate min and max levels from a section of the thumbnail.

The lowest and highest samples are returned in minValue and maxValue, but obviously because the thumb only stores low-resolution data, these numbers will only be a rough approximation of the true values.

Implemented in juce::AudioThumbnail.

◆ getApproximatePeak()

virtual float juce::AudioThumbnailBase::getApproximatePeak ( ) const
pure virtual

Returns the highest level in the thumbnail.

Note that because the thumb only stores low-resolution data, this isn't an accurate representation of the highest value, it's only a rough approximation.

Implemented in juce::AudioThumbnail.

◆ getHashCode()

virtual int64 juce::AudioThumbnailBase::getHashCode ( ) const
pure virtual

Returns the hash code that was set by setSource() or setReader().

Implemented in juce::AudioThumbnail.

◆ getNumChannels()

virtual int juce::AudioThumbnailBase::getNumChannels ( ) const
pure virtualnoexcept

Returns the number of channels in the file.

Implemented in juce::AudioThumbnail.

◆ getNumSamplesFinished()

virtual int64 juce::AudioThumbnailBase::getNumSamplesFinished ( ) const
pure virtualnoexcept

Returns the number of samples that have been set in the thumbnail.

Implemented in juce::AudioThumbnail.

◆ getTotalLength()

virtual double juce::AudioThumbnailBase::getTotalLength ( ) const
pure virtualnoexcept

Returns the length of the audio file, in seconds.

Implemented in juce::AudioThumbnail.

◆ isFullyLoaded()

virtual bool juce::AudioThumbnailBase::isFullyLoaded ( ) const
pure virtualnoexcept

Returns true if the low res preview is fully generated.

Implemented in juce::AudioThumbnail.

◆ loadFrom()

virtual bool juce::AudioThumbnailBase::loadFrom ( InputStream input)
pure virtual

Reloads the low res thumbnail data from an input stream.

This is not an audio file stream! It takes a stream of thumbnail data that would previously have been created by the saveTo() method.

See also
saveTo

Implemented in juce::AudioThumbnail.

◆ removeAllChangeListeners()

void juce::ChangeBroadcaster::removeAllChangeListeners ( )
inherited

Removes all listeners from the list.

◆ removeChangeListener()

void juce::ChangeBroadcaster::removeChangeListener ( ChangeListener listener)
inherited

Unregisters a listener from the list.

If the listener isn't on the list, this won't have any effect.

◆ reset()

virtual void juce::AudioFormatWriter::ThreadedWriter::IncomingDataReceiver::reset ( int  numChannels,
double  sampleRate,
int64  totalSamplesInSource 
)
pure virtualinherited

Implemented in juce::AudioThumbnail.

◆ saveTo()

virtual void juce::AudioThumbnailBase::saveTo ( OutputStream output) const
pure virtual

Saves the low res thumbnail data to an output stream.

The data that is written can later be reloaded using loadFrom().

See also
loadFrom

Implemented in juce::AudioThumbnail.

◆ sendChangeMessage()

void juce::ChangeBroadcaster::sendChangeMessage ( )
inherited

Causes an asynchronous change message to be sent to all the registered listeners.

The message will be delivered asynchronously by the main message thread, so this method will return immediately. To call the listeners synchronously use sendSynchronousChangeMessage().

Referenced by juce::SelectedItemSet< SelectableItemType >::changed().

◆ sendSynchronousChangeMessage()

void juce::ChangeBroadcaster::sendSynchronousChangeMessage ( )
inherited

Sends a synchronous change message to all the registered listeners.

This will immediately call all the listeners that are registered. For thread-safety reasons, you must only call this method on the main message thread.

See also
dispatchPendingMessages

Referenced by juce::SelectedItemSet< SelectableItemType >::changed().

◆ setReader()

virtual void juce::AudioThumbnailBase::setReader ( AudioFormatReader newReader,
int64  hashCode 
)
pure virtual

Gives the thumbnail an AudioFormatReader to use directly.

This will start parsing the audio in a background thread (unless the hash code can be looked-up successfully in the thumbnail cache). Note that the reader object will be held by the thumbnail and deleted later when no longer needed. The thumbnail will actually keep hold of this reader until you clear the thumbnail or change the input source, so the file will be held open for all this time. If you don't want the thumbnail to keep a file handle open continuously, you should use the setSource() method instead, which will only open the file when it needs to.

Implemented in juce::AudioThumbnail.

◆ setSource()

virtual bool juce::AudioThumbnailBase::setSource ( InputSource newSource)
pure virtual

Specifies the file or stream that contains the audio file.

For a file, just call

setSource (new FileInputSource (file))

You can pass a nullptr in here to clear the thumbnail. The source that is passed in will be deleted by this object when it is no longer needed.

Returns
true if the source could be opened as a valid audio file, false if this failed for some reason.

Implemented in juce::AudioThumbnail.

Member Data Documentation

◆ anyListeners

std::atomic<bool> juce::ChangeBroadcaster::anyListeners { false }
privateinherited

◆ broadcastCallback

ChangeBroadcasterCallback juce::ChangeBroadcaster::broadcastCallback
privateinherited

◆ changeListeners

ListenerList<ChangeListener> juce::ChangeBroadcaster::changeListeners
privateinherited

The documentation for this class was generated from the following file:
juce::AudioThumbnailBase::setSource
virtual bool setSource(InputSource *newSource)=0
Specifies the file or stream that contains the audio file.