Exemplo n.º 1
0
        public List <MidiEvent> ToMidiEventList(int MPQN, int channel, CSEQ seq)
        {
            List <MidiEvent> me = new List <MidiEvent>();
            //MidiEvent x;

            int absTime = 0;

            me.Add(new TextEvent(name, MetaEventType.SequenceTrackName, absTime));
            me.Add(new TempoEvent(MPQN, absTime));

            if (channel == 10)
            {
                me.Add(new ControlChangeEvent(absTime, channel, MidiController.BankSelect, 120));
                me.Add(new ControlChangeEvent(absTime, channel, MidiController.BankSelect, 0));
                me.Add(new PatchChangeEvent(absTime, channel, Meta.GetBankIndex(CSEQ.PatchName)));
            }

            if (CSEQ.UseSampleVolumeForTracks && !CSEQ.IgnoreVolume)
            {
                me.Add(new ControlChangeEvent(absTime, channel, MidiController.MainVolume, seq.samplesReverb[instrument].Volume / 2));
            }

            foreach (Command c in cmd)
            {
                me.AddRange(c.ToMidiEvent(absTime, channel, seq, this));
                absTime += c.wait;
            }

            return(me);
        }
Exemplo n.º 2
0
        public void ExportMIDI(string fn, CSEQ seq)
        {
            string cr = Path.GetFileNameWithoutExtension(fn) + "\r\n\r\n" + Properties.Resources.midi_copyright;

            MidiEventCollection mc = new MidiEventCollection(1, TPQN);

            //this is a lazy fix for guitarpro5 bug, 1st track does not import there
            List <MidiEvent> dummy = new List <MidiEvent>();

            dummy.Add(new TextEvent(Path.GetFileNameWithoutExtension(fn), MetaEventType.SequenceTrackName, 0));
            dummy.Add(new TextEvent(cr, MetaEventType.Copyright, 0));
            dummy.Add(new TempoEvent(MPQN, 0));

            mc.AddTrack(dummy);

            int availablechannel = 1;

            for (int i = 0; i < tracks.Count; i++)
            {
                mc.AddTrack(tracks[i].ToMidiEventList(MPQN, tracks[i].isDrumTrack ? 10 : availablechannel, seq));

                if (!tracks[i].isDrumTrack)
                {
                    availablechannel++;

                    //skip drum track
                    if (availablechannel == 10)
                    {
                        availablechannel++;
                    }

                    //limit channel if overflow
                    if (availablechannel > 16)
                    {
                        availablechannel = 16;
                    }
                }
            }

            mc.PrepareForExport();


            try
            {
                MidiFile.Export(fn, mc);
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 3
0
        //reads CSEQ from given binaryreader
        public bool Read(BinaryReaderEx br, CSEQ cs)
        {
            //read header
            if (!header.Read(br))
            {
                return(false);
            }

            //read offsets
            short[] seqOffsets = br.ReadArrayInt16(header.trackNum);

            //padding i guess?
            if (header.trackNum % 2 == 0)
            {
                br.ReadInt16();
            }

            //save current position to read tracks
            int trackData = (int)br.BaseStream.Position;

            //loop through all tracks
            for (int i = 0; i < header.trackNum; i++)
            {
                //jump to track offset
                br.Jump(trackData + seqOffsets[i]);

                //read track
                CTrack t = new CTrack();
                t.Read(br, i);

                //add track to the list
                tracks.Add(t);
            }

            return(true);
        }
Exemplo n.º 4
0
        public List <MidiEvent> ToMidiEvent(int absTime, int channel, CSEQ seq, CTrack ct)
        {
            List <MidiEvent> events = new List <MidiEvent>();

            //TrackPatch tp = new TrackPatch();

            absTime += wait;

            //we can't go beyond 16 with midi
            channel = (channel <= 16) ? channel : 16;

            if (CSEQ.IgnoreVolume)
            {
                velocity = 127;
            }

            var p = pitch;

            if (CSEQ.PatchMidi)
            {
                if (ct.isDrumTrack)
                {
                    if (evt == CSEQEvent.NoteOn || evt == CSEQEvent.NoteOff)
                    {
                        p = (byte)seq.shortSamples[pitch].info.Key;
                    }
                }

                else
                {
                    if (evt == CSEQEvent.ChangePatch)
                    {
                        CSEQ.ActiveInstrument = pitch;
                        p = (byte)seq.longSamples[CSEQ.ActiveInstrument].info.Midi;
                    }
                    else if (evt == CSEQEvent.NoteOn || evt == CSEQEvent.NoteOff)
                    {
                        try
                        {
                            p += (byte)seq.longSamples[CSEQ.ActiveInstrument].info.Pitch;
                        }
                        catch //(Exception ex)
                        {
                        }
                    }
                }
            }

            switch (evt)
            {
            case CSEQEvent.NoteOn: events.Add(new NoteEvent(absTime, channel, MidiCommandCode.NoteOn, p, velocity)); break;

            case CSEQEvent.NoteOff: events.Add(new NoteEvent(absTime, channel, MidiCommandCode.NoteOff, p, velocity)); break;

            case CSEQEvent.ChangePatch:
                // events.Add(new ControlChangeEvent(absTime, channel, MidiController.MainVolume, seq.longSamples[pitch].velocity / 2));
                events.Add(new PatchChangeEvent(absTime, channel, p));
                break;

            case CSEQEvent.BendAssume: events.Add(new PitchWheelChangeEvent(absTime, channel, p * 64)); break;

            case CSEQEvent.PanAssume: events.Add(new ControlChangeEvent(absTime, channel, MidiController.Pan, p / 2)); break;

            case CSEQEvent.VelAssume: events.Add(new ControlChangeEvent(absTime, channel, MidiController.MainVolume, p / 2)); break;     //not really used

            //case CSEQEvent.EndTrack2:
            case CSEQEvent.EndTrack: events.Add(new MetaEvent(MetaEventType.EndTrack, 0, absTime)); break;
            }

            return(events);
        }