VRFS-2498, VRFS-2618 More coherent data model and logic for backing tracks and metronome re: active_music_session_spec.

This commit is contained in:
Steven Miers 2015-01-12 17:44:20 -06:00
parent d0c0c6d01e
commit c6f03a91b8
4 changed files with 198 additions and 7 deletions

View File

@ -1,2 +1,2 @@
ALTER TABLE active_music_sessions ADD COLUMN backing_track_id VARCHAR(1024);
ALTER TABLE active_music_sessions ADD COLUMN backing_track_path VARCHAR(1024);
ALTER TABLE active_music_sessions ADD COLUMN backing_track_initiator_id VARCHAR(64);

View File

@ -1,2 +1,2 @@
ALTER TABLE active_music_sessions ADD COLUMN metronome_id BIGINT;
ALTER TABLE active_music_sessions ADD COLUMN metronome_active BOOLEAN NOT NULL DEFAULT FALSE;
ALTER TABLE active_music_sessions ADD COLUMN metronome_initiator_id VARCHAR(64);

View File

@ -102,17 +102,17 @@ module JamRuby
def validate_other_audio(error_key)
# validate that there is no metronome already open in this session
unless metronome_id_was.nil?
if metronome_active_was
errors.add(error_key, ValidationMessages::METRONOME_ALREADY_OPEN)
end
# validate that there is no backing track already open in this session
unless backing_track_id_was.nil?
if backing_track_path_was.present?
errors.add(error_key, ValidationMessages::BACKING_TRACK_ALREADY_OPEN)
end
# validate that there is no jam track already open in this session
unless jam_track_id_was.nil?
if jam_track_id_was.present?
errors.add(error_key, ValidationMessages::JAM_TRACK_ALREADY_OPEN)
end
@ -629,11 +629,11 @@ module JamRuby
end
def is_backing_track_open?
self.backing_track_id.present?
self.backing_track_path.present?
end
def is_metronome_open?
self.metronome_id.present?
self.metronome_active.present?
end
# is this music session currently recording?
@ -785,6 +785,35 @@ module JamRuby
self.save
end
# @param backing_track_path is a relative path:
def open_backing_track(user, backing_track_path)
self.backing_track_path = backing_track_path
self.backing_track_initiator = user
self.opening_backing_track = true
self.save
self.opening_backing_track = false
end
def close_backing_track
self.backing_track_path = nil
self.backing_track_initiator = nil
self.save
end
def open_metronome(user)
self.metronome_active = true
self.metronome_initiator = user
self.opening_metronome = true
self.save
self.opening_metronome = false
end
def close_metronome
self.metronome_active = false
self.metronome_initiator = nil
self.save
end
def self.sync(session_history)
music_session = MusicSession.find_by_id(session_history.id)

View File

@ -745,6 +745,29 @@ describe ActiveMusicSession do
@music_session.errors[:claimed_recording] == [ValidationMessages::JAM_TRACK_ALREADY_OPEN]
end
it "disallow a claimed recording to be started when backing track is open" do
# open the backing track
@backing_track = "foo.mp3"
@music_session.open_backing_track(@user1, @backing_track)
@music_session.errors.any?.should be_false
# and try to open a recording for playback
@music_session.claimed_recording_start(@user1, @claimed_recording)
@music_session.errors.any?.should be_true
@music_session.errors[:claimed_recording] == [ValidationMessages::BACKING_TRACK_ALREADY_OPEN]
end
it "disallow a claimed recording to be started when metronome is open" do
# open the metronome
@music_session.open_metronome(@user1)
@music_session.errors.any?.should be_false
# and try to open a recording for playback
@music_session.claimed_recording_start(@user1, @claimed_recording)
@music_session.errors.any?.should be_true
@music_session.errors[:claimed_recording] == [ValidationMessages::METRONOME_ALREADY_OPEN]
end
end
end
@ -830,5 +853,144 @@ describe ActiveMusicSession do
music_sessions[0].connections[0].tracks.should have(1).items
end
end
describe "open_backing_track" do
before(:each) do
@user1 = FactoryGirl.create(:user)
@connection = FactoryGirl.create(:connection, :user => @user1)
@instrument = FactoryGirl.create(:instrument, :description => 'a great instrument')
@track = FactoryGirl.create(:track, :connection => @connection, :instrument => @instrument)
@music_session = FactoryGirl.create(:active_music_session, :creator => @user1, :musician_access => true)
# @music_session.connections << @connection
@music_session.save!
@connection.join_the_session(@music_session, true, nil, @user1, 10)
@backing_track = "foo/bar.mp3"
end
it "allow a backing track to be associated" do
# simple success case; just open the backing track and observe the state of the session is correct
@music_session.open_backing_track(@user1, @backing_track)
@music_session.errors.any?.should be_false
@music_session.reload
@music_session.backing_track_path.should == @backing_track
@music_session.backing_track_initiator.should == @user1
end
it "allow a backing track to be closed" do
# simple success case; close an opened backing track and observe the state of the session is correct
@music_session.open_backing_track(@user1, @backing_track)
@music_session.errors.any?.should be_false
@music_session.close_backing_track
@music_session.errors.any?.should be_false
@music_session.reload
@music_session.backing_track_path.should be_nil
@music_session.backing_track_initiator.should be_nil
end
it "disallow a backing track to be opened when another is already opened" do
# if a backing track is open, don't allow another to be opened
@music_session.open_backing_track(@user1, @backing_track)
@music_session.errors.any?.should be_false
@music_session.open_backing_track(@user1, @backing_track)
@music_session.errors.any?.should be_true
@music_session.errors[:backing_track] == [ValidationMessages::BACKING_TRACK_ALREADY_OPEN]
end
it "disallow a backing track to be opened when recording is ongoing" do
@recording = Recording.start(@music_session, @user1)
@music_session.errors.any?.should be_false
@music_session.open_backing_track(@user1, @backing_track)
@music_session.errors.any?.should be_true
@music_session.errors[:backing_track] == [ValidationMessages::RECORDING_ALREADY_IN_PROGRESS]
end
it "disallow a backing track to be opened when recording is playing back" do
# create a recording, and open it for play back
@recording = Recording.start(@music_session, @user1)
@recording.errors.any?.should be_false
@recording.stop
@recording.reload
@claimed_recording = @recording.claim(@user1, "name", "description", Genre.first, true)
@claimed_recording.errors.any?.should be_false
@music_session.claimed_recording_start(@user1, @claimed_recording)
@music_session.errors.any?.should be_false
# while it's open, try to open a jam track
@music_session.open_backing_track(@user1, @backing_track)
@music_session.errors.any?.should be_true
@music_session.errors[:backing_track] == [ValidationMessages::CLAIMED_RECORDING_ALREADY_IN_PROGRESS]
end
end
describe "open_metronome" do
before(:each) do
@user1 = FactoryGirl.create(:user)
@connection = FactoryGirl.create(:connection, :user => @user1)
@instrument = FactoryGirl.create(:instrument, :description => 'a great instrument')
@track = FactoryGirl.create(:track, :connection => @connection, :instrument => @instrument)
@music_session = FactoryGirl.create(:active_music_session, :creator => @user1, :musician_access => true)
# @music_session.connections << @connection
@music_session.save!
@connection.join_the_session(@music_session, true, nil, @user1, 10)
end
it "allow a metronome to be activated" do
# simple success case; just open the metronome and observe the state of the session is correct
@music_session.open_metronome(@user1)
puts "@music_session.errors: #{@music_session.errors.inspect}"
@music_session.errors.any?.should be_false
@music_session.reload
@music_session.metronome_active.should == true
@music_session.metronome_initiator.should == @user1
end
it "allow a metronome to be closed" do
# simple success case; close an opened metronome and observe the state of the session is correct
@music_session.open_metronome(@user1)
@music_session.errors.any?.should be_false
@music_session.close_metronome
@music_session.errors.any?.should be_false
@music_session.reload
@music_session.metronome_active.should be_false
@music_session.metronome_initiator.should be_nil
end
it "disallow a metronome to be opened when another is already opened" do
# if a metronome is open, don't allow another to be opened
@music_session.open_metronome(@user1)
@music_session.errors.any?.should be_false
@music_session.open_metronome(@user1)
@music_session.errors.any?.should be_true
@music_session.errors[:metronome] == [ValidationMessages::METRONOME_ALREADY_OPEN]
end
it "disallow a metronome to be opened when recording is ongoing" do
@recording = Recording.start(@music_session, @user1)
@music_session.errors.any?.should be_false
@music_session.open_metronome(@user1)
@music_session.errors.any?.should be_true
@music_session.errors[:metronome] == [ValidationMessages::RECORDING_ALREADY_IN_PROGRESS]
end
it "disallow a metronome to be opened when recording is playing back" do
# create a recording, and open it for play back
@recording = Recording.start(@music_session, @user1)
@recording.errors.any?.should be_false
@recording.stop
@recording.reload
@claimed_recording = @recording.claim(@user1, "name", "description", Genre.first, true)
@claimed_recording.errors.any?.should be_false
@music_session.claimed_recording_start(@user1, @claimed_recording)
@music_session.errors.any?.should be_false
# while it's open, try to open a jam track
@music_session.open_metronome(@user1)
@music_session.errors.any?.should be_true
@music_session.errors[:metronome] == [ValidationMessages::CLAIMED_RECORDING_ALREADY_IN_PROGRESS]
end
end
end