1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278:
| unit UMain;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, ComCtrls, MPlayer, XPMan, Menus, inifiles;
type TMainForm = class(TForm) Sound2But: TButton; Sound3But: TButton; Sound4But: TButton; OpenDialog: TOpenDialog; TaktTimer: TTimer; MainPan: TPanel; Sp1Lab: TLabel; Sp2Lab: TLabel; Sp3Lab: TLabel; Sp4Lab: TLabel; SpeedLab: TLabel; Sp1T1: TCheckBox; Sp1T1U: TCheckBox; Sp1T3U: TCheckBox; Sp1T3: TCheckBox; Sp1T4U: TCheckBox; Sp1T4: TCheckBox; SpeedBar: TTrackBar; StartBut: TButton; StopBut: TButton; Sound1But: TButton; Sp1Play: TMediaPlayer; Sp2Play: TMediaPlayer; Sp3Play: TMediaPlayer; Sp4Play: TMediaPlayer; CheckNone: TCheckBox; CheckAll: TCheckBox; Sp1T2: TCheckBox; Sp1T2U: TCheckBox; Sp2T1: TCheckBox; Sp2T1U: TCheckBox; Sp2T2: TCheckBox; Sp2T2U: TCheckBox; Sp2T3: TCheckBox; Sp2T3U: TCheckBox; Sp2T4: TCheckBox; Sp2T4U: TCheckBox; Sp3T1: TCheckBox; Sp3T2: TCheckBox; Sp3T2U: TCheckBox; Sp3T3: TCheckBox; Sp3T3U: TCheckBox; Sp3T4: TCheckBox; Sp3T4U: TCheckBox; Sp4T4U: TCheckBox; Sp4T4: TCheckBox; Sp4T3U: TCheckBox; Sp4T3: TCheckBox; Sp4T2: TCheckBox; Sp4T2U: TCheckBox; Sp4T1U: TCheckBox; Sp4T1: TCheckBox; Sp3T1U: TCheckBox; XPManifest1: TXPManifest; MainMenu1: TMainMenu; Datei1: TMenuItem; Laden1: TMenuItem; Speichern1: TMenuItem; N1: TMenuItem; Beenden1: TMenuItem; OpenIniDialog: TOpenDialog; SaveIniDialog: TSaveDialog; Counter: TLabel; procedure SpeedBarChange(Sender: TObject); procedure StartButClick(Sender: TObject); procedure TaktTimerTimer(Sender: TObject); procedure SoundButClick(Sender: TObject); procedure FormCreate(Sender: TObject); procedure CheckNoneClick(Sender: TObject); procedure CheckAllClick(Sender: TObject); procedure Speichern1Click(Sender: TObject); procedure ChangeSpeed; procedure OpenPlayers; procedure SaveIni; procedure LoadIni; procedure Laden1Click(Sender: TObject); private public end;
var MainForm: TMainForm; PosI: Integer = 1; Def_Files: array[1..4] of String = ('sounds\bass_drum.wav', 'sounds\snare_drum.wav', 'sounds\open_hi_hat.wav', 'sounds\closed_hi_hat.wav'); Files: array[1..4] of String; File_Names: array[1..4] of String = ('File1', 'File2', 'File3', 'File4');
const Takt: Array[1..8] of String = ('1', '1U', '2', '2U', '3', '3U', '4', '4U');
implementation
{$R *.dfm}
procedure TMainForm.OpenPlayers; var X: Integer; TempMP: TMediaPlayer; begin for X := 1 to 4 do begin if FileExists(Files[X]) then begin TempMP := TMediaPlayer(FindComponent('Sp' + IntToStr(X) + 'Play'));
TempMP.FileName := Files[X]; TempMP.Open; end; end; end;
procedure TMainForm.ChangeSpeed; begin SpeedLab.Caption := IntToStr(SpeedBar.Position) + ' bpm'; TaktTimer.Interval := Round(((1 / (SpeedBar.Position / 60)) * 1000) / 2); end;
procedure TMainForm.LoadIni; var ini: Tinifile; i, x, y: integer; begin if OpenIniDialog.execute then begin ini := Tinifile.Create(OpenIniDialog.Filename); try with ini do begin SpeedBar.position := readinteger('Settings', 'Speed', 120); for i := 1 to 4 do Files[i] := readstring('Settings', File_Names[i], def_Files[i]); for X := 1 to 4 do for Y := 1 to 8 do TCheckbox(FindComponent('Sp' + IntToStr(X) + 'T' + Takt[Y])).Checked := readbool('SpT', inttostr(x) + Takt[y], TCheckbox(FindComponent('Sp' + IntToStr(X) + 'T' + Takt[Y])).Checked); end; finally ini.Free; end; end; end;
procedure TMainForm.SaveIni; var ini: Tinifile; i, x, y: integer; begin if SaveIniDialog.execute then begin ini := Tinifile.Create(SaveIniDialog.Filename); try with ini do begin writeinteger('Settings', 'Speed', SpeedBar.position); for i := 1 to 4 do writestring('Settings', File_Names[i], Files[i]); for X := 1 to 4 do for Y := 1 to 8 do writebool('SpT', inttostr(x) + Takt[y], TCheckbox(FindComponent('Sp' + IntToStr(X) + 'T' + Takt[Y])).Checked); end; finally ini.Free; end; end; end;
procedure TMainForm.SpeedBarChange(Sender: TObject); begin ChangeSpeed; end;
procedure TMainForm.StartButClick(Sender: TObject); begin if TButton(Sender).Name = 'StartBut' then begin StopBut.Enabled := true; TaktTimer.Enabled := true; SpeedBar.Enabled := false; StartBut.Enabled := false; end; if TButton(Sender).Name = 'StopBut' then begin TaktTimer.Enabled := false; SpeedBar.Enabled := true; StartBut.Enabled := true; StopBut.Enabled := false; end; end;
procedure TMainForm.TaktTimerTimer(Sender: TObject); var X: Integer; begin for X := 1 to 4 do if TCheckBox(FindComponent('Sp' + IntToStr(X) + 'T' + Takt[PosI])).Checked then TMediaPlayer(FindComponent('Sp' + IntToStr(X) + 'Play')).Play;
if (posi mod 2 <> 0) then Counter.caption := inttostr((posi + 1) div 2);
inc(PosI); if PosI = 9 then PosI := 1; end;
procedure TMainForm.SoundButClick(Sender: TObject); var temptag: integer; begin StopBut.Click; if OpenDialog.Execute then begin Temptag := TButton(Sender).Tag; Files[Temptag] := OpenDialog.FileName; if FileExists(Files[Temptag]) then begin TMediaPlayer(FindComponent('Sp' + inttostr(Temptag) + 'Play')).FileName := Files[Temptag]; TMediaPlayer(FindComponent('Sp' + inttostr(Temptag) + 'Play')).Open; end; end; end;
procedure TMainForm.FormCreate(Sender: TObject); var i: integer; begin for i := 1 to 4 do Files[i] := ExtractFilePath(ParamStr(0)) + def_files[i]; OpenPlayers; end;
procedure TMainForm.CheckNoneClick(Sender: TObject); var X, Y: Integer; begin CheckNone.Checked := False;
for X := 1 to 4 do for Y := 1 to 8 do TCheckbox(FindComponent('Sp' + IntToStr(X) + 'T' + Takt[Y])).Checked := False; end;
procedure TMainForm.CheckAllClick(Sender: TObject); var X, Y: Integer; begin CheckAll.Checked := True;
for X := 1 to 4 do for Y := 1 to 8 do TCheckbox(FindComponent('Sp' + IntToStr(X) + 'T' + Takt[Y])).Checked := True; end;
procedure TMainForm.Speichern1Click(Sender: TObject); begin SaveIni; end;
procedure TMainForm.Laden1Click(Sender: TObject); begin StopBut.Click; LoadIni; end;
end. |