[Question]
  [
# Challenge
## Premise
Bob is a novice pianist who can only play sequences of single notes. In addition, he does quite an interesting thing: for every note after the first, if it's higher than the previous note was, he uses the finger directly to the right of the previous finger used; if lower, to the left; if the same pitch, well, the same finger.
Let's take Auld Lang Syne as an example, and arbitrarily suppose, only for the sake of this example, that Bob uses the very right side of his right hand.
```
Pitch: Should < auld = ac- = quain- < tance > be > for- < got
Digit: mid      ring   ring  ring     pinky   ring mid    ring
```
Alice wants to convince him of the stupidity of his playing...
## Task
Input: a sequence of \$n\$ MIDI note numbers (which are integers between 0 and 127 inclusive), where \$2\leq n\leq10000\$.
Output: the number of fingers required to finish the melody with the playing style outlined in 'Premise'.
Please note that the answer may be more than 5.
No consideration of the starting finger is needed. Assume that the choice is optimal for playable melodies and has nothing (else) to do with the number of fingers required.
### Example 1
Input: `0 0 0 0`
Output: `1`
### Example 2
Input: `43 48 48 48 52 50 48 50`
Output: `3`
### Example 3
Input: `86 88 84 81 83 79 74 76 72 69 71 67 62 64 60 57 59 57 56 55`
Output: `9`
### Example 4
Input: `82 79 78 76 78 76 74 73 70 67 66 64 66 64 62 61`
Output: `12`
# Remarks
* This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so fewest bytes wins.
* [Standard rules](https://codegolf.meta.stackexchange.com/questions/2419/default-for-code-golf-program-function-or-snippet/), [I/O rules](https://codegolf.meta.stackexchange.com/questions/2447/default-for-code-golf-input-output-methods) and [loophole rules](https://codegolf.meta.stackexchange.com/questions/1061/loopholes-that-are-forbidden-by-default) apply.
* If possible, link an online demo of your code.
* Please explain your code.
  
[Answer]
# [Perl 6](https://github.com/nxadm/rakudo-pkg), 27 bytes
```
{+minmax [\+] @_ Z<=>0,|@_}
```
[Try it online!](https://tio.run/##RY/RCoIwFIbvfYoDQRTuYk43J2b4HJmIFwlCRtRNUj37@odnefFx9u@c843dL4@rcdNM24Eqcu94Gm9T/6LmHLdUd3Q6VEcpPnX3dWUUPfuZhl2jMkEr7b6kDSVl6GapoMyuaAUkn@UynYZha4TFvYXJJgC7eQGQcwOwa3xGz@TAZ/QMfBpZF1wxq/XiLv5uxTLLslC93D8kWWpYGqp/JOFvKfcD "Perl 6 – Try It Online")
### Explanation
`@_ Z<=>0,|@_` uses the zip metaoperator (`Z`) with the compare operator (`<=>`) to zip the list with itself offset by 1 and return the result of the comparison., e.g. `[43, 48, 48, 48, 52, 50, 48, 50]` -> `(More More Same Same More Less Less More)`
`[\+]` Reduces the list by summing over it (More = 1, Same = 0, Less = -1), however the `\` does a 'triangular reduction' which produces a list of each calculation instead of the end result, e.g. `(More More Same Same More Less Less More)` -> `(More 2 2 2 3 2 1 2)`
`minmax` returns the range of smallest..largest, effectively removing duplicates. `(More 2 2 2 3 2 1 2)` -> `Order::More..3`
`+` just returns the length of this range (list), which is the result
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 8 bytes
```
¥.±ŒOÄZ>
```
[Try it online!](https://tio.run/##yy9OTMpM/f//0FK9QxuPTvI/3BJl9/9/tIWZjoKFBRCbALEhEBvrKJhbAjGQbw6UMzfSUTAD8YFyZuZADOID5cwMdBRMgXxTSygNVGtqGgsA "05AB1E – Try It Online")
---
## Explanation
```
¥              - Get the differences 
 .±            - Get the signs of these (so if they go up or down)    
   ŒO          - Sum the sublists of these 
     ÄZ        - And find the biggest absolute change
       >       - Add one (since we need a finger to play the first note)
```
[Answer]
# [Python 3.8](https://docs.python.org/3.8/), ~~64 63~~ 57 bytes
*-6 bytes thanks to @xnor's abuse of walrus!*
```
lambda l,t=0,a=0:len({(t:=t+(a<b)-(a>(a:=b)))for b in l})
```
[Try it online!](https://tio.run/##PY7NasMwEITvforBvUjUCf63Euq8SNOD4thEVJGNpFBC8LOnK6UUlmXY@WbY5e4vs6nEYp9Tf3xqeT2dJXTm@zyTfb7Xo2EP5ve9f2fy48Q3TB6Y3Pcnzvk0W5ygDPTKn@q6zNbD3V2SBEMrMwaPDlvnz8rsE@ANdpRnOi83n2GYrR0HD2ncz2gx2fmKiBLpsnBGj6tcmPOWOqxasli7dYtWnqWbQ8o5sZowrZxngVWGmt0fwqP/KiKDkeLxjUFqjelmBq9mQ8AZw2Ucvuk9d9OeEEuJielALzZEp/ShV2wOR/OwKz4fBPShef06mpQ/yxr/szmgSOoKtfibpkSTR5EHs0pECyEgaogCokK3Q1eja9GVaEkXaDu0pGu0OZoOzS7uFk0TCnaJKGNIxNBrUwE15THaxuhrU00RXyp/AQ "Python 3.8 (pre-release) – Try It Online")
A function that takes input `l` as a list of integers, and returns the number of fingers needed.
**How**:
`t` keeps track of the current finger (represented by an integer). For each 2 consecutive notes `a, b`, the finger is increased by `-1`, `0`, or `1` depending on whether `a>b`, `a==b` or `a<b`:
```
t:=t+(a<b)-(a>b)
```
All values of `t` are then gathered into a set, whose size is the number of unique fingers.
[Answer]
# [R](https://www.r-project.org/), ~~45~~ 42 bytes
```
`?`=diff;1+?range(0,cumsum(sign(?scan())))
```
[Try it online!](https://tio.run/##NcQxDoAgEATAr2yJ0UKR3GmM4SsQFGIhBYT3nzZMMUXEWXdeT4zHMtric7rVPIX21vaq@qSsbA0@q@Enmwbv4A1MfQNewTOIQQQyfQ1a5AM "R – Try It Online")
Thanks to JDL for -3 bytes.
[Answer]
# [FRACTRAN](https://en.wikipedia.org/wiki/FRACTRAN) 29 fractions (244 bytes)
```
7*61/2^129*59 3*61/2*59 47/59 59/61 2*53/7*47 31/47 47/53 7*37/2^129*31
17/31 31/37 67/2^128*17 5*19/2*3*17 5*11*23/2*13*17 5*11*23/2*17 13*23/3*11*17
13*23/3*17 41/17 17/19 29/3*23 41/23 23/29 3*43/5*41 3*43/2*41 47/41
41/43 2/67 1/3 2/13 2/11
```
Input: \$59\cdot 2^n\$, where \$n\$ is the MIDI list (terminated in the sentinel 128) in base-129. That is, if the list is \$\{n\_0, n\_1, n\_2, \dots, n\_m\}\$, then
\$n=n\_0 + 129n\_1 + 129^2n\_2 + \cdots + 129^{m}n\_m + 129^{m+1}\cdot 128\$.
Output: \$2^k\$, where \$k\$ is the number of necessary fingers.
---
To try this online, the interpreter at <https://pimlu.github.io/fractran/> is able to evaluate the program relatively quickly, and it takes the program in the following syntax:
```
7*61%2^129*59
3*61%2*59
47%59
59%61
2*53%7*47
31%47
47%53
7*37%2^129*31
17%31
31%37
67%2^128*17
5*19%2*3*17
5*11*23%2*13*17
5*11*23%2*17
13*23%3*11*17
13*23%3*17
41%17
17%19
29%3*23
41%23
23%29
3*43%5*41
3*43%2*41
47%41
41%43
2%67
1%3
2%13
2%11
```
For the four examples, the program accepts this syntax for the input:
```
[59, 1], [2, 35446128768]
[59, 1], [2, 9845790461648320003]
[59, 1], [2, 209150948383325817811492382511176427430698872]
[59, 1], [2, 755543512556056338685630134436248304]
```
These are prime factorizations, saving having to multiply out the gigantic exponentials.
## How does it work?
In FRACTRAN, there is a state, which is initially set to the input value. The state is multiplied by each fraction one at a time, and if any results in a whole number, that number replaces the state and the program returns to the beginning of the list. If no fractions apply in this way, then the state is output and the program halts.
This is a terse way of describing a register machine. By prime factorizing everything, a fraction like 75/7 = 3\*5^2/7 means "if register seven is at least 1, then decrement it and add 1 to register three and 2 to register five."
Each prime in the program can be given a descriptive name, like 3 is 'a' and 59 is 'line1'. The rest don't particularly matter, since I'll give a disassembled version of the program, and you could figure out the rest of the assignments if you really wanted. Each line is like a chemical reaction; for example, the first line means "if line1 >= 1 and a >= 129, then decrement line1 by 1, decrement a by 129, increment line1r by 1, and increment adiv1 by 1."
```
0. line1 + 129 a -> line1r + adiv
1. line1 + a -> line1r + b
2. line1 -> line3
3. line1r -> line1
4. line3 + adiv -> line3r + a
5. line3 -> line4
6. line3r -> line3
7. line4 + 129 a -> line4r + adiv
8. line4 -> line5
9. line4r -> line4
10. line5 + 128 a -> line8
11. line5 + a + b -> line5r + c
12. line5 + a + MAX -> line6 + c + MIN
13. line5 + a -> line6 + c + MIN
14. line5 + b + MIN -> line6 + MAX
15. line5 + b -> line6 + MAX
16. line5 -> line7
17. line5r -> line5
18. line6 + b -> line6r
19. line6 -> line7
20. line6r -> line6
21. line7 + c -> line7r + b
22. line7 + a -> line7r + b
23. line7 -> line3
24. line7r -> line7
25. line8 -> a
26. b -> 0
27. MAX -> a
28. MIN -> a
```
So, here's an analysis. At the beginning, the input is `line1 + n a`. This means, the first relevant part of the program is
```
0. line1 + 129 a -> line1r + adiv
1. line1 + a -> line1r + b
2. line1 -> line3
3. line1r -> line1
```
which reduces the a register mod 129, putting the quotient in adiv and the remainder into b, which serves as a register to hold the previous MIDI note, which in this case is the very first one. Once this is done, it continues onto
```
4. line3 + adiv -> line3r + a
5. line3 -> line4
6. line3r -> line3
```
which moves adiv back into the a register, and for the main loop the a register starts with the remaining part of the MIDI list. Then,
```
7. line4 + 129 a -> line4r + adiv
8. line4 -> line5
9. line4r -> line4
```
The MIDI list is reduced mod 129, putting the rest of the list into adiv, leaving the MIDI note in the a register. This continues on to the the core calculation loop.
```
10. line5 + 128 a -> line8
11. line5 + a + b -> line5r + c
12. line5 + a + MAX -> line6 + c + MIN
13. line5 + a -> line6 + c + MIN
14. line5 + b + MIN -> line6 + MAX
15. line5 + b -> line6 + MAX
16. line5 -> line7
17. line5r -> line5
```
Reaction 10 detects if the sentinel 128 has occured, in which case it goes to line8 (the cleanup routine). Otherwise, we begin the comparison of a with b, to see which is larger. There are two registers MAX and MIN, representing the maximum and minimum relative finger numbers relative to note b so far. If a is greater than b, then we need to decrement MAX and increment MIN; if MAX is zero, then we don't decrement it, since this has the effect of widening the necessary number of fingers. Similarly, if b is greater than a, we need to decrement MIN (if nonzero) and increment MAX.
The comparison works by decrementing both a and b until one of them is zero. We will need the a register later on, to store it back into b, so whenever we decrement a, we increment a temporary variable c. Reaction 11 decrements a and b if they are both nonzero. Past this point, we know either b=0 or a=0. Reactions 12 and 13 are for the b=0 case, implementing the decrement-MAX-if-nonzero operation, and reactions 14 and 15 are for a=0. Reaction 16 is when a and be were equal.
If a and b were unequal in some way, then b is zeroed out with the following block
```
18. line6 + b -> line6r
19. line6 -> line7
20. line6r -> line6
```
And, along with the a=b case, this continues on to
```
21. line7 + c -> line7r + b
22. line7 + a -> line7r + b
23. line7 -> line3
24. line7r -> line7
```
which stores a+c into b, clearing a and c in the process. This has the effect of copying the original value of a at the start of the main loop into b. From here, we return to line3 to set up the main loop.
At the very end, once the sentinel is detected, the following block is run.
```
25. line8 -> a
26. b -> 0
27. MAX -> a
28. MIN -> a
```
Since the sentinel detection subtracts 128 from a, we know a is zero when entering this block. Then, the value of 1 + MAX + MIN is stored into a, and the value of b is cleared out. Once done, no other reactions apply, and the program terminates with the number of necessary fingers in the a register.
[Answer]
# JavaScript (ES6), ~~55 53~~ 52 bytes
```
a=>a.map(o=v=>o[i+=-(a>v)|a<(a=v)]=n+=!o[i],i=n=0)|n
```
[Try it online!](https://tio.run/##bczNCsIwEATgu2/hLcGxpDF/gtsXkR5CrVKpiVjJqe9eQ9SLCMswMMt39clP3WO4P7chnvrlTIunxlc3f2eREjXxOGxoy3yT@OwPzFPiLYUNrfPQYqBAgs9h6WKY4thXY7ywMztKhe@1nK9@VrWDcp/TElqUIv58OgPn4BRcDbeD3cMqWAMrYXKvYSxM7gpGQFvofUkDrf9psgiuCO/MWmZFcUxx3pnNOgvLCw "JavaScript (Node.js) – Try It Online")
### Commented
```
a =>                // a[] = input array of notes, re-used to store
  a.map(            //       the previous finger index
    o =             // o = object used to store the fingers
    v =>            // for each note v in a[]:
    o[              //   update o[i]:
      i +=          //     update i:
        -(a > v) |  //       decrement i if the previous value is greater than v
        a < (a = v) //       increment i if it's lower than v; and update a to v
    ] =             //       (if a = v or a is non-numeric, i is left unchanged)
      n += !o[i],   //     mark this finger as used and increment n if it was
                    //     not already used
    i = n = 0       //   start with i = n = 0
  ) | n             // end of map(); return n
```
[Answer]
# [Perl 5](https://www.perl.org/) `-MList::Util=uniq -pa`, 35 bytes
```
$_=uniq map{$c+=$_<=>$p;$p=$_;$c}@F
```
[Try it online!](https://tio.run/##K0gtyjH9/18l3rY0L7NQITexoFolWdtWJd7G1k6lwFqlAMi0VkmudXD7/9/CSMHcUsHcQsHcDEaaKJgbK5gbKJiZK5iZKZiZwEgjBTPDf/kFJZn5ecX/dX1N9QwMDYC0T2ZxiZVVaElmDti6/7oFiQA "Perl 5 – Try It Online")
[Answer]
# [Io](http://iolanguage.org/), ~~107~~ 105 bytes
-2 bytes after using "push" instead of "append".
```
method(x,(r :=x slice(0,-1)map(i,v,(v-x at(i+1))compare(0)))map(i,v,r slice(0,i+1)sum)push(0)unique size)
```
[Try it online!](https://tio.run/##bY3NDoIwEITvPsUeu7EmgLRUE9/ECyqJTfipFAzx5XFqClw8TLbTnf3GdvOtfDg6X@g6N9Xw7B5ikqLHx0S@tvdKJPKQclM6YeVbivdhonIQdp8y37vGlT0SzGugX69CxI8Nu9E/ERlb@xor8vZT8a9T1NYPIsslbWIm19t2qNvdFsmPknKzSWVQEt/J3xOjJRmsDagmhYAoThB8gV0BhA4eO11AwWOngVXw6hQnskr9r8gi0kTkMkNFqEsiWkf0MkNVuiHnLw "Io – Try It Online")
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), ~~53~~ 46 bytes
```
Tr[1^{0}~Union~Accumulate@Sign@Differences@#]&
```
[Try it online!](https://tio.run/##VY3LCsIwEEX3fkVBcNVFWptHF0IEP0BQV6VCCIkGbISarkr763ECU6WQy82dx5lOhafpVHBaRXuI174p7iOZ5pt3bz8ftR664aWCkRf38PLkrDW98dp85LbdxXPvfJC2GUme4Zvaza9a7fOsEn/REkTwv5oULM8EVEUFKkCwyWsQZA49DpssZegxDkoZegxoFDKt0WGW0hW5RJJA0uKJnK4QJDIkLp4uFFMbvw "Wolfram Language (Mathematica) – Try It Online")
Thanks to @J42161217 for pointing out that `Tr[1^list]` is a 1-character-shorter alternative to `Length@list`.
[Answer]
# [Retina](https://github.com/m-ender/retina/wiki/The-Language), 76 bytes
```
\d+
*_:$&*
+`_=_
=
=_
<
_=
>
[_:=]
Lw$`(.)(?>(\1)|(?<-2>.))*
_$#2*
O^`
1G`
```
[Try it online!](https://tio.run/##NYw9C8IwGIT391ccWCWtWJo0H69i6ugiuLhZTQQdXBxEcPG/15AqHA833HPP2@v@uMhhKg4R0Q/9dU5VWBWziuYx@ECeEtYUPHV0DCt/Itq9iyjqUmw60cvyIzbrherqsqwoFBNV0f4cSW4jDYPS@Id0C82/GAXT5NIQWzCDNViCW7glnIazcAo2dQnrYFPXsA2Mg1lmWhhDrPKe835kctNJky2brZHpQX4B "Retina – Try It Online") Link includes test suite. Takes input as a `=`-separated list of integers (I could have used space or `,` but `=` was prettier) but the test suite adapts the space-separated test cases to work with the code. Explanation:
```
\d+
*_:$&*
```
Convert each integer to unary in duplicate.
```
+`_=_
=
```
Subtract pairs of adjacent integers.
```
=_
<
_=
>
```
Note whether adjacent integers were ascending or descending.
```
[_:=]
```
Delete everything else.
```
Lw$`(.)(?>(\1)|(?<-2>.))*
_$#2*
```
Find runs of notes. Runs can be interrupted by a reverse run as long as the run does not return to its starting finger; this is achieved via the .NET regexp balancing group construct `(?<-2>.)`. The run always starts with an ascending or descending pair which requires two fingers; since one finger is added at the end to handle the degenerate case where only one note is played, only one finger is added here, resulting in the number of additional fingers required for this run. The `w` modifier allows all valid runs to be collected.
```
O^`
```
Sort the longest number of fingers to the start.
```
1G`
```
Consider only the longest number of fingers. (I would count the longest fingers using `\G.?` but that doesn't work for some reason.)
```
```
Convert back to decimal and add one for the starting finger.
[Answer]
# [Husk](https://github.com/barbuz/Husk/wiki/Commands), 11 [bytes](https://github.com/barbuz/Husk/wiki/Codepage)
```
→▲mamΣQm±Ẋ-
```
Port of [*@ExpiredData*'s 05AB1E answer](https://codegolf.stackexchange.com/a/203742/52210), so make sure to upvote him!
[Try it online.](https://tio.run/##yygtzv7//1HbpEfTNuUm5p5bHJh7aOPDXV26////j7Yw07Gw0LEw0bEw1LEw1jG31DE30TE30zE30jEDsg11zMx1zIBsEx0zAx1Tcx1TSzBppmNqGgsA)
**Explanation:**
```
         Ẋ   # For each overlapping pair of the (implicit) argument:
          -  #  Subtract them from one another
       m     # Then map over each forward difference:
        ±    #  And take its signum (-1 if <0; 0 if 0; 1 if >0)
      Q      # Get all sublists of those
    m        # Map over each sublist:
     Σ       #  And take its sum
  m          # Map over each sum:
   a         #  And take its absolute value
 ▲           # Then take the maximum of this list
→            # Increase it by 1
             # (after which it is output implicitly as result)
```
[Answer]
# [C#], 86 bytes
```
s.Aggregate(0,(i,y)=>{var t=z>y?++i:z<y?--i:i;h[i]=1;z=y;return t;});return h.Count();
```
[Try It online!](https://tio.run/##bVDBaoNAEL37FYP0oGQjxkRjYkwoKYWWQg899JDmILLVhbCGdW0x4rfb2bg2Fgo@Z2bnvTe7k5bTtGTdVyKA8XMlZxADp9@HIzQQBgTCELFAzBBzAssVAusl9pYegUDV2AuWCFVjL3AJ@Fj7Kx2R6/vQRsbvGG88xtO2obYdohqjRrraPtD2Q1TjZn9s5yPbBUoX4Q0@0n1X5@4f2WIk89D5BkW78coRr98W0c/RcU4Gw0F37iXwwFLJCp6IesO4VDS5tez@DhVy3D4Vmv5Y8VQRD0fyn/L61yZWSSAncLEh3oLRdKVzn2WCZomklkssRmo73jbKXMaXbb2bTNj6sql30ylbsyg/sGM8iy5xHQkqK8FBRq095LmzLyou8aIdHhqfhaBJmlt6IQi9F9toDICzsz/RRKhnwfAogH3By@JEnXfBJH1hnFp35pNSrQGaNykYz5zngnHLJGBe92e3H/y1kldKA8LCIwL4VTZgx0T7tvsB)
My goal was to do this using the Linq Aggregate function, but surely not the best way.
[Answer]
# [J](http://jsoftware.com/), ~~36~~ 18 bytes
Bubbler managed to shave off a full 50% off my program with a few nice tricks and some deft handling of trains.
```
0#@=@(,+/\)2*@-/\]
```
[Try it online!](https://tio.run/##jY3NCsIwEITvPsWgoIlt0yTNn0ElKHgSD16t1x58hz573aYqCB6E3WFg5tt9DHOBVYddxAolJCJtJXC8nk@DXKRdYmVRt1yvU1W394HPLgcBxYq9qKutqLksb5EKr3xKY8HecWLfBf6rsSxJxy@J/VnrBaMi7yMfOmjzmVkH08CE11gNK7ORlASHEBAMgkJo4DfwBt7BazjyCs7DkTdwEtbDbrI6WDvSOhMhE5MSTWdk5lzmJqUb6gk "J – Try It Online")
The dyadic verb `*@-/\` takes a prefix size and a list, then computes the sign of the difference of the list (from inserting `-` between elements of the list). In this case, it is used as `2 *@-/\ ]`, which is a fork that takes a list and gives a list of the signs of differences between adjacent elements. (This is an idiom I hoped would exist but couldn't come up with myself.)
Letting `d` denote this result, the rest of the train is `0 #@=@(, +/\) d`, which is equivalent to `# = (0 , +/\ d)`. First, `+/\ d` computes the sum of each prefix of `d`, which like in the previous answer gives a relative finger numbering of all notes of the song. But, since the differences only give relative differences, the fingering of the first note is not present, so zero is prefixed to the list with the `,` dyad.
For some reason I thought I had to take one more than the difference of the maximum and minimum values of this array to count the number of necessary fingers, despite the fact all I had to do was count the number of distinct elements, which would be `# ~.` of the array. However, J has a one-character shorter idiom for this. The `=` monad gives an array with one row per unique element (the rows indicating where that element appears), and the `#` monad counts the number of rows, hence the number of necessary fingers.
---
The original 36-byte solution:
```
1:+(>./-<./)@(0&,)@(+/\)@(}.(*@-)}:)
```
[Try it online!](https://tio.run/##PYzBCsIwEETvfsXgwTa2TZM02WyDSkHw5Klnzzn4D/32uKYizD4GljfvctRoMq4JDXoYJLlB474@H8Wmrr3pcbjoUS2tOfXCbnwJN92el0FtSRVVMpz/55DhJ3j@JTgEU4uRDxOYwR5swRPijOgRCdGBpFtQBEn3IIMQEeZKQghf21WDq7FTbJkx1aPq7ZQN@wE "J – Try It Online")
This is a monadic verb that takes a list of numbers.
`*@-` takes the sign of the difference of two numbers. Since `}.` and `}:` cut off the head and tail of a list, the fork `}. (*@-) }:` constructs a list of signs of differences between consecutive elements of the given list.
This is composed with `+/\`, which takes the sums of the prefixes of the list, giving relative finger numbers through the song. This is prefixed with 0 using `0&,` since the song starts with some finger.
This is composed with `>./ - <./`, which takes the difference of the maximum and the minimum of these relative finger numbers, and then the `1:+` fixes a fencepost error: we start counting fingers from 1.
[Answer]
# [PHP](https://php.net/), ~~66~~ 59 bytes
```
for(;$b=$argv[++$i];$a=$b)$f[$n+=$b<=>$a]=1;echo count($f);
```
[Try it online!](https://tio.run/##HcZBDsIgEAXQq7iYRRs2ojAzDUUP0nRBG7FuCmnU63@Jm5dXt4rxXpu5HF2gJVI6nt/JGHrNgVKkpac80W7axnijNEcbHutWTmv57O@Och8AKEMV6qAWeoUMEAdhyAXcbsECbnfgM7zAD38Z3v8A "PHP – Try It Online")
Pretty straightforward: uses a index counter `$n` which is incremented each time a superior note is to play and decremented when a lower note, with the PHP comparison operator `<=>`. Then an array is set to the value `1` at this index. At the end count the array.
EDIT: saved 7 bytes removing the test on `$i`, we actually don't care if the starting value for `$n` is `0` or `1`
[Answer]
# [T-SQL](https://www.microsoft.com/sql-server), 125 bytes
Input is taken from table `T` (according to the [Code Golf rules for SQL](https://codegolf.meta.stackexchange.com/a/5341/78876)): column `P` represents position and column `V` represents the value.
```
SELECT MAX(S)-MIN(S)+1FROM(SELECT*,SUM(ISNULL(X,0))OVER(ORDER BY P)S FROM(SELECT*,SIGN(V-LAG(V)OVER(ORDER BY P))X FROM T)A)B
```
[DB Fiddle](https://dbfiddle.uk/?rdbms=sqlserver_2019&fiddle=536abbf32ea54146f0a13e99434ac400)
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 8 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
Port of [Expired Data's solution](https://codegolf.stackexchange.com/a/203742/58974).
```
äÎãx rÔÄ
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=5M7jeCBy1MQ&input=Wzg2LCA4OCwgODQsIDgxLCA4MywgNzksIDc0LCA3NiwgNzIsIDY5LCA3MSwgNjcsIDYyLCA2NCwgNjAsIDU3LCA1OSwgNTcsIDU2LCA1NV0)
[Answer]
# [Stax](https://github.com/tomtheisen/stax), 11 [bytes](https://github.com/tomtheisen/stax/blob/master/docs/packed.md#packed-stax)
```
£→▓J←εm@φ┤»
```
[Run and debug it](https://staxlang.xyz/#p=9c1ab24a1bee6d40edb4af&i=[0+0+0+0]%0A[43+48+48+48+52+50+48+50]%0A[86+88+84+81+83+79+74+76+72+69+71+67+62+64+60+57+59+57+56+55]%0A[82+79+78+76+78+76+74+73+70+67+66+64+66+64+62+61]&a=1&m=2)
Unpacked, ungolfed, and commented, it looks like this.
```
                                    input:[43 48 48 48 52 50 48 50]
:-      get pairwise differences    main:[5, 0, 0, 4, -2, -2, 2] 
Z+      prepend a 0                 main:[0, 5, 0, 0, 4, -2, -2, 2] 
{:+m    map: numeric sign           main:[0, 1, 0, 0, 1, -1, -1, 1] 
:+      prefix sums                 main:[0, 1, 1, 1, 2, 1, 0, 1] 
:s^     max - min + 1               main:3 
```
[Run this one](https://staxlang.xyz/#c=++++%09++++++++++++++++++++++++%09input%3A[43+48+48+48+52+50+48+50]%0A%3A-++%09get+pairwise+differences%09main%3A[5,+0,+0,+4,+-2,+-2,+2]+%0AZ%2B++%09prepend+a+0+++++++++++++%09main%3A[0,+5,+0,+0,+4,+-2,+-2,+2]+%0A%7B%3A%2Bm%09map%3A+numeric+sign+++++++%09main%3A[0,+1,+0,+0,+1,+-1,+-1,+1]+%0A%3A%2B++%09prefix+sums+++++++++++++%09main%3A[0,+1,+1,+1,+2,+1,+0,+1]+%0A%3As%5E+%09max+-+min+%2B+1+++++++++++%09main%3A3+%0A&i=[0+0+0+0]%0A[43+48+48+48+52+50+48+50]%0A[86+88+84+81+83+79+74+76+72+69+71+67+62+64+60+57+59+57+56+55]%0A[82+79+78+76+78+76+74+73+70+67+66+64+66+64+62+61]&a=1&m=2)
]