Jump to content

how to recorde an audio file using bass.dll


Recommended Posts

Hello guys
I have an inquiry regarding bass.dll
I wanted to record an audio file and did not know the way
As well as I want to save the file after applying the effects

can you help me?

am sorry for my english

With my greetings and best wishes

Edited by nacerbaaziz
Link to comment
Share on other sites

I have something that I am cleaning up before I share.

Using bass.dll I have example:

Dynamic select track on hotkey
Preload tracks from file (requires files to be named correctly)
Configure Hotkey dialog
Play track repeating toggle
Modifier with track:
Play track
Record track
Shifting version of track - Uncomplete

 

recorder_dialog1.gif

 

recorder_hotkey_dialog.png

 

This code is missing files and will not run standalone.

The page selection breaks the hotkey_dialog, but aside from that the functionality works.  

I notice Shift track feature was never completed, but that shouldn't matter.

This code still may help you because it provides an example.  It doesn't save a master record track yet, but I can look into that once I clean this up.

;*****************************************
;Recorder.au3 by Xandy
;Created with ISN AutoIt Studio v. 1.01

; Use hotkeys to select tracks.  Use modifier to deside track action: play, record, shift record
;*****************************************

#include <Include\Bass.au3\Bass\Bass.au3>; BrettF
#include <BassEnc.au3>; eukalyptus
;https://autoit.de/index.php/Thread/4251-Mp3-Recording-via-bass-dll/#post42923&page=Thread&postID=42923&highlight=bass.dll
#include "Include\TTS.au3"; Author: Beege, text to speach
#include <Include\loaddialog.au3>; Xandy this thing sucks
#include <GuiConstants.au3>
#include <Misc.au3>
#include <File.au3>
#include <GuiComboBox.au3>

Enum $eMod_record = 1, _
        $eMod_play, _
        $eMod_shift, _
        $eMod_repeat, _
        $eMod_max

; Bass
OnAutoItExitRegister("_Bass_cleanup")

Global $gEncHandle = Null

Global $gEncState = False

Global $gBitrate = 128

Global $gRecHandle = 0

Global $gRecVersion = 1

Global $gRecVersion_Max = 100

; Sounds are stored here and incromented
Global $gaSound[101]; 100 with max at 0
Global $gSound_cur = 1

$gaSound[0] = UBound($gaSound) - 1

$gVoice = _StartTTS()

; Paths
Global $gPath_system = @ScriptDir & "\System\"

Global $gPath_config = @ScriptDir & "\Config\"

; Gui
Global $ghGui = Null

; Load now and pass to _IsPressed() to save time
Global $ghDLL = DllOpen("user32.dll")

Global $gScript_name = StringTrimRight(@ScriptName, 4)

; Control Data Structure
Global $gControl_data_max = 9

Enum $eControl_data, $eControl_label, $eControl_type, $eControl_data_val, $eControl_tooltip, $eControl_width, $eControl_height, $eControl_pad_x, $eControl_pad_y

; Hotkey data
Enum $eKey_code, $eKey_name, $eKey_send, $eKey_data_max

Global $gaKey[1][$eKey_data_max]; ReDimed in key_load() to (Lines in: Key_Names.txt / gKey_data_max)

Global $gHotkey_amount_max = 4

Global $gHotkey_amount = $gHotkey_amount_max

; Constants from http://msdn.microsoft.com/en-us/library/windows/desktop/ms646360(v=vs.85).aspx
Const $SC_CLOSE = 0xF060
Const $SC_MOVE = 0xF010
Const $SC_MAXIMIZE = 0xF030
Const $SC_MINIMIZE = 0xF020
Const $SC_SIZE = 0xF000
Const $SC_RESTORE = 0xF120

; ; Hotkey GUI Fields
Global $gHotkey_control_max = 18

Global $gHotkey_height = 80

Enum $hkc_button_1, $hkc_button_2, $hkc_button_3, $hkc_button_4, $hkc_button_state_1, $hkc_button_state_2, $hkc_button_state_3, $hkc_button_state_4, _;8
        $hkc_macro_description_edit, $hkc_ispressed_checkbox, $hkc_remove_button_1, $hkc_remove_button_2, $hkc_remove_button_3, $hkc_remove_button_4, _;14
        $hkc_keyboard_pic_1, $hkc_keyboard_pic_2, $hkc_keyboard_pic_3, $hkc_keyboard_pic_4;18

; Used with key_get_dialog() Listbox of Keys
Global $gMylistbox = Null

Global $gMylistboxmsg = 0

; Captures Double Click on Listbox gMylistbox: Sets gMylistboxmsg
GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")

; Program Options
opt("GUICloseOnESC", 0)

main()

Func main()

    Local $x = Null

    ; Startup Bass
    $x = _BASS_Startup("BASS.dll")
    ConsoleWrite("Bass_Startup: " & $x & @CRLF)

    ; Init Bass
    $x = _BASS_Init(0, -1, 44100, 0, "")
    ConsoleWrite("Bass_Init: " & $x & @CRLF)

    ; Bass Encoder Startup
    _BASS_Encode_STARTUP()
    $basscb_dll = DllOpen("BASSCB.dll")

    ; Bass Settings
    $KHZ = 44100

    $temp = DllCall($basscb_dll, "dword", "RecordStart", "dword", $KHZ, "dword", 2, "dword", _makelong($BASS_SAMPLE_FX, 10))

    ;_BASS_SetConfig($BASS_CONFIG_REC_BUFFER, 1000)

    $device = _Recording_GetDevices()

    ; Initate Recording
    $r = _BASS_RecordInit($device)

    $input = _Recording_GetInputs()

    ; Load settings
    $aSetting = settings_load()

    ; Load Key Names
    key_load()

    Local $hotkey_action = 0

    Local $aHotkey_control = hotkey_load()

    hotkey_sort($aHotkey_control)

    ; Create GUI
    $label_w = 60
    $ghGui = GUICreate(@ScriptName, 320, 200)
    $aGUI_rect = WinGetPos($ghGui)

    Local $aControl[$eMod_max][2]; label, data

    ; List the hotkeys
    For $i = 1 To $eMod_max - 1
        $aControl[$i][0] = GUICtrlCreateLabel($aHotkey_control[$i][$hkc_macro_description_edit][$eControl_data_val] & ":", 5, $i * 20, $label_w, 20)

        $sHotkey_text = hotkey_name($aHotkey_control, $i)

        $aControl[$i][1] = GUICtrlCreateLabel($sHotkey_text, $label_w+ 10, $i * 20, $aGUI_rect[2] - 15 - $label_w, 20)
    Next

    ; Create readonly edit
    ; Remove bell sounds when keys are pressed
    $control_edit_aborb_bell = GUICtrlCreateEdit("", $aGui_rect[2] - 100, 1, 90, 19, $ES_READONLY)
    GUICtrlSetState($control_edit_aborb_bell, $GUI_FOCUS)

    Local $aMenu = ["&File", _
            "&Config"]

    Enum $eMenu_file, $eMenu_config

    For $i = 0 To UBound($aMenu) - 1
        $aMenu[$i] = GUICtrlCreateMenu($aMenu[$i])
    Next

    $menu_file_exit = GUICtrlCreateMenuItem("&Exit", $aMenu[$eMenu_file])

    $menu_hotkey_dialog = GUICtrlCreateMenuItem("&Hotkeys", $aMenu[$eMenu_config])

    Local $control_id_start = $aMenu[$eMenu_file]

    Local $control_id_end = $aMenu[$eMenu_config]



    GUISetState()

    $temp = DllCall($basscb_dll, "dword", "RecordStart", "dword", $KHZ, "dword", 2, "dword", _makelong($BASS_SAMPLE_FX, 10))

    If IsArray($temp) Then

        $gRecHandle = $temp[0]

    Else

        MsgBox(0, $gScript_name, "basscb DLL not found?", 0, $ghGui)

    EndIf

    Local $record_start = 0

    Local $aHotkey_page_name = hotkey_page_name_load()

    Local $record_repeat = 0

    ; Colors to indictate off or on setting
    Enum $eColor_off, _
        $eColor_on, _
        $eColor_max

    Local $aColor[$eColor_max]

    $aColor[$eColor_off] = 0x000000
    $aColor[$eColor_on] = 0x00DD00

    Do

        ; Read Hotkeys from Shift to end of tracks
        $record_action = hotkey_check($aHotkey_control, $eMod_shift)

        $record_repeat_hotkey_check = hotkey_check($aHotkey_control, $eMod_repeat, $eMod_repeat)
        If $record_repeat_hotkey_check > -1 Then
            If $record_repeat = 0 then
                $record_repeat = 1
            Else
                $record_repeat = 0
            EndIf
            out("record_repeat: " & $record_repeat)
            GUICtrlSetColor($aControl[$eMod_repeat][0], $aColor[$record_repeat])
            keyreleased($gaKey[$aHotkey_control[$eMod_repeat][$hkc_button_1][$eControl_data_val]][$eKey_code])
        EndIf; $record_repeat_hotkey_check > -1

        Switch $record_action
            ; If there has been a record_action (Track) then decide what to do with track: play, record, shift record file

            Case $eMod_max To $aHotkey_control[0][0][0]

                ; Check all the Mod: Do on blank
                ; Else: Do on Modifier

                ; Check Play Mod,
                If $aHotkey_control[$eMod_play][0][$eControl_data_val] = 0 Then

                    sound_play($record_action, $record_repeat, 0, 100)

                    ; one keypress at a time, fellas.
                    keyreleased($gaKey[$aHotkey_control[$record_action][$hkc_button_1][$eControl_data_val]][$eKey_code])

                ElseIf hotkey_check($aHotkey_control, $eMod_play, $eMod_play) > -1 Then

                    out("Play $record_action: " & $record_action)

                    ;If $record_action = 8 + $eMod_max Then

                    sound_play($record_action, $record_repeat, 0, 100)

                    ; one keypress at a time, fellas.
                    keyreleased($gaKey[$aHotkey_control[$record_action][$hkc_button_1][$eControl_data_val]][$eKey_code])

                ;
                Else
                    ; If record modifier key blank, start recording track
                    If $aHotkey_control[$eMod_record][0][$eControl_data_val] = 0 Then

                        $record_start = 1

                    ; Check Hotkey modifier
                    ElseIf hotkey_check($aHotkey_control, $eMod_record, $eMod_record) > -1 Then

                        $record_start = 1

                    EndIf

                    If $record_start = 1 Then

                        If $record_action - $eMod_max < $aSetting[1][$eControl_data_val] Then

                            record($aHotkey_control, $record_action)

                            $record_start = 0

                        EndIf; record_action

                    EndIf; record_start

                EndIf; record_modifiers

            Case $eMod_shift
                ; Shift the record track version file

                $gRecVersion += 1

                If $gRecVersion >= $gRecVersion_Max Then

                    $gRecVersion = 1

                EndIf

                out("Shift: ")

                keyreleased($gaKey[$aHotkey_control[$record_action][$hkc_button_1][$eControl_data_val]][$eKey_code])

        EndSwitch; record_action

        $msg = GUIGetMsg()

        Switch $msg

            Case $menu_hotkey_dialog

                gui_control_set_state($ghGui, $control_id_start, $control_id_end, $GUI_DISABLE)

                hotkey_dialog($aHotkey_control, $aHotkey_page_name)

                gui_control_set_state($ghGui, $control_id_start, $control_id_end, $GUI_ENABLE)

                hotkey_update_display($aControl, $aHotkey_control)

                GUICtrlSetState($control_edit_aborb_bell, $GUI_FOCUS)

            Case $menu_file_exit

                ExitLoop

        EndSwitch; msg

    Until $msg = $GUI_EVENT_CLOSE

    _BASS_Free()

EndFunc   ;==>main

Func read_chunk($file); Remove Label from File Line Label Data pair.
    Local $chunk = FileReadLine($file)
    If @error <> 0 Then
        Return "File EOF"
    EndIf
    Local $chunk_po = StringInStr($chunk, ": "); Find the string position of the first ": "
    Return StringMid($chunk, $chunk_po + 2); Return String 2 spaces right from the chunk_po
EndFunc   ;==>read_chunk

; Key systems
Func key_load($file_path = $gPath_system & "key_names.txt")

    Local $file = FileOpen($file_path)

    If $file > -1 Then

        $key_max = _FileCountLines($file_path) / $eKey_data_max

        ReDim $gaKey[$key_max + 1][$eKey_data_max]

        $gaKey[0][0] = $key_max

        For $i = 1 To $gaKey[0][0]

            $gaKey[$i][$eKey_code] = FileReadLine($file)
            $gaKey[$i][$eKey_name] = FileReadLine($file)
            $gaKey[$i][$eKey_send] = FileReadLine($file)

        Next

        FileClose($file)

    Else

        MsgBox(0, $gScript_name & " Error", "Could not load Keyboard Setup file:" & @CRLF & _
                $file_path, 0, $ghGui)

    EndIf

EndFunc   ;==>key_load

Func key_get()

    Local $key = 0

    Local $timer = TimerInit()

    Local $timer_len = 1000 * 6

    Do

        For $i = 1 To $gaKey[0][0] - 1

            If _IsPressed($gaKey[$i][$eKey_code], $ghDLL) Then

                $key = $i

                ExitLoop

            EndIf

        Next

        If $key > 0 Then ExitLoop

    Until TimerDiff($timer) >= $timer_len

    Return $key

EndFunc   ;==>key_get

; Add hotkey controls to the tab_window[tw_hotkey][twd_win]
Func hotkey_controls(ByRef $aControl, $x, $y, $index, $node = 0)

    $aControl[$index][$hkc_remove_button_1 + $node][$eControl_data] = GUICtrlCreateButton("x", $x, $y, 20, 20); Remove key button

    GUICtrlSetTip(-1, "Remove the Key")

    $aControl[$index][$hkc_button_1 + $node][$eControl_data] = GUICtrlCreateButton("Click to Set", $x + 25, $y, 110, 20); Key button

    GUICtrlSetTip(-1, "Click to Set Key")

    $aControl[$index][$hkc_keyboard_pic_1 + $node][$eControl_data] = GUICtrlCreatePic($gPath_system & "keyboard button.gif", $x + 135, $y, 25, 20);gui pic

    GUICtrlSetTip(-1, "Open Virtual Keyboard")

EndFunc   ;==>hotkey_controls

; add hotkey controls to gui list
Func hotkey_controls_add(ByRef $aControl, $index, $x, $y)

    Local $index_draw = $index - 1

    If $index_draw < 0 Then $index_draw = 0

    $aControl[$index][$hkc_ispressed_checkbox][$eControl_data] = GUICtrlCreateCheckbox("Is Pressed", $x, $y + 45, 70, 20, $BS_Left); Is Pressed Checkbox

    GUICtrlSetTip(-1, "There are two ways to react to hotkeys.  System level hotkeys and _IsPressed" & @CRLF & "Currently this option does nothing and only _IsPressed is ever used for hotkeys.")

    hotkey_controls($aControl, $x, $y, $index)

    If $gHotkey_amount < 2 Then Return

    hotkey_controls($aControl, $x + 170, $y, $index, 1)

    If $gHotkey_amount < 3 Then Return

    hotkey_controls($aControl, $x, $y + 20, $index, 2)

    If $gHotkey_amount < 4 Then Return

    hotkey_controls($aControl, $x + 170, $y + 20, $index, 3)

EndFunc   ;==>hotkey_controls_add

; Dialog Window for configuring Hotkeys
Func hotkey_dialog(ByRef $aHotkey_control, ByRef $aHotkey_page_name)

    Local $items_per_colume = 8

    Local $hotkey_width = 170

    Local $aHotkey_control_new = $aHotkey_control

    Local $setting_height = 20

    Local $gui_base_height = 25

    Local $msg = Null

    ; GUI position
    Local $aGui_rect = WinGetPos($ghGui)

    ; Create new GUI offset from main gui position
    ;$hGui = GUICreate($gScript_name & "- Hotkeys", 490 * 2 - 50, $gui_base_height + ($aHotkey_control_new[0][0][0] - 1) * $gHotkey_height, $aGui_rect[0] + 35, $aGui_rect[1] + 40, Default, Default, $ghGui)
    $hGui = GUICreate($gScript_name & "- Hotkeys", 490 * 3, $gui_base_height + ($items_per_colume) * $gHotkey_height, $aGui_rect[0] + 35, $aGui_rect[1] + 40, Default, Default, $ghGui)

    ; Record GUI rect area
    $aGui_rect = WinGetPos($hGui)

    ; Fit on Desktop
    If $aGui_rect[1] + $aGui_rect[3] > @DesktopHeight Then WinMove($hGui, "", Default, @DesktopHeight - $aGui_rect[3] - 45)

    If $aGui_rect[0] + $aGui_rect[2] > @DesktopWidth Then WinMove($hGui, "", @DesktopWidth - $aGui_rect[2] - 1, Default)

    Local $x_col = 0

    Local $x_col_max = 3

    Local $y_count = 0

    Local $y_loc = 0

    Local $page_hotkeys = $x_col_max * $items_per_colume

    Local $aDescription[$page_hotkeys + 2]

    ; Add Hotkey Controls to GUI {Label Action, Buttons: code, remove, keyboard_gui Checkbox}
    For $i = 1 To $page_hotkeys

        $y_loc = 5 + $y_count * $gHotkey_height

        $aDescription[$i] = GUICtrlCreateLabel($aHotkey_control_new[$i][$hkc_macro_description_edit][$eControl_data_val], 5 + $x_col * 490, $y_loc, 140, 60)

        GUICtrlSetBkColor(-1, 0xf3fcd7)

        hotkey_controls_add($aHotkey_control_new, $i, 150 + $x_col * 490, $y_loc)

        For $ii = 0 To $gHotkey_amount - 1

            GUICtrlSetData($aHotkey_control_new[$i][$hkc_button_1 + $ii][$eControl_data], $gaKey[$aHotkey_control_new[$i][$hkc_button_1 + $ii][$eControl_data_val]][$eKey_name])

        Next; ii

        $y_count += 1

        If Mod($i, $items_per_colume) = 0 Then

            $x_col+= 1

            $y_count = 0

        EndIf

    Next; i create hotkey_controls

    Local $page = 0

    ; Page Name Combo

    $page_name_combo = GUICtrlCreateCombo("", $aGui_rect[2] - 420, $aGui_rect[3] - 55, 160, 20, $CBS_DROPDOWNLIST)

    For $i = 1 To $aHotkey_page_name[0]
        out("$aHotkey_page_name[0]: " & $aHotkey_page_name[0])

        If $aHotkey_page_name[$i] = "File EOF" Or $aHotkey_page_name[$i] = "" Then
            ; blank
            GUICtrlSetData($page_name_combo, $aHotkey_page_name[$i], $i)
        Else
            GUICtrlSetData($page_name_combo, $aHotkey_page_name[$i], $aHotkey_page_name[$page + 1])
        EndIf; not blank
    Next; i

    ; Rename Page Button
    $page_rename_button = GUICtrlCreateButton("Rename", $aGui_rect[2] - 255, $aGui_rect[3] - 55, 45, 20)

    ; Page Back Button
    $page_back_button = GUICtrlCreateButton("< Page", $aGui_rect[2] - 190, $aGui_rect[3] - 55, 45, 20)

    ; Page Next Button
    $page_next_button = GUICtrlCreateButton("Page >", $aGui_rect[2] - 140, $aGui_rect[3] - 55, 45, 20)

    ; Confirm Button
    $confirm_button = GUICtrlCreateButton("Confirm", $aGui_rect[2] - 65, $aGui_rect[3] - 55, 50, 20)

    GUISetState()

    Local $confirm = 0

    Local $point = Null

    Local $hotkey_id = 0

    Local $page_start = 1

    Local $index = 1

    Local $data_index = 0

    Local $update_controls = 0

    Do

        $msg = GUIGetMsg()

        For $i = 1 To $page_hotkeys

            For $ii = 0 To $gHotkey_amount - 1

                $hotkey_id = $hkc_button_1 + $ii

                Switch $msg

                    Case $aHotkey_control_new[$i][$hotkey_id][$eControl_data]
                        ; User clicked Set Key Button

                        GUICtrlSetData($aHotkey_control_new[$i][$hotkey_id][$eControl_data], "Press Any Key")

                        $key = key_get()

                        If $key > 0 Then

                            $page_start = $page * $page_hotkeys

                            $aHotkey_control_new[$page_start + $i][$hotkey_id][$eControl_data_val] = $key

                            GUICtrlSetData($aHotkey_control_new[$i][$hotkey_id][$eControl_data], $gaKey[$key][$eKey_name])

                        EndIf

                    Case $aHotkey_control_new[$i][$hkc_keyboard_pic_1 + $ii][$eControl_data]
                        ; User clicked Set Key Button with Keyboard_GUI Dialog

                        $key = key_get_dialog($hGui)

                        If $key > 0 Then

                            $page_start = $page * $page_hotkeys

                            $aHotkey_control_new[$page_start + $i][$hotkey_id][$eControl_data_val] = $key

                            GUICtrlSetData($aHotkey_control_new[$i][$hotkey_id][$eControl_data], $gaKey[$aHotkey_control_new[$page_start + $i][$hotkey_id][$eControl_data_val]][$eKey_name])

                        EndIf

                    Case $aHotkey_control_new[$i][$hkc_remove_button_1 + $ii][$eControl_data]
                        ; User clicked Remove Key Button

                        $page_start = $page * $page_hotkeys

                        $aHotkey_control_new[$page_start + $i][$hotkey_id][$eControl_data_val] = ""

                        GUICtrlSetData($aHotkey_control_new[$i][$hotkey_id][$eControl_data], $aHotkey_control_new[$page_start + $i][$hotkey_id][$eControl_data_val])

                EndSwitch; msg

            Next; ii in hotkey amount

        Next; i hotkeys in page

        Switch $msg

            ;
            Case $page_name_combo

                $page_combo_id = _GUICtrlComboBox_GetCurSel($page_name_combo)

            ; Back Page Button
            Case $page_back_button

                ; Incroment Page
                $page -= 1

                $page_start = $page * $page_hotkeys

                out("Page Start: " & $page_start)

                ; Wrap Page
                If $page_start < 0 Then

                    $page = Int($aHotkey_control_new[0][0][0] / $page_hotkeys) - 1

                    out("$page "&$page)

                    $page_start = $page * $page_hotkeys

                    out("Wrap Page Start: " & $page_start)

                EndIf

                $update_controls = 1

            ; Next Page Button
            Case $page_next_button

                ; Incroment Page
                $page += 1

                $page_start = $page * $page_hotkeys

                out("Page Start: " & $page_start)

                ; Wrap Page
                If $page_start >= $aHotkey_control_new[0][0][0] - 1 Then

                    $page = 0

                    $page_start = $page * $page_hotkeys

                    out("Wrap Page Start: " & $page_start)

                EndIf

                $update_controls = 1

            ; Confirm Button
            Case $confirm_button

                $confirm = 1

                ExitLoop

        EndSwitch

        If $update_controls = 1 Then
            ;Update keys
            For $i = 1 To $page_hotkeys

                $data_index = $page_start + $i

                If $data_index > $aHotkey_control_new[0][0][0] - 1 Then

                    ; Disabled
                    GUICtrlSetState($aDescription[$i], $GUI_HIDE)

                    For $ii= 0 to $gHotkey_amount - 1

                        GUICtrlSetState($aHotkey_control_new[$i][$hkc_button_1 + $ii][$eControl_data], $GUI_HIDE)

                        GUICtrlSetState($aHotkey_control_new[$i][$hkc_keyboard_pic_1 + $ii][$eControl_data], $GUI_HIDE)

                        GUICtrlSetState($aHotkey_control_new[$i][$hkc_remove_button_1 + $ii][$eControl_data], $GUI_HIDE)

                        GUICtrlSetState($aHotkey_control_new[$i][$hkc_ispressed_checkbox + $ii][$eControl_data], $GUI_HIDE)

                    Next

                Else

                    ; Display
                    GUICtrlSetData($aDescription[$i], $aHotkey_control_new[$data_index][$hkc_macro_description_edit][$eControl_data_val])

                    ; Show Description
                    GUICtrlSetState($aDescription[$i], $GUI_SHOW)

                    For $ii= 0 to $gHotkey_amount - 1

                        GUICtrlSetData($aHotkey_control_new[$i][$hkc_button_1 + $ii][$eControl_data], _
                                        $gaKey[ $aHotkey_control_new[$data_index][$hkc_button_1 + $ii][$eControl_data_val] ][$eKey_name])

                        GUICtrlSetState($aHotkey_control_new[$i][$hkc_button_1 + $ii][$eControl_data], $GUI_SHOW)

                        GUICtrlSetState($aHotkey_control_new[$i][$hkc_keyboard_pic_1 + $ii][$eControl_data], $GUI_SHOW)

                        GUICtrlSetState($aHotkey_control_new[$i][$hkc_remove_button_1 + $ii][$eControl_data], $GUI_SHOW)

                        GUICtrlSetState($aHotkey_control_new[$i][$hkc_ispressed_checkbox + $ii][$eControl_data], $GUI_SHOW)

                    Next

                EndIf

            Next; i in update hotkey controls

            $update_controls = 0

        EndIf; update_controls = 1

    Until $msg = $GUI_EVENT_CLOSE

    If $confirm = 1 Then

        hotkey_page_name_save($aHotkey_page_name)

        hotkey_sort($aHotkey_control_new)

        For $i = 1 To $aHotkey_control_new[0][0][0]

            ; Read the key codes from the buttons
            For $ii = 0 To $gHotkey_amount_max - 1

                $aHotkey_control[$i][$hkc_button_1 + $ii][$eControl_data_val] = $aHotkey_control_new[$i][$hkc_button_1 + $ii][$eControl_data_val]

                $aHotkey_control[$i][$hkc_button_state_1 + $ii][$eControl_data_val] = $aHotkey_control_new[$i][$hkc_button_state_1 + $ii][$eControl_data_val]

            Next

            ; Read IsPressed Checkbox 1 true or 4 false
            $aHotkey_control[$i][$hkc_ispressed_checkbox][$eControl_data_val] = GUICtrlRead($aHotkey_control_new[$i][$hkc_ispressed_checkbox][$eControl_data_val])

        Next

        hotkey_save($aHotkey_control)

    EndIf

    GUIDelete($hGui)

EndFunc   ;==>hotkey_dialog

Func hotkey_load($file_path = $gPath_config & "Hotkeys.txt")

    ; Plus 1 for description, then 4 key max

    Local $hotkey_max = 24 * 3 + 1

    Local $aHotkey_control[$hotkey_max][$gHotkey_control_max][$gControl_data_max]

    $file = FileOpen($file_path)

    If FileOpen($file_path) > -1 Then

        ConsoleWrite("hotkey_load: Reading File" & @CRLF)

        $hotkey_max = 1

        ; Keys to makeup Hotkey
        Do

            ; Read Hotkey Description
            $aHotkey_control[$hotkey_max][$hkc_macro_description_edit][$eControl_data_val] = FileReadLine($file)

            If @error <> 0 Then ExitLoop

            ; Read all the Hotkeys to trigger description
            For $ii = 0 To $gHotkey_amount_max - 1

                $aHotkey_control[$hotkey_max][$hkc_button_1 + $ii][$eControl_data_val] = FileReadLine($file)

                $aHotkey_control[$hotkey_max][$hkc_button_state_1 + $ii][$eControl_data_val] = FileReadLine($file)

            Next

            ; Ispressed flag to use hotkey or ispressed
            $aHotkey_control[$hotkey_max][$hkc_ispressed_checkbox][$eControl_data_val] = FileReadLine($file)

            $hotkey_max += 1

            If $hotkey_max >= UBound($aHotkey_control) Then ReDim $aHotkey_control[UBound($aHotkey_control) + 10][$gHotkey_control_max][$gControl_data_max]

        Until 0

        $hotkey_max += 1

        FileClose($file)

    Else

        ConsoleWrite("hotkey_load: File not Found" & @CRLF)

        ConsoleWrite("hotkey_load: Default Constructor" & @CRLF)

        ; Create a default hotkey array
        ; 1 Count Total [0]
        ; 3 mods record, play, shift, ..
        ; 5 tracks
        ;$hotkey_max = $eMod_max + 5 + 1

        ;Local $aHotkey_control[$hotkey_max + 1][$gHotkey_control_max][$gControl_data_max]

        Local $aMod_labels_default[$eMod_max] = [0, _
                "Record", _
                "Play", _
                "Shift", _
                "Repeat"]

        For $i = 1 To $hotkey_max - 1

            If $i < $eMod_max Then

                $aHotkey_control[$i][$hkc_macro_description_edit][$eControl_data_val] = $aMod_labels_default[$i]

            Else

                $aHotkey_control[$i][$hkc_macro_description_edit][$eControl_data_val] = "Track Number: " & $i - $eMod_max + 1

            EndIf

        Next

    EndIf

    $aHotkey_control[0][0][0] = $hotkey_max - 1

    ConsoleWrite("hotkey_load: " & $aHotkey_control[0][0][0] & " Hotkeys Generated" & @CRLF)

    Return $aHotkey_control

EndFunc   ;==>hotkey_load

Func hotkey_save($aHotkey_control, $file_path = $gPath_config & "Hotkeys.txt")

    $file = FileOpen($file_path, BitOR($FO_CREATEPATH, $FO_OVERWRITE))

    For $i = 1 To $aHotkey_control[0][0][0]

        ; Hotkey Description
        FileWriteLine($file, $aHotkey_control[$i][$hkc_macro_description_edit][$eControl_data_val])

        ; Keys to makeup Hotkey
        For $ii = 0 To $gHotkey_amount_max - 1

            FileWriteLine($file, $aHotkey_control[$i][$hkc_button_1 + $ii][$eControl_data_val])

            FileWriteLine($file, $aHotkey_control[$i][$hkc_button_state_1 + $ii][$eControl_data_val])

        Next

        ; Ispressed flag to use hotkey or ispressed
        FileWriteLine($file, $aHotkey_control[$i][$hkc_ispressed_checkbox][$eControl_data_val])

    Next

    FileClose($file)

EndFunc   ;==>hotkey_save

Func hotkey_page_name_save($aHotkey_page_name, $file_path = $gPath_config & "Hotkey_page_names.txt")

    $file = FileOpen($file_path, BitOR($FO_OVERWRITE, $FO_CREATEPATH))

    If $file > -1 Then

        For $i = 1 to $aHotkey_page_name[0]

            $aHotkey_page_name[$i] = FileWriteLine($file, $i & ": " & $aHotkey_page_name[$i])

        Next

    Else

        MsgBox(0, $gScript_name, "hotkey_page_name_save: Could not open file.", 0, $ghGui)

    EndIf

    Return $aHotkey_page_name

EndFunc

Func hotkey_page_name_load($file_path = $gPath_config & "Hotkey_page_names.txt")

    $file = FileOpen($file_path)

    $lines = _FileCountLines($file_path)

    If $file > -1 And $lines > 0 Then
        ; Size of file
        Local $aHotkey_page_name[$lines + 1]

        $aHotkey_page_name[0] = $lines

        For $i = 1 to $aHotkey_page_name[0]

            $aHotkey_page_name[$i] = read_chunk($file)

        Next

    Else

        ; Default
        Local $aHotkey_page_name[3 + 1]
        $aHotkey_page_name[0] = UBound($aHotkey_page_name) - 1

        For $i = 1 To $aHotkey_page_name[0]
            $aHotkey_page_name[$i] = $i
        Next

        MsgBox(0, $gScript_name, "hotkey_page_name_load: Could not open file."&@CRLF&$file_path&@CRLF&"Generated new", 4, $ghGui)

    EndIf

    FileClose($file)

    out("$aHotkey_page_name[0]: " & $aHotkey_page_name[0])

    Return $aHotkey_page_name

EndFunc; hotkey_page_name_load

Func settings_load($file_path = $gPath_config & "Settings.txt")

    Local $aSetting_name = ["", _ ; Stores the count
                            "Recording Max"]

    Local $setting_max = UBound($aSetting_name)

    Local $aSetting[$setting_max][$gControl_data_max]

    $aSetting[0][0] = $setting_max - 1

    $file = FileOpen($file_path)

    If $file > -1 Then

        For $i = 1 To $setting_max - 1

            $aSetting[$i][$eControl_data_val] = read_chunk($file)

        Next

    Else

        MsgBox(0, $gScript_name, "Settings_load: $file_path: " & @CRLF & $file_path & @CRLF & "Not Found", 0, $ghGui)

        $aSetting[1][$eControl_data_val] = 5

    EndIf

    Return $aSetting

EndFunc; settings_load

Func settings_save($aSetting, $file_path = $gPath_config & "Settings.txt")

    Local $aSetting_name = ["", _
                            "Recording Max: "]

    $file = FileOpen($file_path, BitOR($FO_CREATEPATH, $FO_OVERWRITE))

    For $i = 1 To $aSetting[0]

        FileWriteLine($file, $aSetting_name[$i] & $aSetting[$i][$eControl_data_val])

    Next

EndFunc; settings_save

Func hotkey_sort(ByRef $aHotkey_control)

    For $i = 1 To $aHotkey_control[0][0][0]

        ; Must Fill the First Hotkey [0]
        If $aHotkey_control[$i][$hkc_button_1][$eControl_data_val] < 1 Then

            For $ii = 1 To $gHotkey_amount_max - 1

                If $aHotkey_control[$i][$hkc_button_1 + $ii][$eControl_data_val] > 0 Then

                    ; Assign 0
                    $aHotkey_control[$i][$hkc_button_1][$eControl_data_val] = $aHotkey_control[$i][$hkc_button_1 + $ii][$eControl_data_val]

                    ; Remove
                    $aHotkey_control[$i][$hkc_button_1 + $ii][$eControl_data_val] = 0

                    ExitLoop

                EndIf

            Next

        EndIf

        For $ii = 0 To $gHotkey_amount_max - 1

            If $aHotkey_control[$i][$hkc_button_1 + $ii][$eControl_data_val] > 0 Then; If the hotkeys have been set turn them on

                $aHotkey_control[$i][$hkc_button_state_1 + $ii][$eControl_data_val] = 1

            Else

                $aHotkey_control[$i][$hkc_button_state_1 + $ii][$eControl_data_val] = 0

            EndIf

        Next

    Next

EndFunc   ;==>hotkey_sort

; key_get_dialog()
Func key_get_dialog($hGui)

    $aGui_rect = WinGetPos($hGui)

    Local $tgui = GUICreate("Select a Key", 700, 380, $aGui_rect[0] + 40, $aGui_rect[1] + 40, Default, Default, $hGui)

    Local $key_get_gui_control_data_max = 15

    Local $controls = (_FileCountLines($gPath_system & "keyboard dialog.txt") / $key_get_gui_control_data_max) + 1
    Local $aControl[$controls][$key_get_gui_control_data_max]

    $controls = 0
    loaddialogdata($gPath_system & "keyboard dialog.txt", $aControl, $controls)

    ;fill listbox of keys
    $gMylistbox = GUICtrlCreateCombo("", 455, 5, 135, 180, BitOR($LBS_NOTifY, $WS_VSCROLL))
    Local $match = 0
    For $i = 0 To $controls - 1
        $match = 0
        For $ii = 1 To $gaKey[0][0] - 1
            If GUICtrlRead($aControl[$i][0]) = $gaKey[$ii][$eKey_name] Then
                out("match: " & GUICtrlRead($aControl[$i][0]) & " " & $gaKey[$ii][$eKey_name])
                $match = $ii
                ExitLoop
            EndIf
        Next; ii
        If $match > 0 Then
            ; List key in gMylistbox
            GUICtrlSetData($gMylistbox, $gaKey[$ii][$eKey_name] & "|")
        Else
            ; Hide button
            GUICtrlSetState($aControl[$i][0], $GUI_HIDE)
        EndIf; match = 1
    Next; i

    GUISetState()

    Local $key = -1, $done = 0

    Do

        $msg = GUIGetMsg()

        For $i = 0 To $controls - 1

            If $msg = $aControl[$i][0] Then

                $key = $i

                $key_name = GUICtrlRead($aControl[$key][0])

            EndIf

        Next

        If WinActive($tgui) Then

            If _IsPressed("0d", $ghDLL) Or $gMylistboxmsg = 1 Then

                keyreleased("0d")

                $gMylistboxmsg = 0

                $key = _GUICtrlComboBox_GetCurSel($gMylistbox)

                $key_name = GUICtrlRead($gMylistbox)

            EndIf

        EndIf

    Until $key > -1 Or $msg = $GUI_EVENT_CLOSE

    If $key > -1 Then

        For $i = 1 To $gaKey[0][0] - 1

            If $gaKey[$i][$eKey_name] = $key_name Then

                $key = $i

                ExitLoop

            EndIf

        Next

    EndIf

    GUIDelete($tgui)

    Return $key

EndFunc   ;==>key_get_dialog

; Must sort hotkeys so that Hotkey[0] is always filled with a hotkey
Func hotkey_check($aHotkey_control, $start_id = 1, $end_id = $aHotkey_control[0][0][0])

    Local $return = -1

    For $i = $start_id To $end_id; Question hotkey triggers

        If _IsPressed($gaKey[$aHotkey_control[$i][$hkc_button_1][$eControl_data_val]][$eKey_code], $ghDLL) Then

            If _IsPressed($gaKey[$aHotkey_control[$i][$hkc_button_2][$eControl_data_val]][$eKey_code], $ghDLL) = $aHotkey_control[$i][$hkc_button_state_2][$eControl_data_val] Then

                If _IsPressed($gaKey[$aHotkey_control[$i][$hkc_button_3][$eControl_data_val]][$eKey_code], $ghDLL) = $aHotkey_control[$i][$hkc_button_state_3][$eControl_data_val] Then

                    If _IsPressed($gaKey[$aHotkey_control[$i][$hkc_button_4][$eControl_data_val]][$eKey_code], $ghDLL) = $aHotkey_control[$i][$hkc_button_state_4][$eControl_data_val] Then

;~                      keyreleased($gaKey[$aHotkey_control[$i][$hkc_button_1][$eControl_data_val]][$eKey_code], _
;~                              $gaKey[$aHotkey_control[$i][$hkc_button_2][$eControl_data_val]][$eKey_code], _
;~                              $gaKey[$aHotkey_control[$i][$hkc_button_3][$eControl_data_val]][$eKey_code], _
;~                              $gaKey[$aHotkey_control[$i][$hkc_button_4][$eControl_data_val]][$eKey_code])

                        Return $i

                    EndIf; key 4

                EndIf; key 3

            EndIf; key 2

        EndIf; key 1

    Next;i in hotkeys-1

    Return $return

EndFunc   ;==>hotkey_check

Func control_set_state($iStart, $iEnd, $state)

    For $i = $iStart To $iEnd

        GUICtrlSetState($i, $state)

    Next

EndFunc   ;==>control_set_state

; Enable / Disable list of GUI Controls, alter the exit program button state too
Func gui_control_set_state($hGui, $control_id_start, $control_id_end, $state)

    Switch $state

        Case $GUI_DISABLE

            DisableButton($hGui, $SC_CLOSE)

        Case $GUI_ENABLE

            EnableButton($hGui, $SC_CLOSE)

    EndSwitch

    control_set_state($control_id_start, $control_id_end, $state)

EndFunc   ;==>gui_control_set_state

; First implemented to disable the Window Close X
Func DisableButton($handle, $iButton)

    $dSysMenu = DllCall("User32.dll", "hwnd", "GetSystemMenu", "hwnd", $handle, "int", 0)

    $hSysMenu = $dSysMenu[0]

    DllCall("User32.dll", "int", "RemoveMenu", "hwnd", $hSysMenu, "int", $iButton, "int", 0)

    DllCall("User32.dll", "int", "DrawMenuBar", "hwnd", $handle)

EndFunc   ;==>DisableButton

; First implemented to enable the Window Close X
Func EnableButton($handle, $iButton)

    $dSysMenu = DllCall("User32.dll", "hwnd", "GetSystemMenu", "hwnd", $handle, "int", 1)

    $hSysMenu = $dSysMenu[0]

    DllCall("User32.dll", "int", "RemoveMenu", "hwnd", $hSysMenu, "int", $iButton, "int", 0)

    DllCall("User32.dll", "int", "DrawMenuBar", "hwnd", $handle)

EndFunc   ;==>EnableButton

; Flags a selection when double clicking mylistbox
Func _WM_COMMAND($hWnd, $msg, $wParam, $lParam)
    Local $nCode = BitShift($wParam, 16) ; HiWord
    Local $nIDFrom = BitAND($wParam, 0xFFFF) ; LoWord
    Switch $nIDFrom
        Case $gMylistbox
            Switch $nCode
                Case $LBN_DBLCLK
                    $sListItem = GUICtrlRead($gMylistbox) ; Read selected item
                    $gMylistboxmsg = 1
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_COMMAND

Func out($output = "", $timeout = 0);debug tool

    ConsoleWrite(@CRLF & $output);to console new line, value of $output

    ;MsgBox(0, @ScriptName, $output, $timeout, $ghGui)

EndFunc   ;==>out

Func keyreleased($_key1, $_key2 = "", $_key3 = "", $_key4 = "")
    While _IsPressed($_key1) Or _IsPressed($_key2)
        Sleep(20)
    WEnd
    While _IsPressed($_key3) Or _IsPressed($_key4)
        Sleep(20)
    WEnd
EndFunc   ;==>keyreleased

; Bass Functions
Func _Recording_GetDevices()
    Local $count = 0, $info, $name = "", $sdef = "", $idef = 0
    While 1
        $info = _BASS_RecordGetDeviceInfo($count)
        If @error Then ExitLoop
        $count += 1
        If BitAND($info[2], $BASS_DEVICE_ENABLED) Then $name &= $info[0] & "|"
        If BitAND($info[2], $BASS_DEVICE_DEFAULT) Then
            $sdef = $info[0]
            $idef = $count
        EndIf
    WEnd
    ;GUICtrlSetData($hDevice, $name, $sdef)
    Return $idef - 1
EndFunc   ;==>_Recording_GetDevices

Func _Recording_GetInputs()
    Local $count = 0, $info, $name = "", $flags, $sdef = "", $idef = 0
    $info = _BASS_RecordGetInputName($count)
    While $info <> ""
        $flags = _BASS_RecordGetInput($count)
        $count += 1
        $name &= $info & "|"
        If BitAND($flags[0], $BASS_INPUT_OFF) = 0 Then
            $sdef = $info
            $idef = $count
        EndIf
        $info = _BASS_RecordGetInputName($count)
    WEnd
    ;GUICtrlSetData($hInput, $name, $sdef)
    Return $idef - 1
EndFunc   ;==>_Recording_GetInputs

Func _Bass_Cleanup()

    _BASS_Free(); All your base

EndFunc   ;==>_Bass_Cleanup

Func record($aHotkey_control, $track)

    ; Remove the sound of smacking the keypress?
    Sleep(200)

    out("Recording track: " & $track)

    _Recording_Start($track)

    Do

        $record_track_key = hotkey_check($aHotkey_control, $track, $track)

    Until $record_track_key = -1

    _Recording_Stop($track)

EndFunc   ;==>record

Func sound_play($track, $repeat = 0, $dont_play = 0, $volume = 100)

    $file_path = @ScriptDir & "\Track\"

    $file_name = $track - $eMod_max + 1 & " v" & $gRecVersion & ".mp3"

    $file_path &= $file_name

    _BASS_ChannelStop($gaSound[$gSound_cur])

    ; Free
    _BASS_StreamFree($gaSound[$gSound_cur])

    ; Load
    If $repeat > 0 Then

        $gaSound[$gSound_cur] = _BASS_StreamCreateFile(False, $file_path, 0, 0, $BASS_SAMPLE_LOOP)

    Else

        $gaSound[$gSound_cur] = _BASS_StreamCreateFile(False, $file_path, 0, 0, 0)

    EndIf

    ; Set Volume
    _BASS_ChannelSetVolume($gaSound[$gSound_cur], $volume)

    ;Iniate playback
    If $dont_play = 0 Then

        _BASS_ChannelPlay($gaSound[$gSound_cur], $repeat)

    EndIf

    ; Incroment Sound_cur Index
    $gSound_cur += 1

    If $gSound_cur >= $gaSound[0] Then $gSound_cur = 1

EndFunc   ;==>sound_play

Func _Recording_Start($track)

    Local $file_path = @ScriptDir & "\Track\"

    DirCreate($file_path)

    Local $file_name = $track - $eMod_max + 1 & " v" & $gRecVersion & ".mp3"

    $file_path &= $file_name

    out("_Recording_Start() File_path: " & $file_path)

    ;If GUICtrlRead($hWav) = $GUI_CHECKED Then
    ;$EncHandle = _BASS_Encode_Start($RecHandle, @ScriptDir & "\Test.wav", $BASS_ENCODE_PCM)
    ;Else
    ;$EncHandle = _BASS_Encode_Start($RecHandle, 'lame -r -x -b' & GUICtrlRead($hBitrate) & ' -h - "' & @ScriptDir & '\Test.mp3"', 0)
    ;EndIf

    ;$gEncHandle = _BASS_Encode_Start($RecHandle, 'lame -r -x -b' & GUICtrlRead($Bitrate) & ' -h - "' & @ScriptDir & '\Track' & $file_name"', 0)

    ; Keep Same
    ;$EncHandle = _BASS_Encode_Start($RecHandle, 'lame -r -x -b' & GUICtrlRead($hBitrate) & ' -h - "' & @ScriptDir & '\Test.mp3"', 0)

    ;$gEncHandle = _BASS_Encode_Start($gRecHandle, 'lame -r -x -b' & $gBitrate & ' -h - ' & "$file_path", 0)
    ;$gEncHandle = _BASS_Encode_Start($gRecHandle, 'lame -r -x -b' & $gBitrate & ' -h - "' & @ScriptDir & '\Test.mp3"', 0)
    $gEncHandle = _BASS_Encode_Start($gRecHandle, 'lame -r -x -b' & $gBitrate & ' -h - "' & $file_path & '"', 0)

    If $gEncHandle < 1 Then

        MsgBox(0, $gScript_name, "lame.exe call did not set $gEncHandle: " & $gEncHandle)

        Return 0

    EndIf

    $gEncState = True

EndFunc   ;==>_Recording_Start

Func _Recording_Stop($track)

    _BASS_Encode_Stop($gEncHandle)

    out("$gEncHandle: " & $gEncHandle)

    $gEncState = False

EndFunc   ;==>_Recording_Stop

Func play_rec($track)

    Local $file_path = @ScriptDir & "\Track\"

    $file_name = $track - $eMod_max + 1 & " v" & $gRecVersion & ".mp3"

    Local $file_path2 = $file_path & $file_name

    sound_play($file_path & $file_name)

    out("Pos: " & _BASS_ChannelGetPosition($gRecHandle, $BASS_POS_BYTE))

    _BASS_ChannelSetPosition($gRecHandle, 1, $BASS_POS_BYTE)

    out("New Pos: " & _BASS_ChannelGetPosition($gRecHandle, $BASS_POS_BYTE))

    out("_BASS_ChannelPlay: " & _BASS_ChannelPlay($gRecHandle, 100))

EndFunc   ;==>play_rec

Func hotkey_name($aHotkey_control, $hotkey_id)

    Local $sHotkey_text = ""
    Local $sWasNull = 1
    Local $sNewPart = ""

    For $i = 0 To $gHotkey_amount - 1
        $sNewPart = ""
        If $sHotkey_text = "" Then $sWasNull = 1
        If $sHotkey_text <> "" Then $sWasNull = 0

        If $aHotkey_control[$hotkey_id][$hkc_button_1 + $i][$eControl_data_val] > -1 Then $sNewPart = $gaKey[ $aHotkey_control[$hotkey_id][$hkc_button_1 + $i][$eControl_data_val] ][$eKey_name]

        If $sNewPart <> "" Then
            If $sWasNull = 1 Then
                $sHotkey_text &= $sNewPart
            Else
                $sHotkey_text &= " + " & $sNewPart
            EndIf
        EndIf; newpart
    Next; i

    Return $sHotkey_text
EndFunc; hotkey_name

Func hotkey_update_display(ByRef $aControl, $aHotkey_control)
    For $i = 1 To $eMod_max - 1
        $sHotkey_text = hotkey_name($aHotkey_control, $i)

        GUICtrlSetData($aControl[$i][1], $sHotkey_text)
    Next
EndFunc; hotkey_update_display

 

Edited by Xandy
Added code
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

×
×
  • Create New...