Code Monkey home page Code Monkey logo

ff_meters's Introduction

ff_meters

by Daniel Walz / Foleys Finest Audio Ltd. Published under the BSD License (3 clause)

The ff_meters provide an easy to use Component to display a level reading for an AudioBuffer. It is to be used in the audio framework JUCE (www.juce.com).

Find the API documentation here: https://ffaudio.github.io/ff_meters/

Usage

LevelMeter

To use it create a LevelMeterSource instance next to the AudioBuffer you want to display. To update the meter, call LevelMeterSource::measureBlock (buffer) in your processBlock or getNextAudioBuffer method.

On the Component use LevelMeter::setMeterSource to link to the LevelMeterSource instance. The number of channels will be updated automatically.

You can pull the drawing into your LookAndFeel by inheriting LevelMeter::LookAndFeelMethods and inlining the default implementation from LevelMeterLookAndFeel in ff_meters_LookAndFeelMethods.h into a public section of your class declaration. To setup the default colour scheme, call setupDefaultMeterColours() in your constructor.

Or you can use the LevelMeterLookAndFeel directly because it inherits from juce::LookAndFeel_V3 for your convenience. You can set it as default LookAndFeel, if you used the default, or set it only to the meters, if you don't want it to interfere.

All classes are in the namespace foleys to avoid collisions. You can either prefix each symbol, or import the namespace. N.B. for backward compatibility, FFAU is an alias for foleys.

// In your Editor
public:
    PluginEditor()
    {
        // adjust the colours to how you like them, e.g.
        lnf.setColour (foleys::LevelMeter::lmMeterGradientLowColour, juce::Colours::green);

        meter.setLookAndFeel (&lnf);
        meter.setMeterSource (&processor.getMeterSource());
        addAndMakeVisible (meter);
        // ...
    }
    ~PluginEditor()
    {
        meter.setLookAndFeel (nullptr);
    }

private:
    foleys::LevelMeterLookAndFeel lnf;
    foleys::LevelMeter meter { foleys::LevelMeter::Minimal }; // See foleys::LevelMeter::MeterFlags for options

// and in the processor:
public:
    foleys::LevelMeterSource& getMeterSource()
    {
        return meterSource;
    }

    void prepareToPlay (double sampleRate, int samplesPerBlockExpected) override
    {
        // this prepares the meterSource to measure all output blocks and average over 100ms to allow smooth movements
        meterSource.resize (getTotalNumOutputChannels(), sampleRate * 0.1 / samplesPerBlockExpected);
        // ...
    }
    void processBlock (AudioSampleBuffer& buffer, MidiBuffer&) override
    {
        meterSource.measureBlock (buffer);
        // ...
    }

private:
    foleys::LevelMeterSource meterSource;

OutlineBuffer

Another class is capable of reducing the samples going through into min and max blocks. This way you can see the outline of a signal running through. It can be used very similar:

// in your processor
private:
foleys::OutlineBuffer outline;

// in prepareToPlay
outline.setSize (getTotalNumInputChannels(), 1024);

// in processBlock
outline.pushBlock (buffer, buffer.getNumSamples());

// and in the editor's component:
const Rectangle<float> plotFrame (10.0f, 320.0f, 580f, 80f);
g.setColour (Colours::lightgreen);
g.fillRect (plotFrame);

Path plot;
processor.getChannelOutline (plot, plotFrame, 1000);
g.setColour (Colours::grey);
g.fillPath (plot);
g.setColour (Colours::black);
g.strokePath (plot, PathStrokeType (1.0f));

We hope it is of any use, let us know of any problems or improvements you may come up with...

Brighton, 2nd March 2017


ff_meters's People

Contributors

elandaofficial avatar ffaudio avatar ffont avatar jacobsologub avatar modosc avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.