Что нового

Воспроизведение мелодии MIDI-устройством (не mid, kar -файлов)

AZJIO

Меценат
Меценат
Сообщения
2,805
Репутация
1,168
Собственно используя Midiudf.au3 и способ записи звуков из темы генератор мелодий (для совместимости) сделал функцию воспроизведения последовательности звуков.

Если по каким то причинам не воспроизводится midi, то проверте факторы вызывающие проблемы с midi:
1. Версия AutoIt3 не выше 3.3.0.0 (Midiudf.au3)
2. Не должно быть запущено ни одного MIDI-приложения, например: секвенсор, караоке, скрипт использующий MIDI (Генератор мелодий MIDI.au3), свёрнутая игрушка задействующая MIDI.
3. В настройках микшера проверить громкость MIDI-канала и отсутствие галочки "Выкл", у меня в микшере так и называется "Cинтeзaтop".

Вот примеры:

Код:
#include <Midiudf.au3>
$open = _midiOutOpen ()

Global $t=1.3 ; коэффициент темпа
Global $volume=127 ; громкость 0-127
HotKeySet('{ESC}', "_Quit") ;по желанию выход по ESC


SetInstrument($open, 29) ; выбор музыкального инструмента
_Beep(12,5,50)
_Beep(3,6,50)
_Beep(12,5,50)
_Beep(3,6,50)
_Beep(7,6,100)
_Beep(12,5,50)
_Beep(3,6,50)
_Beep(12,5,50)
_Beep(3,6,50)
_Beep(7,6,100)
_Beep(12,5,50)
_Beep(3,6,50)
_Beep(12,5,50)
_Beep(3,6,50)
_Beep(7,6,100)
_Beep(12,5,50)
_Beep(3,6,50)
_Beep(12,5,50)
_Beep(3,6,50)
_Beep(7,6,100)

_Beep(12,5,50)
_Beep(3,6,50)
_Beep(12,5,50)
_Beep(3,6,50)
_Beep(7,6,200)


_Beep(2,6,50)
_Beep(5,6,50)
_Beep(2,6,50)
_Beep(5,6,50)
_Beep(8,6,100)
_Beep(2,6,50)
_Beep(5,6,50)
_Beep(2,6,50)
_Beep(5,6,50)
_Beep(8,6,100)
_Beep(2,6,50)
_Beep(5,6,50)
_Beep(2,6,50)
_Beep(5,6,50)
_Beep(8,6,100)
_Beep(2,6,50)
_Beep(5,6,50)
_Beep(2,6,50)
_Beep(5,6,50)
_Beep(8,6,100)

_Beep(2,6,50)
_Beep(5,6,50)
_Beep(2,6,50)
_Beep(5,6,50)
_Beep(8,6,200)


_Beep(3,6,50)
_Beep(7,6,50)
_Beep(3,6,50)
_Beep(7,6,50)
_Beep(10,6,100)
_Beep(3,6,50)
_Beep(7,6,50)
_Beep(3,6,50)
_Beep(7,6,50)
_Beep(10,6,100)
_Beep(3,6,50)
_Beep(7,6,50)
_Beep(3,6,50)
_Beep(7,6,50)
_Beep(10,6,100)
_Beep(3,6,50)
_Beep(7,6,50)
_Beep(3,6,50)
_Beep(7,6,50)
_Beep(10,6,100)

_Beep(3,6,50)
_Beep(7,6,50)
_Beep(3,6,50)
_Beep(7,6,50)
_Beep(10,6,200)



_Beep(8,5,100)
_Beep(10,5,100)
_Beep(12,5,100)
_Beep(8,5,100)
_Beep(10,5,100)
_Beep(12,5,100)
_Beep(8,5,100)
_Beep(10,5,100)
_Beep(12,5,100)
_Beep(10,5,100)
_Beep(8,5,100)
_Beep(7,5,100)
_Beep(10,5,100)
_Beep(8,5,100)
_Beep(7,5,100)
_Beep(3,5,100)
_Beep(5,5,600)
_Beep(8,5,90,10)
_Beep(8,5,90,10)
_Beep(8,5,190,10)
_Beep(7,5,50)
_Beep(8,5,50)
_Beep(7,5,100)
_Beep(5,5,200)
_Beep(3,5,190,10)
_Beep(3,5,390,10)
_Beep(2,5,390,10)
_Beep(12,4,390,10)
_Beep(10,4,390,10)

_Beep(12,5,390,10)
_Beep(10,5,100)
_Beep(7,5,100)
_Beep(10,5,100)
_Beep(7,5,200)
_Beep(12,5,100)
_Beep(10,5,100)
_Beep(7,5,100)
_Beep(9,5,100)
_Beep(5,5,100)
_Beep(7,5,190,10)
_Beep(7,5,100)
_Beep(5,5,100)
_Beep(3,5,100)
_Beep(12,4,100)
_Beep(5,5,100)
_Beep(12,4,100)
_Beep(3,5,100)
_Beep(5,5,890,10)



_Beep(12,5,50)
_Beep(3,6,50)
_Beep(12,5,50)
_Beep(3,6,50)
_Beep(7,6,100)
_Beep(12,5,50)
_Beep(3,6,50)
_Beep(12,5,50)
_Beep(3,6,50)
_Beep(7,6,100)
_Beep(12,5,50)
_Beep(3,6,50)
_Beep(12,5,50)
_Beep(3,6,50)
_Beep(7,6,100)
_Beep(12,5,50)
_Beep(3,6,50)
_Beep(12,5,50)
_Beep(3,6,50)
_Beep(7,6,100)
_Beep(12,5,50)
_Beep(3,6,50)
_Beep(12,5,50)
_Beep(3,6,50)
_Beep(7,6,200)


_Beep(2,6,50)
_Beep(5,6,50)
_Beep(2,6,50)
_Beep(5,6,50)
_Beep(8,6,100)
_Beep(2,6,50)
_Beep(5,6,50)
_Beep(2,6,50)
_Beep(5,6,50)
_Beep(8,6,100)
_Beep(2,6,50)
_Beep(5,6,50)
_Beep(2,6,50)
_Beep(5,6,50)
_Beep(8,6,100)
_Beep(2,6,50)
_Beep(5,6,50)
_Beep(2,6,50)
_Beep(5,6,50)
_Beep(8,6,100)
_Beep(2,6,50)
_Beep(5,6,50)
_Beep(2,6,50)
_Beep(5,6,50)
_Beep(8,6,200)


_Beep(3,6,50)
_Beep(7,6,50)
_Beep(3,6,50)
_Beep(7,6,50)
_Beep(10,6,100)
_Beep(3,6,50)
_Beep(7,6,50)
_Beep(3,6,50)
_Beep(7,6,50)
_Beep(10,6,100)
_Beep(3,6,50)
_Beep(7,6,50)
_Beep(3,6,50)
_Beep(7,6,50)
_Beep(10,6,100)
_Beep(3,6,50)
_Beep(7,6,50)
_Beep(3,6,50)
_Beep(7,6,50)
_Beep(10,6,100)
_Beep(3,6,50)
_Beep(7,6,50)
_Beep(3,6,50)
_Beep(7,6,50)
_Beep(10,6,200)


_Beep(8,5,100)
_Beep(10,5,100)
_Beep(12,5,100)
_Beep(8,5,100)
_Beep(10,5,100)
_Beep(12,5,100)
_Beep(8,5,100)
_Beep(10,5,100)
_Beep(12,5,100)
_Beep(10,5,100)
_Beep(8,5,100)
_Beep(7,5,100)
_Beep(10,5,100)
_Beep(8,5,100)
_Beep(7,5,100)
_Beep(3,5,100)
_Beep(5,5,600)
_Beep(8,5,90,10)
_Beep(8,5,90,10)
_Beep(8,5,190,10)
_Beep(7,5,100)

_Beep(8,5,50)
_Beep(7,5,50)
_Beep(5,5,200)
_Beep(3,5,200)

_Beep(12,5,390,10)
_Beep(10,5,390,10)
_Beep(3,5,390,10)
_Beep(5,5,390,10)
_Beep(7,5,1590,10)
_Beep(9,5,600)
_Beep(12,5,200)
_Beep(9,5,800)


Func _Beep($nota,$oktava=4,$Duration=200,$pause=0)
$nota=$nota+12*$oktava
_MidiOutShortMsg($open, 0x90 + ($nota   * 256) + ($volume * 0x10000)) ; воспроизведение ноты ($nota - тон)
Sleep($Duration*$t)
_MidiOutShortMsg($open, 0x90 + ($nota   * 256) + (0 * 0x10000)) ; остановка ноты выключением звука ноты в ноль
If $pause<>0 Then Sleep($pause*$t)
EndFunc

Func SetInstrument($open, $inct) ; выбор музыкального инструмента
    _MidiOutShortMsg($open,256 * $inct + 192)
EndFunc

Func _Quit()
    Exit
EndFunc

Код:
#include <Midiudf.au3>
$open = _midiOutOpen ()

Global $t=1 ; коэффициент темпа
Global $volume=127 ; громкость 0-127
HotKeySet('{ESC}', "_Quit") ;по желанию выход по ESC


SetInstrument($open, 90) ; выбор музыкального инструмента
; вариация 1
_Beep(5,5,130)
_Beep(7,5,130)
_Beep(11,5,130)
_Beep(7,5,130)
_Beep(11,5,130)
_Beep(12,5,130)
_Beep(11,5,450,70)
_Beep(7,5,130,130)
_Beep(7,5,130)
_Beep(5,5,250,130)
_Beep(7,5,260)
_Beep(5,5,65,65)
_Beep(7,5,260)
_Beep(5,5,65,65)
_Beep(7,5,86,130)
_Beep(7,5,65,65)
_Beep(8,5,65,65)
_Beep(8,5,130,130)
_Beep(8,5,170,350)

_Beep(5,5,130)
_Beep(7,5,130)
_Beep(11,5,130)
_Beep(7,5,130)
_Beep(11,5,130)
_Beep(12,5,130)
_Beep(11,5,390)
_Beep(12,5,86)
_Beep(11,5,43)
_Beep(7,5,130,130)
_Beep(7,5,130)
_Beep(5,5,250,130)
_Beep(7,5,260)
_Beep(5,5,65,65)
_Beep(7,5,260)
_Beep(5,5,65,65)
_Beep(5,5,170,86)
_Beep(7,5,65,65)
_Beep(8,5,65,65)
_Beep(8,5,130,130)
_Beep(8,5,170,350)

SetInstrument($open, 30)
; вариация 2
_Beep(7,3,130,130)
_Beep(7,3,170,86)
_Beep(5,3,86,43)
_Beep(7,3,217,43)
_Beep(5,3,86,43)
_Beep(7,3,170,86)
_Beep(7,3,216,434)

_Beep(5,3,86,43)
_Beep(7,3,130,130)
_Beep(7,3,170,86)
_Beep(5,3,86,43)
_Beep(7,3,217,43)
_Beep(5,3,86,43)
_Beep(7,3,170,86)
_Beep(7,3,217,43)

_Beep(8,3,43,86)
_Beep(8,3,43,86)
_Beep(8,3,43,86)
_Beep(8,3,43,86)

_Beep(7,3,130,130)
_Beep(7,3,170,86)
_Beep(5,3,86,43)
_Beep(7,3,217,43)
_Beep(5,3,86,43)
_Beep(7,3,170,86)
_Beep(7,3,216,434)

_Beep(5,3,86,43)
_Beep(7,3,130,130)
_Beep(7,3,170,86)
_Beep(5,3,86,43)
_Beep(7,3,217,43)
_Beep(5,3,86,43)
_Beep(7,3,170,86)
_Beep(7,3,217,43)

_Beep(8,3,520)

; вариация 3
_Beep(12,3,390)
_Beep(7,4,390)
_Beep(6,4,520)
_Beep(5,4,450)
_Beep(3,4,330)

_Beep(12,3,390)
_Beep(7,4,390)
_Beep(6,4,520)
_Beep(5,4,450)
_Beep(3,4,330)

_Beep(5,3,390)
_Beep(12,3,390)
_Beep(11,3,520)
_Beep(10,3,450)
_Beep(8,3,330)

_Beep(5,3,390)
_Beep(12,3,390)
_Beep(11,3,520)
_Beep(10,3,450)
_Beep(8,3,330)


Func _Beep($nota,$oktava=4,$Duration=200,$pause=0)
$nota=$nota+12*$oktava
_MidiOutShortMsg($open, 0x90 + ($nota   * 256) + ($volume * 0x10000)) ; воспроизведение ноты ($nota - тон)
Sleep($Duration*$t)
_MidiOutShortMsg($open, 0x90 + ($nota   * 256) + (0 * 0x10000)) ; остановка ноты выключением звука ноты в ноль
If $pause<>0 Then Sleep($pause*$t)
EndFunc

Func SetInstrument($open, $inct) ; выбор музыкального инструмента
    _MidiOutShortMsg($open,256 * $inct + 192)
EndFunc

Func _Quit()
    Exit
EndFunc

1 Grand Piano
2 Bright Piano
3 Electric Grand Piano
4 Honky-Tonk Piano
5 Electric piano
6 Electric Piano
7 Harpsichord
8 Clavinet
9 Celesta
10 Glockenspiel
11 Music Box
12 Vibraphone
13 Marimba
14 Xylophone
15 Tubular bells
16 Dulcimer
17 Drawbar Organ
18 Percussive Organ
19 Rock Organ
20 Church Organ
21 Reed Organ
22 Accordion
23 Harmonica
24 Tango Accordion
25 Nylon String Guitar
26 Steel String Guitar
27 Jazz Guitar
28 Clean Electric Guitar
29 Muted Electric Guitar
30 Overdrive Guitar
31 Distortion Guitar
32 Guitar Harmonics
33 Accoustic Bass
34 Fingered Bass
35 Picked Bass
36 Fretless Bass
37 Slap Bass 1
38 Slap Bass 2
39 Synth Bass 1
40 Synth Bass 2
41 Violin
42 Viola
43 Cello
44 Contrabass
45 Tremolo Strings
46 Pizzicato Strings
47 Orchestral Harp
48 Timpani
49 String Ensemble 1
50 String Ensemble 2
51 Synth Strings 1
52 Synth Strings 2
53 Choir ahh
54 Choir oohh
55 Synth Voice
56 Orchestral Hit
57 Trumpet
58 Trombone
59 Tuba
60 Muted Trumpet
61 French Horn
62 Brass Section
63 Synth Brass 1
64 Synth Brass 2
65 Soprano Sax
66 Alto Sax
67 Tenor Sax
68 Baritone Sax
69 Oboe
70 English Horn
71 Bassoon
72 Clarinet
73 Piccolo
74 Flute
75 Recorder
76 Pan flute
77 Blown Bottle
78 Shakuhachi
79 Whistle
80 Ocarina
81 Square Wave
82 Sawtooth Wave
83 Caliope
84 Chiff
85 Charang
86 Voice
87 Fifths
88 Bass & Lead
89 New Age
90 Warm
91 PolySynth
92 Choir
93 Bowed
94 Metallic
95 Halo
96 Sweep
97 FX: Rain
98 FX: Soundtrack
99 FX: Crystal
100 FX: Atmosphere
101 FX: Brightness
102 FX: Goblins
103 FX: Echo Drops
104 FX: Star Theme
105 Sitar
106 Banjo
107 Shamisen
108 Koto
109 Kalimba
110 Bagpipe
111 Fiddle
112 Shanai
113 Tinkle bell
114 Agogo
115 Steel Drums
116 Woodblock
117 Taiko Drum
118 Melodic Tom
119 Synth Drum
120 Reverse Cymbal
121 Guitar Fret Noise
122 Breath Noise
123 Seashore
124 Bird Tweet
125 Telephone Ring
126 Helicopter
127 Applause
128 Gunshot

Accordion 22
Accoustic Bass 33
Agogo 114
Alto Sax 66
Applause 127
Bagpipe 110
Banjo 106
Baritone Sax 68
Bass & Lead 88
Bassoon 71
Bird Tweet 124
Blown Bottle 77
Bowed 93
Brass Section 62
Breath Noise 122
Bright Piano 2
Caliope 83
Celesta 9
Cello 43
Charang 85
Chiff 84
Choir 92
Choir ahh 53
Choir oohh 54
Church Organ 20
Clarinet 72
Clavinet 8
Clean Electric Guitar 28
Contrabass 44
Distortion Guitar 31
Drawbar Organ 17
Dulcimer 16
Electric Grand Piano 3
Electric piano 5
Electric Piano 6
English Horn 70
Fiddle 111
Fifths 87
Fingered Bass 34
Flute 74
French Horn 61
Fretless Bass 36
FX: Atmosphere 100
FX: Brightness 101
FX: Crystal 99
FX: Echo Drops 103
FX: Goblins 102
FX: Rain 97
FX: Soundtrack 98
FX: Star Theme 104
Glockenspiel 10
Grand Piano 1
Guitar Fret Noise 121
Guitar Harmonics 32
Gunshot 128
Halo 95
Harmonica 23
Harpsichord 7
Helicopter 126
Honky-Tonk Piano 4
Jazz Guitar 27
Kalimba 109
Koto 108
Marimba 13
Melodic Tom 118
Metallic 94
Music Box 11
Muted Electric Guitar 29
Muted Trumpet 60
New Age 89
Nylon String Guitar 25
Oboe 69
Ocarina 80
Orchestral Harp 47
Orchestral Hit 56
Overdrive Guitar 30
Pan flute 76
Percussive Organ 18
Piccolo 73
Picked Bass 35
Pizzicato Strings 46
PolySynth 91
Recorder 75
Reed Organ 21
Reverse Cymbal 120
Rock Organ 19
Sawtooth Wave 82
Seashore 123
Shakuhachi 78
Shamisen 107
Shanai 112
Sitar 105
Slap Bass 1 37
Slap Bass 2 38
Soprano Sax 65
Square Wave 81
Steel Drums 115
Steel String Guitar 26
String Ensemble 1 49
String Ensemble 2 50
Sweep 96
Synth Bass 1 39
Synth Bass 2 40
Synth Brass 1 63
Synth Brass 2 64
Synth Drum 119
Synth Strings 1 51
Synth Strings 2 52
Synth Voice 55
Taiko Drum 117
Tango Accordion 24
Telephone Ring 125
Tenor Sax 67
Timpani 48
Tinkle bell 113
Tremolo Strings 45
Trombone 58
Trumpet 57
Tuba 59
Tubular bells 15
Vibraphone 12
Viola 42
Violin 41
Voice 86
Warm 90
Whistle 79
Woodblock 116
Xylophone 14
 
Верх