예제 #1
0
        public List <MidiEvent> ToMidiEventList(CSeqHeader header, 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(header.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, CTRJson.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);
        }
예제 #2
0
        private void LoadCseq(string fn)
        {
            Log.Clear();
            sequenceBox.Items.Clear();
            trackBox.Items.Clear();

            string name = Path.GetFileNameWithoutExtension(fn);

            for (int i = 0; i < comboBox1.Items.Count; i++)
            {
                if (name.Contains(comboBox1.Items[i].ToString()))
                {
                    comboBox1.SelectedIndex = i;
                }
            }

            seq = new CSEQ();

            if (seq.Read(fn, textBox1))
            {
                FillUI(fn);
            }
            else
            {
                MessageBox.Show("Failed to read CTR sequence!");
            }
        }
예제 #3
0
        private void testJsonToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog fbd = new FolderBrowserDialog();

            if (fbd.ShowDialog() == DialogResult.OK)
            {
                string[] files = Directory.GetFiles(fbd.SelectedPath);


                List <string> x = new List <string>();

                foreach (string s in files)
                {
                    CSEQ c = new CSEQ(s, textBox1);
                    foreach (SampleDef sd in c.samples)
                    {
                        if (!x.Contains(sd.Tag))
                        {
                            x.Add(sd.Tag);
                        }
                    }
                    foreach (SampleDefReverb sd in c.samplesReverb)
                    {
                        if (!x.Contains(sd.Tag))
                        {
                            x.Add(sd.Tag);
                        }
                    }
                }

                x.Sort();
                StringBuilder sb = new StringBuilder();

                foreach (string s in x)
                {
                    sb.AppendLine(s);
                }

                textBox1.Text = sb.ToString();
            }

            /*
             * string track = "canyon";
             * string instr = "long";
             * int id = 0;
             *
             *
             * MetaInst info = CTRJson.GetMetaInst(track, instr, id);
             * textBox1.Text += "" + info.Midi + " " + info.Key + " " + info.Title + " " + info.Pitch;
             */
        }
예제 #4
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, header.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(header.MPQN, 0));

            mc.AddTrack(dummy);

            int availablechannel = 1;

            for (int i = 0; i < tracks.Count; i++)
            {
                mc.AddTrack(tracks[i].ToMidiEventList(header, 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);
            }
        }
예제 #5
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);
        }
예제 #6
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);
        }