AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

code optimieren

Ein Thema von fwsp · begonnen am 2. Feb 2006 · letzter Beitrag vom 2. Feb 2006
Antwort Antwort
fwsp
(Gast)

n/a Beiträge
 
#1

code optimieren

  Alt 2. Feb 2006, 19:15
wer kann mir helfen diesen code zu verbessern?

Delphi-Quellcode:
function Skale(StartTon, Dauer: integer): string;
var Dur: array[1..8] of integer;
    Moll: array[1..8] of integer;
    Pentatonisch: array[1..6] of integer;
    Ganzton: array[1..7] of integer;
    Dorisch: array[1..8] of integer;
    Chromatisch: array[1..13] of integer;
    Zufall, i: integer;
begin
 case UGlobal.SkArt of
  1: Zufall:= random(2) + 1; //Dur, Moll
  2: Zufall:= random(4) + 1; //Dur, Moll, Pentatonisch, Ganzton
  3: Zufall:= random(6) + 1; //Dur, Moll, Pentatonisch, Ganzton, Dorisch, Chromatisch
  else Zufall:= 3;
  end;

 case Zufall of
  1: begin //Dur
      Dur[1]:= 0;
      Dur[2]:= 2;
      Dur[3]:= 4;
      Dur[4]:= 5;
      Dur[5]:= 7;
      Dur[6]:= 9;
      Dur[7]:= 11;
      Dur[8]:= 12;
      for i:= 1 to Length(Dur) do
       begin
        FMain.MidiOutput.PutShort($90, StartTon + Dur[i], UGlobal.IVLautstaerke);
        UPause.Pause(Dauer);
       end;
      Result:= 'Dur';
     end;

  2: begin //Moll
      Moll[1]:= 0;
      Moll[2]:= 2;
      Moll[3]:= 3;
      Moll[4]:= 5;
      Moll[5]:= 7;
      Moll[6]:= 8;
      Moll[7]:= 10;
      Moll[8]:= 12;
      for i:= 1 to Length(Moll) do
       begin
        FMain.MidiOutput.PutShort($90, StartTon + Moll[i], UGlobal.IVLautstaerke);
        UPause.Pause(Dauer);
       end;
      Result:= 'Moll';
     end;

  3: begin //Pentatonisch
      Pentatonisch[1]:= 0;
      Pentatonisch[2]:= 2;
      Pentatonisch[3]:= 4;
      Pentatonisch[4]:= 7;
      Pentatonisch[5]:= 9;
      Pentatonisch[6]:= 12;
      for i:= 1 to Length(Pentatonisch) do
       begin
        FMain.MidiOutput.PutShort($90, StartTon + Pentatonisch[i], UGlobal.IVLautstaerke);
        UPause.Pause(Dauer);
       end;
      Result:= 'Pentatonisch';
     end;

  4: begin //Ganzton
      Ganzton[1]:= 0;
      Ganzton[2]:= 2;
      Ganzton[3]:= 4;
      Ganzton[4]:= 6;
      Ganzton[5]:= 8;
      Ganzton[6]:= 10;
      Ganzton[7]:= 12;
      for i:= 1 to Length(Ganzton) do
       begin
        FMain.MidiOutput.PutShort($90, StartTon + Ganzton[i], UGlobal.IVLautstaerke);
        UPause.Pause(Dauer);
       end;
      Result:= 'Ganzton';
     end;

  5: begin //Dorisch
      Dorisch[1]:= 0;
      Dorisch[2]:= 2;
      Dorisch[3]:= 3;
      Dorisch[4]:= 5;
      Dorisch[5]:= 7;
      Dorisch[6]:= 9;
      Dorisch[7]:= 10;
      Dorisch[8]:= 12;
      for i:= 1 to Length(Dorisch) do
       begin
        FMain.MidiOutput.PutShort($90, StartTon + Dorisch[i], UGlobal.IVLautstaerke);
        UPause.Pause(Dauer);
       end;
      Result:= 'Dorisch';
     end;

  6: begin //Chromatisch
      Chromatisch[1]:= 0;
      Chromatisch[2]:= 1;
      Chromatisch[3]:= 2;
      Chromatisch[4]:= 3;
      Chromatisch[5]:= 4;
      Chromatisch[6]:= 5;
      Chromatisch[7]:= 6;
      Chromatisch[8]:= 7;
      Chromatisch[9]:= 8;
      Chromatisch[10]:= 9;
      Chromatisch[11]:= 10;
      Chromatisch[12]:= 11;
      Chromatisch[13]:= 12;
      for i:= 1 to Length(Chromatisch) do
       begin
        FMain.MidiOutput.PutShort($90, StartTon + Chromatisch[i], UGlobal.IVLautstaerke);
        UPause.Pause(Dauer);
       end;
      Result:= 'Chromatisch';
     end;

  end;
end;
danke.
  Mit Zitat antworten Zitat
Benutzerbild von Khabarakh
Khabarakh

Registriert seit: 18. Aug 2004
Ort: Brackenheim VS08 Pro
2.876 Beiträge
 
#2

Re: code optimieren

  Alt 2. Feb 2006, 19:22
Code:
function S[s]k[/s][b]c[/b]ale(StartTon, Dauer: integer): string;
Rest folgt gleich .
Sebastian
Moderator in der EE
  Mit Zitat antworten Zitat
Waldteufel
(Gast)

n/a Beiträge
 
#3

Re: code optimieren

  Alt 2. Feb 2006, 19:26
Hi.

Zitat von fwsp:
wer kann mir helfen diesen code zu verbessern?
Ich!

Delphi-Quellcode:
const
  Dur : array[1..8] of integer = (0, 2, 4, 5, 7, 9, 11, 12);
  Moll : array[1..8] of integer = (0, 2, 3, 5, 7, 8, 107, 12);
  Pentatonisch : array[1..6] of integer = (0, 2, 4, 7, 9, 12);
  Dorisch : array[1..8] of integer = (0, 2, 3, 5, 7, 9, 10, 12);

function Skala(StartTon, Dauer: integer): string;
var
  Tonleiter, i: integer;
begin
  if UGlobal.SkArt in [1, 2, 3] then
    Tonleiter := random(2 * UGlobal.SkArt) + 1;
  else Tonleiter := 3;

  case Tonleiter of
    1: begin // Dur
         for i := 1 to Length(Dur) do
         begin
           FMain.MidiOutput.PutShort($90, StartTon + Dur[i], UGlobal.IVLautstaerke);
           UPause.Pause(Dauer);
         end;
         Result := 'Dur';
       end;

    2: begin // Moll
         for i := 1 to Length(Moll) do
         begin
           FMain.MidiOutput.PutShort($90, StartTon + Moll[i], UGlobal.IVLautstaerke);
           UPause.Pause(Dauer);
         end;
         Result := 'Moll';
       end;

    3: begin // Pentatonisch
         for i := 1 to Length(Pentatonisch) do
         begin
           FMain.MidiOutput.PutShort($90, StartTon + Pentatonisch[i], UGlobal.IVLautstaerke);
          UPause.Pause(Dauer);
         end;
         Result := 'Pentatonisch';
       end;

    4: begin // Ganzton
         for i := 0 to 6 do
         begin
           FMain.MidiOutput.PutShort($90, StartTon + (i * 2), UGlobal.IVLautstaerke);
           UPause.Pause(Dauer);
         end;
         Result := 'Ganzton';
       end;

    5: begin // Dorisch
         for i := 1 to Length(Dorisch) do
         begin
           FMain.MidiOutput.PutShort($90, StartTon + Dorisch[i], UGlobal.IVLautstaerke);
           UPause.Pause(Dauer);
         end;
         Result := 'Dorisch';
       end;

    6: begin // Chromatisch
         for i := 0 to 12 do
         begin
           FMain.MidiOutput.PutShort($90, StartTon + i, UGlobal.IVLautstaerke);
           UPause.Pause(Dauer);
         end;
         Result := 'Chromatisch';
       end;
  end;
end;
  Mit Zitat antworten Zitat
Benutzerbild von Khabarakh
Khabarakh

Registriert seit: 18. Aug 2004
Ort: Brackenheim VS08 Pro
2.876 Beiträge
 
#4

Re: code optimieren

  Alt 2. Feb 2006, 19:58
Fertig, kurz genug ?
Delphi-Quellcode:
function Skala(StartTon, Dauer: integer): string;
const
  Scales: array[0..3 * 8 + 6 - 1] of Integer =
  (0, 2, 4, 5, 7, 9, 11, 12, // Dur
   0, 2, 3, 5, 7, 8, 10, 12, // Moll
   0, 2, 4, 7, 9, 12, // Pentatonisch
   0, 2, 3, 5, 7, 9, 10, 12); // Dorisch
  Starts: Array[0..4] of Integer = (0, 8, 8 + 6, 2 * 8 + 6, 3 * 8 + 6);
  Names: Array[0..5] of string = ('Dur', 'Moll', 'Pentatonisch', 'Dorisch',
                                  'Ganzton', 'Chromatisch');
var
  Scale, i: Integer;

  procedure PutIt(const Tone: Integer);
  begin
    // Ieeks, globale Variablen
    FMain.MidiOutput.PutShort($90, Tone, UGlobal.IVLautstaerke);
    UPause.Pause(Dauer);
  end;

begin
  if UGlobal.SkArt in [1, 2, 3] then
    Scale := Random(2 * UGlobal.SkArt);
  else
    Scale := 2;

  case Scale of
    0..3:
      for i := Starts[Scale] to Starts[Scale + 1] - 1 do
        PutIt(Startton + Scales[i]);

    4: // Ganzton
      for i := 0 to 6 do
        PutIt(Startton + 2 * i);

    5: // Chromatisch
      for i := 0 to 12 do
        PutIt(Startton + i);
  end;

  Result := Names[Scale];
end;
Vielleicht sind noch kleine Fehler drin, aber die kannst du ja selbst verbessern.
Sebastian
Moderator in der EE
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 12:10 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz