LoginSignup
1
1

More than 1 year has passed since last update.

JUCEでのprintfデバッグ、およびログへの出力

Last updated at Posted at 2021-08-06

XCodeなどのConsoleへの出力

DBG("TEST")
などで、出力できる。

DBGはsystemに定義されているマクロ
https://docs.juce.com/master/group__juce__core-system.html

ログの出力

juce::Logger
で出力できる。

ここで使われているので参考に
https://docs.juce.com/master/tutorial_simple_synth_noise.html

How to use the FileLogger

FileLoggerの使い方

ログ出力サンプル

ログ出力するプロジェクトをgithubにあげました。
https://github.com/uchidama/SimpleSynthNoiseTutorialMod/

#pragma once

//==============================================================================
class MainContentComponent   : public juce::AudioAppComponent
{
public:
    MainContentComponent() : m_log_file("~/log_test.txt"), m_logger(m_log_file,"Welcome to the log",0)
    {
        juce::Logger::setCurrentLogger(&m_logger);

        setSize (800, 600);
        setAudioChannels (0, 2); // no inputs, two outputs

    }

    ~MainContentComponent() override
    {
        shutdownAudio();
    }

    void prepareToPlay (int samplesPerBlockExpected, double sampleRate) override
    {
        juce::String message;
        message << "Preparing to play audio...\n";
        message << " samplesPerBlockExpected = " << samplesPerBlockExpected << "\n";
        message << " sampleRate = " << sampleRate;
        juce::Logger::getCurrentLogger()->writeToLog (message);
    }

    void releaseResources() override
    {
        juce::Logger::getCurrentLogger()->writeToLog ("Releasing audio resources");
    }

    void getNextAudioBlock (const juce::AudioSourceChannelInfo& bufferToFill) override
    {
        for (auto channel = 0; channel < bufferToFill.buffer->getNumChannels(); ++channel)
        {
            // Get a pointer to the start sample in the buffer for this audio output channel
            auto* buffer = bufferToFill.buffer->getWritePointer (channel, bufferToFill.startSample);

            // Fill the required number of samples with noise between -0.125 and +0.125
            for (auto sample = 0; sample < bufferToFill.numSamples; ++sample)
                buffer[sample] = random.nextFloat() * 0.25f - 0.125f;
        }
    }

private:
    juce::Random random;
    juce::File m_log_file;
    juce::FileLogger m_logger;

    JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainContentComponent)
};

使ってるコア部分。

こんな感じ。

ログを見る

Mac OS Xで見るなら、ターミナルから

tail -n 100 -f ~/log_test.txt

で見ると便利。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1