/** * Functions related to VU meters. * These functions are intimately tied to the markup defined in the * VU templates in _vu_meters.html.erb */ (function(context, $) { "use strict"; context.JK = context.JK || {}; // As these are helper functions, just have a single // static object with functions. Each function should // take all necessary arguments to complete its work. context.JK.TrackHelpers = { getTracks: function(jamClient, groupId) { var tracks = []; var trackIds = jamClient.SessionGetIDs(); var allTracks = jamClient.SessionGetControlState(trackIds); // get client's tracks for (var i=0; i < allTracks.length; i++) { if (allTracks[i].group_id === groupId) { tracks.push(allTracks[i]); } } return tracks; }, /** * This function resolves which tracks to configure for a user * when creating or joining a session. By default, tracks are pulled * from jamClient. If none exist there, the first instrument from the * user's profile is used. */ getUserTracks: function(jamClient) { var localMusicTracks = []; var i; localMusicTracks = context.JK.TrackHelpers.getTracks(jamClient, 2); var trackObjects = []; for (i=0; i < localMusicTracks.length; i++) { var track = {}; track.client_track_id = localMusicTracks[i].id; track.instrument_id = context.JK.client_to_server_instrument_map[localMusicTracks[i].instrument_id].server_id; if (localMusicTracks[i].stereo) { track.sound = "stereo"; } else { track.sound = "mono"; } trackObjects.push(track); } return trackObjects; } }; })(window, jQuery);