context = window @SessionHelper = class SessionHelper constructor: (app, session) -> @app = app @session = session inSession: () -> @session? participants: () -> if @session return @session.participants else [] # if any participant has the metronome open, then we say this session has the metronome open isMetronomeOpen: () -> metronomeOpen = false; for participant in @participants() if participant.metronome_open metronomeOpen = true break metronomeOpen isPlayingRecording: () -> # this is the server's state; there is no guarantee that the local tracks # requested from the backend will have corresponding track information return !!(@session && @session.claimed_recording); recordedTracks: () -> if @session && @session.claimed_recording @session.claimed_recording.recording.recorded_tracks else null recordedBackingTracks: () -> if @session && @session.claimed_recording @session.claimed_recording.recording.recorded_backing_tracks else null backingTracks: () -> backingTracks = [] # this may be wrong if we loosen the idea that only one person can have a backing track open. # but for now, the 1st person we find with a backing track open is all there is to find... for participant in @participants() if participant.backing_tracks.length > 0 backingTracks = participant.backing_tracks break backingTracks jamTracks: () -> if @session && @session.jam_track @session.jam_track.tracks.filter((track)-> track.track_type == 'Track' ) else null recordedJamTracks:() -> if @session && @session.claimed_recording @session.claimed_recording.recording.recorded_jam_track_tracks else null getParticipant: (clientId) -> found = null for participant in @participants() if participant.client_id == clientId found = participant break logger.warn('unable to find participant with clientId: ' + clientId) unless found found