Cycling74 / min-devkit

Tools, documentation, and reference implementation of a Max Package built using the Min-API.
MIT License
161 stars 31 forks source link

Not seeing standard output & error on macOS #215

Closed leoauri closed 7 months ago

leoauri commented 7 months ago

Hello. I am working on a fork of nn_tilde. I see plenty being sent to std::cout and std::cerr in their code, and I want to use this for debugging, but when I build their code and run the externals, I don't see these messages anywhere, not in the Max console, not in Console.app (this is in macOS).

Does anyone have any advice for seeing standard output/error?

In the min-devkit guide it states:

To post to the system console instead of the Max console use std::cout, std::cerr, and std::endl as is typical in C++ rather than the variants implemented in the c74::min namespace.

But I don't see that working for me.

Ideas? Thanks,

leoauri commented 7 months ago

Oh, I am running in max4live.

leoauri commented 7 months ago

It is also the case when running Max standalone.

leoauri commented 7 months ago

I am going to call this "bug", since behaviour and documentation seem to disagree.

leoauri commented 7 months ago

Environment:

{
    "version" : "Version 8.6.0 (16ccdff84ed) (x64 mac)",
    "platform" : "mac",
    "arch" : "x64",
    "osversion" : "Mac OS X Version 14.2.1 (Build 23C71) x86_64 Rosetta",
    "samplerate" : 44100,
    "iovs" : 1024,
    "sigvs" : 1024,
    "scheduler_in_audio_interrupt" : "off",
    "audio_drivername" : "Core Audio",
    "audio_driver_subname" : "",
    "eventinterval" : 2,
    "schedinterval" : 10.0,
    "overdrive" : "on",
    "pollthrottle" : 40,
    "queuethrottle" : 100,
    "sysqelemthrottle" : 1000,
    "refreshrate" : 33.333332061767578,
    "schedslop" : 25.0,
    "eventprobing" : 1,
    "mixerparallel" : "off",
    "mixercrossfade" : 0,
    "mixerlatency" : 30.0,
    "mixerramptime" : 10.0,
    "videoengine" : "avf",
    "gfxengine" : "glcore",
    "packages" :    {
        "BEAP" : "1.0.4",
        "CNMAT Externals" : "1.0.5",
        "FluidCorpusManipulation" : "1.0.6",
        "gl3" : "0.3.3",
        "hap" : "1.0.6",
        "jit.mo" : "1.1.6",
        "Jitter Tools" : "1.0.10",
        "Max for Live" : "1.0.9",
        "Max ToolBox" : "16",
        "max-mxj" : "8.2.0",
        "maxforlive-elements" : "1.0.10",
        "Mira" : "1.2.1",
        "nn_tilde" : "",
        "Node for Max" : "2.1.2",
        "RNBO" : "1.2.4",
        "VIDDLL" : "1.2.8",
        "Vizzie" : "2.2.2"
    }

}
leoauri commented 7 months ago

Setting -DCMAKE_BUILD_TYPE=Debug did not help.

Here's how I am building:

mkdir build
cd build/
cmake ../src/ -DCMAKE_PREFIX_PATH=.../libtorch -DCMAKE_BUILD_TYPE=Debug -DCMAKE_OSX_ARCHITECTURES=x86_64
gmake
cd ..
cp -R src/externals .../Max\ 8/Packages/nn_tilde

cmake version 3.28.1

GNU Make 4.4.1

leoauri commented 7 months ago

With the following I confirmed that sending to std::cout does not post to the system console on my system:

/// @file
/// @ingroup    minexamples
/// @copyright  Copyright 2018 The Min-DevKit Authors. All rights reserved.
/// @license    Use of this source code is governed by the MIT License found in the License.md file.

#include <iostream>
#include "c74_min.h"

using namespace c74::min;

class hello_whole_world : public object<hello_whole_world> {
public:
    MIN_DESCRIPTION {"Post to the Max Console."};
    MIN_TAGS        {"utilities"};
    MIN_AUTHOR      {"Cycling '74"};
    MIN_RELATED     {"print, jit.print, dict.print"};

    inlet<>  input  { this, "(bang) post greeting to the max console" };
    outlet<> output { this, "(anything) output the message which is posted to the max console" };

    // define an optional argument for setting the message
    argument<symbol> greeting_arg { this, "greeting", "Initial value for the greeting attribute.",
        MIN_ARGUMENT_FUNCTION {
            greeting = arg;
        }
    };

    // the actual attribute for the message
    attribute<symbol> greeting { this, "greeting", "hello whole world",
        description {
            "Greeting to be posted. "
            "The greeting will be posted to the Max console when a bang is received."
        }
    };

    // respond to the bang message to do something
    message<> bang { this, "bang", "Post the greeting.",
        MIN_FUNCTION {
            symbol the_greeting = greeting;    // fetch the symbol itself from the attribute named greeting

            cout << the_greeting << endl;    // post to the max console
            std::cout << the_greeting << std::endl;    // post to stdout
            output.send(the_greeting);       // send out our outlet
            return {};
        }
    };

    // post to max window == but only when the class is loaded the first time
    message<> maxclass_setup { this, "maxclass_setup",
        MIN_FUNCTION {
            cout << "hello whole world" << endl;
            std::cout << "hello whole world" << std::endl;
            return {};
        }
    };

};

MIN_EXTERNAL(hello_whole_world);

Does it work for others as stated in the docs, or does it generally not work?

isabelgk commented 7 months ago

Hi @leoauri ,

Can you try using cout << "hello whole world" << endl; instead? This will post to the Max console since it'll use c74::min::cout. If you use std::cout, you should see the output when Max is launched via a terminal (the "console" it's referring to in the docs), but you're right that you won't see anything in Console.app or the Max console.

leoauri commented 6 months ago

Hi @isabelgk, thanks for the tip. Indeed, if I run the Max from the command line (something like /Applications/Max.app/Contents/MacOS/Max) I get output from standard out. Useful for working with existing code, or situations where Max is crashing.