Cycling74 / min-api

High-level C++-language application programming interface for Max
MIT License
58 stars 23 forks source link

Vector Operator initialization #160

Open scblakely opened 4 years ago

scblakely commented 4 years ago

When I tried to use a vector operator, I was having issues with there being no outlets defined. I think the issue is with this :

template\<class min_class_type\>
void min_dsp64_io(minwrap\<min_class_type\>\* self, const short\* count) {
   int i = 0;

    while (i < self->m_min_object.inlets().size()) {
        self->m_min_object.inlets()[i]->update_signal_connection(count[i] != 0);
        ++i;
    }
    while (i < self->m_min_object.outlets().size()) {
        self->m_min_object.outlets()[i - self->m_min_object.inlets().size()]->update_signal_connection(count[i] != 0);
        ++i;
    }
}

After incrementing for the inlets,

while (i < self->m_min_object.outlets().size())

never executes.

I suspect the intent was

template<class min_class_type>
void min_dsp64_io(minwrap<min_class_type>\* self, const short\* count) {
    int i = 0;

    while (i < self->m_min_object.inlets().size()) {
        self->m_min_object.inlets()[i]->update_signal_connection(count[i] != 0);
        ++i;
    }
    while (i - self->m_min_object.inlets().size() < self->m_min_object.outlets().size()) {
        self->m_min_object.outlets()[i - self->m_min_object.inlets().size()]->update_signal_connection(count[i] != 0);
        ++i;
    }
}

or maybe

template<class min_class_type>
void min_dsp64_io(minwrap<min_class_type>* self, const short* count) {
    int i = 0;

    while (i < self->m_min_object.inlets().size()) {
        self->m_min_object.inlets()[i]->update_signal_connection(count[i] != 0);
        ++i;
    }
    i = 0;
    while (i < self->m_min_object.outlets().size()) {
        self->m_min_object.outlets()[i]->update_signal_connection(count[i + m_min_object.inlets().size()] != 0);
        ++i;
    }
}
x37v commented 3 years ago

@scblakely I'm planning to look into this, I'm wondering if you can provide a small code example that shows the problem that you're seeing?

scblakely commented 3 years ago

Basically, if you define inputs and outputs for your object, you ht this issue

class sitool_tilde : public object<sitool_tilde>, public vector_operator<> {
public:
    MIN_DESCRIPTION {"example"};
    MIN_TAGS        {"utilities"};
    MIN_AUTHOR      {"Simon Blakely"};
    MIN_RELATED     {""};

    long rb_sampleRate;
    long vectorSize;
    long sampleChannels;
    long maxvector;

    float** m_input;

    size_t m_blockSize;
    size_t m_reserve;
    size_t m_minfill;

    float** m_scratch;

    int m_sampleRate;
    size_t m_channels;

    int channels = 1;
    float ratio = 1;

    fifo<number>* in_fifo[2];
    fifo<number>* out_fifo[2];

    inlet<>  audio_in_0 { this, "(signal) audio in channel 0", "signal" };
    inlet<>  audio_in_1 { this, "(signal) audio in channel 1", "signal" };
    inlet<>  messages_in { this, "(anything) incoming messages" };
    inlet<>  ratio_in { this, "(float) pitch shift ratio" };
    outlet<> audio_out_0 { this, "(signal) audio out channel 0", "signal" };
    outlet<> audio_out_1 { this, "(signal) audio out channel 1", "signal" };
    outlet<> messages_out { this, "(anything) outgoing messages" };
   ...

The outlets never get added by the template.

x37v commented 3 years ago

great, thanks @scblakely !