more work

This commit is contained in:
Mike Slemmer 2013-01-22 11:15:52 -08:00
parent 81d37f13b9
commit 8a54a0a116
7 changed files with 60 additions and 29 deletions

View File

@ -13,8 +13,7 @@ module JamRuby
has_and_belongs_to_many :genres, :class_name => "JamRuby::Genre", :join_table => "bands_genres"
# recordings
has_many :band_recordings, :class_name => "JamRuby::BandRecording", :foreign_key => "band_id"
has_many :recordings, :through => :band_recordings, :class_name => "JamRuby::Recording", :foreign_key => "recording_id"
has_many :recordings, :class_name => "JamRuby::Recording", :foreign_key => "band_id"
# likers
has_many :likers, :class_name => "JamRuby::BandLiker", :foreign_key => "band_id", :inverse_of => :band

View File

@ -1,14 +0,0 @@
module JamRuby
class BandRecording < ActiveRecord::Base
self.table_name = "bands_recordings"
attr_accessible :band_id, :recording_id
# bands
has_many :bands, :through => :band_recordings, :class_name => "JamRuby::Band"
belongs_to :band, :class_name => "JamRuby::Band", :foreign_key => "band_id"
belongs_to :recording, :class_name => "JamRuby::Recording", :foreign_key => "recording_id"
end
end

View File

@ -7,7 +7,7 @@ module JamRuby
has_many :musician_instruments, :class_name => "JamRuby::MusicianInstrument"
has_many :users, :through => :musician_instruments, :class_name => "JamRuby::User"
has_many :tracks, :class_name => "JamRuby::Track", :inverse_of => :instrument
has_many :saved_tracks, :class_name => "JamRuby::SavedTrack", :inverse_of => :instrument
has_many :recorded_tracks, :class_name => "JamRuby::RecordedTrack", :inverse_of => :instrument
# music sessions
has_and_belongs_to_many :music_sessions, :class_name => "JamRuby::MusicSession", :join_table => "genres_music_sessions"

View File

@ -161,6 +161,10 @@ module JamRuby
return self.users.exists? user
end
def recording?
return self.recording
end
def to_s
return description
end

View File

@ -1,25 +1,26 @@
module JamRuby
class SavedTrack < ActiveRecord::Base
class RecordedTrack < ActiveRecord::Base
self.table_name = "saved_tracks"
self.table_name = "recorded_tracks"
self.primary_key = 'id'
SOUND = %w(mono stereo)
belongs_to :user, :class_name => "JamRuby::User", :inverse_of => :saved_tracks
belongs_to :user, :class_name => "JamRuby::User", :inverse_of => :recorded_tracks
belongs_to :recording, :class_name => "JamRuby::Recording", :inverse_of => :recorded_tracks
belongs_to :instrument, :class_name => "JamRuby::Instrument"
validates :sound, :inclusion => {:in => SOUND}
# Copy an ephemeral track to create a saved one. Some fields are ok with defaults
def self.create_from_track(track)
saved_track = self.new
saved_track.user_id = track.connection.user.id
saved_track.instrument_id = track.instrument_id
saved_track.sound = track.sound
saved_track.save
saved_track
recorded_track = self.new
recorded_track.user_id = track.connection.user.id
recorded_track.instrument_id = track.instrument_id
recorded_track.sound = track.sound
recorded_track.save
recorded_track
end
def upload_start
@ -49,7 +50,7 @@ module JamRuby
# Format: "recording_#{saved_track_id}"
# File extension is irrelevant actually.
def self.filename_to_saved_track_id(filename)
def self.filename_to_recorded_track_id(filename)
matches = /^recording_([\w-]+)$/.match(filename)
return nil unless matches && matches.length > 1
matches[1]

View File

@ -4,7 +4,9 @@ module JamRuby
self.primary_key = 'id'
has_many :musician_recordings, :class_name => "JamRuby::MusicianRecording"
has_many :band_recordings, :class_name => "JamRuby::BandRecording"
belongs_to :band, :class_name => "JamRuby::Band", :inverse_of => :recording
has_many :recorded_tracks, :class_name => "JamRuby::RecordedTrack", :foreign_key => :recording_id
# genres
has_and_belongs_to_many :genres, :class_name => "JamRuby::Genre", :join_table => "recordings_genres"
@ -19,6 +21,28 @@ module JamRuby
return self.favorites.size
end
# Start recording a session.
def self.start(music_session_id, creator_id)
music_session = MusicSession.find(music_session_id)
if music_session.recording?
raise PermissionError, "the session is already being recorded"
end
recording = Recording.new
music_session.connections.each do |connection|
recording.musician_recordings << MusicianRecording.create(user_id: connection.user.id, recording_id: recording.id)
connection.tracks.each do |track|
RecordedTrack.create_from_track(track)
end
end
recording.band_id = music_session.band_id
end
def self.search(query, options = { :limit => 10 })
# only issue search if at least 2 characters are specified
@ -36,8 +60,25 @@ module JamRuby
return Recording.where("description_tsv @@ to_tsquery('jamenglish', ?)", query).limit(options[:limit])
end
def self.save(id, is_public, description, genres, updater_id, owner_id, is_band)
# Spec: https://jamkazam.atlassian.net/wiki/display/PS/Product+Specification+-+Studio
# This is seriously wrong. A recording needs to be created from inside a session. I'm not sure who owns
# the recording, but I do know that it's affiliated with the session and then should be able to get the band id
# and probably all this other stuff (genre, etc) from that. I need to read the recording spec in more detail
# to figure that out. I'll read it on bart.
#
# The studio spec is the key here. A couple notes:
# * Multiple musicians are all associated with a recording -- everyone who is in the music session when the recording starts
# * Associating a band with the recording is optional
# * The recording needs to be associated with a music_session for sure. Probably also a set of tracks (NOT musicians). Then, on
# recording completion is when you have the track -> saved_track (rename this to recorded_track) transition.
# * The metadata in general is filled in *after* the recording ends. This is important because it means the save method below
# is sort of jacked.
creator = User.find(updater_id)
if is_band

View File

@ -81,7 +81,7 @@ module JamRuby
has_many :music_session_histories, :foreign_key => "user_id", :class_name => "JamRuby::MusicSessionHistory"
# saved tracks
has_many :saved_tracks, :foreign_key => "user_id", :class_name => "JamRuby::SavedTrack", :inverse_of => :user
has_many :recorded_tracks, :foreign_key => "user_id", :class_name => "JamRuby::RecordedTrack", :inverse_of => :user
# This causes the authenticate method to be generated (among other stuff)
has_secure_password