rtttl-player

amperka/colony/rtttl-player

RTTTL format sound player module. See RTTTL data format at: https://en.wikipedia.org/wiki/Ring_Tone_Transfer_Language
rtttl-player
@/rtttl-player
RTTTL format sound player module. See RTTTL data format at: https://en.wikipedia.org/wiki/Ring_Tone_Transfer_Language
PINport
RTTTLstring
String of RTTTL data of melody
ENpulse
rtttl-player
PIN
RTTTL
EN
DONE
DONEpulse
Fires when done
To use the node in your project you should have the amperka/colony library installed. Use the “File → Add Library” menu item in XOD IDE if you don’t have it yet. See Using libraries for more info.

C++ implementation

#pragma XOD require "https://github.com/end2endzone/AnyRtttl"

{{#global}}
#include <anyrtttl.h>
#include <binrtttl.h>
#include <pitches.h>
{{/global}}

struct State {
    char* notearray;
};

{{ GENERATED_CODE }}

void evaluate(Context ctx) {
    XString rtttlString = getValue<input_RTTTL>(ctx);
    auto buzzerPin = getValue<input_PIN>(ctx);
    State* state = getState(ctx);
    
    if (isInputDirty<input_EN>(ctx)) {
        // if "enable" play string
        anyrtttl::blocking::play(buzzerPin, state->notearray);
        emitValue<output_DONE>(ctx, true);
    } else {
        // else update string
        if(state->notearray != nullptr) { delete state->notearray; }
        auto len = length(rtttlString);
        state->notearray = new char[len + 1];
        dump(rtttlString,state->notearray);
    }
}