Exemplo n.º 1
0
        public MixItemViewModel(
            IMessenger messenger, 
            IMixItem mixItem,
            PlayPauseTrackCommand playPauseCommand,
            IMix mix,
            MixViewModel mixViewModel) : base(messenger)
        {
            this.mix = mix;
            this.mixViewModel = mixViewModel;
            if (messenger == null) throw new ArgumentNullException("messenger");
            if (mixItem == null) throw new ArgumentNullException("mixItem");
            if (playPauseCommand == null) throw new ArgumentNullException("playPauseCommand");
            if (mix == null) throw new ArgumentNullException("mix");
            if (mixViewModel == null) throw new ArgumentNullException("mixViewModel");
            MixItem = mixItem;
            PlayPauseCommand = playPauseCommand;
            messenger.Register<TransitionChangedEvent>(this, OnTransitionChanged);
            messenger.Register<PlaybackSpeedAdjustedEvent>(this, OnPlaybackSpeedAdjusted);
            messenger.Register<TrackUpdatedEvent>(this, OnTrackUpdated);

            messenger.Register<MixLockedEvent>(this, _ => RaisePropertyChanged(() => IsPitchFaderEnabled));
            messenger.Register<MixUnlockedEvent>(this, _ => RaisePropertyChanged(() => IsPitchFaderEnabled));

            // Required for play/pause status
            messenger.Register<PlayerPlayingEvent>(this, _ => RaisePropertyChanged(() => Track));
            messenger.Register<PlayerStoppedEvent>(this, _ => RaisePropertyChanged(() => Track));
            messenger.Register<ConfigSavedEvent>(this, _ => RaisePropertyChanged(() => ActualKey));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Invoked when the user click on an item in the tree list view
        /// Retrieve the IPathway or IMix object stored in the tag and sends it to the ResultsControl
        /// for displaying the results associated with that pathway or mix main output
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void treeView1_MouseDown(object sender, MouseEventArgs e)
        {
            treeView1.SelectedNode = treeView1.GetNodeAt(e.Location);

            if (this.treeView1.SelectedNode != null)
            {
                Object   tag       = this.treeView1.SelectedNode.Tag;
                IResults result    = null;
                int      productID = -1;
                string   name      = "";

                //if the retrieved object is a pathway
                if (tag is IPathway)
                {
                    IPathway path = tag as IPathway;
                    //We ask the pathway what is the product defined as the main product for this pathway
                    //then store an integer that corresponds to an IResource.ID
                    productID = path.MainOutputResourceID;
                    //We use the ID of the Resource that corresponds to the main output of the pathway to get the correct results
                    Dictionary <int, IResults> availableResults = path.GetUpstreamResults(ResultsAccess.controler.CurrentProject.Data);
                    if (availableResults.ContainsKey(productID))
                    {
                        result = availableResults[productID];
                    }
                    //We set the string variable as the name of the pathway
                    name = path.Name;
                }
                //if the retrieved object is a pathway
                else if (tag is IMix)
                {
                    IMix mix = tag as IMix;
                    //We ask the mix what is the product defined as the main product for this mix
                    //then store an integer that corresponds to an IResource.ID
                    productID = mix.MainOutputResourceID;
                    //We use the ID of the Resource that corresponds to the main output of the pathway to get the correct results
                    Dictionary <int, IResults> availableResults = mix.GetUpstreamResults(ResultsAccess.controler.CurrentProject.Data);
                    if (availableResults.ContainsKey(productID))
                    {
                        result = availableResults[productID];
                    }
                    //We set the string variable as the name of the pathway
                    name = mix.Name;
                }

                //if we found a pathway or a mix and we have all the necessary parameters
                //we Invoke the SetResults method of our user control in charge of displaying the life cycle upstream results
                if (result != null && productID != -1 && !String.IsNullOrEmpty(name))
                {
                    this.resultsControl1.SetResults(name, result, productID);
                }
            }
        }
        public AutoMixingContext CreateContext(IMix mix, IEnumerable<IMixItem> selectedTracks)
        {
            if (mix == null) throw new ArgumentNullException("mix");
            if (selectedTracks == null) throw new ArgumentNullException("selectedTracks");

            if (selectedTracks.Count() == mix.Count)
            {
                // Entire mix is selected, everything can be moved (no
                // preceeeding/following keys that need to be observed)
                return new AutoMixingContext(selectedTracks);
            }

            IMixItem preceeding = mix.GetPreceedingItem(selectedTracks.First());
            IMixItem following = mix.GetFollowingItem(selectedTracks.Last());

            // Only uphold preceeding/following keys if they are known.
            IgnoreIfUnknownKeyOrBpm(ref preceeding);
            IgnoreIfUnknownKeyOrBpm(ref following);

            return new AutoMixingContext(selectedTracks, preceeding, following);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates a new mix with a few pathways and mixes references, then inserts that mix in the database
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonNewMix_Click(object sender, EventArgs e)
        {
            //Hardcoded crude oil resource ID, could be fetched from the IData class instead
            int CRUDE_RES_ID = 23;
            //Hardcoded pathway IDs
            int CONV_CRD = 34, OILS_CRD = 36;
            //Hardcoded mix ID (for the fun of it)
            int MIX_CRD = 0;

            //Creating a new instance of a mix
            IMix mix = _dataHelper.CreateNewMix("Example4 Mix");

            //Set the resource ID produced by this mix
            _dataHelper.MixSetResource(mix, CRUDE_RES_ID);

            //Retriving pathways to be added to the mix
            IPathway path1 = _controller.CurrentProject.Data.Pathways.ValueForKey(CONV_CRD);
            IPathway path2 = _controller.CurrentProject.Data.Pathways.ValueForKey(OILS_CRD);
            IMix     mix1  = _controller.CurrentProject.Data.Mixes.ValueForKey(MIX_CRD);

            //Adding the different production items to the mix and define their shares
            bool success = _dataHelper.MixAddFeed(mix, path1, 0.3);

            success &= _dataHelper.MixAddFeed(mix, path2, 0.6);
            success &= _dataHelper.MixAddFeed(mix, mix1, 0.1);

            //Inserting the newly created mix to the database
            success &= _dataHelper.DataInsertOrUpdateMix(mix);

            if (success)
            {
                MessageBox.Show("Mix named : '" + mix.Name + "' inserted in dataset");
            }
            else
            {
                MessageBox.Show("Failure");
            }
        }
Exemplo n.º 5
0
        public async Task WriteAsync(IMix mix, string filename)
        {
            if (mix == null) throw new ArgumentNullException("mix");
            if (String.IsNullOrWhiteSpace(filename)) 
                throw new ArgumentException("Invalid filename.", "filename");

            var jsonMix = new JsonMix
                              {
                                  Items = mix.Select(ToJsonItem).ToList(),
                                  Comment = FormatComment()
                              };

            try
            {
                Log.DebugFormat("Saving mix {0} ({1} tracks)...", filename, mix.Count);

                long numberOfBytesWritten;

                using (FileStream file = File.Open(filename, FileMode.Create, FileAccess.Write))
                using (var writer = new StreamWriter(file))
                {
                    string json = await JsonConvert.SerializeObjectAsync(
                        jsonMix, GlobalJsonSettings.Formatting, GlobalJsonSettings.Settings);

                    await writer.WriteAsync(json);

                    numberOfBytesWritten = file.Position;
                }

                Log.DebugFormat("Mix saved successfully ({0} bytes).", numberOfBytesWritten);
            }
            catch (Exception e)
            {
                Log.Error(String.Format("Error saving mix {0}.", filename), e);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Invoked when the user click on an item in the tree list view
        /// Retrieve the IPathway or IMix object stored in the tag and sends it to the ResultsControl
        /// for displaying the results associated with that pathway or mix main output
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void treeView1_MouseDown(object sender, MouseEventArgs e)
        {
            treeView1.SelectedNode = treeView1.GetNodeAt(e.Location);

            if (this.treeView1.SelectedNode != null)
            {
                Object   tag       = this.treeView1.SelectedNode.Tag;
                IResults result    = null;
                int      productID = -1;
                string   name      = "";

                if (tag is IPathway)
                {//if the retrieved object is a pathway
                    IPathway path = tag as IPathway;
                    //We ask the pathway what is the product defined as the main product for this pathway
                    //then store an integer that corresponds to an IResource.ID
                    productID = ResultsAccess.controler.CurrentProject.Data.Helper.PathwayMainOutputResouce(path.Id);
                    //We use the ID of the Resource that corresponds to the main output of the pathway to get the correct results
                    Dictionary <IIO, IResults> availableResults = path.GetUpstreamResults(ResultsAccess.controler.CurrentProject.Data);
                    Guid desiredOutput = new Guid();
                    if (null == availableResults.Keys.SingleOrDefault(item => item.ResourceId == productID))
                    {
                        MessageBox.Show("Selected pathway does not produce the fuel selected. Please remove it from the Fule Types list");
                        return;
                    }
                    else
                    {
                        foreach (IIO io in availableResults.Keys.Where(item => item.ResourceId == productID))
                        {
                            desiredOutput = io.Id;
                            if (io.Id == path.MainOutput)
                            {
                                desiredOutput = io.Id;
                                break;
                            }
                        }
                    }
                    result = availableResults.SingleOrDefault(item => item.Key.Id == desiredOutput).Value;
                    //We set the string variable as the name of the pathway
                    name = path.Name;
                }
                else if (tag is IMix)
                {//if the retrieved object is a mix
                    IMix mix = tag as IMix;
                    //We ask the mix what is the product defined as the main product for this mix
                    //then store an integer that corresponds to an IResource.ID
                    productID = mix.MainOutputResourceID;
                    //We use the ID of the Resource that corresponds to the main output of the pathway to get the correct results
                    var upstream = mix.GetUpstreamResults(ResultsAccess.controler.CurrentProject.Data);

                    if (null == upstream.Keys.SingleOrDefault(item => item.ResourceId == productID))
                    {
                        MessageBox.Show("Selected mix does not produce the fuel selected. Please remove it from the Fule Types list");
                        return;
                    }

                    //a mix has a single output so we can safely do the folowing
                    result = upstream.SingleOrDefault(item => item.Key.ResourceId == productID).Value;

                    //We set the string variable as the name of the pathway
                    name = mix.Name;
                }

                //if we found a pathway or a mix and we have all the necessary parameters
                //we Invoke the SetResults method of our user control in charge of displaying the life cycle upstream results
                if (result != null && productID != -1 && !String.IsNullOrEmpty(name))
                {
                    this.resultsControl1.SetResults(name, result, productID);
                }
            }
        }
Exemplo n.º 7
0
 public MixLoadedEvent(IMix mix)
 {
     if (mix == null) throw new ArgumentNullException("mix");
     Mix = mix;
 }
 public MixItemViewModel CreateFor(IMix mix, IMixItem item, MixViewModel mixViewModel)
 {
     return new MixItemViewModel(messenger, item, playPauseCommand, mix, mixViewModel);
 }