这个音乐程序,有个缺点,就是节拍不好控制,你不懂要输入多少个空格(表示延时多少)?读简谱时钟的时钟周期是多少? /* 甩葱歌简谱 测试用 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); mciSendString(@"open " + alldir + " alias temp_alias",0); //("play temp_alias repeat",0); mciSendString("play temp_alias ",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; } } }版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。