Exemple #1
0
        private void CreateMidi(string trackName, int[] notes, int tempo, int[] instruments, int[] durations, string fileName)
        {
            MIDISong song = new MIDISong();

            song.AddTrack(trackName);
            song.SetTimeSignature(0, 4, 4);
            song.SetTempo(0, m_nBeats[tempo]);

            for (int channel = 0; channel < instruments.Length; channel++)
            {
                song.SetChannelInstrument(0, channel, instruments[channel]);
                foreach (int duration in durations)
                {
                    for (int i = 0; i < notes.Length; i++)
                    {
                        int noteNumber = notes[i];
                        noteNumber += 12 * (6 + (channel % 2));
                        song.AddNote(0, channel, noteNumber, duration);
                    }
                }
            }


            try
            {
                MemoryStream ms = new MemoryStream();
                song.Save(ms);
                ms.Seek(0, SeekOrigin.Begin);
                byte[] src = ms.GetBuffer();
                byte[] dst = new byte[src.Length];
                for (int i = 0; i < src.Length; i++)
                {
                    dst[i] = src[i];
                }
                ms.Close();
                FileInfo FI = new FileInfo(fileName + ".mid");
                if (!FI.Directory.Exists)
                {
                    FI.Directory.Create();
                }
                FileStream objWriter = File.Create(FI.FullName);
                objWriter.Write(dst, 0, dst.Length);
                objWriter.Close();
                objWriter.Dispose();
                objWriter = null;
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Exemple #2
0
        //  Ecriture musique dans fichier temporaire
        private void WriteMusic(Individu individu, int numeroPiste)
        {
            // 1) Créer le fichier MIDI
            // a. Créer un fichier et une piste audio ainsi que les informations de tempo
            MIDISong song = new MIDISong();

            song.AddTrack("Piste1");
            song.SetTimeSignature(0, 4, 4);
            song.SetTempo(0, tempo);

            //  Récupération du tableau contenant les notes de musique
            int[] tabMusique = individu.GetNotesDeMusique();

            //  Récupération du type d'instrument dans l'individu présent dans la population
            int instrument = individu.GetTypeInstrument();

            song.SetChannelInstrument(0, 0, instrument);

            //  Ajout des notes une à une dans la piste son
            for (int i = 0; i < numberIndividu; i++)
            {
                song.AddNote(0, 0, tabMusique[i], lengthNote);
            }

            // d. Enregistrer le fichier .mid (lisible dans un lecteur externe par exemple)
            // on prépare le flux de sortie
            MemoryStream ms = new MemoryStream();

            song.Save(ms);
            ms.Seek(0, SeekOrigin.Begin);
            byte[] src = ms.GetBuffer();
            ms.Close();

            FileStream objWriter = File.Create(directory + "/piste" + numeroPiste + ".midi");

            objWriter.Write(src, 0, src.Length);
            objWriter.Close();
            objWriter.Dispose();
            objWriter = null;
        }
Exemple #3
0
        public static void Main(string[] args)
        {
            /*var hip = new JHPlayer();
             * using(var stream = new FileStream("hipc.Title", FileMode.Open))
             * {
             *      hip.loader(stream);
             *      var mid = new MIDISong();
             *      for(int i = 0; i < 4; i++) mid.AddTrack();
             *
             * }*/

            var hip  = HippelCosoFile.Open("hipc.City_Walk", null);
            var song = new MIDISong();

            for (int i = 0; i < 4; i++)
            {
                var track = song.AddTrack(null);
                song.SetTempo(track, 3000 / hip.Songs[0].Speed);
                song.SetTimeSignature(track, 4, 4);
            }

            /*for(int i = 0; i < hip.Voices.Length/4; i++)
             * {
             *      for(int j = 0; j < 4; j++)
             *      {
             *              var voice = hip.Voices[i*4+j];
             *              int vsize = 12;
             *              for(int k = 0; k < vsize; k++)
             *              {
             *                      int note = hip.Patterns[voice.PatternAddress*vsize+k].Note*2;
             *                      //if(note <= 5) note = 0;
             *                      song.AddNote(j, 0, note-1, 12);
             *              }
             *      }
             * }*/

            for (int i = 0; i < hip.Patterns.Length; i++)
            {
                int note = hip.Patterns[i].Note;
                song.AddNote(0, 0, note * 2 - 1, 12);
            }

            using (var stream = new FileStream("hip.mid", FileMode.Create))
            {
                song.Save(stream);
            }

            return;

            var cfg = ReadConfig();

            Console.WriteLine("AmiMus v" + Assembly.GetExecutingAssembly().GetName().Version.ToString(2));
            Console.WriteLine("Created by [email protected]");
            if (args.Length != 2)
            {
                Console.WriteLine("Usage:");
                Console.WriteLine("  amimus [input] [output]");
                Console.WriteLine("Example:");
                Console.WriteLine("  amimus [sa.Song1] [Song1.mid]");
                Console.WriteLine("Currently supported formats:");
                Console.WriteLine("Input - Sonic Arranger (classic or with replayer)");
                Console.WriteLine("Output - MIDI");
            }
            else
            {
                SA2MIDI(args[0], args[1]);
                Console.WriteLine("Song converted.");
            }
        }