Thank you for your donation!


Cloudsmith graciously provides open-source package management and distribution for our project.


Solved: Random album script
#1
Hi all

I'm trying to beef up my Denon RC-1173 remote with moOde-tied functionality and would like to set a button queuing up a random album, behaving exactly like the random album icon on the playback panel in the web interface. 
As far as I can tell this is the javascript responsible for the functionality but I don't know how to call it as a script that irexec can run. Could anyone shed some light on this?

/www/js/scripts-library.js lines 654-694
Code:
// Random album instant play (button on Playback panel)

$('.ralbum').click(function(e) {

    if ($('.tab-content').hasClass('fancy')) {

        $('.ralbum svg').attr('class', 'spin');

        setTimeout(function() {

            $('.ralbum svg').attr('class', '');

        }, 1500);

    }

    var array = new Uint16Array(1);

    window.crypto.getRandomValues(array);

    pos = Math.floor((array[0] / 65535) * filteredAlbums.length);




    UI.libPos[0] = pos;

    UI.libPos[1] = filteredAlbumCovers.map(function(e) {return e.album;}).indexOf(filteredAlbums[pos].album);

    var albumobj = filteredAlbums[pos];




    storeLibPos(UI.libPos);

    LIB.albumClicked = true; // For renderSongs()




   // Song list for regular album

    clickedLibItem(e, keyAlbum(albumobj), LIB.filters.albums, renderSongs);




    var files = [];

    for (var i in filteredSongs) {

        files.push(filteredSongs[i].file);

    }




   if (SESSION.json['library_instant_play'] == 'Add/Play') {

       mpdDbCmd('playall', files);

   }

   // Clear/play using add first followed by delete. This approach makes for a smoother visual transition.

   else {

       var endpos = $(".playlist li").length

       mpdDbCmd('addall', files);

       setTimeout(function() {

           endpos == 1 ? cmd = 'delplitem&range=0' : cmd = 'delplitem&range=0:' + endpos;

           var result = sendMoodeCmd('GET', cmd, '', true);

           sendMpdCmd('play 0');

       }, 500);

   }

});
Reply
#2
Looking a bit at how irexec works with moode (sends commands to mpc) you probably need additional software like this:

http://lirc.org/html/irxevent.html

It looks like can simulate button clicks by using screen coordinates but it’d be better if keyboard shortcuts were added.
Reply
#3
We also have a mechanism (engine-cmd.php) to send commands from the server to the client so in theory it should be possible to use it to provide an interface to the non-MPD features of the UI. There are a lot of moving parts though so not a trivial dev project.

It would be something like below

- LIRC maps button X to command: /var/www/command/new_script.php 'random_album'
- When X is pressed new_script.php executes function sendEngCmd($cmd);
- JS code running in Browser receives 'random_album' command and performs $('.ralbum).click()

Something like that.
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#4
Update:

I found a solution much simpler than emulating button presses in X: https://github.com/cbumae/mpdrandom

Calling mpdrandom will select an album at random from the current playlist, and by calling the option -l the script will select, queue and play an album from the entire library.

The script offers a daemon function as well, queuing an entire album when the end of the playlist is reached. I'm an album guy so will replace the ashuffle implementation with this.
Reply
#5
Added to TODO list, thanks.

My thought is to change the Auto-shuffle option in Audio Config from ON/OFF to a dropdown that contains

Off
Tracks
Albums
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply


Forum Jump: