Exemplo n.º 1
0
 public bool LoadMidi(MidiFile midi, bool UnloadUnusedInstruments)
 {
     if (playing == true)
         return false;
     _MidiFile = midi;
     if (_MidiFile.SequencerReady == false)
     {
         try
         {
             //Combine all tracks into 1 track that is organized from lowest to highest abs time
             _MidiFile.CombineTracks();
             //Convert delta time to sample time
             eventIndex = 0;
             uint lastSample = 0;
             for (int x = 0; x < _MidiFile.Tracks[0].MidiEvents.Length; x++)
             {
                 _MidiFile.Tracks[0].MidiEvents[x].deltaTime = lastSample + (uint)DeltaTimetoSamples(_MidiFile.Tracks[0].MidiEvents[x].deltaTime);
                 lastSample = _MidiFile.Tracks[0].MidiEvents[x].deltaTime;
                 //Update tempo
                 if (_MidiFile.Tracks[0].MidiEvents[x].midiMetaEvent == MidiHelper.MidiMetaEvent.Tempo)
                 {
                     _MidiFile.BeatsPerMinute = MidiHelper.MicroSecondsPerMinute / System.Convert.ToUInt32(_MidiFile.Tracks[0].MidiEvents[x].Parameters[0]);
                 }
             }
             //Set total time to proper value
             _MidiFile.Tracks[0].TotalTime = _MidiFile.Tracks[0].MidiEvents[_MidiFile.Tracks[0].MidiEvents.Length-1].deltaTime;
             //reset tempo
             _MidiFile.BeatsPerMinute = 120;
             //mark midi as ready for sequencing
             _MidiFile.SequencerReady = true;
         }
         catch (Exception ex)
         {
             //UnitySynth
             Debug.Log("Error Loading Midi:\n" + ex.Message);
             return false;
         }
     }
     blockList.Clear();
     if (UnloadUnusedInstruments == true)
     {
         if (synth.SoundBank == null)
         {//If there is no bank warn the developer =)
             Debug.Log("No Soundbank loaded !");
         }
         else
         {
             string bankStr = synth.SoundBank.BankPath;
             //Remove old bank being used by synth
             synth.UnloadBank();
             //Add the bank and switch to it with the synth
             BankManager.addBank(new InstrumentBank(synth.SampleRate, bankStr, _MidiFile.Tracks[0].Programs, _MidiFile.Tracks[0].DrumPrograms));
             synth.SwitchBank(BankManager.Count - 1);
         }
     }
     return true;
 }
Exemplo n.º 2
0
        public void AddTracks(MidiFile file)
        {
            List<MidiTrack> trackList = new List<MidiTrack>();
            foreach (MidiTrack track in tracks) {
                trackList.Add(track);
            }

            foreach (MidiTrack track in file.tracks) {
                trackList.Add(track);
            }

            tracks = trackList.ToArray();
        }
Exemplo n.º 3
0
 public void Dispose()
 {
     Stop(true);
     //Set anything that may become a circular reference to null...
     synth = null;
     _MidiFile = null;
     seqEvt = null;
 }
Exemplo n.º 4
0
 public bool LoadMidi(string file, bool UnloadUnusedInstruments)
 {
     if (playing == true)
         return false;
     MidiFile mf = null;
     try
     {
         mf = new MidiFile(file);
     }
     catch (Exception ex)
     {
         //UnitySynth
         Debug.Log("Error Loading Midi:\n" + ex.Message);
         return false;
     }
     return LoadMidi(mf, UnloadUnusedInstruments);
 }
Exemplo n.º 5
0
 public bool LoadMidi(string file, bool UnloadUnusedInstruments)
 {
     if (playing == true)
         return false;
     MidiFile mf = null;
     try
     {
         mf = new MidiFile(file);
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine("Error Loading Midi:\n" + ex.Message);
         return false;
     }
     return LoadMidi(mf, UnloadUnusedInstruments);
 }
Exemplo n.º 6
0
    public void PlayLevelMusic(GMD stalk, GMD fight)
    {
        _bIsPlayingLevelMusic = true;

        MidiFile stalkMidi = new MidiFile(stalk.MidiData);

        _stalkSequences = new MusicSequences();
        _stalkSequences.FirstTrack = 0;
        _stalkSequences.NumTracks = stalkMidi.Tracks.Length;

        foreach (var Track in stalkMidi.Tracks) {
            _stalkSequences.TrackSections.Add(Track.Sections);
        }

        if (fight != null) {
            MidiFile fightMidi = new MidiFile(fight.MidiData);

            _fightSequences = new MusicSequences();
            _fightSequences.FirstTrack = _stalkSequences.NumTracks;
            _fightSequences.NumTracks = fightMidi.Tracks.Length;

            foreach (var Track in fightMidi.Tracks) {
                _fightSequences.TrackSections.Add(Track.Sections);
            }

            // merge
            stalkMidi.AddTracks(fightMidi);
        }

        PitchTo(0f, 0f);

        lock (this) {
            _midiSequencer.LoadMidi(stalkMidi, false);
            _currentTrack = 0;
            _currentSection = _stalkSequences.TrackSections[0][0];
            _midiSequencer.Play();
            _midiSequencer.SwitchSection(_currentTrack, _currentSection, 0f);
        }
    }
Exemplo n.º 7
0
 public bool LoadMidi(byte[] filecontent, bool UnloadUnusedInstruments)
 {
     if (playing == true)
         return false;
     MidiFile mf = new MidiFile(filecontent);
     return LoadMidi(mf, UnloadUnusedInstruments);
 }