Beispiel #1
0
 public MidiImporter()
 {
     AudioTools.GenerateProgramMap();
 }
Beispiel #2
0
        public void PostProcess(string name, ref Block[] blocks)
        {
            // playback IO
            LogicGate startConnector = blocks[blocks.Length - 3].Specialise <LogicGate>();
            LogicGate stopConnector  = blocks[blocks.Length - 2].Specialise <LogicGate>();
            LogicGate resetConnector = blocks[blocks.Length - 1].Specialise <LogicGate>();
            uint      count          = 0;

            // generate channel data
            byte[] channelPrograms = new byte[16];
            for (byte i = 0; i < channelPrograms.Length; i++) // init array
            {
                channelPrograms[i] = 5;                       // Piano
            }

            foreach (TimedEvent e in openFiles[name].GetTimedEvents())
            {
                if (e.Event.EventType == MidiEventType.ProgramChange)
                {
                    ProgramChangeEvent pce = (ProgramChangeEvent)e.Event;
                    channelPrograms[pce.Channel] = AudioTools.TrackType(pce.ProgramNumber);
#if DEBUG
                    Logging.MetaLog($"Detected channel {pce.Channel} as program {pce.ProgramNumber} (index {channelPrograms[pce.Channel]})");
#endif
                }
            }

            Timer t = null;
            //count = 0;
            foreach (Note n in openFiles[name].GetNotes())
            {
                while (blocks[count].Type == BlockIDs.Timer)
                {
                    // set timing info
#if DEBUG
                    Logging.Log($"Handling Timer for notes at {n.TimeAs<MetricTimeSpan>(openFiles[name].GetTempoMap()).TotalMicroseconds * 0.000001f}s");
#endif
                    t       = blocks[count].Specialise <Timer>();
                    t.Start = 0;
                    t.End   = 0.01f + n.TimeAs <MetricTimeSpan>(openFiles[name].GetTempoMap()).TotalMicroseconds * 0.000001f;
                    count++;
                }
                // set notes info
                SfxBlock sfx = blocks[count].Specialise <SfxBlock>();
                sfx.Pitch      = n.NoteNumber - 60 + Key; // In MIDI, 60 is middle C, but GC uses 0 for middle C
                sfx.TrackIndex = channelPrograms[n.Channel];
                sfx.Is3D       = ThreeDee;
                sfx.Volume     = AudioTools.VelocityToVolume(n.Velocity) * VolumeMultiplier;
                count++;
                // connect wires
                if (t == null)
                {
                    continue;            // this should never happen
                }
                t.Connect(0, sfx, 0);
                startConnector.Connect(0, t, 0);
                stopConnector.Connect(0, t, 1);
                resetConnector.Connect(0, t, 2);
            }
            openFiles.Remove(name);
        }