用VB6来实现QBASIC中的Play语句

2023-10-22 08:52
文章标签 实现 语句 vb6 play qbasic

本文主要是介绍用VB6来实现QBASIC中的Play语句,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

很久以前写的了,用Midi的API函数来实现以前QBasic中的Play语句,控制符实现可能还不完善,感觉演奏的还是有些问题,懒得弄了,发出来吧。希望有人可以接着完善一下,关于Play语句可以参考一下这个https://www.cnblogs.com/djcsch2001/articles/1965318.html

用法,Play "ABCDEFGAB"

下边是这个bas模块文件的代码,例程代码下载地址 https://download.csdn.net/download/bakw/88457053

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Public Declare Function midiOutOpen Lib "winmm.dll" (lphMidiOut As Long, ByVal uDeviceID As Long, ByVal dwCallback As Long, ByVal dwInstance As Long, ByVal dwFlags As Long) As Long
Public Declare Function timeEndPeriod Lib "winmm.dll" (ByVal uPeriod As Long) As Long
Public Declare Function midiOutGetNumDevs Lib "winmm.dll" () As Long
Public Declare Function midiOutGetDevCaps Lib "winmm.dll" Alias "midiOutGetDevCapsA" (ByVal uDeviceID As Long, lpCaps As MIDIOUTCAPS, ByVal uSize As Long) As Long
Public Declare Function waveOutGetNumDevs Lib "winmm.dll" () As Long
Public Declare Function timeGetDevCaps Lib "winmm.dll" (lpTimeCaps As TIMECAPS, ByVal uSize As Long) As Long
Public Declare Function timeBeginPeriod Lib "winmm.dll" (ByVal uPeriod As Long) As Long
Public Declare Function midiOutClose Lib "winmm.dll" (ByVal hMidiOut As Long) As Long
Public Declare Function midiOutShortMsg Lib "winmm.dll" (ByVal hMidiOut As Long, ByVal dwMsg As Long) As Long
Public Const MIDI_MAPPER = -1      'MIDI
Public Const DSSCL_PRIORITY = 2    'DX7Type MIDIOUTCAPSwMid As IntegerwPid As IntegervDriverVersion As LongszPname As String * 32wTechnology As IntegerwVoices As IntegerwNotes As IntegerwChannelMask As IntegerdwSupport As Long
End TypeType TIMECAPSwPeriodMin As LongwPeriodMax As Long
End TypePrivate NumDevs As Long
Private WaveNumDevs As LongPrivate BestRes As LongPublic Function Initialize() As LongDim TC As TIMECAPS, Rv As LongDim hMidiOut As LongInitialize = 0NumDevs = midiOutGetNumDevs()WaveNumDevs = waveOutGetNumDevs()Rv = timeGetDevCaps(TC, Len(TC))If Rv <> 0 Then Exit Function   'ExitBestRes = TC.wPeriodMinRv = timeBeginPeriod(BestRes)If Rv <> 0 Then Exit Function   'ExitRv = midiOutOpen(hMidiOut, MIDI_MAPPER, 0, 0, 0)If Rv <> 0 ThentimeEndPeriod BestResExit Function    'ExitEnd IfInitialize = hMidiOut
End FunctionPublic Sub Terminate(ByVal hMidiOut As Long)timeEndPeriod BestResmidiOutClose hMidiOut
End SubPublic Sub Play(ByVal MusicStr As String)Dim hMidiOut As Long, dwMsg As Long, I As Long, J As Integer, L As Integer, F As IntegerDim CH As String, Num As Integer, BFlip As Integer, T As Long, XT As LongDim Volume As Integer, Channel As Integer, BT As Long, Flip As IntegerMusicStr = Replace(MusicStr, Chr(0), "")MusicStr = Replace(MusicStr, Chr(32), "")hMidiOut = 0Volume = 100Channel = 0BT = 500BFlip = 60L = Len(MusicStr)If L = 0 Then Exit SubhMidiOut = InitializeIf hMidiOut = 0 ThenDebug.Print "Initialize Error"Exit SubEnd IfI = 1T = BTXT = 0F = 0Flip = BFlipDoXT = 0Flip = 0CH = UCase(Mid(MusicStr, I, 1))I = I + 1Select Case CHCase "A", "B", "C", "D", "E", "F", "G"Select Case CHCase "A"Flip = BFlip + 10Case "B"Flip = BFlip + 12Case "C"Flip = BFlipCase "D"Flip = BFlip + 2Case "E"Flip = BFlip + 4Case "F"Flip = BFlip + 6Case "G"Flip = BFlip + 8End SelectIf I <= L Then CH = Mid(MusicStr, I, 1) Else CH = ""If (CH = "+") Or (CH = "#") ThenFlip = Flip + 1I = I + 1ElseIf (CH = "-") Or (CH = "$") ThenFlip = Flip - 1I = I + 1End IfCH = ""If I <= L ThenDo Until Not IsNumeric(Mid(MusicStr, I, 1))CH = CH & Mid(MusicStr, I, 1)I = I + 1If I > L Then Exit DoLoopEnd IfIf IsNumeric(CH) Then Num = CInt(CH) Else Num = 1If Num = 0 Then Num = 1If I <= L Then CH = Mid(MusicStr, I, 1) Else CH = ""T = CLng(BT / Num)If CH = "." ThenI = I + 1XT = 0.5 * TEnd IfCase "L"CH = ""Do Until Not IsNumeric(Mid(MusicStr, I, 1))CH = CH & Mid(MusicStr, I, 1)I = I + 1If I > L Then Exit DoLoopIf IsNumeric(CH) Then Num = CInt(CH) Else Num = 1If Num = 0 Then Num = 1T = CLng(BT / Num)XT = -TCase "M"Select Case Mid(MusicStr, I, 1)Case "N"F = 1Case "L"F = 0End SelectCase "O"CH = ""Do Until Not IsNumeric(Mid(MusicStr, I, 1))CH = CH & Mid(MusicStr, I, 1)I = I + 1If I > L Then Exit DoLoopIf IsNumeric(CH) Then Num = CInt(CH) Else Num = 4BFlip = 4 + 14 * NumXT = -TCase "P", "R"CH = ""Do Until Not IsNumeric(Mid(MusicStr, I, 1))CH = CH & Mid(MusicStr, I, 1)I = I + 1If I > L Then Exit DoLoopIf IsNumeric(CH) Then Num = CInt(CH) Else Num = 1If Num = 0 Then Num = 1If I <= L Then CH = Mid(MusicStr, I, 1) Else CH = ""T = CLng(BT / Num)If CH = "." ThenI = I + 1XT = 0.5 * TEnd IfCase "T"CH = ""Do Until Not IsNumeric(Mid(MusicStr, I, 1))CH = CH & Mid(MusicStr, I, 1)I = I + 1If I > L Then Exit DoLoopIf IsNumeric(CH) Then Num = CInt(CH) Else Num = 0If Num > 0 Then BT = 60000 \ NumCase "V"CH = ""Do Until Not IsNumeric(Mid(MusicStr, I, 1))CH = CH & Mid(MusicStr, I, 1)I = I + 1If I > L Then Exit DoLoopIf IsNumeric(CH) Then Num = CInt(CH) Else Num = 100Volume = NumCase "Y"CH = ""Do Until Not IsNumeric(Mid(MusicStr, I, 1))CH = CH & Mid(MusicStr, I, 1)I = I + 1If I > L Then Exit DoLoopIf IsNumeric(CH) Then Num = CInt(CH) Else Num = 0If hMidiOut <> 0 Then midiOutShortMsg hMidiOut, CLng(Num) * &H100 + &HC0 + CLng(Channel)XT = -TCase ElseEnd SelectIf Flip > 0 ThendwMsg = CLng(Volume) * &H10000 + CLng(Flip) * &H100 + &H90 + CLng(Channel)If hMidiOut <> 0 Then midiOutShortMsg hMidiOut, dwMsgEnd IfSleep T + XTIf Flip > 0 Or F > 0 ThendwMsg = CLng(Flip) * &H100 + &H80 + CLng(Channel)If hMidiOut <> 0 Then midiOutShortMsg hMidiOut, dwMsgEnd IfLoop Until I > Len(MusicStr)If hMidiOut <> 0 Then Terminate hMidiOut
End Sub

这篇关于用VB6来实现QBASIC中的Play语句的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/260407

相关文章

SpringBoot3实现Gzip压缩优化的技术指南

《SpringBoot3实现Gzip压缩优化的技术指南》随着Web应用的用户量和数据量增加,网络带宽和页面加载速度逐渐成为瓶颈,为了减少数据传输量,提高用户体验,我们可以使用Gzip压缩HTTP响应,... 目录1、简述2、配置2.1 添加依赖2.2 配置 Gzip 压缩3、服务端应用4、前端应用4.1 N

SpringBoot实现数据库读写分离的3种方法小结

《SpringBoot实现数据库读写分离的3种方法小结》为了提高系统的读写性能和可用性,读写分离是一种经典的数据库架构模式,在SpringBoot应用中,有多种方式可以实现数据库读写分离,本文将介绍三... 目录一、数据库读写分离概述二、方案一:基于AbstractRoutingDataSource实现动态

Python FastAPI+Celery+RabbitMQ实现分布式图片水印处理系统

《PythonFastAPI+Celery+RabbitMQ实现分布式图片水印处理系统》这篇文章主要为大家详细介绍了PythonFastAPI如何结合Celery以及RabbitMQ实现简单的分布式... 实现思路FastAPI 服务器Celery 任务队列RabbitMQ 作为消息代理定时任务处理完整

Java枚举类实现Key-Value映射的多种实现方式

《Java枚举类实现Key-Value映射的多种实现方式》在Java开发中,枚举(Enum)是一种特殊的类,本文将详细介绍Java枚举类实现key-value映射的多种方式,有需要的小伙伴可以根据需要... 目录前言一、基础实现方式1.1 为枚举添加属性和构造方法二、http://www.cppcns.co

使用Python实现快速搭建本地HTTP服务器

《使用Python实现快速搭建本地HTTP服务器》:本文主要介绍如何使用Python快速搭建本地HTTP服务器,轻松实现一键HTTP文件共享,同时结合二维码技术,让访问更简单,感兴趣的小伙伴可以了... 目录1. 概述2. 快速搭建 HTTP 文件共享服务2.1 核心思路2.2 代码实现2.3 代码解读3.

MySQL双主搭建+keepalived高可用的实现

《MySQL双主搭建+keepalived高可用的实现》本文主要介绍了MySQL双主搭建+keepalived高可用的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,... 目录一、测试环境准备二、主从搭建1.创建复制用户2.创建复制关系3.开启复制,确认复制是否成功4.同

Java实现文件图片的预览和下载功能

《Java实现文件图片的预览和下载功能》这篇文章主要为大家详细介绍了如何使用Java实现文件图片的预览和下载功能,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... Java实现文件(图片)的预览和下载 @ApiOperation("访问文件") @GetMapping("

使用Sentinel自定义返回和实现区分来源方式

《使用Sentinel自定义返回和实现区分来源方式》:本文主要介绍使用Sentinel自定义返回和实现区分来源方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录Sentinel自定义返回和实现区分来源1. 自定义错误返回2. 实现区分来源总结Sentinel自定

Java实现时间与字符串互相转换详解

《Java实现时间与字符串互相转换详解》这篇文章主要为大家详细介绍了Java中实现时间与字符串互相转换的相关方法,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录一、日期格式化为字符串(一)使用预定义格式(二)自定义格式二、字符串解析为日期(一)解析ISO格式字符串(二)解析自定义

opencv图像处理之指纹验证的实现

《opencv图像处理之指纹验证的实现》本文主要介绍了opencv图像处理之指纹验证的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学... 目录一、简介二、具体案例实现1. 图像显示函数2. 指纹验证函数3. 主函数4、运行结果三、总结一、