写入简谱(flash钢琴谱)自动播放简谱琴声程序 c#

来源:互联网 发布:android建服务器软件 编辑:程序博客网 时间:2024/04/19 03:06

这个音乐程序,有个缺点,就是节拍不好控制,你不懂要输入多少个空格(表示延时多少)?读简谱时钟的时钟周期是多少?
/*
甩葱歌简谱 测试用
QTTUVTTTVUSSSUTT
TTQTTUVTTTOQQQPOUVTT
XXWVUSSSUWWWWVUOTT
TTXXWVUSSSUWWWWVUVTT
*/
using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;




namespace gangqinzidongbofang
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        public static uint SND_ASYNC = 0x0001; //
        public static uint SND_FILENAME = 0x00020000;
        [DllImport("winmm.dll")]
        public static extern uint mciSendString(string lpstrCommand,
        string lpstrReturnString, uint uReturnLength, uint hWndCallback);


        string path = @"D:\Download\Silverlightkey\codefans.net\键盘钢琴\AphroditePiano\Sound\";
        string keyname = "";
        string stryinjie = "";
        int i;


        
        private void button1_Click(object sender, EventArgs e)
        {
             stryinjie = richTextBox1.Text;
             i = 0;
             timer1.Interval = 200;
             timer1.Enabled = true;


        }


        private void timer1_Tick(object sender, EventArgs e)
        {


            if (char.IsLetter(stryinjie[i]))
            {


                //D:\Download\Silverlightkey\codefans.net\键盘钢琴\AphroditePiano\Sound\目录,保存了A.mp3  B.mp3  C.mp3到Z.mp3,分别存放了不同的音阶MP3文件
                string keyname = char.ToUpper(stryinjie[i]) + ".mp3";


                string alldir = path + keyname;


                mciSendString(@"close temp_alias", null, 0, 0);
                mciSendString(@"open " + alldir + " alias temp_alias", null, 0, 0);
                //("play temp_alias repeat", null, 0, 0);
                mciSendString("play temp_alias ", null, 0, 0);
            }
            else
            {
                if (stryinjie[i].Equals(' '))//等于空格
                {
                    System.Threading.Thread.Sleep(2000);
                    //if(Delay(1));
                        
                }
            }
            i++;
            if (i == stryinjie.Length)
            {
                timer1.Enabled = false;
            }
        }


        /// <summary>
        /// 延时函数
        /// </summary>
        /// <param name="delayTime">需要延时多少秒</param>
        /// <returns></returns>
        public static bool Delay(int delayTime)
        {
            DateTime now = DateTime.Now;
            int s;
            do
            {
                TimeSpan spand = DateTime.Now - now;
                s = spand.Seconds;
                Application.DoEvents();
            }
            while (s < delayTime);
            return true;
        }




    }
}
原创粉丝点击