Jump to content

Midi keyboard


sandin
 Share

Recommended Posts

I've started making this program ages ago, and I dun have the time to finish it. It's a music scripting program with MIDI keyboard feature. Means you can compose your own MIDI music.

In this stage the following things needs to be fixed:

-right click menu on the list with Add above, Add bellow, Edit, Remove item in it

-updating list item's location on item's removal, item's starting time, etc...

-making the "hold keys" option easier (click on item in the list with more than 1 index makes the hit down/up select those keys)

-instant update on the edit/add item window (like when you change octave for example, all related items should change, like index, etc...)

-making Save and SaveAS separate (SaveAs is only one working for now)

-make (PC) keyboard hotkeys for the keys in the application

-maybe rewrite the whole script (since the one is messy, and hard to read if you see it for the first time)

Posted Image

Btw, this script wouldn't have happened if there weren't midi udf by eynstyne

to start, click RECORD button, and click on to any keyboard key in the program, you can check the "Instant record" checkbox, in that case you skip the "add" window, and adding the key instantly. Program can detect how long have you been holding your key, and will set that time as default (which you can change). To edit item -> double click on item in the list. To remove item click DELETE on your keyboard when you select any of the item in the list. Hold Down and Release buttons are holding desired key/tone until the Release function releases it (see the example script in the zip).

feel free to develope it, since I dun have the time

edit: few more examples added (rename to *.PSC file, or you can open like TXT)

midi_keyboard_snd.zip

example2.PSC.txt

example3.PSC.txt

Edited by sandin
Link to comment
Share on other sites

WHOA!.. i haven't tested it.. but that looks sweet ^_^

Link to comment
Share on other sites

There's no doubt about it, sandin is king of the AutoIt GUI! It's such a good start that someone *should* develop from here.

WBD

Edited by WideBoyDixon
Link to comment
Share on other sites

I have no talent for creating music but wonderful GUI and nice program anyway!

Well done! :)

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Absolutely Wonderful :)

Some Projects:[list][*]ZIP UDF using no external files[*]iPod Music Transfer [*]iTunes UDF - fully integrate iTunes with au3[*]iTunes info (taskbar player hover)[*]Instant Run - run scripts without saving them before :)[*]Get Tube - YouTube Downloader[*]Lyric Finder 2 - Find Lyrics to any of your song[*]DeskBox - A Desktop Extension Tool[/list]indifference will ruin the world, but in the end... WHO CARES :P---------------http://torels.altervista.org

Link to comment
Share on other sites

  • 2 months later...

Well done sandin,thats fantastic work. Thankyou!

I too have been interested in midi for a while, alas i dabble in a few scripting languages but am not a master of autoit.

I've put this together to play midi notes directly from the keyboard. It has the abilty to play multiple notes at once but i've found it difficult to make it s responsive as it should be to user input.

Instrument can be set from the menu.

There are some things about the WindowEvents and dll calls i don't really understand fully to know where i've gone wrong. Its eating up CPU, and perhaps those who are more familiar with autoit can help make it better and offer some input on where i've gone wrong.

requires MidiUdf

#include <SendMessage.au3>
;#include <misc.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <Midiudf.au3>
Opt("GUIOnEventMode", 1)  ; OnEvent mode
    Global $Q                    =   2890 ;20
    Global $W                    =   2990 ;20
    Global $E                    =   "2A90" ;20
    Global $R                    =   "2B90" ;20
    Global $T                    =   "2C90" ;20
    Global $Y                    =   "2D90" ;20
    Global $U                    =   "2E90" ;20
    Global $I                    =   "2F90" ;20
    Global $O                    =   "3090" ;20
    Global $P                    =   "3190" ;20

    Global $A                    =   "3290" ;21
    Global $S                    =   "3390" ;20
    Global $D                    =   "3490" ;20
    Global $F                    =    "3590" ;20
    Global $G                    =   "3690" ;20
    Global $H                    =   "3790" ;20
    Global $J                    =   "3890" ;20
    Global $K                    =   "3990" ;20
    Global $L                    =   "3A90" ;20

    Global $Z                    =   "3B90" ;20
    Global $X                    =   "3C90" ;20
    Global $C                    =   "3D90" ;20
    Global $V                    =   "3E90" ;20
    Global $B                    =   "3F90" ;20
    Global $N                    =   "4090" ;20
    Global $M                    =   "4190" ;20
Global $instrument_String="Grand Piano|Bright Piano|Electric Grand Piano|Honky-Tonk Piano|Electric piano|Electric Piano|" & _
"Harpsichord|Clavinet|Celesta|Glockenspiel|Music Box|Vibraphone|Marimba|Xylophone|Tubular bells|Dulcimer|Drawbar Organ|" & _
"Percussive Organ|Rock Organ|Church Organ|Reed Organ|Accordion|Harmonica|Tango Accordion|Nylon String Guitar|Steel String Guitar|" & _
"Jazz Guitar|Clean Electric Guitar|Muted Electric Guitar|Overdrive Guitar|Distortion Guitar|Guitar Harmonics|Accoustic Bass|" & _
"Fingered Bass|Picked Bass|Fretless Bass|Slap Bass 1|Slap Bass 2|Synth Bass 1|Synth Bass 2|Violin|Viola|Cello|Contrabass|" & _
"Tremolo Strings|Pizzicato Strings|Orchestral Harp|Timpani|String Ensemble 1|String Ensemble 2|Synth Strings 1|" & _
"Synth Strings 2|Choir ahh|Choir oohh|Synth Voice|Orchestral Hit|Trumpet|Trombone|Tuba|Muted Trumpet|French Horn|" & _
"Brass Section|Synth Brass 1|Synth Brass 2|Soprano Sax|Alto Sax|Tenor Sax|Baritone Sax|Oboe|English Horn|Bassoon|" & _
"Clarinet|Piccolo|Flute|Recorder|Pan flute|Blown Bottle|Shakuhachi|Whistle|Ocarina|Square Wave|Sawtooth Wave|Caliope|" & _
"Chiff|Charang|Voice|Fifths|Bass & Lead|New Age|Warm|PolySynth|Choir|Bowed|Metallic|Halo|Sweep|FX: Rain|FX: Soundtrack|" & _
"FX: Crystal|FX: Atmosphere|FX: Brightness|FX: Goblins|FX: Echo Drops|FX: Star Theme|Sitar|Banjo|Shamisen|Koto|Kalimba|" & _
"Bagpipe|Fiddle|Shanai|Tinkle bell|Agogo|Steel Drums|Woodblock|Taiko Drum|Melodic Tom|Synth Drum|Reverse Cymbal|" & _
"Guitar Fret Noise|Breath Noise|Seashore|Bird Tweet|Telephone Ring|Helicopter|Applause|Gunshot"
Global $instrument_Array= StringSplit($instrument_String,"|")
;Global Const $WM_KEYDOWN = 0x0100
;Global Const $WM_KEYUP = 0x0101
Dim $iKeyIndex=""
Global $sKeyName,$fileitem

$Gui = GUICreate("Key Name Demo (Esc to exit)", 400, 50)
GUISetOnEvent($GUI_EVENT_CLOSE, "Quit")

$instr_Menu=GUICtrlCreateMenu("&Instrument")
GUICtrlSetOnEvent(-1, "_instChanged")

for $zz = 1 to $instrument_Array[0]
    $men1=GUICtrlCreateMenuItem($instrument_Array[$zz],$instr_Menu,-1,1)
    GUICtrlSetOnEvent(-1, "_instChanged")

    if $zz=1 then GUICtrlSetState(-1, $GUI_CHECKED)
Next

GUISetState(@SW_SHOW, $Gui)

GUIRegisterMsg($WM_NCLBUTTONUP, "WindowEvents")
GUIRegisterMsg($WM_KEYDOWN, "WindowEvents")
GUIRegisterMsg($WM_KEYUP, "WindowEvents")
HotKeySet("{Esc}", "Quit");  Esc to Exit

Dim $Open = _MidiOutOpen()
SetInstrument($Open,0);piano

While 1
    _SendMessage($Gui, $WM_SYSCOMMAND, 0xF012, 0)
     $sKeyName = ""
    ;sleep(100)
  WEnd

Func _instChanged()
$ind=GUICtrlRead(@GUI_CtrlId,1)
    if StringLen($ind>0) Then
        for $zz = 1 to $instrument_Array[0]
            if $ind=$instrument_Array[$zz] Then
                SetInstrument($Open,$zz-1)
                ;MsgBox(0,"",$ind & ":" & $zz-1)
                ExitLoop
            EndIf
        Next

    EndIf
EndFunc


Func NoteOn($Handle, $NoteIdx)
    If IsDeclared ( $NoteIdx ) Then
        $NoteIdx = Eval($NoteIdx)
        _MidiOutShortMsg($Handle, "0x0040" & $NoteIdx)
    EndIf
EndFunc

Func NoteOff($Handle, $NoteIdx)
    If IsDeclared ( $NoteIdx ) Then
        $NoteIdx = Eval($NoteIdx)
        _MidiOutShortMsg($Handle, "0x0000" & $NoteIdx)
    EndIf
Endfunc

Func Play($Handle, $Notes, $Duration); Can play Single notes or use arrays for chords
If Isarray($Notes) Then
    For $i in $Notes
    If $i > 87 then Return 0
    $i-=1
    _MidiOutShortMsg($Handle, $Notes[$i])
    Next
    Sleep($Duration)
    For $i in $Notes
    $i-=1
    _MidiOutShortMsg($Handle, $Notes[$i])
    Next
Else
    _MidiOutShortMsg($Handle, $Notes)
    Sleep($Duration)
    _MidiOutShortMsg($Handle, $Notes)
EndIf
EndFunc

Func SetInstrument($Handle, $Instrument)
    _MidiOutShortMsg($Handle,256 * $Instrument + 192)
EndFunc

Func Quit()
    Exit
EndFunc  ;==>Quit
Func OnAutoItExit()
    _MidiOutClose($Open)
    GUIDelete($Gui)
EndFunc   ;==>OnAutoItExit


Func WindowEvents($hWnd, $Msg, $wParam, $lParam)
    Switch $Msg
        Case $WM_KEYUP
            $aRet = DllCall('user32.dll', 'int', 'GetKeyNameText', 'int', $lParam, 'str', "", 'int', 256)
            $sKeyName = $aRet[2]

            $iKeyIndex=StringReplace($iKeyIndex,$sKeyName,"")

            NoteOff($Open, $sKeyName)
            ;ConsoleWrite($iKeyIndex & @CRLF)
            ;ConsoleWrite("keyUp: " & $sKeyName & @CRLF)

        Case $WM_KEYDOWN
            $aRet = DllCall('user32.dll', 'int', 'GetKeyNameText', 'int', $lParam, 'str', "", 'int', 256)
            $sKeyName = $aRet[2]
            if Not StringInStr($iKeyIndex,$sKeyName) Then
                $iKeyIndex  = $iKeyIndex & $sKeyName
                NoteOn($Open, $sKeyName)

            EndIf
                ;ConsoleWrite("keyDn: " & $sKeyName & @CRLF)
    EndSwitch
EndFunc  ;==>WindowEvents
Link to comment
Share on other sites

  • 5 years later...

This thread is about 6 years old. AutoIt has changed a lot in this time.
This is clearly a bug but without seeing line 273 we can't tell what happened.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...