node-red-contrib-musiccast
Version:
A Node-RED collection for monitoring and controlling a Yamaha Musiccast network.
524 lines (477 loc) • 24.6 kB
HTML
<!--
Apache-2.0
Copyright (c) 2023 Vahdettin
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
-->
<script src="resources/node-red-contrib-musiccast/musiccast-ui.js"></script>
<script type="text/javascript">
(function () {
const BASE = 'input';
RED.nodes.registerType('musiccast-input', {
category: 'Musiccast',
defaults: {
mc: {type: "musiccast-config", required: true},
name: {value: "", required: false},
device: {value: "", required: false},
type_device: {value: "", required: false},
inp: {value: "server", required: false},
type_inp: {value: "", required: false},
command: {value: "getPlayInfo", required: false},
type_command: {value: "", required: false},
payload: {value: "{}", required: false},
type_payload: {value: "", required: false},
f_show_status: {value: false, required: false}
},
inputs: 1,
outputs: 1,
color: "#9c86bc",
label: function () {
return this.name || this.command;
},
icon: "font-awesome/fa-music",
align: 'right',
paletteLabel: "input",
oneditprepare: function () {
const mc = RED.nodes.node($("#node-input-mc").val()) || null;
let ui = new MCUI(BASE, mc, RED);
const Fields = ui.cFields;
let mcInputDraw = function (done) {
ui.popDevices(null, function (err, curDev) {
ui.popInputs(curDev, function (err, curInp) {
ui.popCommands(curInp, function (err, curCommand) {
ui.popAttributes();
ui.loadCommand(curCommand, function (err, curCommand) {
})
done(true);
});
});
});
}
mcInputDraw(function (drawn) {
if (drawn) {
//init listeners
Fields.c.on('change', function (event, type, value) {
ui.loadCommand({
v: value,
t: Fields.c.typedInput("type")
}, function (err, curCommand) {
})
});
Fields.i.on('change', function (event, type, value) {
ui.popCommands({
v: value,
t: Fields.i.typedInput("type")
}, function (err, curCommand) {
});
});
Fields.d.on('change', function (event, type, value) {
ui.popInputs({
v: value,
t: Fields.d.typedInput("type"),
}, function (err, curInp) {
});
});
Fields.p.on('change', function (event, type, value) {
if (type && type === 'json') {
if (!value) {
Fields.p.typedInput('value', '{}')
}
}
});
$("#lookup-command").on("click", function () {
ui.showSidebarHelpPanel({
v: Fields.c.typedInput("value"),
t: Fields.c.typedInput("type")
});
});
$("#set-attribute-default").on("click", function () {
ui.popExampleAttributes({
v: Fields.c.typedInput("value"),
t: Fields.c.typedInput("type")
}, function (err, data) {
})
});
RED.events.on("nodes:change", function (theNode) {
if (theNode && theNode.type === 'musiccast-config') {
if (theNode.dirty && theNode.dirty !== false && theNode.valid && theNode.valid !== false) {
ui.refresh(theNode, function (err, done) {
ui.popDevices(null, function (err, curZone) {
})
})
}
}
});
ui.finish();
}
});
},
oneditsave: function () {
const mc = RED.nodes.node($("#node-input-mc").val()) || null;
let ui = new MCUI(BASE, mc, RED);
const Fields = ui.cFields;
$("#lookup-command").off();
$("#set-attribute-default").off();
this.device = Fields.d.typedInput("value");
this.inp = Fields.i.typedInput("value");
this.command = Fields.c.typedInput("value");
this.payload = Fields.p.typedInput("value");
},
oneditcancel: function () {
$("#lookup-command").off();
$("#set-attribute-default").off();
}
});
})();
</script>
<script type="text/html" data-template-name="musiccast-input">
<link rel="stylesheet" href="resources/node-red-contrib-musiccast/style.css"/>
<div class="form-row">
<label for="node-input-mc"> Musiccast</label>
<input type="text" id="node-input-mc">
</div>
<div class="form-row ">
<label for="node-input-inp"><i class="fa fa-sign-in"></i> Input</label>
<div style="display: inline-block; position: relative; width: 70%; height: 20px;">
<div style="position: absolute; left: 0px; right: 40px;">
<input type="text" id="node-input-inp" style="width:80%">
</div>
</div>
</div>
<div class="form-row ">
<label for="node-input-device"><i class="fa fa-crosshairs"></i> Device</label>
<div style="display: inline-block; position: relative; width: 70%; height: 20px;">
<div style="position: absolute; left: 0px; right: 40px;">
<input type="text" id="node-input-device" style="width:80%">
</div>
</div>
</div>
<div class="form-row ">
<label for="node-input-command"><i class="fa fa-cogs"></i> Command</label>
<div style="display: inline-block; position: relative; width: 70%; height: 20px;">
<div style="position: absolute; left: 0px; right: 40px;">
<input type="text" id="node-input-command" style="width:100%">
</div>
<a id="lookup-command" class="red-ui-button" style="position: absolute; right: 0px; top: 0px;"><i
class="fa fa-book"></i></a>
</div>
</div>
<div class="form-row musiccast-form-row-cmd-addt ">
<label> </label>
<input type="checkbox" id="node-input-f_show_status"
style="display:inline-block; width:15px; vertical-align:baseline;" autocomplete="off">
<label style="width: 60% !important;" for="node-input-f_show_status"
title="Show playback status for the designated input on the palette when the command runs.">Show on
palette</label>
</div>
<div class="form-row musiccast-form-row-payload">
<label for="node-input-payload"><i class="fa fa-puzzle-piece"></i> Attributes</label>
<div style="display: inline-block; position: relative; width: 70%; height: 20px;">
<div style="position: absolute; left: 0px; right: 40px;">
<input type="text" id="node-input-payload" style="width:100%">
</div>
<a id="set-attribute-default" class="red-ui-button"
style="position: absolute; right: 0px; top: 0px;"><i class="fa fa-paste"></i></a>
</div>
</div>
<div class="form-row ">
<label for="node-input-name"><i class="fa fa-tag"></i> Label</label>
<div style="display: inline-block; position: relative; width: 70%; height: 20px;">
<div style="position: absolute; left: 0px; right: 40px;">
<input type="text" id="node-input-name" placeholder="optional" style="width:100%">
</div>
</div>
</div>
<div class="form-row musiccast-form-row-ah">
<input type="text" id="node-input-type_device">
</div>
<div class="form-row musiccast-form-row-ah">
<input type="text" id="node-input-type_inp">
</div>
<div class="form-row musiccast-form-row-ah">
<input type="text" id="node-input-type_command">
</div>
<div class="form-row musiccast-form-row-ah">
<input type="text" id="node-input-type_payload">
</div>
<div class="form-row musiccast-form-row-ah">
<input type="text" id="node-input-status_func">
</div>
</script>
<script type="text/html" data-help-name="musiccast-input">
<link rel="stylesheet" href="resources/node-red-contrib-musiccast/style.css"/>
<p>Control playback or obtain information for an audio input such as a USB drive or streaming service.</p>
<h4>Yamaha API Relationship</h4>
<p>The Yamaha API command types included in this node are:</p>
<dl>
<dd>
<ul>
<li>Network\USB </li>
<li>Tuner </li>
<li>CD </li>
</ul>
</dd>
</dl>
<p>Note: commands related to browsing and playback of an input's media lists are available under the "list" node.</p>
<h4>Basic Configuration</h4>
<p>The following items can only be set via the palette editor. All other configuration items can be set in the
editor or via inbound message or context variable. Details for these items are in the Input section below. </p>
<dl>
<dt>Musiccast</dt>
<dd>Select the Musiccast configuration to use.</dd>
<dt>Label</dt>
<dd>Optional. Enter a name for the node or the default will be assigned.</dd>
<dt>Show on palette</dt>
<dd>Optional. If this option appears under the Command dropdown and is checked, basic information from a
response will be displayed on the palette under the node when a command is sent.
</dl>
<h4>Helpful Features</h4>
<p>There are several buttons that when clicked, provide helpful functionality to assist with configuration.</p>
<dl>
<dd>
<ul>
<li><a class="red-ui-button"><i class="fa fa-question"></i></a> Shows inline help for the selected
command.
</li>
<li><a class="red-ui-button"><i class="fa fa-paste"></i></a> Populates the Attributes field with example
values to start with.
</li>
</ul>
</dd>
</dl>
<h3>Input</h3>
<dl class="message-properties">
<dt>input
<span class="property-type">string</span>
</dt>
<dd> The input system name or label.
</dd>
<dt>device
<span class="property-type">string</span>
</dt>
<dd> The target device name or label.
</dd>
<dt>command
<span class="property-type">string</span>
</dt>
<dd> The command to send.
</dd>
<dt>attributes
<span class="property-type">object</span>
</dt>
<dd> Additional attributes if needed by the command. This can also be supplied as <code>payload</code>.
</dd>
</dl>
<h3>Output</h3>
<dl class="message-properties">
<dt>input
<span class="property-type">string</span>
</dt>
<dd> The affected input.
</dd>
<dt>device
<span class="property-type">string</span>
</dt>
<dd> The device the command was sent to.
</dd>
<dt>command <span class="property-type">string</span></dt>
<dd> The command that was sent.</dd>
<dt>payload <span class="property-type">object</span></dt>
<dd> The response received from the device. This will always include <i>response_code</i> and <i>response_message</i>.
</dd>
</dl>
<h3>Command Reference</h3>
<!-- BEGIN COMMAND HELP -->
<dl class="message-properties">
<dt id="musiccast-command-info-togglerepeat">toggleRepeat</dt>
<dd>Enable or disable repeat for the specified network source or CD player.</dd><p></p>
<dt id="musiccast-command-info-getrecentinfo">getRecentInfo</dt>
<dd>Enable list of recently played items.</dd><p></p>
<dt id="musiccast-command-info-toggleshuffle">toggleShuffle</dt>
<dd>Enable or disable shuffle for the specified network source or CD player.</dd><p></p>
<dt id="musiccast-command-info-setplayback">setPlayback</dt>
<dd>Various options to alter the playback state of the input.</dd><p></p>
<dd>Attribute structure:
<pre class="musiccast-attributes-example">{
<span class="key">"playback":</span> <span class="string">"stop|pause|play|previous|next|fast_reverse_start|fast_reverse_end|fast_forward_start|fast_forward_end|track_select"</span>,
<span class="key">"num":</span> <span class="string">"1|...|512"</span>
}</pre><p></p>
</dd>
<dt id="musiccast-command-info-setplayback_cd">setPlayback (CD)</dt>
<dd>Various options to alter the playback state of the input. Attribute [num] is only used when [playback] is 'track_select'.</dd><p></p>
<dd>Attribute structure:
<pre class="musiccast-attributes-example">{
<span class="key">"playback":</span> <span class="string">"stop|pause|play|previous|next|fast_reverse_start|fast_reverse_end|fast_forward_start|fast_forward_end|track_select"</span>,
<span class="key">"num":</span> <span class="string">"1|...|512"</span>
}</pre><p></p>
</dd>
<dt id="musiccast-command-info-setplayposition">setPlayPosition</dt>
<dd>For setting track play position. This command is available only when input is set to Server</dd><p></p>
<dd>Attribute structure:
<pre class="musiccast-attributes-example">{
<span class="key">"position":</span> <span class="string">"1|3|65|..."</span>
}</pre><p></p>
</dd>
<dt id="musiccast-command-info-getplayinfo">getPlayInfo</dt>
<dd>Get information on currently playing media of the active network service. Optionally, the returned playback state can be displayed on the palette.<p>Note: Value of [Input] is redundant for this command.</p</dd><p></p>
<dt id="musiccast-command-info-getpresetinfo">getPresetInfo</dt>
<dd>Get preset information of the network sources or tuner.</dd><p></p>
<dd>Attribute structure:
<pre class="musiccast-attributes-example">{
<span class="key">"band":</span> <span class="string">"common|am|fm|dab"</span>
}</pre><p></p>
</dd>
<dt id="musiccast-command-info-getsettings">getSettings</dt>
<dd>Retrieve netusb settings.</dd><p></p>
<dt id="musiccast-command-info-recallpreset">recallPreset</dt>
<dd>Recalls presets for the MusicCast system. Use zone name from [getLocationInfo]. Command will cause an input change if applicable.</dd><p></p>
<dd>Attribute structure:
<pre class="musiccast-attributes-example">{
<span class="key">"zone":</span> <span class="string">"main|zone1|..."</span>,
<span class="key">"num":</span> <span class="string">"1|2|3|..."</span>
}</pre><p></p>
</dd>
<dt id="musiccast-command-info-movepreset">movePreset</dt>
<dd>Move preset from one location to the other.</dd><p></p>
<dd>Attribute structure:
<pre class="musiccast-attributes-example">{
<span class="key">"from":</span> <span class="string">"1|2|3|..."</span>,
<span class="key">"to":</span> <span class="string">"1|2|3|..."</span>
}</pre><p></p>
</dd>
<dt id="musiccast-command-info-storepreset">storePreset</dt>
<dd>Store the currently playing media as a preset.</dd><p></p>
<dd>Attribute structure:
<pre class="musiccast-attributes-example">{
<span class="key">"num":</span> <span class="string">"1|2|3|..."</span>
}</pre><p></p>
</dd>
<dt id="musiccast-command-info-startautopreset">startAutoPreset</dt>
<dd>Store the currently playing media as a preset.</dd><p></p>
<dd>Attribute structure:
<pre class="musiccast-attributes-example">{
<span class="key">"band":</span> <span class="string">"fm"</span>
}</pre><p></p>
</dd>
<dt id="musiccast-command-info-cancelautopreset">cancelAutoPreset</dt>
<dd>Store the currently playing media as a preset.</dd><p></p>
<dd>Attribute structure:
<pre class="musiccast-attributes-example">{
<span class="key">"band":</span> <span class="string">"fm"</span>
}</pre><p></p>
</dd>
<dt id="musiccast-command-info-startdabinitialscan">startDabInitialScan</dt>
<dd>Start initial scan for DAB.</dd><p></p>
<dt id="musiccast-command-info-canceldabinitialscan">cancelDabInitialScan</dt>
<dd>Cancel initial scan for DAB.</dd><p></p>
<dt id="musiccast-command-info-setdabtuneaid">setDabTuneAid</dt>
<dd>Execute DAB tune aid.</dd><p></p>
<dt id="musiccast-command-info-getaccountstatus">getAccountStatus</dt>
<dd>Get current status of all streaming accounts.</dd><p></p>
<dt id="musiccast-command-info-getserviceinfo">getServiceInfo</dt>
<dd>Get specific information about a streaming service. Types vary depending on provider. NOTE: input must be specified in attributes as a service as well as in the primary configuration dropdown as netusb. </dd><p></p>
<dd>Attribute structure:
<pre class="musiccast-attributes-example">{
<span class="key">"input":</span> <span class="string">"pandora|tidal|..."</span>,
<span class="key">"type":</span> <span class="string">"account_list|licensing|..."</span>,
<span class="key">"timeout":</span> <span class="string">"60000"</span>
}</pre><p></p>
</dd>
<dt id="musiccast-command-info-switchaccount">switchAccount</dt>
<dd>Get status of the play queue for a given input. Timeout is in milliseconds. NOTE: input must be specified in attributes as well as in the primary configuration dropdown.</dd><p></p>
<dd>Attribute structure:
<pre class="musiccast-attributes-example">{
<span class="key">"input":</span> <span class="string">"pandora|tidal|..."</span>,
<span class="key">"index":</span> <span class="string">"0|1|2|..."</span>,
<span class="key">"timeout":</span> <span class="string">"60000"</span>
}</pre><p></p>
</dd>
<dt id="musiccast-command-info-getplayqueue">getPlayQueue</dt>
<dd>Get status of the play queue for a given input.</dd><p></p>
<dd>Attribute structure:
<pre class="musiccast-attributes-example">{
<span class="key">"index":</span> <span class="string">"0|1|2|..."</span>
}</pre><p></p>
</dd>
<dt id="musiccast-command-info-setfreq">setFreq</dt>
<dd>Set the frequency of the over-the-air tuner in kHz.</dd><p></p>
<dd>Attribute structure:
<pre class="musiccast-attributes-example">{
<span class="key">"band":</span> <span class="string">"am|fm"</span>,
<span class="key">"tuning":</span> <span class="string">"direct"</span>,
<span class="key">"num":</span> <span class="string">"87500|..."</span>
}</pre><p></p>
</dd>
<dt id="musiccast-command-info-setband">setBand</dt>
<dd>Change the tuner band.</dd><p></p>
<dd>Attribute structure:
<pre class="musiccast-attributes-example">{
<span class="key">"band":</span> <span class="string">"am|fm|dab"</span>
}</pre><p></p>
</dd>
<dt id="musiccast-command-info-setdabservice">setDabService</dt>
<dd>Change to next or previous DAB service.</dd><p></p>
<dd>Attribute structure:
<pre class="musiccast-attributes-example">{
<span class="key">"dir":</span> <span class="string">"previous|next"</span>
}</pre><p></p>
</dd>
<dt id="musiccast-command-info-toggletray">toggleTray</dt>
<dd>Open or close the CD tray.</dd><p></p>
<dt id="musiccast-command-info-setrepeat">setRepeat</dt>
<dd>Set the repeat mode for a network source.</dd><p></p>
<dd>Attribute structure:
<pre class="musiccast-attributes-example">{
<span class="key">"mode":</span> <span class="string">"on|off|all"</span>
}</pre><p></p>
</dd>
<dt id="musiccast-command-info-setrepeat_cd">setRepeat (CD)</dt>
<dd>Set the repeat mode for the CD player.</dd><p></p>
<dd>Attribute structure:
<pre class="musiccast-attributes-example">{
<span class="key">"mode":</span> <span class="string">"one|off|all|folder"</span>
}</pre><p></p>
</dd>
<dt id="musiccast-command-info-setshuffle">setShuffle</dt>
<dd>Set the shuffle mode for a network source.</dd><p></p>
<dd>Attribute structure:
<pre class="musiccast-attributes-example">{
<span class="key">"mode":</span> <span class="string">"on|off|songs|albums"</span>
}</pre><p></p>
</dd>
<dt id="musiccast-command-info-setshuffle_cd">setShuffle (CD)</dt>
<dd>Set the shuffle mode for the CD player.</dd><p></p>
<dd>Attribute structure:
<pre class="musiccast-attributes-example">{
<span class="key">"mode":</span> <span class="string">"on|off|folder"</span>
}</pre><p></p>
</dd>
<dt id="musiccast-command-info-setquality">setQuality</dt>
<dd>Set playback quality for the service.</dd><p></p>
<dd>Attribute structure:
<pre class="musiccast-attributes-example">{
<span class="key">"input":</span> <span class="string">"pandora|tidal|..."</span>,
<span class="key">"value":</span> <span class="string">"hr_192_24|hr_96_24|cd_44_16|mp3_320"</span>
}</pre><p></p>
</dd>
<dt id="musiccast-command-info-clearrecentinfo">clearRecentInfo</dt>
<dd>Clear list of recently played tracks for all network sources.</dd><p></p>
<dt id="musiccast-command-info-manageplay">managePlay</dt>
<dd>For special processing of track.</dd><p></p>
<dt id="musiccast-command-info-getplaydescription">getPlayDescription</dt>
<dd>For retrieving track’s detail information.</dd><p></p>
</dl>
<!-- END COMMAND HELP -->
<h4>Collection Information</h4>
<ul>
<li>Version: 4.5.2</li>
</ul>
<div style="height: 700px;"></div>
<span>This space intentionally left blank</span>
</script>