Skip to content

Instantly share code, notes, and snippets.

@sente
Created June 4, 2020 08:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sente/0927a242a0670919fac77439210f611b to your computer and use it in GitHub Desktop.
Save sente/0927a242a0670919fac77439210f611b to your computer and use it in GitHub Desktop.
snippets from violano.js
// Version 03-08-2018
var CurrentViewEnum = {
NONE: 0,
SONGS: 1,
PLAYLISTS: 2,
ALBUMS: 3
};
const numberOfButtons = numberOfRows * numberOfColumns;
window.initialStartup = true;
window.mobilePhoneBtnCnt = 0;
window.masterSongsArray = [];
window.masterSongsEndingSongNumber = -1;
window.allSongsArray = [];
window.allSongsEndingSongNumber = -1;
window.masterSongsArraySaved = [];
window.masterSongsEndingSongNumberSaved = -1;
window.allSongsArraySaved = [];
window.allSongsEndingSongNumberSaved = -1;
window.currentPlaylistSongs = [];
window.playListSongsEndingSongNumber = -1;
window.editingPlaylistActive = 0;
window.currentlyViewingPlaylistSongs = 0;
window.currentlyViewingAlbumSongs = 0;
window.activePlayList = "";
window.playlistsArray = [];
window.playlistsEndingNumber = -1;
window.albumsArray = [];
window.albumsEndingNumber = -1;
window.playlistsArraySaved = [];
window.playlistsEndingNumberSaved = -1;
window.albumsArraySaved = [];
window.albumsEndingNumberSaved = -1;
window.activeAlbum = "";
window.renameSongMode = 0;
window.currentPlayingSong = "";
window.currentView = CurrentViewEnum.NONE;
window.mainLineDefaultMessage = "";
/*
The privateData can be anything that the sender wants returned when the response is sent.
It is commonly used as an id for a text field that is to be populated.
Note: The communication between the broweser is totally asynchronous (non blocking).
Commands TO C# Server:
midiCommand STOP / PAUSE / RESUME / REPEAT / PLAY_SONG / SET_POSITION / SET_TEMPO / PLAY_LIST .....
dirCommand GET_SONGS folderName privateData
dirCommand GET_FOLDERS folderName privateData
dirCommand REMOVE_SONG folderName fileName
dirCommand REMOVE_FOLDER folderName
dirCommand CREATE_FOLDER folderName
dirCommand COPY_SONG fileName folderName
registryCommand GET_MIDI
registryCommand GET_MIDI_DEVICES privateData
registryCommand SET_MIDI midiDeviceNumber
systemCommand GET_MACHINE_ID privateData
systemCommand GET_VERSION privateData
systemCommand GET_LICENSE_KEY privateData
systewmCommand SET_LICENSE_KEY licenseKey privateData
testMsg (Used bt Dave for internatl testing)
Commands FROM C# Server:
Status Update
System Update
midiPlayerCurrentPosition
currentMidiDeviceInfo
File List Update
testMsg
*/
function viewModeButtonClicked(id) {
if (document.getElementById("viewModeButton").value == "List View") {
document.getElementById("viewModeButton").value = "Table View";
$(document.getElementById("tableButtonViewDiv")).fadeOut(TableListViewFadeDelay, function () {
$(document.getElementById("mobilePhoneButtonView")).fadeIn(TableListViewFadeDelay);
var elements = document.getElementsByClassName("listButton");
for (i = 0; i < elements.length; i++)
{
elements[i].style.width= window.ListButtonWidth; //((jQuery(window).width() * .90) + "px";
}
});
document.getElementById("previousButton").style.display = "none";
document.getElementById("nextButton").style.display = "none";
} else {
document.getElementById("viewModeButton").value = "List View";
$(document.getElementById("mobilePhoneButtonView")).fadeOut(TableListViewFadeDelay, function () {
$(document.getElementById("tableButtonViewDiv")).fadeIn(TableListViewFadeDelay);
});
updatePrevNextButtons();
}
}
function enableSearch() {
document.getElementById("searchTextField").value = "";
search = prompt(SearchPrompt);
if (search == "" || search == null)
return;
document.getElementById("searchTextField").value = search;
$(document.getElementById("searchTextFieldDiv")).fadeIn(SearchFadeDelay, function() {
document.getElementById("searchButton").value = "Exit Search";
searchTextFieldUpdated();
});
}
function disableSearch() {
$(document.getElementById("searchTextFieldDiv")).fadeOut(SearchFadeDelay, function() {
document.getElementById("searchTextField").value = "";
document.getElementById("searchButton").value = "Search";
searchTextFieldUpdated();
});
document.getElementById("searchTextField").value = "";
searchTextFieldUpdated();
}
function searchButtonClicked() {
if (document.getElementById("searchButton").value == "Exit Search")
disableSearch();
else
enableSearch();
document.body.style.marginTop = $('#header').css('height');
}
function filterCheck(str, filter) {
if (filter == null)
return true;
if (filter == "")
return true;
if (SmartSearch == true)
{
if (filter.length > 3)
filter = "*" + filter + "*";
}
str = str.toLowerCase();
filter = filter.toLowerCase();
if (str.startsWith(filter) == true) {
return true;
}
if (filter.charAt(0) == '*') {
if (filter.endsWith('*')) {
if (str.includes(filter.substring(1, filter.length - 1)) == true) {
return true;
}
}
if (str.endsWith(filter.substring(1, filter.length)) == true) {
return true;
}
}
return false;
}
function searchTextFieldUpdated() {
// Restore original data if saved data present
if (window.masterSongsArraySaved.length != 0) {
window.masterSongsArray = window.masterSongsArraySaved.slice();
window.masterSongsArraySaved.splice(0);
window.masterSongsEndingSongNumber = window.masterSongsEndingSongNumberSaved;
}
window.masterSongsEndingSongNumberSaved = -1;
if (window.allSongsArraySaved.length != 0) {
window.allSongsArray = window.allSongsArraySaved.slice();
window.allSongsArraySaved.splice(0);
window.allSongsEndingSongNumber = window.allSongsEndingSongNumberSaved;
}
window.allSongsEndingSongNumberSaved = -1;
if (window.playlistsArraySaved.length != 0) {
window.playlistsArray = window.playlistsArraySaved.slice();
window.playlistsArraySaved.splice(0);
window.playlistsEndingNumber = window.playlistsEndingNumberSaved;
}
window.playlistsEndingNumberSaved = -1;
if (window.albumsArraySaved.length != 0) {
window.albumsArray = window.albumsArraySaved.slice();
window.albumsArraySaved.splice(0);
window.albumsEndingNumber = window.albumsEndingNumberSaved;
}
window.albumsEndingNumberSaved = -1;
//Now save the original data and erase the original data
if (window.masterSongsArray.length != 0) {
window.masterSongsArraySaved = window.masterSongsArray.slice();
window.masterSongsArray.splice(0);
window.masterSongsEndingSongNumberSaved = window.masterSongsEndingSongNumber;
}
window.masterSongsEndingSongNumber = -1;
if (window.allSongsArray.length != 0) {
window.allSongsArraySaved = window.allSongsArray.slice();
window.allSongsArray.splice(0);
window.allSongsEndingSongNumberSaved = window.allSongsEndingSongNumber;
}
window.allSongsEndingSongNumber = -1;
if (window.playlistsArray.length != 0) {
window.playlistsArraySaved = window.playlistsArray.slice();
window.playlistsArray.splice(0);
window.playlistsEndingNumberSaved = window.playlistsEndingNumber;
}
window.playlistsEndingNumber = -1;
if (window.albumsArray.length != 0) {
window.albumsArraySaved = window.albumsArray.slice();
window.albumsArray.splice(0);
window.albumsEndingNumberSaved = window.albumsEndingNumber;
}
window.albumsEndingNumber = -1;
// Now build the original data with the search filter applied
for (i = 0; i < window.allSongsArraySaved.length; i++) {
if (filterCheck(window.allSongsArraySaved[i], document.getElementById("searchTextField").value) == true) {
window.allSongsArray.push(window.allSongsArraySaved[i]);
window.allSongsEndingSongNumber++;
}
}
for (i = 0; i < window.masterSongsArraySaved.length; i++) {
if (filterCheck(window.masterSongsArraySaved[i], document.getElementById("searchTextField").value) == true) {
window.masterSongsArray.push(window.masterSongsArraySaved[i]);
window.masterSongsEndingSongNumber++;
}
}
for (i = 0; i < window.playlistsArraySaved.length; i++) {
if (filterCheck(window.playlistsArraySaved[i], document.getElementById("searchTextField").value) == true) {
window.playlistsArray.push(window.playlistsArraySaved[i]);
window.playlistsEndingNumber++;
}
}
for (i = 0; i < window.albumsArraySaved.length; i++) {
if (filterCheck(window.albumsArraySaved[i], document.getElementById("searchTextField").value) == true) {
window.albumsArray.push(window.albumsArraySaved[i]);
window.albumsEndingNumber++;
}
}
if (window.masterSongsEndingSongNumber >= numberOfButtons)
window.masterSongsEndingSongNumber = numberOfButtons - 1;
if (window.allSongsEndingSongNumber >= numberOfButtons)
window.allSongsEndingSongNumber = numberOfButtons - 1;
if (window.playlistsEndingNumber >= numberOfButtons)
window.playlistsEndingNumber = numberOfButtons - 1;
if (window.albumsEndingNumber >= numberOfButtons)
window.albumsEndingNumber = numberOfButtons - 1;
refreshAllSongs();
}
var sock = null;
function launchIntoFullscreen(element) {
// These function will not exist in the browsers that don't support fullscreen mode yet,
// so we'll have to check to see if they're available before calling them.
// Fow now we won't support this capability. When testing it seemed kind of weird so we will
// just let the user manually enter full screen mode if he/she wants to.
return;
//console.log("About to put browser in full screen mode, element = " + element);
if(element.requestFullscreen) {
element.requestFullscreen();
} else if(element.mozRequestFullScreen) {
element.mozRequestFullScreen();
} else if(element.webkitRequestFullscreen) {
//console.log("Telling safari to go into full screen mode");
element.webkitRequestFullscreen();
} else if(element.msRequestFullscreen) {
element.msRequestFullscreen();
}
}
function connectToViolano(violanoIpAddress) {
if (window.AllowRenameSongMode == false)
document.getElementById("renameSongModeButton").style.display = "none";
document.getElementById("mainLineTextField").value = "Connecting to " + MusicMachineName + " " + violanoIpAddress;
$(document.getElementById("tableButtonViewDiv")).fadeIn(TableListViewFadeDelay);
sock = io.connect('http://' + violanoIpAddress);
sock.on('Status Update', statusUpdate);
sock.on('connect', function () {
document.getElementById("mainLineTextField").value = "Connected to " + MusicMachineName + " " + violanoIpAddress;;
sock.emit('systemCommand', {
command: 'GET_STATUS_UPDATE'
});
loadSongs('Master', 'allSongs', '');
if (window.initialStartup == true) {
window.initialStartup = false;
if (numberOfColumns == 1 ||
window.neverShowTableViewOption == true) {
if (document.getElementById("viewModeButton").value == "List View")
{
viewModeButtonClicked();
}
// hide the list / table view button if we are on a phone (i.e. columns is 1) or if the config file states we should not allow the user to
// select table view
document.getElementById("viewModeButton").style.display = "none";
}
}
switch (screenToShowFirst)
{
case SHOW_ALBUMS_FIRST:
showAlbumButtons();
break;
case SHOW_PLAYLISTS_FIRST:
showPlayListButtons();
break;
case SHOW_SONGS_FIRST:
default:
loadSongs('Master', 'allSongs', '');
break;
}
});
sock.on("midiPlayerCurrentPosition", midiPlayerCurrentPosition);
sock.on("currentMidiDeviceInfo", currentMidiDeviceInfo);
sock.on("midiDeviceNameUpdate", midiDeviceNameUpdate);
sock.on("System Update", systemUpdate);
sock.on("File List Update", fileListUpdate);
sock.on('disconnect', socketDisconnectEvent);
sock.on('testMsg', function (data) {
;
});
}
/*
GENERAL_INFORMATION = 0,
LICENSE_STATE_CHANGE = 1,
VIOLANO_MODE_CHANGE = 2,
BROWSER_CONNECTED = 3,
SOFTWARE_EXCEPTION = 4
public STATUS_UPDATE_TYPE statusUpdateType;
public string statusUpdateTypeString;
public string informationMsg;
public VIOLANO_MODE violanoMode;
public string violanoModeString;
public int violanoRunningSeconds;
public int violanoCoolOffSeconds;
public LICENSE_MODE licenseMode;
public string licenseModeString;
public string defaultMusicFolder;
public string licenseKey;
public string maxRunTime;
public string coolOffTime;
public string softwareExceptionString;
public enum LICENSE_MODE : uint
{
NOT_LICENSED = 0,
LICENSED = 1
}
*/
function stopViolanoPLayer() {
sock.emit('midiCommand', {
command: 'STOP'
});
document.getElementById("nextSongButton").style.display = 'none';
}
function statusUpdate(data) {
var parsedData = JSON.parse(data);
if (parsedData.statusUpdateType == 1) // License Change
{
document.getElementById('mainLineTextField').value = "License mode set to " + parsedData.licenseModeString;
if (parsedData.licenseMode == 0)
window.mainLineDefaultMessage = MusicMachineName + "Connected " + " (" + window.violanoIpAddress + ")" + "\n Invalid license. Songs cut to 15%";
else
{
window.mainLineDefaultMessage = MusicMachineName + " Connected " + window.violanoIpAddress;
}
} else if (parsedData.statusUpdateType == 6) // Coin Deposited
{
if (showCoinInserted == true)
{
element = document.getElementById('mainLineTextField');
jQuery(element).css("background", window.coinInsertedColor);
//alert("Server detected a coin was deposited");
}
}else if (parsedData.statusUpdateType == 3) // Browser Connected
{
// The statusUpdateTypeString says "Browser Connected to Violano"
//window.mainLineDefaultMessage = parsedData.statusUpdateTypeString + " (" + window.violanoIpAddress + ")";
window.mainLineDefaultMessage = MusicMachineName + " Connected (" + window.violanoIpAddress + ")";
if (parsedData.licenseMode == 0)
{
//window.mainLineDefaultMessage += " License key is not valid, playback limited to 15% of song.";
window.mainLineDefaultMessage = "Invalid license. Songs cut to 15% \n" + window.mainLineDefaultMessage;
}
document.getElementById("mainLineTextField").value = window.mainLineDefaultMessage;
} else if (parsedData.statusUpdateType == 2) // Violano Mode Change
{
if (parsedData.violanoMode == 1) {
//msg = parsedData.statusUpdateTypeString + ". " + MusicMachineName + " disabled for " + parsedData.coolOffTime + " minutes. \n";
/*
document.getElementById('violanoModeLogTextarea').value += msg;
*/
msg = MusicMachineName + " has exceeded the maximum allowed playing time. It will be reset and after " + parsedData.coolOffTime / 60 + " minute(s) you may continue playing your selections.";
//msg = "Violano has been playing too long. It has been paused for " + parsedData.coolOffTime + " minute(s). You will receive another alert when it is OK to resume playing the violano.";
alert(msg);
document.getElementById("mainLineTextField").value = "Maximum playing time exceeded. System resetting.";
} else {
//msg = parsedData.statusUpdateTypeString + ". Violano has cooled off. It is now available \n";
msg = MusicMachineName + " is now available to play.";
/*
document.getElementById('violanoModeLogTextarea').value += msg ;
*/
alert(msg);
//document.getElementById("mainLineTextField").value = "Cool down complete. " + MusicMachineName + " is now available."
document.getElementById("mainLineTextField").value = MusicMachineName + " is now available to play."
}
element = document.getElementById('violanoModeLogTextarea');
element.scrollTop = element.scrollHeight;
} else if (parsedData.statusUpdateType == 4) // Software Exception
{
if (showSoftwareExceptions == true)
alert("Software exception. Details: " + parsedData.informationMsg + " " + parsedData.softwareExceptionString);
} else if (parsedData.statusUpdateType == 0) // General Information
{
if (showGeneralInformationMessages == true)
alert(parsedData.informationMsg);
} else if (parsedData.statusUpdateType == 5) // Midi Player Update
{
element = document.getElementById('mainLineTextField');
tempoSlider = document.getElementById("tempoSlider");
resetTempoButton = document.getElementById("resetTempoButton");
saveTempoButton = document.getElementById("saveTempoButton");
positionSlider = document.getElementById("positionSlider");
midiCurrentPositionTextfield = document.getElementById("midiCurrentPositionTextfield");
switch (parsedData.midiPlayerUpdate) {
case 4: // Fast Forward Play
case 3: // Playing
// Don't overwrite the display if the file name is "" because
// the display probably says playing a playlist or album
if (parsedData.midiFileName != "") {
if (window.activePlayList != "") {
element.value = "Playlist: " + window.activePlayList + " (" + parsedData.midiFileName + ")";
} else if (window.activeAlbum != "")
element.value = "Album: " + window.activeAlbum + " (" + parsedData.midiFileName + ")";
else
element.value = "Now playing: " + parsedData.midiFileName;
document.getElementById("tempoTextField").value = parsedData.midiTempo;
}
if (parsedData.licenseMode == 0) {
element.value += "\n Invalid license. Songs cut to 15%";
alert("License key is not valid. Playback limited to 15% of song. Please go to settings and enter a valid license key.");
}
window.currentPlayingSong = parsedData.midiFileName;
tempoSlider.value = parsedData.midiTempo;
document.getElementById("pauseResumeButton").value = "Pause";
$(document.getElementById("violanoPlayingButtons")).fadeIn(PlayingButtonsFadeDelay, function () {
document.getElementById("renameSongModeButton").style.display = "none";
document.getElementById("changeSystemSettingsButton").style.display = "none";
document.body.style.marginTop = $('#header').css('height');
});
document.getElementById("playingTextPositionSlider").style.display="initial";
updateButtonPlayColor();
document.body.style.marginTop = $('#header').css('height');
break;
case 1: // Stopped
element.value = "";
window.currentPlayingSong = element.value;
document.getElementById('midiCurrentPositionTextfield').value = "";
tempoSlider.value = 100;
positionSlider.value = 0;
updateButtonPlayColor();
document.getElementById("mainLineTextField").value = window.mainLineDefaultMessage;
$(document.getElementById("violanoPlayingButtons")).fadeOut(PlayingButtonsFadeDelay, function () {
document.body.style.marginTop = $('#header').css('height');
});
document.body.style.marginTop = $('#header').css('height');
document.getElementById("playingTextPositionSlider").style.display="none";
element = document.getElementById('mainLineTextField');
jQuery(element).css("background", "white");
break;
case 2: // Paused
element.value = parsedData.midiFileName + " PAUSED";
document.getElementById("stopButton").style.display = "initial";
document.getElementById("pauseResumeButton").style.display = "initial";
document.getElementById("pauseResumeButton").value = "Resume";
break;
}
}
}
function updateButtonPlayColor() {
if (window.currentView == CurrentViewEnum.SONGS &&
window.editingPlaylistActive == 0) {
for (i = 1; i <= numberOfButtons; i++) {
btn = document.getElementById("button" + i);
if (window.currentPlayingSong.indexOf(btn.value) != -1 && btn.value != "") {
jQuery(btn).css("color", window.playingSongColor);
jQuery(btn).css("background", window.playingSongBackgroundColor);
} else {
jQuery(btn).css("color", window.songColorText);
jQuery(btn).css("background", window.SongBackroundColor);
}
}
for (i = 1; i <= window.mobilePhoneBtnCnt; i++) {
btn = document.getElementById("mobileButton" + i);
if (btn == null)
continue;
if (window.currentPlayingSong.indexOf(btn.value) != -1 && btn.value != "") {
jQuery(btn).css("color", window.playingSongColor);
jQuery(btn).css("background", window.playingSongBackgroundColor);
} else {
jQuery(btn).css("color", window.songColorText);
jQuery(btn).css("background", window.SongBackroundColor);
}
}
}
}
/*
function midiPlayerStateChange(msg)
{
/*
* 1 Stopped
* 2 Paused
* 3 Playing
* 4 ScanForward The current media item is fast forwarding.
* 5 ScanReverse The current media item is fast rewinding.
* 6 Buffering The current media item is getting additional data from the server.
* 7 Waiting Connection is established, but the server is not sending data. Waiting for session to begin.
* 8 MediaEnded Media item has completed playback.
* 9 Transitioning Preparing new media item.
* 10 Ready Ready to begin playing.
* 11 Reconnecting Reconnecting to stream.
* * /
*/
function showPlayListButtons() {
disableSearch();
for (i = 1; i <= numberOfButtons; i++) {
btn = document.getElementById("button" + i);
jQuery(btn).css("color", "black");
}
getFolderNames('PlayLists', 'playListListBox');
}
function showAlbumButtons() {
disableSearch();
for (i = 1; i <= numberOfButtons; i++) {
btn = document.getElementById("button" + i);
jQuery(btn).css("color", "black");
}
getFolderNames('Albums', 'AlbumsListBox');
}
function changeTempo(amount)
{
oldTempoValue = Number(document.getElementById("tempoTextField").value);
newTempoValue = oldTempoValue + amount;
//alert("amount: " + amount + " oldTempoValue: " + oldTempoValue + " newTemppValue: " + newTempoValue);
if (newTempoValue < 0)
newTempoValue = 0;
if (newTempoValue > 199)
newTempoValue = 199;
document.getElementById("tempoTextField").value = newTempoValue;
tempoSlider.value = newTempoValue;
setSongTempo(newTempoValue);
}
function updateTempoSlider(newValue) {
setSongTempo(newValue);
}
function updatePositionSlider(newPosition) {
sock.emit('midiCommand', {
command: 'SET_POSITION',
position: newPosition
});
}
function resetTempo() {
tempoSlider = document.getElementById("tempoSlider");
tempoSlider.value = 100;
setSongTempo("100");
}
function setSongTempo(newTempo) {
document.getElementById("tempoTextField").value = newTempo;
sock.emit('midiCommand', {
command: 'SET_TEMPO',
folderName: '',
fileName: '',
tempo: newTempo
});
}
function savePlayingSongTempo() {
if (window.currentPlayingSong == "")
return;
tempoSlider = document.getElementById("tempoSlider");
sendDirCommand("SAVE_TEMPO", "", window.currentPlayingSong, "", tempoSlider.value);
}
function renameSongModeButtonClick() {
btn = document.getElementById("renameSongModeButton");
if (window.renameSongMode == 0) {
window.renameSongMode = 1;
btn.value = "Done Renaming Songs";
} else {
window.renameSongMode = 0;
btn.value = "Rename Songs";
loadSongs('Master', 'allSongs', '');
}
}
function clearSongsButtons() {
for (i = 1; i <= numberOfButtons; i++) {
btn = document.getElementById("button" + i);
btn.value = "";
btn.style.display = 'none';
jQuery(btn).css("color", window.songColorText);
}
}
function refreshAllSongs() {
clearSongsButtons();
for (i = 1; i <= numberOfButtons; i++) {
btn = document.getElementById("button" + i);
jQuery(btn).css("color", window.songColorText);
}
cnt = 1;
$('#mobilePhoneButtonView').html('');
html = '<center><table border="0" width="' + window.ListViewTableWidth + '"><tbody>'; // was 95%
window.mobilePhoneBtnCnt = 0;
if (window.editingPlaylistActive == 1) {
//console.log("editing PlaylistActive set to true");
i = (window.masterSongsEndingSongNumber - numberOfButtons);
if (i < 0)
i = 0;
for (; i < window.masterSongsArray.length && cnt <= numberOfButtons; i++) {
btn = document.getElementById("button" + cnt);
btn.style.display = "initial";
btn.value = window.masterSongsArray[i];
cnt++;
}
for (i = 0; i < window.masterSongsArray.length; i++) {
window.mobilePhoneBtnCnt++;
btn = "mobileButton" + window.mobilePhoneBtnCnt;
html += '<tr><td><input class="listButton" type="button" name="' + btn + '" id="' + btn + '" value="' + window.masterSongsArray[i] + '" onClick="javascript:playSong(this.id);"></td></tr>';
}
} else {
switch (window.currentView) {
case CurrentViewEnum.ALBUMS:
{
i = (window.albumsEndingNumber - numberOfButtons);
if (i < 0)
i = 0;
for (; i < window.albumsArray.length && cnt <= numberOfButtons; i++) {
btn = document.getElementById("button" + cnt);
btn.style.display = "initial";
btn.value = window.albumsArray[i];
cnt++;
}
for (i = 0; i < window.albumsArray.length; i++) {
window.mobilePhoneBtnCnt++;
btn = "mobileButton" + window.mobilePhoneBtnCnt;
html += '<tr><td><input class="listButton" type="button" name="' + btn + '" id="' + btn + '" value="' + window.albumsArray[i] + '" onClick="javascript:playSong(this.id);"></td></tr>';
}
break;
}
case CurrentViewEnum.PLAYLISTS:
{
i = (window.playlistsEndingNumber - numberOfButtons);
if (i < 0)
i = 0;
for (; i < window.playlistsArray.length && cnt <= numberOfButtons; i++) {
btn = document.getElementById("button" + cnt);
btn.style.display = "initial";
btn.value = window.playlistsArray[i];
cnt++;
}
for (i = 0; i < window.playlistsArray.length; i++) {
window.mobilePhoneBtnCnt++;
btn = "mobileButton" + window.mobilePhoneBtnCnt;
html += '<tr><td><input class="listButton" type="button" name="' + btn + '" id="' + btn + '" value="' + window.playlistsArray[i] + '" onClick="javascript:playSong(this.id);"></td></tr>';
}
//console.log("html in refreshAllSongs: " + html);
break;
}
case CurrentViewEnum.SONGS:
{
i = (window.allSongsEndingSongNumber - numberOfButtons);
if (i < 0)
i = 0;
for (; i < window.allSongsArray.length && cnt <= numberOfButtons; i++) {
btn = document.getElementById("button" + cnt);
btn.style.display = "initial";
btn.value = window.allSongsArray[i];
cnt++;
}
for (i = 0; i < window.allSongsArray.length; i++) {
window.mobilePhoneBtnCnt++;
btn = "mobileButton" + window.mobilePhoneBtnCnt;
html += '<tr><td><input class="listButton" type="button" name="' + btn + '" id="' + btn + '" value="' + window.allSongsArray[i] + '" onClick="javascript:playSong(this.id);"></td></tr>';
}
break;
}
}
}
for (; cnt <= numberOfButtons; cnt++) {
btn = document.getElementById("button" + cnt);
btn.style.display = "none";
}
html = html + "</tbody></table></center>";
$('#mobilePhoneButtonView').html(html);
reorganizeButtons();
updateSongsPrevNextButtons();
updateRedStateOfSongs();
updateButtonPlayColor();
document.body.style.marginTop = $('#header').css('height');
var elements = document.getElementsByClassName("listButton");
for (i = 0; i < elements.length; i++)
{
elements[i].style.width= window.ListButtonWidth; //((jQuery(window).width() * .90) + "px";
}
}
function nextAllSongsButtonClick() {
clearSongsButtons();
for (i = 1; i <= numberOfButtons; i++) {
btn = document.getElementById("button" + i);
jQuery(btn).css("color", window.songColorText);
}
cnt = 1;
if (window.editingPlaylistActive == 1) {
for (i = window.masterSongsEndingSongNumber + 1; i < window.masterSongsArray.length && cnt <= numberOfButtons; i++) {
btn = document.getElementById("button" + cnt);
btn.style.display = "initial";
btn.value = window.masterSongsArray[i];
window.masterSongsEndingSongNumber++;
cnt++;
}
} else {
switch (window.currentView) {
case CurrentViewEnum.ALBUMS:
{
for (i = window.albumsEndingNumber + 1; i < window.albumsArray.length && cnt <= numberOfButtons; i++) {
btn = document.getElementById("button" + cnt);
btn.style.display = "initial";
btn.value = window.albumsArray[i];
window.albumsEndingNumber++;
cnt++;
}
break;
}
case CurrentViewEnum.PLAYLISTS:
{
for (i = window.playlistsEndingNumber + 1; i < window.playlistsArray.length && cnt <= numberOfButtons; i++) {
btn = document.getElementById("button" + cnt);
btn.style.display = "initial";
btn.value = window.playlistsArray[i];
window.playlistsEndingNumber++;
cnt++;
}
break;
}
case CurrentViewEnum.SONGS:
{
for (i = window.allSongsEndingSongNumber + 1; i < window.allSongsArray.length && cnt <= numberOfButtons; i++) {
btn = document.getElementById("button" + cnt);
btn.style.display = "initial";
btn.value = window.allSongsArray[i];
window.allSongsEndingSongNumber++;
cnt++;
}
break;
}
}
}
for (; cnt <= numberOfButtons; cnt++) {
btn = document.getElementById("button" + cnt);
btn.style.display = "none";
}
reorganizeButtons();
updateSongsPrevNextButtons();
updateRedStateOfSongs();
}
function updatePrevNextButtons() {
updateSongsPrevNextButtons();
}
function previousButtonClick() {
prevAllSongsButtonClick();
updateButtonPlayColor();
}
function nextButtonClick() {
nextAllSongsButtonClick();
updateButtonPlayColor();
}
function prevAllSongsButtonClick() {
clearSongsButtons();
if (window.editingPlaylistActive == 1) {
if (window.masterSongsEndingSongNumber >= numberOfButtons)
window.masterSongsEndingSongNumber = window.masterSongsEndingSongNumber - ((window.masterSongsEndingSongNumber % numberOfButtons) + numberOfButtons + 1);
else
window.masterSongsEndingSongNumber = 0;
if (window.masterSongsEndingSongNumber < -1)
window.masterSongsEndingSongNumber = -1;
cnt = 1;
for (i = window.masterSongsEndingSongNumber; i < window.masterSongsArray.length && cnt <= numberOfButtons; i++) {
btn = document.getElementById("button" + cnt);
btn.style.display = "initial";
window.masterSongsEndingSongNumber++;
btn.value = window.masterSongsArray[window.masterSongsEndingSongNumber];
cnt++;
}
} else {
switch (window.currentView) {
case CurrentViewEnum.ALBUMS:
{
if (window.albumsEndingNumber >= numberOfButtons)
window.albumsEndingNumber = window.albumsEndingNumber - ((window.albumsEndingNumber % numberOfButtons) + numberOfButtons + 1);
else
window.albumsEndingNumber = 0;
if (window.albumsEndingNumber < -1)
window.albumsEndingNumber = -1;
cnt = 1;
for (i = window.albumsEndingNumber; i < window.albumsArray.length && cnt <= numberOfButtons; i++) {
btn = document.getElementById("button" + cnt);
btn.style.display = "initial";
window.albumsEndingNumber++;
btn.value = window.albumsArray[window.albumsEndingNumber];
cnt++;
}
break;
}
case CurrentViewEnum.PLAYLISTS:
{
if (window.playlistsEndingNumber >= numberOfButtons)
window.playlistsEndingNumber = window.playlistsEndingNumber - ((window.playlistsEndingNumber % numberOfButtons) + numberOfButtons + 1);
else
window.playlistsEndingNumber = 0;
if (window.playlistsEndingNumber < -1)
window.playlistsEndingNumber = -1;
cnt = 1;
for (i = window.playlistsEndingNumber; i < window.playlistsArray.length && cnt <= numberOfButtons; i++) {
btn = document.getElementById("button" + cnt);
btn.style.display = "initial";
window.playlistsEndingNumber++;
btn.value = window.playlistsArray[window.playlistsEndingNumber];
cnt++;
}
break;
}
case CurrentViewEnum.SONGS:
{
if (window.allSongsEndingSongNumber >= numberOfButtons)
window.allSongsEndingSongNumber = window.allSongsEndingSongNumber - ((window.allSongsEndingSongNumber % numberOfButtons) + numberOfButtons + 1);
else
window.allSongsEndingSongNumber = 0;
if (window.allSongsEndingSongNumber < -1)
{
window.allSongsEndingSongNumber = -1;
}
cnt = 1;
for (i = window.allSongsEndingSongNumber; i < window.allSongsArray.length && cnt <= numberOfButtons; i++) {
btn = document.getElementById("button" + cnt);
btn.style.display = "initial";
window.allSongsEndingSongNumber++;
btn.value = window.allSongsArray[window.allSongsEndingSongNumber];
cnt++;
}
break;
}
}
}
updateSongsPrevNextButtons();
updateRedStateOfSongs();
}
function updateSongsPrevNextButtons() {
if (document.getElementById("viewModeButton").value == "Table View") {
document.getElementById("nextButton").style.display = "none";
document.getElementById("previousButton").style.display = "none";
return;
}
if (window.editingPlaylistActive == 1) {
if (window.masterSongsEndingSongNumber < numberOfButtons) {
document.getElementById("previousButton").style.display = "none";
} else {
document.getElementById("previousButton").style.display = "initial";
}
if (window.masterSongsEndingSongNumber >= window.masterSongsArray.length - 1) {
document.getElementById("nextButton").style.display = "none";
} else {
document.getElementById("nextButton").style.display = "initial";
}
} else {
switch (window.currentView) {
case CurrentViewEnum.ALBUMS:
{
if (window.albumsEndingNumber < numberOfButtons) {
document.getElementById("previousButton").style.display = "none";
} else {
document.getElementById("previousButton").style.display = "initial";
}
if (window.albumsEndingNumber >= window.albumsArray.length - 1) {
document.getElementById("nextButton").style.display = "none";
} else {
document.getElementById("nextButton").style.display = "initial";
}
break;
}
case CurrentViewEnum.PLAYLISTS:
{
if (window.playlistsEndingNumber < numberOfButtons) {
document.getElementById("previousButton").style.display = "none";
} else {
document.getElementById("previousButton").style.display = "initial";
}
if (window.playlistsEndingNumber >= window.playlistsArray.length - 1) {
document.getElementById("nextButton").style.display = "none";
} else {
document.getElementById("nextButton").style.display = "initial";
}
break;
}
case CurrentViewEnum.SONGS:
{
if (window.allSongsEndingSongNumber < numberOfButtons) {
document.getElementById("previousButton").style.display = "none";
} else {
document.getElementById("previousButton").style.display = "initial";
}
if (window.allSongsEndingSongNumber >= window.allSongsArray.length - 1) {
document.getElementById("nextButton").style.display = "none";
} else {
document.getElementById("nextButton").style.display = "initial";
}
break;
}
}
}
}
function createNewPlaylist() {
var newPlaylistname = prompt("Please enter the name of the new playlist (leave blank to cancel):", "");
if (newPlaylistname == "" || newPlaylistname == null)
return;
folder = "PlayLists" + '/' + newPlaylistname;
sendDirCommand('CREATE_FOLDER', folder, '');
showPlayListButtons();
}
function reorganizeButtons() {
activeButtons = 0;
tempBtns = [];
btn = document.getElementById("button" + numberOfButtons);
// No need to reorganize if all buttons are being used.
if (btn.style.display == "initial")
return;
for (i = 1; i <= numberOfButtons; i++) {
btn = document.getElementById("button" + i);
tempBtns.push(btn.value);
if (btn.value != "")
activeButtons++;
btn.value = "";
btn.style.display = "none";
}
if (activeButtons == 0 || activeButtons == numberOfButtons)
return;
buttonsPerColumn = activeButtons % (numberOfButtons / numberOfColumns);
buttonsPerColumn = activeButtons / numberOfColumns;
if (activeButtons % numberOfColumns != 0)
buttonsPerColumn++;
if (buttonsPerColumn == 0)
buttonsPerColumn = numberOfButtons / numberOfColumns;
cnt = 0;
currentBtn = 1;
for (col = 1; col <= numberOfColumns; col++) {
for (row = 1; row <= numberOfRows; row++) {
if (row > buttonsPerColumn) {
document.getElementById("button" + currentBtn).value = "";
currentBtn++;
} else {
if (cnt < tempBtns.length) {
if (tempBtns[cnt] != "") {
document.getElementById("button" + currentBtn).value = tempBtns[cnt];
document.getElementById("button" + currentBtn).style.display = "initial";
}
}
cnt++;
currentBtn++;
}
}
}
}
/*
public enum FILE_TYPE : int
{
SONG = 0,
FOLDER = 1,
MUSIC_UPDATE = 2,
SOFTWARE_UPDATE
}
*/
function fileListUpdate(data) {
disableSearch();
document.body.style.marginTop = $('#header').css('height');
if (window.masterSongsArraySaved.length != 0) {
window.masterSongsArraySaved.splice(0);
}
window.masterSongsEndingSongNumberSaved = -1;
if (window.allSongsArraySaved.length != 0) {
window.allSongsArraySaved.splice(0);
}
window.allSongsEndingSongNumberSaved = -1;
var parsedData = JSON.parse(data);
var fileList = parsedData.listOfFiles;
if (parsedData.fileType == 2) // Performed an update to the music library
{
msg = "The following songs have been added to your " + MusicMachineName + " music library:";
for (i = 0; i < fileList.length; i++) {
if (fileList[i] == null)
continue;
msg += "\n " + fileList[i];
}
alert(msg);
loadSongs('Master', 'allSongs', '');
return;
}
if (parsedData.fileType == 3) // Performed an update to the software library
{
msg = "The following software files have been added to the " + MusicMachineName + " server.:";
for (i = 0; i < fileList.length; i++) {
if (fileList[i] == null)
continue;
msg += "\n " + fileList[i];
}
alert(msg);
loadSongs('Master', 'allSongs', '');
return;
}
document.getElementById("editPlaylistButton").style.display = "none";
document.getElementById("removePlaylistButton").style.display = "none";
document.getElementById("startPlaylistButton").style.display = "none";
document.getElementById("createNewPlaylistButton").style.display = "none";
document.getElementById("startAlbumButton").style.display = "none";
document.getElementById("renameSongModeButton").style.display = "none";
document.getElementById("changeSystemSettingsButton").style.display = "none";
window.currentlyViewingPlaylistSongs = 0;
window.currentlyViewingAlbumSongs = 0;
if (window.allSongsArray.length > 0)
window.allSongsArray.splice(0);
window.currentlyViewingPlaylistSongs = 0;
window.playListSongsEndingSongNumber = -1;
if (window.currentPlaylistSongs.length > 0)
window.currentPlaylistSongs.splice(0);
if (parsedData.privateData == "playListListBox") {
window.playlistsEndingNumber = -1;
if (window.playlistsArray.length > 0)
window.playlistsArray.splice(0);
window.currentView = CurrentViewEnum.PLAYLISTS;
updatelistSelectionButtons();
document.getElementById("createNewPlaylistButton").style.display = "initial";
} else if (parsedData.privateData == "AlbumsListBox") {
window.albumsEndingNumber = -1;
if (window.albumsArray.length > 0)
window.albumsArray.splice(0);
window.currentView = CurrentViewEnum.ALBUMS;
updatelistSelectionButtons();
}
if (parsedData.privateData == "allSongs") // Must be in response to getting all the songs
{
if (window.allSongsArray.length > 0)
window.allSongsArray.splice(0);
if (window.masterSongsArray.length > 0)
window.masterSongsArray.splice(0);
window.allSongsEndingSongNumber = -1;
clearSongsButtons();
window.currentView = CurrentViewEnum.SONGS;
updatelistSelectionButtons();
if (window.currentPlayingSong == "")
{
if (window.AllowRenameSongMode == true)
document.getElementById("renameSongModeButton").style.display = "initial";
document.getElementById("changeSystemSettingsButton").style.display = "initial";
}
} else if (parsedData.fileType == 0) // Song, and not AllSongs so must be a playlist or an album
{
if (window.allSongsArray.length > 0)
window.allSongsArray.splice(0);
window.allSongsEndingSongNumber = -1;
clearSongsButtons();
updatelistSelectionButtons();
window.currentView = CurrentViewEnum.SONGS;
if (window.currentPlaylistSongs.length > 0)
window.currentPlaylistSongs.splice(0);
if (parsedData.privateData == "songsInPlayListListBox") {
window.currentlyViewingPlaylistSongs = 1;
document.getElementById("editPlaylistButton").style.display = "initial";
document.getElementById("removePlaylistButton").style.display = "initial";
document.getElementById("removePlaylistButton").value = "Remove Playlist " + window.activePlayList;
document.getElementById("startPlaylistButton").style.display = "initial";
document.getElementById("startPlaylistButton").value = "Start Playlist " + window.activePlayList;
document.getElementById("editPlaylistButton").value = "Edit Playlist";
// Only be able to create new playlists when viewing the playlist names
// not when viewing the contents of a playlist.
document.getElementById("createNewPlaylistButton").style.display = "none";
} else {
window.currentlyViewingAlbumSongs = 1;
document.getElementById("startAlbumButton").style.display = "initial";
}
}
cnt = 1;
$('#mobilePhoneButtonView').html('');
html = '<center><table border="0" width="' + window.ListViewTableWidth + '"><tbody>'; // was 95%
window.mobilePhoneBtnCnt = 0;
for (i = 0; i < fileList.length; i++) {
if (fileList[i] == null)
continue;
//console.log("fileList: " + fileList);
/*
if (fileList[i].length > 30 && numberOfColumns == 1)
fileList[i] = fileList[i].substring(0,30);
*/
if (document.getElementById("searchTextField").value != "")
if (fileList[i].substr(0, document.getElementById("searchTextField").value.length) !=
document.getElementById("searchTextField").value) {
continue;
}
window.mobilePhoneBtnCnt++;
btn = "mobileButton" + mobilePhoneBtnCnt;
html += '<tr><td><input class="listButton" type="button" name="' + btn + '" id="' + btn + '" value="' + fileList[i] + '" onClick="javascript:playSong(this.id);"></td></tr>';
// Don't load song button if filetype is FOLDER
if (parsedData.fileType == 1) //FOLDER
{
if (parsedData.privateData == "playListListBox") {
// Clear the playlistsarraysaved because it might have been loaded
// if the search feature was used during a playlist edit.
window.playlistsArraySaved.splice(0);
document.getElementById("createNewPlaylistButton").style.display = "initial";
if (cnt <= numberOfButtons) {
btn = document.getElementById("button" + cnt);
btn.style.display = 'initial';
cnt++;
btn.value = fileList[i];
//console.log("Creating button " + i + " for " + fileList[i]);
window.playlistsEndingNumber++;
}
window.playlistsArray.push(fileList[i]);
} else if (parsedData.privateData == "AlbumsListBox") {
if (cnt <= numberOfButtons) {
btn = document.getElementById("button" + cnt);
btn.style.display = 'initial';
cnt++;
btn.value = fileList[i];
window.albumsEndingNumber++;
}
window.albumsArray.push(fileList[i]);
}
} else // Must be a song
{
window.allSongsArray.push(fileList[i]);
if (parsedData.privateData == "allSongs") // Must be in response to getting all the songs
{
window.masterSongsArray.push(fileList[i]);
}
if (parsedData.privateData == "songsInPlayListListBox")
window.currentPlaylistSongs.push(fileList[i]);
if (cnt <= numberOfButtons) {
btn = document.getElementById("button" + cnt);
btn.style.display = 'initial';
cnt++;
btn.value = fileList[i];
if (parsedData.privateData == "allSongs" ||
parsedData.privateData == "songsInPlayListListBox" ||
parsedData.privateData == "songsInAlbumsListBox") {
window.allSongsEndingSongNumber++;
window.masterSongsEndingSongNumber++;
} else {
window.playListSongsEndingSongNumber++;
}
}
}
}
for (; cnt <= numberOfButtons; cnt++) {
document.getElementById("button" + cnt).style.display = 'none';
document.getElementById("button" + cnt).value = "";
}
html = html + "</tbody></table></center>";
$('#mobilePhoneButtonView').html(html);
//console.log("html: " + html);
var elements = document.getElementsByClassName("listButton");
for (i = 0; i < elements.length; i++)
{
elements[i].style.width= window.ListButtonWidth; //((jQuery(window).width() * .90) + "px";
}
//$("listButton").css("width", "200px");
//document.getElementsByClassName(".listButton").style.width = "200px";
//document.getElementsByClassName(".button").style.width = "200px";
//document.getElementsByClassName("button").style.width = "200px";
refreshAllSongs();
}
function updatelistSelectionButtons() {
btn = document.getElementById("allSongsButton");
jQuery(btn).css("color", window.inactiveSongModeButtonColor);
btn = document.getElementById("playlistsButton");
jQuery(btn).css("color", window.inactiveSongModeButtonColor);
btn = document.getElementById("albumsButton");
jQuery(btn).css("color",window.inactiveSongModeButtonColor);
switch (window.currentView) {
case CurrentViewEnum.ALBUMS:
{
btn = document.getElementById("albumsButton");
break;
}
case CurrentViewEnum.PLAYLISTS:
{
btn = document.getElementById("playlistsButton");
break;
}
case CurrentViewEnum.SONGS:
defaut: {
btn = document.getElementById("allSongsButton");
break;
}
}
jQuery(btn).css("color", window.activeSongModeButtonColor);
}
function systemUpdate(data) {
var parsedData = JSON.parse(data);
var textBox = document.getElementById(parsedData.privateData);
textBox.value = parsedData.msg;
}
function midiDeviceNameUpdate(data) {
var parsedData = JSON.parse(data);
var listbox = document.getElementById(parsedData.privateData);
var c = document.createElement("option");
c.text = parsedData.midiDeviceName;
c.value = parsedData.midiDeviceName;
listbox.options.add(c, listbox.length);
}
function currentMidiDeviceInfo(data) {
var parsedData = JSON.parse(data);
document.getElementById('currentMidiOutTextfield').value = parsedData.deviceName + " (Device Number " + parsedData.deviceNumber + ")";
}
function getCoinPlayLicenseKey(privateData) {
sock.emit('systemCommand', {
command: 'GET_COIN_PLAY_LICENSE_KEY',
privateData: privateData
});
}
function getLicenseKey(privateData) {
sock.emit('systemCommand', {
command: 'GET_LICENSE_KEY',
privateData: privateData
});
}
function getMachineId(privateData) {
sock.emit('systemCommand', {
command: 'GET_MACHINE_ID',
privateData: privateData
});
}
function getVersion(privateData) {
sock.emit('systemCommand', {
command: 'GET_VERSION',
privateData: privateData
});
}
function checkForSoftwareUpdate() {
sock.emit('systemCommand', {
command: 'CHECK_FOR_SOFTWARE_UPDATE'
});
}
function checkForMusicUpdate() {
sock.emit('systemCommand', {
command: 'CHECK_FOR_MUSIC_UPDATE'
});
}
function submitLicenseKeys(licenseKey, coinPlayLicenseKey, privateData) {
sock.emit('systemCommand', {
command: 'SET_LICENSE_KEY',
licenseKey: licenseKey,
coinPlayLicenseKey: coinPlayLicenseKey,
privateData: privateData
});
}
function submitLicenseKey(licenseKey, privateData) {
sock.emit('systemCommand', {
command: 'SET_LICENSE_KEY',
licenseKey: licenseKey,
coinPlayLicenseKey: '0',
privateData: privateData
});
}
function getMidiDevices(MidiDeviceListBox) {
var listbox = document.getElementById(MidiDeviceListBox);
while (listbox.length != 0)
listbox.options.remove(0);
sock.emit('registryCommand', {
command: 'GET_MIDI_DEVICES',
privateData: MidiDeviceListBox
});
}
function getMidiDeviceInformation() {
sock.emit('registryCommand', {
command: 'GET_MIDI'
});
}
function setMidiOutDevice(MidiDeviceListBox) {
var newDeviceNumber = document.getElementById(MidiDeviceListBox).selectedIndex;
sock.emit('registryCommand', {
command: 'SET_MIDI',
midiDeviceNumber: newDeviceNumber
});
}
function midiPlayerCurrentPosition(data) {
var parsedData = JSON.parse(data);
var violanoPlayerButtonsDisplayStyle = document.getElementById("violanoPlayingButtons").style.display;
// If the violano playe buttons are hidden and the songName is not null we probably started the
// browser while a song was playing so turn on the player buttons.
if (violanoPlayerButtonsDisplayStyle == "none" && parsedData.songName != "")
{
$(document.getElementById("violanoPlayingButtons")).fadeIn(PlayingButtonsFadeDelay, function () {
document.getElementById("renameSongModeButton").style.display = "none";
document.getElementById("changeSystemSettingsButton").style.display = "none";
document.body.style.marginTop = $('#header').css('height');
document.getElementById("mainLineTextField").value = parsedData.songName;
});
document.getElementById("playingTextPositionSlider").style.display="initial";
}
if (parsedData.duration != 0 && parsedData.duration != "") {
var percentDone = parsedData.currentPosition / parsedData.duration * 100;
percentDone = percentDone.toFixed(1);
if (percentDone == 0) {
document.getElementById('midiCurrentPositionTextfield').value = "";
} else {
document.getElementById('midiCurrentPositionTextfield').value = //parsedData.currentPositionString + " / " + parsedData.durationString + " " + percentDone + "%";
// Per Gretchen's request, do not show percent done
parsedData.currentPositionString + " / " + parsedData.durationString;
var newSliderPosition = parsedData.currentPosition / parsedData.duration * 100;
document.getElementById("positionSlider").value = newSliderPosition.toFixed(0);
document.getElementById("tempoSlider").value = parsedData.midiTempo;
document.getElementById("tempoTextField").value = parsedData.midiTempo;
}
}
}
function sendDirCommand(command, folderName = "", fileName1 = "", fileName2 = "", tempo = "100") {
sock.emit('dirCommand', {
command: command,
folderName: folderName,
fileName1: fileName1,
fileName2: fileName2,
tempo: tempo
});
}
function connectionEvent(msg) {
}
function socketDisconnectEvent(msg) {
}
window.onload = function () {
document.getElementById("allSongs").onclick = function () {
}
}
function saveTempo(tempoTextField, songListBox) {
var newTempo = document.getElementById(tempoTextField).value;
var song = document.getElementById(songListBox).value;
if (song == "")
return;
sendDirCommand("SAVE_TEMPO", "", song, "", newTempo);
}
function setPosition(midiSetCurrentPositionTextfield) {
var newPosition = document.getElementById(midiSetCurrentPositionTextfield).value;
sock.emit('midiCommand', {
command: 'SET_POSITION',
position: newPosition
});
}
function renameFile(fileListBox, renametextField) {
oldSong = document.getElementById(fileListBox).value;
if (oldSong == "")
return;
newSong = document.getElementById(renametextField).value;
if (newSong == "")
return;
sendDirCommand('RENAME_FILE', "", oldSong, newSong);
}
function copySongToDynamicPlaylist(fileListBox, fileCategory) {
song = document.getElementById(fileListBox).value;
if (song == "")
return;
folder = fileCategory + '/' + "Dynamic";
sendDirCommand('COPY_SONG', folder, song);
}
function copySong(folderListBox, fileListBox, fileCategory) {
selectedIndex = document.getElementById(fileListBox).selectedIndex;
song = document.getElementById(fileListBox).value;
if (song == "")
return;
selectedIndex = document.getElementById(folderListBox).selectedIndex;
folder = document.getElementById(folderListBox).value;
if (folder == "")
return;
folder = fileCategory + '/' + folder;
sendDirCommand('COPY_SONG', folder, song);
}
function removeSongFromDynamicPlaylist(fileListBox, fileCategory) {
song = document.getElementById(fileListBox).value;
if (song == "")
return;
folder = fileCategory + '/' + "Dynamic";
sendDirCommand('REMOVE_SONG', folder, song);
}
function removeSong(folderListBox, fileListBox, fileCategory) {
selectedIndex = document.getElementById(fileListBox).selectedIndex;
song = document.getElementById(fileListBox).value;
if (song == "")
return;
selectedIndex = document.getElementById(folderListBox).selectedIndex;
folder = document.getElementById(folderListBox).value;
if (folder == "")
return;
folder = fileCategory + '/' + folder;
sendDirCommand('REMOVE_SONG', folder, song);
}
function removeAllSongsFromDynamicPlayList(fileCategory) {
folder = fileCategory + '/' + "Dynamic";
sendDirCommand('REMOVE_FOLDER', folder, '');
sendDirCommand('CREATE_FOLDER', folder, '');
}
function removeFolder(folderListBox, fileCategory) {
selectedIndex = document.getElementById(folderListBox).selectedIndex;
folder = document.getElementById(folderListBox).value;
if (folder == "")
return;
folder = fileCategory + '/' + folder;
sendDirCommand('REMOVE_FOLDER', folder, '');
}
function addFolder(folderListBox, fileCategory) {
folder = document.getElementById(folderListBox).value;
if (folder == "")
return;
folder = fileCategory + '/' + folder;
sendDirCommand('CREATE_FOLDER', folder, '');
}
function setTempo(tempoTextField) {
var newTempo = document.getElementById(tempoTextField).value;
sock.emit('midiCommand', {
command: 'SET_TEMPO',
folderName: '',
fileName: '',
tempo: newTempo
});
}
function playDynamicPlayList() {
sock.emit('midiCommand', {
command: 'PLAY_LIST',
folderName: "PlayLists",
playlistName: "Dynamic",
tempo: 0
});
}
function playPlayList(playListType, windowListBox) {
name = document.getElementById(windowListBox).value;
sock.emit('midiCommand', {
command: 'PLAY_LIST',
folderName: playListType,
playlistName: name,
tempo: 0
});
}
function makeAllPlaylistButtonsInactive() {
for (i = 1; i <= 5; i++) {
btn = document.getElementById("playListButton" + i);
jQuery(btn).toggleClass('inactive');
}
for (i = 1; i <= 5; i++) {
btn = document.getElementById("albumButton" + i);
jQuery(btn).toggleClass('inactive');
}
}
function editPlaylist() {
for (i = 0; i < numberOfButtons; i++) {
btn = document.getElementById("button" + (i + 1));
jQuery(btn).css("background-color", window.songColorText);
btn.value = "";
btn.style.display = 'none';
}
window.masterSongsEndingSongNumber = -1;
for (i = 0; i < numberOfButtons && i < window.masterSongsArray.length; i++) {
btn = document.getElementById("button" + (i + 1));
jQuery(btn).css("background-color", window.songColorText);
btn.style.display = 'initial';
btn.value = window.masterSongsArray[i];
window.masterSongsEndingSongNumber++;
}
html = '<center><table border="0" width="' + window.ListViewTableWidth + '"><tbody>'; // was 95%
window.mobilePhoneBtnCnt = 0;
for (i = 0; i < window.masterSongsArray.length; i++) {
window.mobilePhoneBtnCnt++;
btn = "mobileButton" + window.mobilePhoneBtnCnt;
html += '<tr><td><input class="listButton" type="button" name="' + btn + '" id="' + btn + '" value="' + window.masterSongsArray[i] + '" onClick="javascript:playSong(this.id);"></td></tr>';
}
html = html + "</tbody></table></center>";
$('#mobilePhoneButtonView').html(html);
if (document.getElementById("editPlaylistButton").value == "Edit Playlist") {
document.getElementById("editPlaylistButton").value = "DONE EDITING " + window.activePlayList + " Playlist";
document.getElementById("startPlaylistButton").style.display = "none";
document.getElementById("removePlaylistButton").style.display = "none";
document.getElementById("allSongsButton").style.display = "none";
document.getElementById("playlistsButton").style.display = "none";
document.getElementById("albumsButton").style.display = "none";
window.editingPlaylistActive = 1;
window.currentlyViewingPlaylistSongs = 0;
window.currentView = CurrentViewEnum.SONGS;
} else {
document.getElementById("editPlaylistButton").value = "Edit Playlist";
document.getElementById("startPlaylistButton").style.display = "initial";
document.getElementById("removePlaylistButton").style.display = "initial";
document.getElementById("allSongsButton").style.display = "initial";
document.getElementById("playlistsButton").style.display = "initial";
document.getElementById("albumsButton").style.display = "initial";
window.editingPlaylistActive = 0;
refreshAllSongs();
showPlayListButtons();
return;
}
var elements = document.getElementsByClassName("listButton");
for (i = 0; i < elements.length; i++)
{
elements[i].style.width= window.ListButtonWidth; //(jQuery(window).width() * .90) + "px";
}
updateSongsPrevNextButtons();
updateRedStateOfSongs();
}
function updateRedStateOfSongs() {
for (i = 1; i <= numberOfButtons; i++) {
btn = document.getElementById("button" + i);
var idx = window.currentPlaylistSongs.indexOf(document.getElementById("button" + i).value);
if (idx != -1 && window.editingPlaylistActive == 1) {
jQuery(btn).css("color", window.songInPlaylistColor);
jQuery(btn).css("background", window.editingSongInPlaylistBackgroundColor);
} else {
jQuery(btn).css("color", window.songColorText);
jQuery(btn).css("background", window.editingSongNotInPlaylistBackgroundColor);
}
}
for (i = 1; i <= window.mobilePhoneBtnCnt; i++) {
btn = document.getElementById("mobileButton" + i);
if (btn == null)
continue;
var idx = window.currentPlaylistSongs.indexOf(document.getElementById("mobileButton" + i).value);
if (idx != -1 && window.editingPlaylistActive == 1) {
jQuery(btn).css("color", window.songInPlaylistColor);
jQuery(btn).css("background", window.editingSongInPlaylistBackgroundColor);
} else {
jQuery(btn).css("color", window.songColorText);
jQuery(btn).css("background", window.editingSongNotInPlaylistBackgroundColor);
}
}
}
function removePlaylist() {
playList = window.activePlayList;
if (playList == "")
return;
reallyDelete = confirm("Click OK to confirm that you really want to delete " + playList);
deselectPlayListButtons();
makeAllPlaylistButtonsInactive();
clearSongsButtons();
window.editingPlaylistActive = 0;
document.getElementById("editPlaylistButton").style.display = "initial";
document.getElementById("removePlaylistButton").style.display = "initial";
if (reallyDelete == false) {
showPlayListButtons();
return;
}
sendDirCommand('REMOVE_FOLDER', "PlayLists/" + playList, '');
showPlayListButtons();
}
function showPlayListSongs(id) {
if (window.renameSongMode == 1)
renameSongModeButtonClick();
window.editingPlaylistActive = 0;
window.activeAlbum = "";
document.getElementById("editPlaylistButton").style.display = "initial";
document.getElementById("removePlaylistButton").style.display = "initial";
document.getElementById("startPlaylistButton").style.display = "initial";
document.getElementById("startAlbumButton").style.display = "none";
folder = "PlayLists" + '/' + btn.value;
sock.emit('dirCommand', {
command: "GET_SONGS",
folderName: folder,
privateData: "songsInPlayListListBox"
});
txtField = window.activePlayList;
window.activePlayList = btn.value;
window.activeAlbum = "";
}
function showAlbumSongs(id) {
if (window.renameSongMode == 1)
renameSongModeButtonClick();
window.editingPlaylistActive = 0;
document.getElementById("editPlaylistButton").style.display = "none";
document.getElementById("removePlaylistButton").style.display = "none";
document.getElementById("startPlaylistButton").style.display = "none";
document.getElementById("startAlbumButton").style.display = "initial";
btn = document.getElementById(id);
window.activeAlbum = btn.value;
window.activePlayList = "";
folder = "Albums" + '/' + btn.value;
sock.emit('dirCommand', {
command: "GET_SONGS",
folderName: folder,
privateData: "songsInAlbumsListBox"
});
}
function beginPlaylist() {
playlistName = window.activePlayList;
if (playlistName == "")
return;
document.getElementById("nextSongButton").style.display = 'initial';
document.getElementById("mainLineTextField").value = "Playing Playlist " + playlistName;
sock.emit('midiCommand', {
command: 'PLAY_LIST',
folderName: "PlayLists",
playlistName: playlistName,
tempo: 100
});
}
function beginAlbum() {
album = window.activeAlbum;
if (album == "")
return;
document.getElementById("mainLineTextField").value = "Playing Album " + album;
document.getElementById("nextSongButton").style.display = 'initial';
sock.emit('midiCommand', {
command: 'PLAY_LIST',
folderName: "Albums",
playlistName: album,
tempo: 100
});
}
function playSong(id) {
btn = document.getElementById(id);
if (window.currentView == CurrentViewEnum.PLAYLISTS) {
showPlayListSongs(id);
return;
} else if (window.currentView == CurrentViewEnum.ALBUMS) {
showAlbumSongs(id);
return;
}
if (window.renameSongMode == 1) {
var newSongName = prompt("Enter the new name for song " + btn.value, "");
if (newSongName == "" || newSongName == null)
return;
if (btn.value.includes(".mp3")) {
if (newSongName.includes(".mp3") == false)
newSongName += ".mp3";
}
sendDirCommand('RENAME_FILE', "", btn.value, newSongName);
btn.value = newSongName;
return;
}
if (window.editingPlaylistActive == 1) {
var idx = window.currentPlaylistSongs.indexOf(btn.value);
if (idx == -1) // Not currently in play list, so add it
{
jQuery(btn).css("color", window.songInPlaylistColor);
jQuery(btn).css("background", window.editingSongInPlaylistBackgroundColor);
window.currentPlaylistSongs.push(btn.value);
sendDirCommand('COPY_SONG', "PlayLists/" + window.activePlayList, btn.value);
} else {
jQuery(btn).css("color", window.songColorText);
jQuery(btn).css("background", window.editingSongNotInPlaylistBackgroundColor);
window.currentPlaylistSongs.splice(idx, 1);
sendDirCommand('REMOVE_SONG', "PlayLists/" + window.activePlayList, btn.value);
}
return;
}
song = btn.value;
sock.emit('midiCommand', {
command: 'PLAY_SONG',
folderName: 'Master',
fileName: song,
tempo: 0
});
}
function selectSong(privateData) {
selectedIndex = document.getElementById(privateData).selectedIndex;
song = document.getElementById(privateData).value;
if (song == "")
return;
song = song.replace(/\\/g, "@");
sock.emit('midiCommand', {
command: 'PLAY_SONG',
folderName: 'Master',
fileName: song,
tempo: 0
});
}
function loadSongsInDynamicPlaylist(privateData, fileCategory) {
folder = fileCategory + '/' + "Dynamic";
var listbox = document.getElementById(privateData);
while (listbox.length != 0)
listbox.options.remove(0);
sock.emit('dirCommand', {
command: "GET_SONGS",
folderName: folder,
privateData: privateData
});
}
function deselectPlayListButtons() {
document.getElementById("editPlaylistButton").value = "Edit Playlist";
window.activePlayList = "";
}
function loadSongs(folderListBox, privateData, fileCategory) {
disableSearch();
if (window.renameSongMode == 1)
renameSongModeButtonClick();
if (folderListBox == "Master") {
deselectPlayListButtons();
folder = "Master";
window.activeAlbum = "";
document.getElementById("nextSongButton").style.display = 'none';
window.activePlayList = "";
} else {
document.getElementById("editPlaylistButton").style.display = "initial";
document.getElementById("removePlaylistButton").style.display = "initial";
document.getElementById("startPlaylistButton").style.display = "initial";
document.getElementById("startAlbumButton").style.display = "initial";
selectedIndex = document.getElementById(folderListBox).selectedIndex;
folder = document.getElementById(folderListBox).value;
if (folder == "")
return;
folder = fileCategory + '/' + folder;
}
sock.emit('dirCommand', {
command: "GET_SONGS",
folderName: folder,
privateData: privateData
})
}
function getFolderNames(folderName, privateData) {
sock.emit('dirCommand', {
command: "GET_FOLDERS",
folderName: folderName,
privateData: privateData
})
}
function pauseResumeButtonClick(id) {
btn = document.getElementById(id);
if (btn.value == "Pause") {
btn.value = "Resume";
sock.emit('midiCommand', {
command: 'PAUSE'
});
} else {
btn.value = "Pause";
sock.emit('midiCommand', {
command: 'RESUME'
});
jQuery(btn).css("color", "black");
}
}
function report(period) {
}
function testMsg() {
sock.emit("testMsg", {
Param1Name: "Param1 Value",
Param2Name: "Param2 Value",
Param3Name: "Param3 Value"
});
}
function changeSystemSettings(id) {
showTab("changeSystemSettings");
}
function updateMusicButtonClick() {
if (confirm("Please confirm thumb drive with new music is plugged into computer.") == true)
checkForMusicUpdate();
}
function updateSoftwareButtonClick() {
if (confirm("Please confirm thumb drive with new software is plugged into computer.") == true)
checkForSoftwareUpdate();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment