Вверх ↑
Ответов: 1429
Рейтинг: 50
#1: 2010-09-30 17:55:05 ЛС | профиль | цитата
С Вашего позволения, еще одна важная деталь:
этот компонент включает в себя работу с midi-портами "как полноценное I/O":
Add(MainForm,7074072,119,119)
{
Width=518
Height=692
link(onCreate,2369059:InitModule,[])
}
Add(ListBox,8427868,392,147)
{
Left=5
Top=20
Width=205
Height=260
Point(Index)
}
Add(ArrayEnum,7098403,287,140)
{
link(onItem,9569418:doAdd,[])
link(onEndEnum,3852497:doEnum,[])
link(Array,2369059:DevOut,[(293,128)(258,128)(258,204)(223,204)])
}
Add(Button,5172207,287,217)
{
Left=120
Top=280
Width=90
Caption="MidiInOpen"
Data=Integer(0)
link(onClick,14554003:doData,[])
}
Add(Button,11251310,318,203)
{
Left=225
Top=280
Width=90
Caption="MidiOutOpen"
Data=Integer(1)
link(onClick,14151462:doData,[])
}
Add(ListBox,9569418,445,140)
{
Left=225
Top=20
Width=205
Height=260
Point(Index)
}
Add(ArrayEnum,3852497,350,147)
{
link(onItem,8427868:doAdd,[])
link(Array,2369059:DevIn,[(356,135)(264,135)(264,209)(216,209)])
}
Add(DoData,14151462,466,203)
{
link(onEventData,2369059:OpenMidiOut,[(510,209)(510,245)(189,245)(189,153)])
link(Data,9569418:Index,[])
}
Add(DoData,14554003,413,217)
{
link(onEventData,2369059:OpenMidiIn,[(457,223)(457,261)(180,261)(180,146)])
link(Data,8427868:Index,[])
}
Add(Memo,3929589,728,133)
{
Left=10
Top=310
Width=475
Height=335
Point(onKeyDown)
}
Add(FormatStr,3777109,672,133)
{
DataCount=5
Mask="%1:%2:%3:%4"
link(onFString,3929589:doAdd,[])
}
Add(MT_MultiMem,5475031,532,140)
{
Count=4
link(onData,2369059:SendToOut,[(576,146)(576,230)(198,230)(198,160)])
}
Add(Hub,2972307,497,133)
{
link(onEvent1,3777109:doString,[])
link(onEvent2,5475031:doValue,[])
}
Add(InlineCode,2369059,210,133)
{
WorkPoints=#10:InitModule|10:OpenMidiIn|11:OpenMidiOut|9:SendToOut|13:SetInstrument|9:MidiReset|9:SetVolume|9:GetVolume|
EventPoints=#10:onSendData|12:onInitModule|11:onGetVolume|
VarPoints=#5:DevIn|6:DevOut|10:instrument|
DataPoints=#8:qaStatus|7:qaData1|7:qaData2|
Code=#15:unit HiAsmUnit;|0:|9:interface|0:|38:uses kol,Share,Debug,mmsystem,windows;|4:type|32: HiEvent = procedure of object;|5:const|41: Instruments:array [0..127] of String=(|67:'AcousticGrandPiano', 'BrightAcousticPiano', 'ElectricGrandPiano', |69:'HonkyTonkPiano', 'ElectricPiano1', 'ElectricPiano2', 'Harpsichord', |76:'Clavinet', 'Celesta', 'Glockenspiel', 'MusicBox', 'Vibraphone', 'Marimba', |75:'Xylophone', 'TubularBells', 'Dulcimer', 'DrawbarOrgan', 'PercussiveOrgan',|85: 'RockOrgan', 'ChurchOrgan', 'ReedOrgan', 'Accordion', 'Harmonica', 'TangoAccordion',|69: 'AcousticNylonGuitar', ' AcousticSteelGuitar', 'JazzElectricGuitar',|66: 'CleanElectricGuitar', 'MutedElectricGuitar', 'OverdrivenGuitar',|80: 'DistortionGuitar', 'GuitarHarmonics', 'AcousticBass', 'FingeredElectricBass', |78:'PickedElectricBass', 'FretlessBass', 'SlapBass1', 'SlapBass2', 'SynthBass1', |73:'SynthBass2', 'Violin', 'Viola', 'Cello', 'Contrabass', 'TremoloStrings',|68: 'PizzicatoStrings', 'OrchestralHarp', 'Timpani', 'StringEnsemble1',|79: 'StringEnsemble2', 'SynthStrings1', 'SynthStrings2', 'ChoirAahs', 'VoiceOohs',|91: 'SynthVoice', 'OrchestraHit', 'Trumpet', 'Trombone', 'Tuba', 'MutedTrumpet', 'FrenchHorn',|98: 'BrassSection', 'SynthBrass1', 'SynthBrass2', 'SopranoSax', 'AltoSax', 'TenorSax', 'BaritoneSax',|105: 'Oboe', 'EnglishHorn', 'Bassoon', 'Clarinet', 'Piccolo', 'Flute', 'Recorder', 'PanFlute', 'BlownBottle',|110: 'Shakuhachi', 'Whistle', 'Ocarina', 'SquareLead', 'SawtoothLead', 'CalliopeLead', 'ChiffLead', 'CharangLead',|106: 'VoiceLead', 'FifthsLead', 'BassandLead', 'NewAgePad', 'WarmPad', 'PolySynthPad', 'ChoirPad', 'BowedPad',|113: 'MetallicPad', 'HaloPad', 'SweepPad', 'SynthFXRain', 'SynthFXSoundtrack', 'SynthFXCrystal', 'SynthFXAtmosphere',|110: 'SynthFXBrightness', 'SynthFXGoblins', 'SynthFXEchoes', 'SynthFXSciFi', 'Sitar', 'Banjo', 'Shamisen', 'Koto',|105: 'Kalimba', 'Bagpipe', 'Fiddle', 'Shanai', 'TinkleBell', 'Agogo', 'SteelDrums', 'Woodblock', 'TaikoDrum',|103: 'MelodicTom', 'SynthDrum', 'ReverseCymbal', 'GuitarFretNoise', 'BreathNoise', 'Seashore', 'BirdTweet',|55: 'TelephoneRing', 'Helicopter', 'Applause', 'Gunshot');|4:type|28: THiAsmClass = class(TDebug)|1: |10: private|14: Arr:PArray;|15: Arr1:PArray;|22: fDevices :PStrList;|22: fDevices1:PStrList;|14: ban:PArray;|9: public|78: onInitModule, onSendData,qaStatus,qaData1,qaData2,onGetVolume:THI_Event; |1021: |47: procedure InitModule(var dt:TData;Ind:Word);|46: procedure SendToOut(var dt:TData;Ind:Word);|47: procedure OpenMidiIn(var dt:TData;Ind:Word);|48: procedure OpenMidiOut(var dt:TData;Ind:Word);|50: procedure SetInstrument(var dt:TData;Ind:Word);|46: procedure MidiReset(var dt:TData;Ind:Word);|47: procedure SetVolume(var dt:TData;Ind:Word);|48: procedure GetVolume(var dt:TData;Ind:Word);|2: |43: procedure DevIn (var dt:TData;Ind:Word);|44: procedure DevOut (var dt:TData;Ind:Word);|48: procedure Instrument (var dt:TData;Ind:Word);|9: |49: procedure _Set(var Item:TData; var Val:TData);|56: function _Get(Var Item:TData; var Val:TData):boolean;|27: function _Count:integer;|33: procedure _Add(var Val:TData);|50: procedure _Set1(var Item:TData; var Val:TData);|57: function _Get1(Var Item:TData; var Val:TData):boolean;|28: function _Count1:integer;|59: function _GetIns(Var Item:TData; var Val:TData):boolean;|30: function _CountIns:integer;|34: procedure _Add1(var Val:TData);|20: Procedure Events;|24: constructor Create; |22: destructor Destroy;|5: end;|0:|14:implementation|0:|31:constructor THiAsmClass.Create;|20:begin |17:inherited Create;|23:fDevices := NewStrList;|24:fDevices1 := NewStrList;|4:end;|0:|31:destructor THiAsmClass.Destroy;|5:begin|14:fDevices.Free;|15:fDevices1.Free;|4:end;|0:|123:var aMIH: PHMIDIIN; aMsg1: UInt; aData1, aMidiData1, aTimeStamp1, IndDevice: integer; outdata:HiEvent;DeviceHandle:THandle;|0:|29:procedure THiAsmClass.Events;|33:var dt,d1,d2,d3,d4:TData;s:PData;|5:begin|11:dtNull(dt);|22:dtInteger(d1, aData1);|40:dtInteger(d2, aMidiData1 and $000000FF);|48:dtInteger(d3, (aMidiData1 and $0000FF00) shr 8);|49:dtInteger(d4, (aMidiData1 and $00FF0000) shr 16);|21:AddMTData(@dt,@d1,s);|21:AddMTData(@dt,@d2,s);|21:AddMTData(@dt,@d3,s);|21:AddMTData(@dt,@d4,s);|28:_hi_OnEvent(onSendData, dt);|14:FreeData(@d1);|14:FreeData(@d2);|14:FreeData(@d3);|14:FreeData(@d4);|14:FreeData(@dt);|4:end;|0:|33:procedure THiAsmClass.InitModule;|3:var|13: i: integer;|23: lInCaps: TMidiInCaps;|25: lOutCaps: TMidiOutCaps;|20: lResult: MMRESULT;|21: lResult1: MMRESULT;|6:begin |16: fDevices.Clear;|16: fDevices.Clear;|2: |38: for I:= 0 to midiInGetNumDevs - 1 do|8: begin|69: lResult := midiInGetDevCaps( i, @lInCaps, SizeOf( TMidiInCaps ));|80: if lResult = MMSYSERR_NOERROR then fDevices.Add( String( lInCaps.szPname ));|7: end;|3: |3: |38: for i:=0 to midiOutGetNumDevs - 1 do|7: begin|73: lResult1 := midiOutGetDevCaps( i, @lOutCaps, SizeOf( TMidiOutCaps ));|83: if lResult1 = MMSYSERR_NOERROR then fDevices1.Add( String( lOutCaps.szPname ));|6: end;|43:_hi_OnEvent(onInitModule,Integer(lResult));|16:outdata:=Events;|4:end;|0:|27:procedure THiAsmClass._Set;|18:var ind:integer;|5:begin|27: ind := ToIntIndex(Item);|48: if (ind >= 0) and (ind < fDevices.Count) then|43: fDevices.Items[ind] := ToString(Val);|4:end;|0:|27:procedure THiAsmClass._Add;|5:begin|31: fDevices.Add(ToString(val));|4:end;|0:|26:function THiAsmClass._Get;|18:var ind:integer;|5:begin|27: ind := ToIntIndex(Item);|54: if (ind >= 0) and (ind < fDevices.Count) then begin|21: Result := true;|40: dtString(Val,fDevices.Items[ind]);|11: end else|22: Result := false;|4:end;|0:|28:function THiAsmClass._Count;|5:begin|28: Result := fDevices.Count;|4:end;|0:|28:procedure THiAsmClass._Set1;|18:var ind:integer;|5:begin|27: ind := ToIntIndex(Item);|49: if (ind >= 0) and (ind < fDevices1.Count) then|44: fDevices1.Items[ind] := ToString(Val);|4:end;|0:|28:procedure THiAsmClass._Add1;|5:begin|31: fDevices.Add(ToString(val));|4:end;|0:|27:function THiAsmClass._Get1;|18:var ind:integer;|5:begin|27: ind := ToIntIndex(Item);|55: if (ind >= 0) and (ind < fDevices1.Count) then begin|21: Result := true;|41: dtString(Val,fDevices1.Items[ind]);|11: end else|22: Result := false;|4:end;|0:|29:function THiAsmClass._Count1;|5:begin|29: Result := fDevices1.Count;|4:end;|0:|28:procedure THiAsmClass.DevIn;|5:begin|63:if Arr = nil then Arr := CreateArray(_Set, _Get, _Count, _Add);|16:dtArray(dt,Arr);|4:end;|0:|29:procedure THiAsmClass.DevOut;|5:begin|69:if Arr1 = nil then Arr1 := CreateArray(_Set1, _Get1, _Count1, _Add1);|17:dtArray(dt,Arr1);|4:end;|0:|0:|107:procedure CallBackData(aMidiInHandle: PHMIDIIN; aMsg: UInt; aData, aMidiData, aTimeStamp: integer);stdcall;|5:begin|21:aMIH:= aMidiInHandle;|12:aMsg1:=aMsg;|15:aData1:= aData;|22:aMidiData1:=aMidiData;|24:aTimeStamp1:=aTimeStamp;|8:outdata;|4:end;|0:|33:procedure THiAsmClass.OpenMidiIn;|3:var|19: lHandle: THandle;|20: lResult: MMResult;|5:begin|52: if ToInteger(dt) > fDevices.Count then Exit;|110: lResult := midiInOpen( @lHandle, ToInteger(dt), cardinal(@CallBackData), ToInteger(dt), CALLBACK_FUNCTION );|28: midiInStart(lHandle); |4:end;|0:|0:|34:procedure THiAsmClass.OpenMidiOut;|3:var|20: lResult: MMRESULT;|19: lHandle: THandle;|5:begin|47: if ToInteger(dt) > fDevices.Count then Exit;|26: IndDevice:=ToInteger(dt);|69: lResult := midiOutOpen( @lHandle, IndDevice, 0, 0, CALLBACK_NULL );|24: DeviceHandle:=lHandle;|53: if lResult <> MMSYSERR_NOERROR then case lResult of|44:MIDIERR_NODEVICE:_debug('MIDIERR_NODEVICE');|48:MMSYSERR_ALLOCATED:_debug('MMSYSERR_ALLOCATED');|52:MMSYSERR_BADDEVICEID:_debug('MMSYSERR_BADDEVICEID');|50:MMSYSERR_INVALPARAM:_debug('MMSYSERR_INVALPARAM');|40:MMSYSERR_NOMEM:_debug('MMSYSERR_NOMEM');|6: end;|4:end;|0:|32:procedure THiAsmClass.SendToOut;|24:var MidiResult:MMResult;|19: lMsg: cardinal;|20: lHandle:THandle;|5:begin|39:if IndDevice>fDevices1.Count then Exit;|112: //lMsg := ReadInteger(dt, qaStatus) + (ReadInteger(dt, qaData1) * $100) + (ReadInteger(dt, qaData2) * $10000);|52: lHandle := THandle( fDevices1.items[ IndDevice] );|114: lMsg := ReadInteger(dt, qaStatus) + ( ReadInteger(dt, qaData1) * $100 ) + ( ReadInteger(dt, qaData2) * $10000 );|74: MidiResult := midiOutShortMsg(DeviceHandle{lHandle},{test$7F3C90} lMSG);|57: // if MidiResult <> MMSYSERR_NOERROR then _debug('eror')|60: if MidiResult <> MMSYSERR_NOERROR then case MidiResult of|50:MIDIERR_BADOPENMODE:_debug('MIDIERR_BADOPENMODE');|44:MIDIERR_NOTREADY:_debug('MIDIERR_NOTREADY');|52:MMSYSERR_INVALHANDLE:_debug('MMSYSERR_INVALHANDLE');|4:end;|4:end;|0:|36:procedure THiAsmClass.SetInstrument;|21:var midimsg:cardinal;|5:begin|34:midimsg := $C0+$100*ToInteger(dt);|40:midiOutShortMsg (DeviceHandle, midimsg);|4:end;|0:|29:function THiAsmClass._GetIns;|18:var ind:integer;|5:begin|27: ind := ToIntIndex(Item);|44: if (ind >= 0) and (ind <= 127) then begin|21: Result := true;|37: dtString(Val,Instruments[ind]);|11: end else|22: Result := false;|4:end;|0:|31:function THiAsmClass._CountIns;|5:begin|17: Result := 127;|4:end;|0:|33:procedure THiAsmClass.Instrument;|5:begin|65:if ban = nil then ban:=CreateArray(nil, _GetIns, _CountIns, nil);|17:dtArray(dt, ban);|4:end;|0:|32:procedure THiAsmClass.MidiReset;|5:begin|27:MidiOutReset(DeviceHandle);|4:end;|0:|32:procedure THiAsmClass.GetVolume;|14:var vol:Dword;|5:begin|37:midiOutGetVolume(DeviceHandle, @vol);|39:_hi_OnEvent(onGetVolume, integer(vol));|4:end;|0:|32:procedure THiAsmClass.SetVolume;|14:var vol:Dword;|5:begin|33:vol:=ToInteger(dt)+ToInteger(dt);|36:midiOutSetVolume(DeviceHandle, vol);|4:end;|4:end.|
link(onSendData,2972307:doEvent1,[])
link(onInitModule,7098403:doEnum,[])
link(qaStatus,5475031:Value2,[(216,121)(380,121)(380,184)(545,184)])
link(qaData1,5475031:Value3,[(223,121)(387,121)(387,184)(552,184)])
link(qaData2,5475031:Value4,[(230,121)(394,121)(394,184)(559,184)])
}




карма: 0

1
файлы: 1code_20842.txt [8.2KB] [354]
Голосовали:Poputchik