void Start() { mat = new Material(Shader.Find("Sprites/Default")); var root = new GameObject(); root.transform.parent = gameObject.transform; root.name = "Music Layers"; stingerSource = root.AddComponent <AudioSource>(); stingerSource.spatialBlend = 0.0f; stingerSource.dopplerLevel = 0.0f; stingerSource.outputAudioMixerGroup = stingerMixerGroup; for (int n = 0; n < layers.Length; n++) { layers[n] = new MusicLayer(n, root, "Layer " + (n + 1)); } currSegment = startSegment; nextSegment = startSegment; if (currSegment.mixerSnapshot != null) { currSegment.mixerSnapshot.TransitionTo(currSegment.snapshotTransitionTime); } FindAllSegments(startSegment); startTime = AudioSettings.dspTime; nextSegmentStartTime = startTime + 2.0; // It may take some time before we are done initializing all game objects }
public void DeleteMusicSegment(MusicSegmentViewModel segmentVM) { MusicSegment segment = segmentVM.GetModel(); if (segment.GetIndex() == 0) { return; } foreach (var b in model.Blocks) { if (b.SegmentContext == segment) { b.SegmentContext = model.MusicSegments[0]; } } if (model.DefaultMusicSegment == segment) { model.DefaultMusicSegment = model.MusicSegments[0]; } if (ActiveMusicSegment == segmentVM) { ActiveMusicSegment = MusicSegments[model.DefaultMusicSegment.GetIndex()]; } model.MusicSegments.Remove(segment); }
public void GroupSelectedBlocks() { if (!SelectedBlocks.Any()) { return; } var relatedSegments = Enumerable.Select(SelectedBlocks, b => b.SegmentContext).Distinct().ToList(); MusicSegment segmentForGroup = (relatedSegments.Count == 1 ? relatedSegments.Single().GetModel() : model.MusicSegments[0]); var group = new LoopBlock(model); group.SegmentContext = segmentForGroup; group.StartTime = SelectedBlocks.Min(b => b.StartTime); foreach (var b in SelectedBlocks) { // create an independent copy of the block so transforming its time to local reference frame does not screw up undo Block newChild = Block.FromXML(model, b.GetModel().ToXML()); group.AddChild(newChild, true); } using (ActionManager.CreateTransaction()) { DeleteSelectedBlocks(); ActionManager.RecordAdd(model.Blocks, group); } SelectBlock(BlockViewModel.FromModel(this, group), CompositionMode.None); }
public void TransitionTo(MusicSegment s) { nextSegment = (s != null) ? s : currSegment.transitions[random.Next(0, currSegment.transitions.Length)]; float beatLength = 60.0f / currSegment.bpm; double len = currSegment.lengthInBeats * beatLength; nextSegmentStartTime = currSegmentStartTime + len + nextSegment.startTime * beatLength; }
public MusicSegmentViewModel AddMusicSegment() { var newSegment = new MusicSegment(model) { Label = "Unnamed", Bpm = 120, BeatsPerBar = 4, TimeOrigin = 0 }; model.MusicSegments.Add(newSegment); // should be logically equivalent to MusicSegments.Last() return(MusicSegments.Single(segVm => segVm.GetModel() == newSegment)); }
void Update() { double currTime = AudioSettings.dspTime; if (currSegment != null) { if (currTime + prefetchTime >= nextSegmentStartTime) { currSegment = nextSegment; nextSegment = currSegment.transitions[random.Next(0, currSegment.transitions.Length)]; if (currSegment.mixerSnapshot != null) { currSegment.mixerSnapshot.TransitionTo(currSegment.snapshotTransitionTime); } float beatLength = 60.0f / currSegment.bpm; double len = currSegment.lengthInBeats * beatLength; for (int n = 0; n < layers.Length; n++) { layers[n].NextClip(this); if (n == 0 && layers[n].currDebugRect != null) { DrawStuff.AddTextMesh(gameObject, layers[n].currDebugRect.x1, -3.0f, currSegment.name); } } currSegmentStartTime = nextSegmentStartTime; nextSegmentStartTime += len + nextSegment.startTime * beatLength; } for (int n = 0; n < layers.Length; n++) { layers[n].Update(this, currTime); } } foreach (var s in scheduledStingers) { if (s.time < currTime) { stingerSource.PlayOneShot(s.clip, s.level); s.disposed = true; } } scheduledStingers.RemoveAll(item => item.disposed); if (camera != null) { camPosition += (camTarget - camPosition) * 0.02f; camera.transform.position = new Vector3(camPosition, camera.transform.position.y, camera.transform.position.z); } }
public static MusicSegment ParseMusicSegment(byte[] data) { using (var reader = new BinaryReader(new MemoryStream(data))) { var musicSegment = new MusicSegment(data.Length); musicSegment.Id = reader.ReadUInt32(); musicSegment.MidiBehavior = (MidiInteractiveMusicBehavior)reader.ReadByte(); musicSegment.Properties = reader.ReadAudioProperties(); musicSegment.ChildCount = reader.ReadUInt32(); musicSegment.ChildIds = new uint[musicSegment.ChildCount]; for (var i = 0; i < musicSegment.ChildCount; i++) { musicSegment.ChildIds[i] = reader.ReadUInt32(); } musicSegment.GridPeriodTime = reader.ReadDouble(); musicSegment.GridOffsetTime = reader.ReadDouble(); musicSegment.Tempo = reader.ReadSingle(); musicSegment.TimeSignatureUpper = reader.ReadByte(); musicSegment.TimeSignatureLower = reader.ReadByte(); musicSegment.Unknown = reader.ReadByte(); musicSegment.StingerCount = reader.ReadUInt32(); musicSegment.Stingers = new Stinger[musicSegment.StingerCount]; for (var i = 0; i < musicSegment.StingerCount; i++) { Stinger stinger = default; stinger.TriggerId = reader.ReadUInt32(); stinger.SegmentId = reader.ReadUInt32(); stinger.PlayAt = (StingerKeyPoint)reader.ReadUInt32(); stinger.CueId = reader.ReadUInt32(); stinger.DoNotRepeatIn = reader.ReadUInt32(); stinger.AllowPlayingInNextSegment = reader.ReadUInt32() == 1; musicSegment.Stingers[i] = stinger; } musicSegment.EndTrimOffset = reader.ReadDouble(); musicSegment.MusicCueCount = reader.ReadUInt32(); musicSegment.MusicCues = new MusicCue[musicSegment.MusicCueCount]; for (var i = 0; i < musicSegment.MusicCueCount; i++) { MusicCue musicCue = default; musicCue.Id = reader.ReadUInt32(); musicCue.Time = reader.ReadDouble(); musicCue.CustomNameLength = reader.ReadUInt32(); if (musicCue.CustomNameLength > 0) { musicCue.CustomName = String.Concat(reader.ReadChars((int)musicCue.CustomNameLength - 1)); reader.BaseStream.Position++; // Skip null byte } musicSegment.MusicCues[i] = musicCue; } return(musicSegment); } }
void FindAllSegments(MusicSegment segment) { List <MusicSegment> newSegments = new List <MusicSegment>(); if (!allSegments.Contains(segment)) { allSegments.Add(segment); } foreach (var s in segment.transitions) { if (!allSegments.Contains(s)) { newSegments.Add(s); } } if (newSegments.Count > 0) { allSegments.AddRange(newSegments); foreach (var s in newSegments) { FindAllSegments(s); } } }
public HIRCObject(BNK mainBnk, BinaryReader br) { Bnk = mainBnk; if (!hircError.errorOccured) { int type = br.ReadByte(); LastPos = br.BaseStream.Position; switch (type) { case 1: SettingsObject = new Settings(br, type); break; case 2: SoundSFXObject = new SoundSFX(this, br, type); break; case 3: EventAction = new EventAction(this, br, type); break; case 4: Event = new Event(this, br, type); break; case 5: RandomContainer = new RandomContainer(this, br, type); break; case 6: SwitchContainer = new SwitchContainer(this, br, type); break; case 7: ActorMixer = new ActorMixer(this, br, type); break; case 8: AudioBus = new AudioBus(this, br, type); break; case 9: BlendContainer = new BlendContainer(this, br, type); break; case 10: MusicSegment = new MusicSegment(this, br, type); break; case 11: MusicTrack = new MusicTrack(this, br, type); break; case 12: MusicSwitchContainer = new MusicSwitchContainer(this, br, type); break; case 13: MusicSequence = new MusicSequence(this, br, type); break; case 14: Attenuation = new Attenuation(br, type); break; case 16: FeedbackBus = new FeedbackBus(this, br, type); break; case 17: FeedbackNode = new FeedbackNode(this, br, type); break; case 18: FxShareSet = new FxShareSet(this, br, type); break; case 19: FxCustom = new FxCustom(this, br, type); break; case 20: AuxiliaryBus = new AuxiliaryBus(this, br, type); break; case 21: LFO = new LFO(br, type); break; case 22: Envelope = new Envelope(br, type); break; default: int length = br.ReadInt32(); br.BaseStream.Position -= 5; Data = br.ReadBytes(length + 5); System.Windows.MessageBox.Show("Detected unkown HIRC Object type at: " + (LastPos - 1).ToString("X"), "Toolkit"); break; } } }
public int GetLength() { int length = 5; if (SettingsObject != null) { length += SettingsObject.GetLength(); } else if (SoundSFXObject != null) { length += SoundSFXObject.GetLength(); } else if (EventAction != null) { length += EventAction.GetLength(); } else if (Event != null) { length += Event.GetLength(); } else if (RandomContainer != null) { length += RandomContainer.GetLength(); } else if (SwitchContainer != null) { length += SwitchContainer.GetLength(); } else if (ActorMixer != null) { length += ActorMixer.GetLength(); } else if (AudioBus != null) { length += AudioBus.GetLength(); } else if (BlendContainer != null) { length += BlendContainer.GetLength(); } else if (MusicSegment != null) { length += MusicSegment.GetLength(); } else if (MusicTrack != null) { length += MusicTrack.GetLength(); } else if (MusicSwitchContainer != null) { length += MusicSwitchContainer.GetLength(); } else if (MusicSequence != null) { length += MusicSequence.GetLength(); } else if (Attenuation != null) { length += Attenuation.GetLength(); } else if (FeedbackNode != null) { length += FeedbackNode.GetLength(); } else if (FxShareSet != null) { length += FxShareSet.GetLength(); } else if (FxCustom != null) { length += FxCustom.GetLength(); } else if (AuxiliaryBus != null) { length += AuxiliaryBus.GetLength(); } else if (LFO != null) { length += LFO.GetLength(); } else if (Envelope != null) { length += Envelope.GetLength(); } else if (FeedbackBus != null) { length += FeedbackBus.GetLength(); } else { if (Data != null) { length += Data.Length; } else { length = -1; } } return(length); }
public static TimeUnit WrapAbsolute(float?seconds, MusicSegment musicData, Action <float> setter = null) { return(new TimeUnit { _seconds = seconds, _setter = setter, _musicData = musicData, _absolute = true }); }