Beispiel #1
0
 public static void SaveLevel(Map map, string fileName)
 {
     XmlSerializer serializer = new XmlSerializer(typeof(Map));
     XmlWriter writer = new XmlTextWriter(Path.Combine(Path.GetFullPath(Application.ExecutablePath), @"..\Files\Level", fileName + ".xml"), Encoding.UTF8);
     serializer.Serialize(writer, map);
     writer.Close();
 }
Beispiel #2
0
        public static void SaveLibraryConfig(Map map)
        {
            string libraryConfig = Path.Combine(Directory.GetParent(Application.ExecutablePath).FullName, @"Files\Sound\Library", map.LibraryName, map.LibraryName + "_Config.xml");

            XmlSerializer serializer = new XmlSerializer(typeof(Map));
            XmlWriter writer = new XmlTextWriter(libraryConfig, Encoding.UTF8);
            serializer.Serialize(writer, map);
            writer.Close();
        }
Beispiel #3
0
        public Cell(Map map, int x, int y, float left, float top)
        {
            this.Map = map;
            this.Coord = new Point(x, y);
            this.Location = new Vector2(left, top);
            this.InitialLocation = new Vector2(left, top);
            this.ListWave = new List<TimeValue<Vector2>>();
            this.Size = 1f;

            this.Neighbourghs = new Cell[6];
        }
Beispiel #4
0
        public void Init(Map map)
        {
            if (waveOutDevice != null)
            {
                waveOutDevice.Stop();
                waveOutDevice.Dispose();

                mixer.Close();
            }

            OpenMidiFile();

            mixer = new WaveMixerStream32();
            mixer.AutoStop = true;

            waveOutDevice = new NAudio.Wave.DirectSoundOut();
            //waveOutDevice = new NAudio.Wave.AsioOut();

            waveOutDevice.Init(mixer);

            int countSample = 0;
            map.Channels.ForEach(c => c.ListSample.ForEach(s => countSample++));
            countSample *= CountInstancePerSample;

            reader = new WaveStream[countSample];
            offsetStream = new EffectStream[countSample];
            channelSteam = new WaveChannel32[countSample];
            PlayingNote = new bool[countSample];
            dicSample = new Dictionary<String, List<int>>();
            dicEffect = new Dictionary<String, List<List<Effect>>>();

            LoadSample(map);

            waveOutDevice.Play();
            mixer.Position = long.MaxValue;
            mixer.AutoStop = false;

            CreateMidi();
        }
Beispiel #5
0
        private void LoadSample(Map map)
        {
            try
            {
                int index = 0;
                foreach (Channel channel in map.Channels)
                {
                    foreach (Sample sample in channel.ListSample)
                    {
                        List<int> listIndexSample = new List<int>();
                        dicSample.Add(sample.Name, listIndexSample);

                        for (int i = 0; i < CountInstancePerSample; i++)
                        {
                            WaveStream outStream = new WaveFileReader(sample.FileName);

                            //--- Détection de la fréquence moyenne du son
                            if (i == 0 && sample.Frequency == -1f)
                            {

                                //=======
                                IWaveProvider waveFloat = null;

                                if (outStream.WaveFormat.Channels > 1)
                                {
                                    StereoToMonoProvider16 stereo = new StereoToMonoProvider16(outStream);
                                    stereo.LeftVolume = 1f;
                                    stereo.RightVolume = 1f;

                                    waveFloat = new Wave16ToFloatProvider(stereo);
                                }
                                else
                                {
                                    waveFloat = new Wave16ToFloatProvider(outStream);
                                }

                                IWaveProvider outStream2 = new AutoTuneWaveProvider(waveFloat);
                                IWaveProvider wave16 = new WaveFloatTo16Provider(outStream2);

                                byte[] buffer = new byte[8192];
                                int _bytesRead;
                                do
                                {
                                    _bytesRead =
                                    wave16.Read(buffer, 0, buffer.Length);
                                    //writer.WriteData(buffer, 0, _bytesRead);
                                } while (_bytesRead != 0);//&& writer.Length < waveFileReader.Length);
                                //writer.Close();
                                //=======
                                outStream.Position = 0;

                                //---> Fréquence sonore du sample
                                sample.Frequency = ((AutoTuneWaveProvider)outStream2).Frequency;
                                //---> Note sur un clavier de 88 touches pour la fréqence
                                sample.NoteKey = (12f * (float)Math.Log(sample.Frequency / 55f) + 13f * (float)Math.Log(2f)) / ((float)Math.Log(2f));

                                Debug.WriteLine(sample.Name + " == " + sample.Frequency.ToString() + " == " + sample.NoteKey.ToString());
                            }
                            //---

                            outStream = WaveFormatConversionStream.CreatePcmStream(outStream);
                            outStream = new BlockAlignReductionStream(outStream);

                            reader[index] = outStream;

                            offsetStream[index] = new EffectStream(CreateEffectChain(sample), reader[index]);
                            channelSteam[index] = new WaveChannel32(offsetStream[index]);

                            channelSteam[index].Position = channelSteam[index].Length;
                            mixer.AddInputStream(channelSteam[index]);

                            listIndexSample.Add(index);

                            index++;
                        }

                        sample.Duration = channelSteam[dicSample[sample.Name][0]].TotalTime;
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
Beispiel #6
0
        private void InitializeChannel(Map map)
        {
            map.Channels = new List<Channel>();

            map.Channels.Add(new Channel("Empty", new Color(0.3f, 0.3f, 0.3f)));
            map.Channels.Add(new Channel("Drum", new Color(1f, 0.2f, 0.2f)));
            map.Channels.Add(new Channel("Key", new Color(0f, 0.3f, 0.8f)));
            map.Channels.Add(new Channel("Guitar", new Color(0f, 0.6f, 0.3f)));
            map.Channels.Add(new Channel("Bass", new Color(0.7f, 0f, 0.5f)));
            map.Channels.Add(new Channel("String", new Color(237, 158, 0)));

            if (GameEngine.Mini)
            {
                foreach (Channel channel in map.Channels)
                {
                    channel.Color = Color.Lerp(Color.Black, channel.Color, 0.3f);
                }
            }

            foreach (Cell cell in map.Cells)
            {
                cell.Life = new float[map.Channels.Count];
            }
        }
Beispiel #7
0
        public void LoadLibrary(string libraryName, Map map)
        {
            map.LibraryName = libraryName;
            string libraryDirectory = Path.Combine(Directory.GetParent(Application.ExecutablePath).FullName, @"Files\Sound\Library", libraryName);

            InitializeChannel(map);

            foreach (string channelDirectory in Directory.GetDirectories(libraryDirectory))
            {
                Channel channel = map.Channels.Find(c => c.Name.ToUpper() == Path.GetFileName(channelDirectory).ToUpper());

                if (channel != null)
                {
                    channel.ListSample = new List<Sample>();
                    foreach (string sampleFileName in Directory.GetFiles(channelDirectory))
                    {
                        Sample sample = new Sample(channel, sampleFileName);
                        channel.ListSample.Add(sample);
                    }
                }
            }

            //---
            bool writeNewConfig = false;
            Map mapConfig = FileSystem.LoadLevelConfig(this, map.LibraryName);

            if (mapConfig != null)
            {
                foreach (Channel channel in map.Channels)
                {
                    Channel channelConfig = mapConfig.Channels.Find(c => c.Name == channel.Name);

                    if (channelConfig != null)
                    {
                        foreach (Sample sample in channel.ListSample)
                        {
                            Sample sampleConfig = channelConfig.ListSample.Find(s => s.Name == sample.Name);

                            if (sampleConfig != null)
                            {
                                sample.NoteKey = sampleConfig.NoteKey;
                                sample.Frequency = sampleConfig.Frequency;
                            }

                            if (sample.Frequency == -1f)
                                writeNewConfig = true;
                        }
                    }
                }
            }

            GameEngine.Sound.Init(map);

            if (writeNewConfig || mapConfig == null)
                FileSystem.SaveLibraryConfig(map);
            //---

            map.Channels.RemoveAll(c => c.ListSample.Count == 0 && c.Name != "Empty");
        }