Ejemplo n.º 1
0
    public void Play(bool isPlayback = false)
    {
        KeepScaleOscillators();
        Stop();
        m_IsPlayback          = isPlayback;
        m_PlayMelodyCoroutine = PlayMelody();

        if (!m_IsPlayback)
        {
            m_CurrentMusicSequence = new MusicSequence
            {
                m_Bpm            = m_Bpm,
                m_Scale          = m_Scale,
                m_DefaultVolume  = m_DefaultVolume,
                m_TimeMultiplier = m_TimeMultiplier,
                m_BeatsPerBar    = m_BeatsPerBar,
                m_MusicUnits     = new Queue <MusicUnit>(),
            };

            float barsPerMin = m_Bpm / m_BeatsPerBar;
            float barsPerSec = barsPerMin / 60;
            int   barsToKeep = Mathf.CeilToInt(barsPerSec * m_SecondsToKeep);
            m_MaxMusicUnitsToKeep = barsToKeep * m_BeatsPerBar;
        }
        else
        {
            m_Bpm            = m_CurrentMusicSequence.m_Bpm;
            m_Scale          = m_CurrentMusicSequence.m_Scale;
            m_DefaultVolume  = m_CurrentMusicSequence.m_DefaultVolume;
            m_TimeMultiplier = m_CurrentMusicSequence.m_TimeMultiplier;
            m_BeatsPerBar    = m_CurrentMusicSequence.m_BeatsPerBar;
        }

        StartCoroutine(m_PlayMelodyCoroutine);
    }
Ejemplo n.º 2
0
 public void Defaults()
 {
     using (var ms = new MusicSequence()) {
         Assert.NotNull(ms.AUGraph, "AUGraph");
         Assert.That(ms.Handle, Is.Not.EqualTo(IntPtr.Zero), "Handle");
         Assert.That(ms.SequenceType, Is.EqualTo(MusicSequenceType.Beats), "SequenceType");
         Assert.That(ms.TrackCount, Is.EqualTo(0), "TrackCount");
     }
 }
Ejemplo n.º 3
0
        public void SMPTEResolution()
        {
            // calls are CF_INLINE (in header files) which means it can't be p/invoked
            // it will throw EntryPointNotFoundException since it's not part of the library
            using (var ms = new MusicSequence()) {
                sbyte fps;
                byte  ticks;
                ms.GetSmpteResolution(Int16.MaxValue, out fps, out ticks);
                Assert.That(fps, Is.EqualTo(127), "fps");
                Assert.That(ticks, Is.EqualTo(127), "ticks");

                // not a roundtip - but identical to ObjC results
                Assert.That(ms.SetSmpteResolution(fps, ticks), Is.EqualTo(-32385), "set");
            }
        }
Ejemplo n.º 4
0
    private void Awake()
    {
        m_Rhythms  = GetComponent <Rhythms>();
        m_Bpm      = 120.0f;
        m_NextWait = 1;

        m_CurrentMusicSequence = new MusicSequence
        {
            m_Bpm            = m_Bpm,
            m_Scale          = m_Scale,
            m_DefaultVolume  = m_DefaultVolume,
            m_TimeMultiplier = m_TimeMultiplier,
            m_BeatsPerBar    = m_BeatsPerBar,
            m_MusicUnits     = new Queue <MusicUnit>(),
        };
    }
Ejemplo n.º 5
0
    public void Load()
    {
        string     destination = Application.persistentDataPath + "/save.dat";
        FileStream file;

        if (File.Exists(destination))
        {
            file = File.OpenRead(destination);
        }
        else
        {
            m_ToasterManager.ShowToast("Save not found!");
            return;
        }

        var bf = new BinaryFormatter();

        m_MusicSequencePlayback = (MusicSequence)bf.Deserialize(file);
        file.Close();

        // Begin Playback
        m_IsPlayback = true;
        m_LoadButton.interactable = false;
        m_SaveButton.interactable = false;
        m_QuitPlaybackButtonGameObject.SetActive(true);
        m_QuitPlaybackButton.interactable  = true;
        m_SettingsCanvasGroup.alpha        = 0.2f;
        m_SettingsCanvasGroup.interactable = false;
        m_PlaybackLabel.enabled            = true;
        m_LoadSaveCanvasGroup.alpha        = 0;
        m_LoadSaveCanvasGroup.interactable = false;
        if (!m_IsPlaying)
        {
            TogglePlay();
        }
        else
        {
            Replay();
        }
    }
Ejemplo n.º 6
0
		public async void MidiTest (UILabel label)
		{
			this.label = label;
			CreateAUGraph ();
			ConfigureAndStartAudioProcessingGraph (processingGraph);

			virtualMidi = new MidiClient ("VirtualClient");
			virtualMidi.IOError += (object sender, IOErrorEventArgs e) => {
				Console.WriteLine ("IO Error, messageId={0}", e.ErrorCode);
			};

			virtualMidi.PropertyChanged += (object sender, ObjectPropertyChangedEventArgs e) => {
				Console.WriteLine ("Property changed: " + e.MidiObject + ", " + e.PropertyName);
			};

			MidiError error;
			virtualEndpoint = virtualMidi.CreateVirtualDestination ("Virtual Destination", out error);

			if (error != MidiError.Ok)
				throw new Exception ("Error creating virtual destination: " + error);
			virtualEndpoint.MessageReceived += MidiMessageReceived;

			var sequence = new MusicSequence ();

			var midiFilePath = NSBundle.MainBundle.PathForResource ("simpletest", "mid");
			var midiFileurl = NSUrl.FromFilename (midiFilePath);

			sequence.LoadFile (midiFileurl, MusicSequenceFileTypeID.Midi);

			var player = new MusicPlayer ();

			sequence.SetMidiEndpoint (virtualEndpoint);

			var presetUrl = CFUrl.FromFile (NSBundle.MainBundle.PathForResource ("Gorts_Filters", "sf2"));

			LoadFromDLSOrSoundFont (presetUrl, 10);

			player.MusicSequence = sequence;
			player.Preroll ();
			player.Start ();

			MusicTrack track;
			track = sequence.GetTrack (1);
			var length = track.TrackLength;

			while (true) {
				await Task.Delay (TimeSpan.FromSeconds (3));
				double now = player.Time;
				if (now > length)
					break;
			}

			player.Stop ();
			sequence.Dispose ();
			player.Dispose ();
			label.Text = "Done";
		}
Ejemplo n.º 7
0
 public MusicSequenceEventArgs(int index, MusicSequence sequence)
 {
     Index    = index;
     Sequence = sequence;
 }
Ejemplo n.º 8
0
        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;
                }
            }
        }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
 public void SetUp()
 {
     sequence = new MusicSequence();
     track    = MusicTrack.FromSequence(sequence);
 }
Ejemplo n.º 11
0
        public async void MidiTest(UILabel label)
        {
            this.label = label;
            CreateAUGraph();
            ConfigureAndStartAudioProcessingGraph(processingGraph);

            virtualMidi          = new MidiClient("VirtualClient");
            virtualMidi.IOError += (object sender, IOErrorEventArgs e) => {
                Console.WriteLine("IO Error, messageId={0}", e.ErrorCode);
            };

            virtualMidi.PropertyChanged += (object sender, ObjectPropertyChangedEventArgs e) => {
                Console.WriteLine("Property changed: " + e.MidiObject + ", " + e.PropertyName);
            };

            MidiError error;

            virtualEndpoint = virtualMidi.CreateVirtualDestination("Virtual Destination", out error);

            if (error != MidiError.Ok)
            {
                throw new Exception("Error creating virtual destination: " + error);
            }
            virtualEndpoint.MessageReceived += MidiMessageReceived;

            var sequence = new MusicSequence();

            var midiFilePath = NSBundle.MainBundle.PathForResource("simpletest", "mid");
            var midiFileurl  = NSUrl.FromFilename(midiFilePath);

            sequence.LoadFile(midiFileurl, MusicSequenceFileTypeID.Midi);

            var player = new MusicPlayer();

            sequence.SetMidiEndpoint(virtualEndpoint);

            var presetUrl = CFUrl.FromFile(NSBundle.MainBundle.PathForResource("gorts_filters", "sf2"));

            LoadFromDLSOrSoundFont(presetUrl, 10);

            player.MusicSequence = sequence;
            player.Preroll();
            player.Start();

            MusicTrack track;

            track = sequence.GetTrack(1);
            var length = track.TrackLength;

            while (true)
            {
                await Task.Delay(TimeSpan.FromSeconds(3));

                double now = player.Time;
                if (now > length)
                {
                    break;
                }
            }

            player.Stop();
            sequence.Dispose();
            player.Dispose();
            label.Text = "Done";
        }
Ejemplo n.º 12
0
        /// <summary>
        /// The details.
        /// </summary>
        /// <param name="id">
        /// The music sequence's id.
        /// </param>
        /// <returns>
        /// The <see cref="System.Threading.Tasks.Task"/>.
        /// </returns>
        public async Task <ActionResult> Details(long?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            using (var db = new LibiadaWebEntities())
            {
                MusicSequence musicSequence = db.MusicSequence.Include(m => m.Matter).Single(m => m.Id == id);
                if (musicSequence == null)
                {
                    return(HttpNotFound());
                }

                var musicChainAlphabet = db.GetAlphabetElementIds(musicSequence.Id)
                                         .Select(el => db.Fmotif.Single(f => f.Id == el))
                                         .ToList();
                var musicChainBuilding = db.GetSequenceBuilding(musicSequence.Id);
                var sortedFmotifs      = new Dictionary <LibiadaWeb.Fmotif, int>();
                for (int i = 0; i < musicChainAlphabet.Count; i++)
                {
                    sortedFmotifs.Add(musicChainAlphabet[i], musicChainBuilding.Count(el => el == i + 1));
                }
                sortedFmotifs = sortedFmotifs.OrderByDescending(pair => pair.Value)
                                .ToDictionary(pair => pair.Key, pair => pair.Value);

                var fmotifsChain = new List <Fmotif>();
                foreach (var fmotif in sortedFmotifs.Keys)
                {
                    var newFmotif = new Fmotif(fmotif.FmotifType, musicSequence.PauseTreatment, fmotif.Id);

                    var fmotifAlphabet = db.GetFmotifAlphabet(fmotif.Id);
                    var fmotifBuilding = db.GetFmotifBuilding(fmotif.Id);
                    foreach (var position in fmotifBuilding)
                    {
                        var dbNoteId   = fmotifAlphabet.ElementAt(position - 1);
                        var dbNote     = db.Note.Single(n => n.Id == dbNoteId);
                        var newPitches = new List <Pitch>();
                        foreach (var pitch in dbNote.Pitch)
                        {
                            newPitches.Add(new Pitch(pitch.Midinumber));
                        }

                        var newNote = new ValueNote(newPitches,
                                                    new Duration(dbNote.Numerator, dbNote.Denominator),
                                                    dbNote.Triplet,
                                                    dbNote.Tie);
                        newNote.Id = dbNote.Id;
                        newFmotif.NoteList.Add(newNote);
                    }
                    fmotifsChain.Add(newFmotif);
                }
                var result = new Dictionary <string, object> {
                    { "fmotifs", fmotifsChain },
                    { "sequentialTransfer", musicSequence.SequentialTransfer }
                };
                ViewBag.data = JsonConvert.SerializeObject(new Dictionary <string, object> {
                    { "data", result }
                });
                return(View(musicSequence));
            }
        }