File: acomp.pl

package info (click to toggle)
midicsv 1.1%2Bdfsg.1-1
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye, buster, stretch, trixie
  • size: 316 kB
  • ctags: 183
  • sloc: ansic: 1,304; perl: 471; makefile: 159
file content (69 lines) | stat: -rw-r--r-- 1,848 bytes parent folder | download | duplicates (2)
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

    #	Incredibly dumb algorithmic composer

    require 'general_midi.pl';

    $instrument = $GM_Patch{'Distortion Guitar'};
    $tonespan = 32;
    $num_notes = 120;
    $percussion = $GM_Percussion{'Ride Cymbal 1'};
    $beat = 6;

    print << "EOD";
0, 0, Header, 1, 1, 480
1, 0, Start_track
1, 0, Tempo, 500000
1, 0, Program_c, 1, $instrument
EOD

    $time = 0;
    srand(time());
    
    for ($i = 0; $i < $num_notes; $i++) {
    	$n = 60 + int((rand() * $tonespan) - int($tonespan / 2));
    	$notelength = 120 + (60 * int(rand() * 6));
	&note(1, $n, $notelength, 127);
	if (($i % $beat) == 0) {
	    print("1, $time, Note_on_c, 9, $percussion, 127\n");
	} elsif (($i % $beat) == ($beat - 1)) {
	    print("1, $time, Note_off_c, 9, $percussion, 0\n");
	}
    }
    
    #	Cymbal crash at end
    $cymbal = $GM_Percussion{'Crash Cymbal 2'};
    print("1, $time, Note_on_c, 9, $cymbal, 127\n");
    $time += 480;
    print("1, $time, Note_off_c, 9, $cymbal, 0\n");
    
    #	Audience applause
    $time += 480;
    print("1, $time, Program_c, 1, $GM_Patch{'Applause'}\n");     
    print("1, $time, Note_on_c, 1, 60, 100\n");
    for ($i = 16; $i <= 32; $i++) {
    	$time += 120;
	$v = int(127 * ($i / 32));
	print("1, $time, Poly_aftertouch_c, 1, 60, $v\n");
    }
    for ($i = 32; $i >= 0; $i--) {
    	$time += 240;
	$v = int(127 * ($i / 32));
	print("1, $time, Poly_aftertouch_c, 1, 60, $v\n");
    }
    print("1, $time, Note_off_c, 1, 60, 0\n");
   
    print << "EOD";
1, $time, End_track
0, 0, End_of_file
EOD

    sub note {	# &note($channel, $note_number, $duration [, $velocity])
    	local ($channel, $which, $duration, $vel) = @_;
	
	if (!defined($vel)) {
	    $vel = 127;
	}
    	print("1, $time, Note_on_c, $channel, $which, $vel\n");
	$time += $duration;
    	print("1, $time, Note_off_c, $channel, $which, 0\n");
    }