Merge branch 'develop' into feature/find_session_start_session

This commit is contained in:
Brian Smith 2015-01-09 07:08:41 -05:00
commit 4e0d2cd1cf
13 changed files with 207 additions and 128 deletions

View File

@ -26,8 +26,6 @@ ActiveAdmin.register JamRuby::JamTrack, :as => 'JamTracks' do
column :id
column :name
column :description
column :bpm
column :tap_in_count
column :initial_play_silence
column :time_signature
column :status

View File

@ -7,8 +7,6 @@
| JamTrack should only be made available (to end users) if all its sub-component are in place:
= f.input :available, as: :boolean
= f.input :description, :input_html => { :rows=>5, :maxlength=>1000 }
= f.input :bpm
= f.input :tap_in_count
= f.input :initial_play_silence, :label => 'Initial Play Silence (seconds)'
= f.input :time_signature, collection: JamRuby::JamTrack::TIME_SIGNATURES, include_blank: false
= f.input :status, collection: JamRuby::JamTrack::STATUS, include_blank: false

View File

@ -1,6 +1,8 @@
= f.inputs name: 'Tap In fields' do
ol.nested-fields
= f.input :bpm, :label => 'BPM', :required => true
= f.input :tap_in_count, :label => 'Tap In Count', :required => true, :hint => 'number of taps in leading up to the Offset Time to play'
= f.input :offset_time_raw, :label => 'Offset Time', :hint => 'MM:SS:MLS', :required => true, :as => :string
- if f.object.new_record?

View File

@ -239,3 +239,4 @@ private_key_in_jam_track_rights.sql
jam_track_tap_in.sql
jam_track_available.sql
active_jam_track.sql
bpms_on_tap_in.sql

3
db/up/bpms_on_tap_in.sql Normal file
View File

@ -0,0 +1,3 @@
ALTER TABLE jam_track_tap_ins ADD COLUMN bpm DECIMAL NOT NULL;
ALTER TABLE jam_track_tap_ins ADD COLUMN tap_in_count INTEGER NOT NULL DEFAULT 0;
ALTER TABLE jam_tracks DROP COLUMN tap_in_count;

View File

@ -15,7 +15,7 @@ module JamRuby
attr_accessible :name, :description, :bpm, :time_signature, :status, :recording_type,
:original_artist, :songwriter, :publisher, :licensor, :licensor_id, :pro, :genre, :genre_id, :sales_region, :price,
:reproduction_royalty, :public_performance_royalty, :reproduction_royalty_amount,
:licensor_royalty_amount, :pro_royalty_amount, :plan_code, :tap_in_count, :initial_play_silence, :jam_track_tracks_attributes,
:licensor_royalty_amount, :pro_royalty_amount, :plan_code, :initial_play_silence, :jam_track_tracks_attributes,
:jam_track_tap_ins_attributes, :available, as: :admin
validates :name, presence: true, uniqueness: true, length: {maximum: 200}
@ -30,7 +30,6 @@ module JamRuby
validates :pro, inclusion: {in: [nil] + PRO}
validates :sales_region, inclusion: {in: [nil] + SALES_REGION}
validates_format_of :price, with: /^\d+\.*\d{0,2}$/
validates :tap_in_count, presence: true, numericality: {only_integer: true}
validates :initial_play_silence, numericality: true, :allow_nil => true
validates :reproduction_royalty, inclusion: {in: [nil, true, false]}

View File

@ -1,10 +1,13 @@
module JamRuby
class JamTrackTapIn < ActiveRecord::Base
attr_accessible :jam_track_id, :offset_time, :offset_time_raw, as: :admin
attr_accessible :jam_track_id, :offset_time, :offset_time_raw, :bpm, :tap_in_count, as: :admin
validates :offset_time, presence: true, numericality: {only_integer: true}, length: {in: 1..1000}
validates :jam_track, presence: true
validates :bpm, presence: true
validates_format_of :bpm, with: /^\d+\.*\d{0,1}$/
validates :tap_in_count, presence: true, numericality: {only_integer: true}
belongs_to :jam_track, class_name: "JamRuby::JamTrack"

View File

@ -57,22 +57,26 @@ module JamRuby
limit = 1000
recording_ids = recording_ids.uniq
if recording_ids.nil?
return []
else
recording_ids = recording_ids.uniq
raise "too many recording_ids" if recording_ids.length > limit
raise "too many recording_ids" if recording_ids.length > limit
found_recording_ids =
UserSync
.select('user_syncs.recording_id')
.joins("LEFT OUTER JOIN claimed_recordings ON claimed_recordings.user_id = user_syncs.user_id")
.where(%Q{
((claimed_recordings IS NULL OR claimed_recordings.discarded = TRUE) AND fully_uploaded = FALSE) OR (claimed_recordings IS NOT NULL AND claimed_recordings.discarded = FALSE)
})
.where(user_id: user_id)
.paginate(:page => 1, :per_page => limit)
.group('user_syncs.recording_id').map(&:recording_id)
found_recording_ids =
UserSync
.select('user_syncs.recording_id')
.joins("LEFT OUTER JOIN claimed_recordings ON claimed_recordings.user_id = user_syncs.user_id")
.where(%Q{
((claimed_recordings IS NULL OR claimed_recordings.discarded = TRUE) AND fully_uploaded = FALSE) OR (claimed_recordings IS NOT NULL AND claimed_recordings.discarded = FALSE)
})
.where(user_id: user_id)
.paginate(:page => 1, :per_page => limit)
.group('user_syncs.recording_id').map(&:recording_id)
recording_ids - found_recording_ids
recording_ids - found_recording_ids
end
end
end
end

View File

@ -743,5 +743,7 @@ FactoryGirl.define do
factory :jam_track_tap_in, :class => JamRuby::JamTrackTapIn do
association :jam_track, factory: :jam_track
offset_time 0
bpm 120
tap_in_count 3
end
end

View File

@ -352,6 +352,12 @@ describe UserSync do
result.should eq(['1'])
end
it "null recording_ids allowed" do
# observed that the client can send null for recording_ids
result = UserSync.deletables(user_id: mix.recording.recorded_tracks[0].user.id, recording_ids: nil)
result.should eq([])
end
end
describe "two recordings" do

View File

@ -70,14 +70,14 @@ else
# only show currently open jam track info if the current user is in the session
child({:jam_track => :jam_track}, :if => lambda { |music_session| music_session.users.exists?(current_user) }) {
attributes :id, :name, :description, :bpm, :initial_play_silence, :tap_in_count
attributes :id, :name, :description, :initial_play_silence
child(:jam_track_tracks => :tracks) {
attributes :id, :part, :instrument
}
child(:jam_track_tap_ins => :tap_ins) {
attributes :offset_time
attributes :offset_time, :bpm, :tap_in_count
}
}

View File

@ -1,32 +1,34 @@
require 'factory_girl'
require 'open-uri'
namespace :db do
desc "Add a simple one track recording to the database"
task single_recording: :environment do
User.where(:musician => true).order('RANDOM()').limit(10).each do |uu|
@user = uu
next if @user.connections.present?
@connection = FactoryGirl.create(:connection, :user => @user)
@track = FactoryGirl.create(:track, :connection => @connection, :instrument => Instrument.find('violin'), :client_track_id => "t1")
@music_session = FactoryGirl.create(:active_music_session, :creator => @user, :musician_access => true)
@music_session.connections << @connection
@music_session.save
@recording = FactoryGirl.create(:recording, :music_session => @music_session, :owner => @user, :id=>"R#{rand(10000)}")
@recorded_track = RecordedTrack.create_from_track(@track, @recording)
@recorded_track.save
#@recording = Recording.start(@music_session, @user)
@recording.stop
@recording.reload
@genre = Genre.find('ambient')
@recording.claim(@user, "name", "description", @genre, true)
@recording.reload
@claimed_recording = @recording.claimed_recordings.first
end
User.where(:musician => true).order('RANDOM()').limit(10).each do |uu|
@user = uu
next if @user.connections.present?
@connection = FactoryGirl.create(:connection, :user => @user)
@track = FactoryGirl.create(:track, :connection => @connection, :instrument => Instrument.find('violin'), :client_track_id => "t1")
@music_session = FactoryGirl.create(:active_music_session, :creator => @user, :musician_access => true)
@music_session.connections << @connection
@music_session.save
@recording = FactoryGirl.create(:recording, :music_session => @music_session, :owner => @user, :id => "R#{rand(10000)}")
@recorded_track = RecordedTrack.create_from_track(@track, @recording)
@recorded_track.save
#@recording = Recording.start(@music_session, @user)
@recording.stop
@recording.reload
@genre = Genre.find('ambient')
@recording.claim(@user, "name", "description", @genre, true)
@recording.reload
@claimed_recording = @recording.claimed_recordings.first
end
end
task clean: :environment do
DatabaseCleaner.strategy = :truncation, {:except => %w[instruments genres users] }
DatabaseCleaner.clean_with(:truncation, {:except => %w[instruments genres users] })
DatabaseCleaner.strategy = :truncation, {:except => %w[instruments genres users]}
DatabaseCleaner.clean_with(:truncation, {:except => %w[instruments genres users]})
DatabaseCleaner.start
DatabaseCleaner.clean
end
@ -86,36 +88,36 @@ namespace :db do
end
def make_music_sessions_history
users = User.all.map(&:id)
bands = Band.all.map(&:id)
genres = Genre.all.map(&:description)
50.times do |nn|
obj = MusicSession.new
obj.music_session_id = rand(100000000).to_s
obj.description = Faker::Lorem.paragraph
obj.user_id = users[rand(users.count)]
obj.band_id = bands[rand(bands.count)]
obj.created_at = Time.now - rand(1.month.seconds)
obj.session_removed_at = obj.created_at + (rand(3)+1).hour
obj.genres = genres.shuffle[0..rand(4)].join(' | ')
obj.save!
end
users = User.all.map(&:id)
bands = Band.all.map(&:id)
genres = Genre.all.map(&:description)
50.times do |nn|
obj = MusicSession.new
obj.music_session_id = rand(100000000).to_s
obj.description = Faker::Lorem.paragraph
obj.user_id = users[rand(users.count)]
obj.band_id = bands[rand(bands.count)]
obj.created_at = Time.now - rand(1.month.seconds)
obj.session_removed_at = obj.created_at + (rand(3)+1).hour
obj.genres = genres.shuffle[0..rand(4)].join(' | ')
obj.save!
end
end
def make_music_sessions_user_history
users = User.all.map(&:id)
hists = MusicSession.all
hists.each do |msh|
(rand(9)+1).times do |nn|
obj = MusicSessionUserHistory.new
obj.music_session_id = msh.music_session_id
obj.user_id = users[rand(users.count)]
obj.created_at = msh.created_at
obj.session_removed_at = obj.created_at + (rand(3)+1).hour
obj.client_id = rand(100000000).to_s
obj.save!
end
users = User.all.map(&:id)
hists = MusicSession.all
hists.each do |msh|
(rand(9)+1).times do |nn|
obj = MusicSessionUserHistory.new
obj.music_session_id = msh.music_session_id
obj.user_id = users[rand(users.count)]
obj.created_at = msh.created_at
obj.session_removed_at = obj.created_at + (rand(3)+1).hour
obj.client_id = rand(100000000).to_s
obj.save!
end
end
end
def make_band_members
@ -136,51 +138,51 @@ def make_band_genres
end
def make_bands
10.times do |nn|
name = Faker::Name.name
website = Faker::Internet.url
biography = Faker::Lorem.sentence
city = 'Austin' # Faker::Address.city
state = 'TX' # Faker::Address.state_abbr
country = 'US'
10.times do |nn|
name = Faker::Name.name
website = Faker::Internet.url
biography = Faker::Lorem.sentence
city = 'Austin' # Faker::Address.city
state = 'TX' # Faker::Address.state_abbr
country = 'US'
bb = Band.new(
bb = Band.new(
name: name,
website: website,
biography: biography,
city: city,
state: state,
country: country,
)
biography: biography,
city: city,
state: state,
country: country,
)
Genre.order('RANDOM()').limit(rand(3)+1).each do |gg|
bb.genres << gg
end
Genre.order('RANDOM()').limit(rand(3)+1).each do |gg|
bb.genres << gg
end
begin
bb.save!
rescue
puts $!.to_s + ' ' + bb.errors.inspect
end
begin
bb.save!
rescue
puts $!.to_s + ' ' + bb.errors.inspect
end
end
end
end
end
def make_users(num=99)
admin = User.create!( first_name: Faker::Name.name,
last_name: Faker::Name.name,
email: "example@railstutorial.org",
admin = User.create!(first_name: Faker::Name.name,
last_name: Faker::Name.name,
email: "example@railstutorial.org",
password: "foobar",
password_confirmation: "foobar",
terms_of_service: true)
terms_of_service: true)
admin.toggle!(:admin)
num.times do |n|
email = "example-#{n+1}@railstutorial.org"
password = "password"
password = "password"
User.create!(first_name: Faker::Name.name,
last_name: Faker::Name.name,
terms_of_service: true,
email: email,
last_name: Faker::Name.name,
terms_of_service: true,
email: email,
password: password,
password_confirmation: password)
end
@ -196,11 +198,11 @@ end
def make_relationships
users = User.all
user = users.first
user = users.first
followed_users = users[2..50]
followers = users[3..40]
followers = users[3..40]
followed_users.each { |followed| user.followings << followed }
followers.each { |follower| follower.follow!(user) }
followers.each { |follower| follower.follow!(user) }
end
def make_followings
@ -210,7 +212,7 @@ def make_followings
uuu.followings << uu unless 0 < Follow.where(:followable_id => uu.id, :user_id => uuu.id).count
uu.followings << uuu unless 0 < Follow.where(:followable_id => uuu.id, :user_id => uu.id).count if rand(3)==0
end
end
end
end
def make_friends
@ -219,7 +221,7 @@ def make_friends
users[0..5].shuffle.each do |uuu|
Friendship.save(uu.id, uuu.id)
end
end
end
end
def make_recorded_track(recording, user, instrument, md5, length, filename)
@ -249,11 +251,10 @@ def make_claimed_recording(recording, user, name, description)
end
def make_recording
# need 4 users.
users = User.where(musician: true).limit(4)
raise "need at least 4 musicians in the database to create a recording" if users.length < 4
raise "need at least 4 musicians in the database to create a recording" if users.length < 4
user1 = users[0]
user2 = users[1]
@ -264,13 +265,13 @@ def make_recording
recording.name = 'sample data'
recording.owner = user1
make_recorded_track(recording, user1, 'bass guitar', 'f86949abc213a3ccdc9d266a2ee56453', 2579467, 'https://jamjam:blueberryjam@int.jamkazam.com/stuff/lc_rocks_poison/track-adrian-bass.ogg')
make_recorded_track(recording, user1, 'voice', '264cf4e0bf14d44109322a504d2e6d18', 2373055, 'https://jamjam:blueberryjam@int.jamkazam.com/stuff/lc_rocks_poison/track-adrian-vox.ogg')
make_recorded_track(recording, user2, 'electric guitar', '9f322e1991b8c04b00dc9055d6be933c', 2297867, 'https://jamjam:blueberryjam@int.jamkazam.com/stuff/lc_rocks_poison/track-chris-guitar.ogg')
make_recorded_track(recording, user2, 'voice', '3c7dcb7c4c35c0bb313fc15ee3e6bfd5', 2244968, 'https://jamjam:blueberryjam@int.jamkazam.com/stuff/lc_rocks_poison/track-chris-vox.ogg')
make_recorded_track(recording, user3, 'voice', '10ca4c6ef5b98b3489ae8da1c7fa9cfb', 2254275, 'https://jamjam:blueberryjam@int.jamkazam.com/stuff/lc_rocks_poison/track-matt-lead-vox.ogg')
make_recorded_track(recording, user4, 'drums', 'ea366f482fa969e1fd8530c13cb75716', 2386250, 'https://jamjam:blueberryjam@int.jamkazam.com/stuff/lc_rocks_poison/track-randy-drum1.ogg')
make_recorded_track(recording, user4, 'drums', '4c693c6e99117719c6340eb68b0fe574', 2566463, 'https://jamjam:blueberryjam@int.jamkazam.com/stuff/lc_rocks_poison/track-randy-drum2.ogg')
make_recorded_track(recording, user1, 'bass guitar', 'f86949abc213a3ccdc9d266a2ee56453', 2579467, 'https://jamjam:blueberryjam@int.jamkazam.com/stuff/lc_rocks_poison/track-adrian-bass.ogg')
make_recorded_track(recording, user1, 'voice', '264cf4e0bf14d44109322a504d2e6d18', 2373055, 'https://jamjam:blueberryjam@int.jamkazam.com/stuff/lc_rocks_poison/track-adrian-vox.ogg')
make_recorded_track(recording, user2, 'electric guitar', '9f322e1991b8c04b00dc9055d6be933c', 2297867, 'https://jamjam:blueberryjam@int.jamkazam.com/stuff/lc_rocks_poison/track-chris-guitar.ogg')
make_recorded_track(recording, user2, 'voice', '3c7dcb7c4c35c0bb313fc15ee3e6bfd5', 2244968, 'https://jamjam:blueberryjam@int.jamkazam.com/stuff/lc_rocks_poison/track-chris-vox.ogg')
make_recorded_track(recording, user3, 'voice', '10ca4c6ef5b98b3489ae8da1c7fa9cfb', 2254275, 'https://jamjam:blueberryjam@int.jamkazam.com/stuff/lc_rocks_poison/track-matt-lead-vox.ogg')
make_recorded_track(recording, user4, 'drums', 'ea366f482fa969e1fd8530c13cb75716', 2386250, 'https://jamjam:blueberryjam@int.jamkazam.com/stuff/lc_rocks_poison/track-randy-drum1.ogg')
make_recorded_track(recording, user4, 'drums', '4c693c6e99117719c6340eb68b0fe574', 2566463, 'https://jamjam:blueberryjam@int.jamkazam.com/stuff/lc_rocks_poison/track-randy-drum2.ogg')
make_claimed_recording(recording, user1, 'Poison', 'Classic song that you all know -- user1')
make_claimed_recording(recording, user2, 'Poison', 'Classic song that you all know -- user2')
@ -278,7 +279,7 @@ def make_recording
make_claimed_recording(recording, user4, 'Poison', 'Classic song that you all know -- user4')
mix = Mix.new
mix.started_at = Time.now
mix.started_at = Time.now
mix.completed_at = Time.now
mix[:ogg_url] = 'https://jamjam:blueberryjam@int.jamkazam.com/stuff/lc_rocks_poison/master-out.ogg'
mix.ogg_md5 = 'f1fee708264602e1705638e53f0ea667'
@ -288,26 +289,87 @@ def make_recording
mix.mp3_length = 3666137
mix.completed = true
recording.mixes << mix
recording.save!(validate:false)
recording.save!(validate: false)
end
def make_jam_track(user)
number = 0
track = JamTrack.where('name like ?', 'boostrapped-%').order('name DESC').first
if track
index = track.name.index('-')
number = track.name[index+1..-1].to_i + 1 # increment most recent bootstrapped by 1
JamTrack.transaction do
track = JamTrack.where('name like ?', 'bootstrapped-%').order('name DESC').first
if track
puts "found existing JamTrack with name #{track.name}"
index = track.name.index('-')
number = track.name[index+1..-1].to_i + 1 # increment most recent bootstrapped by 1
end
suffix = number.to_s.rjust(3, '0') # 0 pad a bit
new_name ='bootstrapped-' + suffix
puts "creating jam_track with name #{new_name}"
licensor = JamTrackLicensor.first
if licensor
jam_track = FactoryGirl.create(:jam_track, name: new_name, licensor: licensor)
else
jam_track = FactoryGirl.create(:jam_track, name: new_name)
end
jam_track_track = jam_track.jam_track_tracks[0]
download_filename = Dir::Tmpname.make_tmpname(["#{Dir.tmpdir}/bootstrapped-" + suffix, '.ogg'], nil)
puts "downloading ogg file from int.jamkazam.com"
File.open(download_filename, "wb") do |saved_file|
open("https://int.jamkazam.com/stuff/lc_rocks_poison/track-adrian-vox.ogg", "rb", {http_basic_authentication: ["jamjam", "blueberryjam"]}) do |read_file|
saved_file.write(read_file.read)
end
end
puts "uploading ogg file to s3"
# let's put in a real ogg file into S3, so that the JamTracksBuilder job can succeed
s3_manager = S3Manager.new(APP_CONFIG.aws_bucket, APP_CONFIG.aws_access_key_id, APP_CONFIG.aws_secret_access_key)
url = jam_track_track.store_dir + "/" + jam_track_track.filename
s3_manager.upload(url, download_filename)
jam_track_track[:url] = url
jam_track_track.length = File.size(download_filename)
jam_track_track.md5 = '264cf4e0bf14d44109322a504d2e6d18'
jam_track_track.save!
puts "'purchasing' jamtrack for user #{user.email}"
right = FactoryGirl.create(:jam_track_right, user: user, jam_track: jam_track)
puts "creating .jkz file"
JamTracksBuilder.perform(right.id)
puts "------------------------------------"
puts "------------------------------------"
puts "---- SAVING JKZ AND PEM TO DISK ----"
puts "------------------------------------"
puts "------------------------------------"
right.reload
jkz_outfile = "tmp/#{jam_track.id}.jkz"
jkz_private_key = "tmp/#{jam_track.id}.pem"
File.open(jkz_private_key, 'w') {|f| f.write(right.private_key) }
s3_manager.download(right[:url], jkz_outfile)
puts "------------------------------------"
puts "------------------------------------"
puts "JKZ PACKAGE: #{jkz_outfile}"
puts "JKZ PRIVATE KEY: #{jkz_private_key}"
puts "------------------------------------"
puts "------------------------------------"
end
suffix = number.to_s.rjust(3, '0') # 0 pad a bit
jam_track = FactoryGirl.create(:jam_track, name: 'bootstrapped-' + suffix)
right = FactoryGirl.create(:jam_track_right, user: user, jam_track: jam_track)
JamTracksBuilder.perform(right.id)
end
def populate_conversation(target_email)

View File

@ -709,7 +709,6 @@ FactoryGirl.define do
licensor_royalty_amount 0.999
pro_royalty_amount 0.999
plan_code 'jamtrack-acdc-backinblack'
tap_in_count 0
ignore do
make_track true
end
@ -739,5 +738,7 @@ FactoryGirl.define do
factory :jam_track_tap_in, :class => JamRuby::JamTrackTapIn do
association :jam_track, factory: :jam_track
offset_time 0
bpm 120
tap_in_count 3
end
end