Exemplo n.º 1
0
        public void LoadPatch(string patchFile, int bankNumber, int startRange, int endRange)
        {
            string patchName = Path.GetFileNameWithoutExtension(patchFile);
            string directory = Path.GetDirectoryName(patchFile);
            //check for duplicate patch
            PatchAsset patchAsset = assets.FindPatch(patchName);

            if (patchAsset != null)
            {
                AssignPatchToBank(patchAsset.Patch, bankNumber, startRange, endRange);
                return;
            }
            //load patch here
            Patch patch;

            switch (Path.GetExtension(patchFile).ToLower())
            {
            case ".patch":
                patch = LoadMyPatch(CrossPlatformHelper.OpenResource(patchFile), patchName, directory);
                break;

            case ".sfz":
                patch = LoadSfzPatch(CrossPlatformHelper.OpenResource(patchFile), patchName, directory);
                break;

            default:
                throw new InvalidDataException("The patch: " + Path.GetFileName(patchFile) + " is unsupported.");
            }
            AssignPatchToBank(patch, bankNumber, startRange, endRange);
            assets.PatchAssetList.Add(new PatchAsset(patchName, patch));
        }
Exemplo n.º 2
0
        //--Properties

        //--Methods
        public WaveFileReader(string fileName)
        {
            if (!Path.GetExtension(fileName).ToLower().Equals(".wav") || !CrossPlatformHelper.ResourceExists(fileName))
            {
                throw new InvalidDataException("Invalid wave file : " + fileName);
            }
            reader = new BinaryReader(CrossPlatformHelper.OpenResource(fileName));
        }
Exemplo n.º 3
0
 //--Methods
 public SoundFont(string fileName)
 {
     if (!Path.GetExtension(fileName).ToLower().Equals(".sf2"))
     {
         throw new InvalidDataException("Invalid soundfont : " + fileName + ".");
     }
     Load(CrossPlatformHelper.OpenResource(fileName));
 }
Exemplo n.º 4
0
        public void LoadSampleAsset(string assetName, string patchName, string directory)
        {
            string assetNameWithoutExtension;
            string extension;

            if (Path.HasExtension(assetName))
            {
                assetNameWithoutExtension = Path.GetFileNameWithoutExtension(assetName);
                extension = Path.GetExtension(assetName).ToLower();
            }
            else
            {
                assetNameWithoutExtension = assetName;
                assetName += ".wav"; //assume .wav
                extension  = ".wav";
            }
            if (FindSample(assetNameWithoutExtension) == null)
            {
                string waveAssetPath;
                if (CrossPlatformHelper.ResourceExists(assetName))
                {
                    waveAssetPath = assetName; //ex. "asset.wav"
                }
                else if (CrossPlatformHelper.ResourceExists(directory + Path.DirectorySeparatorChar + assetName))
                {
                    waveAssetPath = directory + Path.DirectorySeparatorChar + assetName; //ex. "C:\asset.wav"
                }
                else if (CrossPlatformHelper.ResourceExists(directory + "/SAMPLES/" + assetName))
                {
                    waveAssetPath = directory + "/SAMPLES/" + assetName; //ex. "C:\SAMPLES\asset.wav"
                }
                else if (CrossPlatformHelper.ResourceExists(directory + Path.DirectorySeparatorChar + patchName + Path.DirectorySeparatorChar + assetName))
                {
                    waveAssetPath = directory + Path.DirectorySeparatorChar + patchName + Path.DirectorySeparatorChar + assetName; //ex. "C:\Piano\asset.wav"
                }
                else
                {
                    throw new IOException("Could not find sample asset: (" + assetName + ") required for patch: " + patchName);
                }
                using (BinaryReader reader = new BinaryReader(CrossPlatformHelper.OpenResource(waveAssetPath)))
                {
                    switch (extension)
                    {
                    case ".wav":
                        sampleAssets.Add(new SampleDataAsset(assetNameWithoutExtension, WaveFileReader.ReadWaveFile(reader)));
                        break;
                    }
                }
            }
        }
Exemplo n.º 5
0
        public void LoadBank(string bankFile)
        {
            bank.Clear();
            assets.PatchAssetList.Clear();
            assets.SampleAssetList.Clear();
            bankName = string.Empty;
            comment  = string.Empty;
            switch (Path.GetExtension(bankFile).ToLower())
            {
            case ".bank":
                bankName = Path.GetFileNameWithoutExtension(bankFile);
                LoadMyBank(CrossPlatformHelper.OpenResource(bankFile));
                break;

            case ".sf2":
                bankName = "SoundFont";
                LoadSf2(CrossPlatformHelper.OpenResource(bankFile));
                break;
            }
            assets.PatchAssetList.TrimExcess();
            assets.SampleAssetList.TrimExcess();
        }
Exemplo n.º 6
0
        public void Close()
        {
            if (writer == null)
            {
                return;
            }
            writer.Close();
            writer = null;
            BinaryWriter bw2 = new BinaryWriter(CrossPlatformHelper.CreateResource(fname));

            bw2.Write((Int32)1179011410);
            bw2.Write((Int32)44 + length - 8);
            bw2.Write((Int32)1163280727);
            bw2.Write((Int32)544501094);
            bw2.Write((Int32)16);
            bw2.Write((Int16)1);
            bw2.Write((Int16)channels);
            bw2.Write((Int32)sRate);
            bw2.Write((Int32)(sRate * channels * (bits / 8)));
            bw2.Write((Int16)(channels * (bits / 8)));
            bw2.Write((Int16)bits);
            bw2.Write((Int32)1635017060);
            bw2.Write((Int32)length);
            using (BinaryReader br = new BinaryReader(CrossPlatformHelper.OpenResource(ftemp)))
            {
                byte[] buffer = new byte[1024];
                int    count  = br.Read(buffer, 0, buffer.Length);
                while (count > 0)
                {
                    bw2.Write(buffer, 0, count);
                    count = br.Read(buffer, 0, buffer.Length);
                }
            }
            bw2.Close();
            CrossPlatformHelper.RemoveResource(ftemp);
        }
Exemplo n.º 7
0
 public MidiFile(string fileName)
     : this(CrossPlatformHelper.OpenResource(fileName))
 {
 }
Exemplo n.º 8
0
 public SfzReader(string sfzFile)
 {
     name = Path.GetFileNameWithoutExtension(sfzFile);
     Load(CrossPlatformHelper.OpenResource(sfzFile));
 }