Attack, Decay, Sustain, Release
TikZ, 195 193 181 177 172 167 163 160 159 bytes
Thanks to David Carlisle for his helpful answer here
\documentclass[tikz]{standalone}\begin{document}\tikz\def~#1{\typein[#1];}~\a~\s~\d~\r\def\u{)--(\a+\d}\draw(,)--(\a,127\u,\s\u+64,\s\u+\r+64,);\end{document}
Yes, you heard right TikZ.
Explanation
This uses a couple of techniques to achieve its goal. The first thing is input. Most people might not know that LATEX can take input. Well it can. This is achieved with the command \typein
. This will halt the compiler and request input from the user as assign it to a variable.
The other main technique is the use of \def
. \def
in Tikz is absurdly powerful. It essentially defines a piece of code and pastes it everywhere you call the variable. In this code we define two things \typein[#1]{}
so that we can assign our variables golfily and )--(\a+\d
because this code shows up a bunch of times in the ungolfed version.
Here are two versions of the code (without the wrapper):
Golfed:
\documentclass[tikz]{standalone}\begin{document}\tikz\def~#1{\typein[#1];}~\a~\s~\d~\r\def\u{)--(\a+\d}\draw(,)--(\a,127\u,\s\u+64,\s\u+\r+64,);\end{document}
Ungolfed:
\typein[\a]{}\typein[\s]{}\typein[\d]{}\typein[\r]{}\draw(0,0)--(\a,127)--(\a+\d,)--(\a+\d+64,)--(\a+\d+\r+64,0);
Image:
Since I cannot upload a pdf image directly, and converting it to any other format seems to cause the line to disappear altogether, here is what an image might look like when opened in Preview (input for this image is [64 64 64 64]
):
As you can see it is very thin. However because it is a PDF image and not a raster image does not have to comply with thickness requirements.
Python 2, 83 80 79 bytes
from turtle import*
def f(A,D,S,R):X=A+D+64;map(goto,[A,A+D,X,X+R],[127,S,S,0])
Try it online (83-byte version, because it runs online)
Note that certain outputs may not be completely visible using Trinket, because of the way the canvas works. You'll need to download and install Python if you want it to work better.
Ungolfed:
from turtle import*
A,D,S,R=input()
goto(A,127)
goto(A+D,S)
goto(A+D+64,S)
goto(A+D+64+R,0)
This version doesn't work in Trinket, because Trinket doesn't support value unpacking of input.
Mathematica, 61 58 bytes
ListLinePlot[{Accumulate@{0,##3,64,#2},{0,127,#,#,0}}]&
is the operator for Transpose
and is rendered as a superscript T
by Mathematica.
Takes the arguments in the order S, R, A, D
and returns a vector graphics object.
Results for all seven test cases:
Click for larger version.