/// <summary> /// Add new track to the database and collections. /// </summary> public void AddTrack() { var trackNumber = 1; if (this._currentProject.Tracks.Any()) { trackNumber = this._currentProject.Tracks.Count + 1; } var trackName = AppResources.TrackString + " " + trackNumber; var newTrack = new ToDoTrack { Name = trackName, ProjectRef = this._currentProject, Instrument = this.DataBaseContext.Instruments.First() }; this.DataBaseContext.Tracks.InsertOnSubmit(newTrack); this.DataBaseContext.SubmitChanges(); this._currentProject.Tracks.Add(newTrack); newTrack.Instruments = new ObservableCollection <ToDoInstrument>(this.DataBaseContext.Instruments); var sample = new ToDoSample { InitialTact = 1, Size = 4, TrackRef = newTrack, Name = newTrack.Name + "_" + newTrack.Samples.Count }; this.DataBaseContext.Samples.InsertOnSubmit(sample); this.DataBaseContext.SubmitChanges(); newTrack.Samples.Add(sample); }
/// <summary> /// Query database and load the information for project /// </summary> /// <param name="trackId">ID of loading project</param> public override void LoadData(int trackId) { var options = new DataLoadOptions(); options.AssociateWith <ToDoTrack>(x => x.Samples.OrderBy(y => y.InitialTact)); this.DataBaseContext.LoadOptions = options; this._currentTrack = this.DataBaseContext.Tracks.FirstOrDefault(x => x.Id == trackId); }
/// <summary> /// Start playing samples /// </summary> public void Play(ToDoTrack onPlayTrack, int initialTact) { _audioController.Start(); _onPlayTracks = new List <TrackManager> { new TrackManager(onPlayTrack, initialTact) }; _position = 0; Tact = initialTact; _playerTimer.Start(); State = PlayerState.Playing; }
/// <summary> /// Control for playing notes of track /// </summary> public TrackManager(ToDoTrack onPlayTrack, int initialTact) { Instrument = onPlayTrack.Instrument.Waveform; OnPlayNotes = new Queue <ToDoNote>(); PlayedNotes = new List <ToDoNote>(); foreach (var note in onPlayTrack.Samples.OrderBy(x => x.InitialTact) .Select(sample => sample.Notes.Where(x => x.Tact >= initialTact).OrderBy(x => x.Tact).ThenBy(x => x.Position)) .SelectMany(notes => notes)) { OnPlayNotes.Enqueue(note); } }
/// <summary> /// Add a project with specific name to the database and collections. /// </summary> /// <param name="projectName">Name of project</param> /// <returns>New project</returns> public ToDoProject CreateProject(string projectName) { var newProject = new ToDoProject() { Name = projectName, CreationTime = DateTime.Now, Tempo = 120 }; this.DataBaseContext.Projects.InsertOnSubmit(newProject); this.DataBaseContext.SubmitChanges(); this._projectsList.Add(newProject); var trackName = AppResources.TrackString + " 1"; var newTrack = new ToDoTrack { Name = trackName, ProjectRef = newProject, Instrument = this.DataBaseContext.Instruments.First() }; this.DataBaseContext.Tracks.InsertOnSubmit(newTrack); this.DataBaseContext.SubmitChanges(); newProject.Tracks.Add(newTrack); var sample = new ToDoSample { InitialTact = 1, Size = 4, TrackRef = newTrack, Name = newTrack.Name + "_" + newTrack.Samples.Count }; this.DataBaseContext.Samples.InsertOnSubmit(sample); this.DataBaseContext.SubmitChanges(); newTrack.Samples.Add(sample); return(newProject); }
public void SelectInstrument(ToDoTrack track, ToDoInstrument instrument) { _currentProject.Tracks.First(x => track.Id == x.Id).Instrument = instrument; SaveChangesToDb(); }