public void SaveMusicalInstrument(MusicalInstrument MusicalInstrument) { DanielsEntities context = new DanielsEntities(); COSC4210.MusicalIntruments.Web.Models.Item instrumentItem = new COSC4210.MusicalIntruments.Web.Models.Item(); if (MusicalInstrument.ID != 0) { var etItem = from t in context.Items where t.ID == MusicalInstrument.ID select t; instrumentItem = etItem.FirstOrDefault(); instrumentItem.ItemName = MusicalInstrument.Name; instrumentItem.Brand = MusicalInstrument.Brand; instrumentItem.TypeID = MusicalInstrument.TypeID; instrumentItem.Price = MusicalInstrument.Price; } else { instrumentItem.ItemName = MusicalInstrument.Name; instrumentItem.Brand = MusicalInstrument.Brand; instrumentItem.Price = MusicalInstrument.Price; instrumentItem.TypeID = MusicalInstrument.TypeID; context.Items.Add(instrumentItem); } instrumentItem.LastModified = DateTime.Now; instrumentItem.LastModifiedBy = "Phil"; context.SaveChanges(); }
// Methods public override bool Test(Sim a, MusicalInstrument target, bool isAutonomous, ref GreyedOutTooltipCallback greyedOutTooltipCallback) { try { if (target.ActorsUsingMe.Count == 0x0) { return(false); } Sim sim = target.ActorsUsingMe[0x0]; Relationship relationship = Relationship.Get(a, sim, false); if ((relationship != null) && (relationship.LTR.CurrentLTR == LongTermRelationshipTypes.Enemy)) { return(false); } if (target.ActorsUsingMe.Contains(a)) { return(false); } return(CelebrityManager.CanSocialize(a, sim)); } catch (ResetException) { throw; } catch (Exception e) { Common.Exception(a, target, e); return(false); } }
public PlayData(Notation notation, bool MIDI, Schema schema, MusicalInstrument musicalInstrument) { this.notation = notation; this.MIDI = MIDI; this.schema = schema; this.musicalInstrument = musicalInstrument; }
public void ChageToneEvent(List <PlayKey> plays) { //1、变调时应该停止所有按下键的音源播放。并且对其重新播放音源,所以需要一个标记[use]确定是否按下但是没有弹起 //2、变调时应该更改是否有音源 如果没有应该改为灰色,若果有应该改为 正常颜色 changeTone = GetPlayV.risingTune.tuneValue + GetPlayV.changeTune.changeTuneValue; MusicalInstrument musical = GetMusical(); if (musical == null) { Debug.Log("musical is null"); return; } Debug.Log(musical.musicalInstrumentName); int length = plays.Count; for (int i = 0; i < length; i++) { if (plays[i].IsUse) { StopToneEvent(plays[i].keyTone); PlayToneEvent(plays[i].keyTone, plays[i].toneValue); } if (musical.ExistClip(plays[i].toneValue + changeTone)) { plays[i].Show(); } else { plays[i].Hide(); } } }
public List <ItemInfo> ToSerializable(MusicalInstrument instrument) { var itemList = new List <ItemInfo>(); Type type = instrument.GetType(); itemList.Add(new ItemInfo { Type = type.Name, Value = instrument.Value }); foreach (PropertyInfo property in type.GetProperties()) { if (property.Name != "Value") { itemList.Add(new ItemInfo { Type = property.Name, Value = ((Description)property.GetValue(instrument, null))?.Value }); } } return(itemList); }
public PlayData() { this.notation = Notation.NumberedMusicalNotation; this.MIDI = false; this.schema = Schema.Study; this.musicalInstrument = null; }
//Initializes instrument object with properties getting from view. private void InitializeInstrument(MusicalInstrument instrument, List <ItemInfo> itemInfo) { for (int i = 1; i < itemInfo.Count; i++) { var item = itemInfo.ElementAt(i); InitializeField(instrument, item.Type, item.Value); } }
//Initializes certain field. private void InitializeField(MusicalInstrument instrument, string name, string value) { var fieldInfo = instrument.GetType().GetProperty(name); fieldInfo.SetValue(instrument, new Description() { Value = value }); }
/// <inheritdoc/> public void EmbedMelody(IList <IBar> melody, MusicalInstrument instrument = MusicalInstrument.Flute, byte?trackNumber = null) { // use utility private helper method to convert the melody into a midi track TrackChunk melodyTrack = ConvertMelodyToTrackChunk(melody, trackName: DefaulTrackName, instrument); // assemble the midi file with new track which contains the melody's midi events int indexOfNewTrack = trackNumber ?? _midiContent.Chunks.Count; _midiContent.Chunks.Insert(indexOfNewTrack, melodyTrack); }
public void SetMusicalEvent(int value) { MusicalInstrument musical = musicals[value]; musical.Init(); GetPlayM.data.musicalInstrument = musical; GetPlayV.ChangeToneEvent(); GetPlayV.SetKeyTone(musical.KeyTone); }
public override string ToString() { return(ArtisansTools.ToString() + ' ' + DisguiseKit.ToString() + ' ' + ForgeryKit.ToString() + ' ' + GamingSet.ToString() + ' ' + HerbalismKit.ToString() + ' ' + MusicalInstrument.ToString() + ' ' + NavigatorsTools.ToString() + ' ' + PoisonersKit.ToString() + ' ' + ThievesTools.ToString()); }
public int CompareTo(MusicalInstrument o) { MusicalInstrument p = o as MusicalInstrument; if (p != null) { return(this.Cost.CompareTo(p.Cost)); } else { throw new Exception("Невозможно сравнить два объекта"); } }
public override bool Test(Sim a, MusicalInstrument target, bool isAutonomous, ref GreyedOutTooltipCallback greyedOutTooltipCallback) { if (!base.Test(a, target, isAutonomous, ref greyedOutTooltipCallback)) return false; if (isAutonomous) { if (!NRaas.StoryProgression.Main.GetValue<GuitarPlay.Option, bool>()) { if (Party.IsInvolvedInAnyTypeOfParty(a)) { return false; } } } return true; }
//Initializing instrument description from already created instrument object. public void Initialize(List <ItemInfo> itemInfo, MusicalInstrument instrument) { foreach (ItemInfo item in itemInfo) { if (item == itemInfo.First()) { continue; } PropertyInfo fieldInfo = instrument.GetType().GetProperty(item.Type); string value = (fieldInfo.GetValue(instrument) as Description).Value; if (value != null) { item.Value = value; } } }
public override bool Test(Sim a, MusicalInstrument target, bool isAutonomous, ref GreyedOutTooltipCallback greyedOutTooltipCallback) { if (!base.Test(a, target, isAutonomous, ref greyedOutTooltipCallback)) { return(false); } if (isAutonomous) { if (!NRaas.StoryProgression.Main.GetValue <Option, bool>()) { if (Party.IsInvolvedInAnyTypeOfParty(a)) { return(false); } } } return(true); }
public static bool Tip(Sim actor, Sim player, MusicalInstrument target, int moneyPerLevel, int moneyPerComposition) { int originalActorFunds = actor.FamilyFunds; if (originalActorFunds <= 0) { return(false); } int originalTargetFunds = player.FamilyFunds; if (target is BandInstrument) { return(GiveTip(target as BandInstrument, actor, player, moneyPerLevel, moneyPerComposition)); } else if (target is SnakeCharmingBasket) { return(GiveTip(target as SnakeCharmingBasket, actor, player, moneyPerLevel, moneyPerComposition)); } return(false); }
public MusicalInstrument GetMusicalInstrument(int ID) { DanielsEntities context = new DanielsEntities(); MusicalInstrument instrument = null; var queryItem = from t in context.Items where t.ID == ID select new MusicalInstrument { ID = t.ID, Name = t.ItemName, TypeID = t.TypeID, Brand = t.Brand, Price = t.Price }; instrument = queryItem.FirstOrDefault(); instrument.Categories = GetCategoryAssociations(instrument.ID); return(instrument); }
private static void ParseControlEvent(MidiBigEndianReader reader, Track track, byte eventType, byte channel, uint absoluteTime, ref uint size, byte nextByte) { switch (eventType) { case 0x8: //note number out of bound if (nextByte > 127) { break; } track.Channels[channel].Events.Add(new NoteOff { AbsoluteTime = absoluteTime, ChannelNumber = channel, NoteNumber = nextByte, Velocity = reader.ReadByte() }); size += 1; break; case 0x9: //note number out of bound if (nextByte > 127) { break; } track.Channels[channel].Events .Add(new NoteOn { AbsoluteTime = absoluteTime, ChannelNumber = channel, NoteNumber = nextByte, Volume = reader.ReadByte() }); size += 1; break; case 0xA: //note number out of bound if (nextByte > 127) { break; } track.Channels[channel].Events.Add(new NoteAftertouch { AbsoluteTime = absoluteTime, ChannelNumber = channel, NoteNumber = nextByte, AftertouchValue = reader.ReadByte() }); size += 1; break; case 0xB: track.Channels[channel].Events.Add(new Controller { AbsoluteTime = absoluteTime, ChannelNumber = channel, ControllerNumber = nextByte, ControllerValue = Math.Min(reader.ReadByte(), (byte)127) }); size += 1; break; case 0xC: var instrument = new MusicalInstrument(nextByte); track.Channels[channel].Events.Add(new InstrumentChange { AbsoluteTime = absoluteTime, ChannelNumber = channel, Instrument = instrument }); break; case 0xD: track.Channels[channel].Events.Add(new ChannelAftertouch { AbsoluteTime = absoluteTime, ChannelNumber = channel, AfterTouchValue = nextByte }); break; case 0xE: var lsb = nextByte; var msb = reader.ReadByte(); var pitchValue = (ushort)((msb << 7) | lsb); if (pitchValue > 16383) { throw new FormatException("Pitch value shouldn't be greater than 16383"); } track.Channels[channel].Events.Add(new PitchBend { AbsoluteTime = absoluteTime, ChannelNumber = channel, PitchValue = pitchValue }); size += 1; break; default: throw new FormatException("Unsupported event type"); } }
/// <summary> /// Composes a solo-melody over this composition's midi playback file and chord progression, /// using the additional preferences and constraints parameters. /// </summary> /// <returns> A new midi file containing the composed solo-melody. </returns> /// <param name="strategy">Requested composition strategy algorithm for composing the melody. </param> /// <param name="overallNoteDurationFeel">Requested generic density overall feeling of the outcome melody.</param> /// <param name="musicalInstrument">Requested virtual music instrumen tha would play the output melody.</param> /// <param name="pitchRangeSource">Determins whether to set the pitch range from the original melody in the /// midi file, or from the custom values mentiones in <paramref name="minPitch"/> /// and <paramref name="maxPitch"/>.</param> /// <param name="minPitch">Requested lowest available pitch that would can be used for the composition. /// This is relevant only if <paramref name="pitchRangeSource"/> was set to /// <see cref="PitchRangeSource.Custom"/>.</param> /// <param name="maxPitch">Requested highest available pitch that would can be used for the composition. /// This is relevant only if <paramref name="pitchRangeSource"/> was set to /// <see cref="PitchRangeSource.Custom"/>.</param> /// <param name="useExistingMelodyAsSeed">If set, then the original melody might be used in initialization phase /// of the compositon strategy algorithm. This is relevant only if the /// midi file contains an existing melody to begin with. /// Moreover, this feature is implementation dependent: some strategies /// might make high use of original melody as the main initialization seed /// and some may not use it at all.</param> /// <param name="customParams"> Currently unused. This a placeholder for additional parameters that could be used /// in the future to extened existing implementations and developing new ones without /// breaking the existing interface. </param> /// <returns></returns> public IMidiFile[] Compose( CompositionStrategy strategy = CompositionStrategy.GeneticAlgorithmStrategy, OverallNoteDurationFeel overallNoteDurationFeel = OverallNoteDurationFeel.Medium, MusicalInstrument musicalInstrument = MusicalInstrument.AcousticGrandPiano, PitchRangeSource pitchRangeSource = PitchRangeSource.Custom, NotePitch minPitch = DefaultMinPitch, NotePitch maxPitch = DefaultMaxPitch, bool useExistingMelodyAsSeed = true, params object[] customParams) { // set compositor according to composition strategy _composer = ComposerFactory.CreateComposer(strategy); // make a copy of the input midi file for the output file MidiOutputFile = MidiFactory.CreateMidiFile(_midiInputFilePath); /* if the midi file already contains a melody track, * extract it out of the intended midi output file * and if requested, save it in a separate bar sequence for further usage * as a melody initialization seed for the composition if needed. */ if (_melodyTrackIndex.HasValue && _melodyTrackIndex.Value != MelodyTrackIndex.NoMelodyTrackInFile) { /* if the existing melody should serve as a seed, * initialize a bar-sequence place-holder for it, * based on the chord progression structure */ _melodySeed = useExistingMelodyAsSeed ? CompositionContext.CloneChordProgressionBars(ChordProgression) : null; /* extract/remove the existing melody from midi file and * save it in the place holder if it was initialized */ MidiOutputFile.ExtractMelodyTrack((byte)_melodyTrackIndex, _melodySeed); } // initialize pitch range from midi file if requested if (pitchRangeSource == PitchRangeSource.MidiFile && _melodyTrackIndex.HasValue) { NotePitch?lowestPitch, highestPitch; MidiInputFile.GetPitchRangeForTrack((int)_melodyTrackIndex, out lowestPitch, out highestPitch); if (lowestPitch.HasValue && highestPitch.HasValue) { minPitch = (NotePitch)lowestPitch; maxPitch = (NotePitch)highestPitch; } } // validate pitch range is at least one octave long (12 semi-tones) if (!IsPitchRangeValid((int)minPitch, (int)maxPitch, out string errorMessage)) { throw new ArgumentException(errorMessage); } // compose a new melody IList <IBar>[] composedMelodies = _composer.Compose( chordProgression: ChordProgression, melodyInitializationSeed: _melodySeed, overallNoteDurationFeel: overallNoteDurationFeel, minPitch: minPitch, maxPitch: maxPitch, customParams: customParams) .ToArray(); // Embed each new generated melody into a new separate midi file IMidiFile[] midiOutputs = new IMidiFile[composedMelodies.Length]; for (int i = 0; i < composedMelodies.Length; i++) { midiOutputs[i] = MidiFactory.CreateMidiFile(_midiInputFilePath); midiOutputs[i].ExtractMelodyTrack((byte)_melodyTrackIndex); midiOutputs[i].EmbedMelody(composedMelodies[i], musicalInstrument); midiOutputs[i].FadeOut(); } // save first output in dedicated placeholder MidiOutputFile = midiOutputs[0]; // return the first composed melody from the output return(midiOutputs); }
/// <summary>Add a specific instument to the equipment collection</summary> /// <param name="instrument">the instrument to add as a string</param> public void AddMusicalinstrumentToEquipment(MusicalInstrument instrument) { MusicalInstruments.Add(instrument); }
private new void ExitAndTip(bool keepWatching) { try { AnimateSim("AfterWatch"); Vector3 position = Actor.Position; if ((mTippingStatus == Tipping.WillTip) && (mPlayInstance != null)) { bool flag = false; if (Actor.ExitReason == ExitReason.Finished) { flag = true; Actor.ClearExitReasons(); } if (Tip(Actor, mPlayer, Target, Tuning.MoneyPerLevel, Tuning.MoneyPerCompositionPlayed)) { mTippingStatus = Tipping.HasTipped; } if (flag) { Actor.AddExitReason(ExitReason.Finished); } } if (keepWatching) { Route r = Actor.CreateRoute(); r.PlanToPoint(position); r.DoRouteFail = false; if (!Actor.DoRoute(r)) { if (mDanceFloor != null) { mDanceFloor.RemoveFromUseList(Actor); mDanceFloor = null; } DanceFloor danceFloor = null; MusicalInstrument.DoRouteForWatchOrDance(Actor, Target, out danceFloor); mDanceFloor = danceFloor; if (mDanceFloor != null) { mDanceFloor.AddToUseList(Actor); } } Actor.RouteTurnToFace(mPlayer.Position); AnimateSim("Watch"); mbIsWatchingRightNow = true; } else { AnimateSim("Exit"); } } catch (ResetException) { throw; } catch (Exception e) { Common.Exception(Actor, Target, e); } }
public override bool Run() { try { mPlayer = Target.ActorsUsingMe[0x0]; bool flag = (mPlayer.Occupation is Music) && (mPlayer.Occupation.Level >= Music.GuitarBonusLevel); DanceFloor danceFloor = null; if (!MusicalInstrument.DoRouteForWatchOrDance(Actor, Target, out danceFloor)) { return(false); } mDanceFloor = danceFloor; if (mDanceFloor != null) { mDanceFloor.AddToUseList(Actor); } mPlayInstance = mPlayer.CurrentInteraction as MusicalInstrument.PlayInstrument <TTarget>; if (mPlayInstance != null) { if (!mPlayInstance.Performing) { return(false); } AddEventListeners(); } if (flag) { BeginCommodityUpdate(CommodityKind.Fun, Music.GuitarBonusFunMultiplier); } BeginCommodityUpdates(); bool success = false; try { AcquireStateMachine(Target.StateMachineName, AnimationPriority.kAPNormal); SetActorAndEnter("x", Actor, "Enter"); AddJamControllerWatchListener(); AnimateSim("Watch"); mbIsWatchingRightNow = true; Target.AddWatcher(); mFriendGainAlarm = Target.AddAlarmRepeating(Tuning.MinutesForLikingGain, TimeUnit.Minutes, new AlarmTimerCallback(GainFriendly), Tuning.MinutesForLikingGain, TimeUnit.Minutes, "Friendship Gain for Watch Music Playing", AlarmType.AlwaysPersisted); MusicSkill element = mPlayer.SkillManager.GetElement(Target.SkillName) as MusicSkill; if (element != null) { element.BeingWatched(); } if (Target.mPlayingForTips && (Actor.IsOutside || Actor.LotCurrent.IsCommunityLot)) { mTipChancePerCheck = Tuning.ChanceOfTipPerLevel[element.SkillLevel]; foreach (TraitNames names in Tuning.TraitsLessLikelyToTip) { if (Actor.TraitManager.HasElement(names)) { mTipChancePerCheck *= Tuning.LessLikelyToTipMultiplier; } } foreach (TraitNames names2 in Tuning.TraitsMoreLikelyToTip) { if (Actor.TraitManager.HasElement(names2)) { mTipChancePerCheck *= Tuning.MoreLikelyToTipMultiplier; } } mGoalTimeToTestTip = Tuning.TimePerTipTest; timeTillTip = RandomUtil.RandomFloatGaussianDistribution(Target.Tuning.ShortestSongLengthForTip, Target.Tuning.LongestSongLengthForTip); success = DoLoop(~(ExitReason.Replan | ExitReason.MidRoutePushRequested | ExitReason.ObjectStateChanged | ExitReason.PlayIdle | ExitReason.MaxSkillPointsReached), new Interaction <Sim, TTarget> .InsideLoopFunction(TippingLoop), mCurrentStateMachine); } else { success = DoLoop(~(ExitReason.Replan | ExitReason.MidRoutePushRequested | ExitReason.ObjectStateChanged | ExitReason.PlayIdle | ExitReason.MaxSkillPointsReached), new Interaction <Sim, TTarget> .InsideLoopFunction(WatchLoopBase), mCurrentStateMachine); } Target.RemoveAlarm(mFriendGainAlarm); Target.RemoveWatcher(); SongFinished(true, mTryToTip); RemoveJamControllerWatchListener(); if (mPlayInstance != null) { RemoveEventListeners(); mPlayInstance = null; } } finally { EndCommodityUpdates(success); } return(success); } catch (ResetException) { throw; } catch (Exception e) { Common.Exception(Actor, Target, e); return(false); } }
public override string GetInteractionName(Sim actor, MusicalInstrument target, InteractionObjectPair iop) { return base.GetInteractionName(actor, target, new InteractionObjectPair(sOldSingleton, target)); }
public static Model Parse(string filename, int frameRateMillis = 50, bool showBeats = false, bool showChords = false, bool randomize = true) { var track = new Track(); var midi = new Model { Tracks = new[] { track } }; byte[] fileBytes = File.ReadAllBytes(filename); var random = new Random(123456); var timeMillis = 0; var beatLength = 12 * frameRateMillis; var actualNotes = new NoteOn[16, 128]; var actualPercussion = new NoteOn[128]; var instrumentsOnChannels = new MusicalInstrument[16]; for (byte i = 0; i < Model.NumberOfChannels; i++) { track.Channels[i].Events.Add(new Controller { AbsoluteRealTime = TimeSpan.Zero, AbsoluteTime = 0, ChannelNumber = i, ControllerNumber = 7, ControllerValue = 64 }); } for (int i = 0; i < fileBytes.Length; i += 4) { var eventType = (EventType)(fileBytes[i] & 0x0F); if (i == 400 * 4) { track.MetaEvents.Add(new ImprovisationStartMetaEvent { AbsoluteRealTime = TimeSpan.FromMilliseconds(timeMillis) }); } switch (eventType) { case EventType.NoteOnEvent: { var channel = (byte)(fileBytes[i] >> 4); var pitch = (byte)(fileBytes[i + 1] + ClusterRanges.Min((InstrumentCluster)channel)); var instrument = (MusicalInstrument)Instrument.TypicalInstrument((InstrumentCluster)channel); var volume = fileBytes[i + 2] / 128.0 - 1; volume = Math.Pow(volume, 2) * Math.Sign(volume); if (randomize) { volume = (byte)(volume * (0.9 + random.NextDouble() * 0.1)); } volume = 64.0 + 64.0 * volume; if (!instrument.Equals(instrumentsOnChannels[channel])) { track.Channels[channel].Events.Add(new InstrumentChange { AbsoluteRealTime = TimeSpan.FromMilliseconds(timeMillis - 1), AbsoluteTime = (uint)(timeMillis / frameRateMillis + 0.5), ChannelNumber = channel, Instrument = instrument }); instrumentsOnChannels[channel] = instrument; } var prevNote = actualNotes[channel, pitch]; if (prevNote != null) { TimeSpan end; if (timeMillis < prevNote.AbsoluteRealTime.TotalMilliseconds + 5000) { end = TimeSpan.FromMilliseconds(timeMillis); } else { end = prevNote.AbsoluteRealTime + TimeSpan.FromMilliseconds(5000); } prevNote.End = end; prevNote.RealTimeLength = end - prevNote.AbsoluteRealTime; prevNote.Length = (uint)(prevNote.RealTimeLength.TotalMilliseconds / frameRateMillis); track.Channels[prevNote.ChannelNumber].Events.Add(new NoteOff { ChannelNumber = prevNote.ChannelNumber, AbsoluteRealTime = prevNote.End, AbsoluteTime = (uint)(timeMillis / frameRateMillis + 0.5), NoteNumber = prevNote.NoteNumber, Velocity = 64 }); } var note = new NoteOn { ChannelNumber = channel, NoteNumber = pitch, Volume = (byte)Calc.Clamp((int)(volume + 0.5), 0, 127), AbsoluteTime = (uint)(timeMillis / frameRateMillis + 0.5), Length = (uint)(4800 / frameRateMillis), AbsoluteRealTime = TimeSpan.FromMilliseconds(timeMillis), End = TimeSpan.FromMilliseconds(timeMillis + 4800), RealTimeLength = TimeSpan.FromMilliseconds(4800) }; track.Channels[channel].Events.Add(note); actualNotes[channel, pitch] = note; break; } case EventType.NoteOffEvent: { var channel = (byte)fileBytes[i + 2]; var pitch = (byte)(fileBytes[i + 1] + ClusterRanges.Min((InstrumentCluster)channel)); var note = actualNotes[channel, pitch]; if (note == null) //throw new Exception("neni na co navazovat"); { continue; } TimeSpan end; if (timeMillis < note.AbsoluteRealTime.TotalMilliseconds + 5000) { end = TimeSpan.FromMilliseconds(timeMillis); } else { end = note.AbsoluteRealTime + TimeSpan.FromMilliseconds(5000); } note.End = end; note.RealTimeLength = end - note.AbsoluteRealTime; note.Length = (uint)(note.RealTimeLength.TotalMilliseconds / frameRateMillis); track.Channels[note.ChannelNumber].Events.Add(new NoteOff { ChannelNumber = note.ChannelNumber, AbsoluteRealTime = note.End, AbsoluteTime = (uint)(timeMillis / frameRateMillis + 0.5), NoteNumber = note.NoteNumber, Velocity = 64 }); actualNotes[channel, pitch] = null; break; } case EventType.PercussionOnEvent: { var percussionType = (byte)(fileBytes[i + 1] + Percussion.MinNoteNumber); //var volume = (byte)(clusterVolumes[InstrumentCluster.Percussion] * 128.0); var volume = fileBytes[i + 2] / 128.0 - 1; volume = Math.Pow(volume, 2) * Math.Sign(volume); if (randomize) { volume = (byte)(volume * (0.9 + random.NextDouble() * 0.1)); } volume = 64.0 + 64.0 * volume; var prevNote = actualPercussion[percussionType]; if (prevNote != null) { TimeSpan end; if (timeMillis < prevNote.AbsoluteRealTime.TotalMilliseconds + 4800) { end = TimeSpan.FromMilliseconds(timeMillis); } else { end = prevNote.AbsoluteRealTime + TimeSpan.FromMilliseconds(4800); } prevNote.End = end; prevNote.RealTimeLength = end - prevNote.AbsoluteRealTime; prevNote.Length = (uint)(prevNote.RealTimeLength.TotalMilliseconds / frameRateMillis); track.Channels[prevNote.ChannelNumber].Events.Add(new NoteOff { ChannelNumber = prevNote.ChannelNumber, AbsoluteRealTime = prevNote.End, AbsoluteTime = (uint)(timeMillis / frameRateMillis + 0.5), NoteNumber = prevNote.NoteNumber, Velocity = 64 }); } var note = new NoteOn { ChannelNumber = Channel.PercussionChannelNumber, NoteNumber = percussionType, Volume = (byte)Calc.Clamp((int)(volume + 0.5), 0, 127), AbsoluteTime = (uint)(timeMillis / frameRateMillis + 0.5), Length = (uint)(4800 / frameRateMillis), AbsoluteRealTime = TimeSpan.FromMilliseconds(timeMillis), End = TimeSpan.FromMilliseconds(timeMillis + 4800), RealTimeLength = TimeSpan.FromMilliseconds(4800) }; track.Channels[Channel.PercussionChannelNumber].Events.Add(note); actualPercussion[percussionType] = note; break; } case EventType.PercussionOffEvent: { var percussionType = (byte)(fileBytes[i + 1] + Percussion.MinNoteNumber); var percussion = actualPercussion[percussionType]; if (percussion == null) //throw new Exception("neni na co navazovat"); { continue; } TimeSpan end; if (timeMillis < percussion.AbsoluteRealTime.TotalMilliseconds + 4800) { end = TimeSpan.FromMilliseconds(timeMillis); } else { end = percussion.AbsoluteRealTime + TimeSpan.FromMilliseconds(4800); } percussion.End = end; percussion.RealTimeLength = end - percussion.AbsoluteRealTime; percussion.Length = (uint)(percussion.RealTimeLength.TotalMilliseconds / frameRateMillis); track.Channels[percussion.ChannelNumber].Events.Add(new NoteOff { ChannelNumber = percussion.ChannelNumber, AbsoluteRealTime = percussion.End, AbsoluteTime = (uint)(timeMillis / frameRateMillis + 0.5), NoteNumber = percussion.NoteNumber, Velocity = 64 }); actualPercussion[percussionType] = null; break; } case EventType.SmallSpaceEvent: { var tempo = fileBytes[i + 1] | fileBytes[i + 2] << 8; var chord = fileBytes[i + 3]; if (timeMillis % beatLength == 0 && chord != 24) { var beat = new BeatEvent { AbsoluteTime = (uint)(timeMillis / frameRateMillis + 0.5 + beatLength), AbsoluteRealTime = TimeSpan.FromMilliseconds(timeMillis + beatLength), Length = TimeSpan.FromMilliseconds(beatLength), Chord = new Key(chord), Level = 2 }; track.MetaEvents.Add(beat); } timeMillis += frameRateMillis /** tempo / 600.0*/; break; } case EventType.BigSpaceEvent: { var tempo = fileBytes[i + 1] | fileBytes[i + 2] << 8; var chord = fileBytes[i + 3]; if (timeMillis % beatLength == 0 && chord != 24) { var beat = new BeatEvent { AbsoluteTime = (uint)(timeMillis / frameRateMillis + 0.5 + beatLength), AbsoluteRealTime = TimeSpan.FromMilliseconds(timeMillis + beatLength), Length = TimeSpan.FromMilliseconds(beatLength), Chord = new Key(chord), Level = 2 }; track.MetaEvents.Add(beat); } timeMillis += frameRateMillis * 6 /** tempo / 600.0*/; break; } case EventType.EndEvent: { timeMillis += frameRateMillis * 200; break; } } } track.MetaEvents.Add(new EndOfTrack { AbsoluteRealTime = TimeSpan.FromMilliseconds(timeMillis + 1200) }); { var collector = new VolumeChangeCollector(midi); collector.DetermineVolumes(); } { var collector = new InstrumentChangeCollector(midi); collector.DetermineInstruments(); } if (showBeats) { Normalizer.AddBeats(midi, false, 32); } if (showChords) { var analyzer = new ChordAnalyzer(midi); analyzer.AddChordNotesToModel(48); } if (randomize) { foreach (var note in midi.EventsOfType <NoteOn>()) { var startOffset = random.Next(10); var lengthChange = 0.1 * random.NextDouble() * note.RealTimeLength.TotalMilliseconds; note.AbsoluteRealTime += TimeSpan.FromMilliseconds(startOffset); note.RealTimeLength -= TimeSpan.FromMilliseconds(lengthChange); note.End -= TimeSpan.FromMilliseconds(startOffset + lengthChange); } } ChannelPlayabilityChecker.Check(midi); midi.Length = midi.EventsOfType <EndOfTrack>().Max(e => e.AbsoluteRealTime); return(midi); }
public override string GetInteractionName(Sim actor, MusicalInstrument target, InteractionObjectPair iop) { return(base.GetInteractionName(actor, target, new InteractionObjectPair(sOldSingleton, target))); }
private void cBoxInstruments_SelectedIndexChanged(object sender, EventArgs e) { _musicalInstrument = (MusicalInstrument)cBoxInstruments.SelectedItem; }