Further data driven sequences for Sonic Pi

I liked @davanzaldi External API driven sequence, and thought it would be fun to look at other data sequences with Sonic Pi. I looked at the Transport For London Site and there are some free datasets there.
I chose the passenger numbers entering three stations durning a weekday and on a Saturday in comparison and used live loops to use the data to control a note pitch and amplitude for each one.
The sequence runs continually at different rates. A slow rate shows the build up of passengers in the morning and the falloff at night with different peaks.
This is just a crude first play. The code could be simplified and done more effectively, but it was fun for a quick play.

#Tube Day. A day in the life of three London Tube Stations by Robin Newman Oct 2021
#uses datasets for the number of passengers tapping in at each station every 15 minutes
# I normalise the data in range 0 to 1 for each set and use it to adjust the frequency
#and volume of the note being played.
#the sets are played at a range of bpm from 20 to 480 then back down again
#data sets from https://tfl.gov.uk/info-for/open-data-users/our-open-data?intcmp=3671#on-this-page-10
use_debug false
#time data
t=(ring "0200-0215", "0215-0230", "0230-0245", "0245-0300",\
   "0300-0315", "0315-0330", "0330-0345", "0345-0400",\
   "0400-0415", "0415-0430", "0430-0445", "0445-0500",\
   "0500-0515", "0515-0530", "0530-0545", "0545-0600",\
   "0600-0615", "0615-0630", "0630-0645", "0645-0700",\
   "0700-0715", "0715-0730", "0730-0745", "0745-0800",\
   "0800-0815", "0815-0830", "0830-0845", "0845-0900",\
   "0900-0915", "0915-0930", "0930-0945", "0945-1000",\
   "1000-1015", "1015-1030", "1030-1045", "1045-1100",\
   "1100-1115", "1115-1130", "1130-1145", "1145-1200",\
   "1200-1215", "1215-1230", "1230-1245", "1245-1300",\
   "1300-1315", "1315-1330", "1330-1345", "1345-1400",\
   "1400-1415", "1415-1430", "1430-1445", "1445-1500",\
   "1500-1515", "1515-1530", "1530-1545", "1545-1600",\
   "1600-1615", "1615-1630", "1630-1645", "1645-1700",\
   "1700-1715", "1715-1730", "1730-1745", "1745-1800",\
   "1800-1815", "1815-1830", "1830-1845", "1845-1900",\
   "1900-1915", "1915-1930", "1930-1945", "1945-2000",\
   "2000-2015", "2015-2030", "2030-2045", "2045-2100",\
   "2100-2115", "2115-2130", "2130-2145", "2145-2200",\
   "2200-2215", "2215-2230", "2230-2245", "2245-2300",\
   "2300-2315", "2315-2330", "2330-2345", "2345-2400",\
   "0000-0015", "0015-0030", "0030-0045", "0045-0100",\
   "0100-0115", "0115-0130", "0130-0145", "0145-0200")
#kennington saturday
kns=(ring 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\
     0, 0, 0, 0, 2, 7, 9, 7, 5, 6, 5, 6,\
     5, 8, 9, 10, 13, 23, 24, 12, 22, 35, 36, 26,\
     37, 55, 52, 52, 63, 93, 95, 105, 101, 100, 91, 130,\
     145, 153, 145, 161, 165, 138, 198, 265, 269, 230, 245, 228,\
     190, 207, 233, 255, 225, 187, 173, 178, 167, 168, 178, 153,\
     135, 144, 152, 170, 149, 122, 59, 24, 4, 13, 18, 19,\
     25, 17, 10, 1, 2, 1, 0, 0, 0, 0, 0, 0)
kxs=(ring 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\
     #kingscross saturday
     89, 91, 108, 111, 146, 183, 225, 253, 303, 409, 430, 496,\
     540, 780, 895, 1073, 1239, 1580, 1742, 1864, 2027, 2301, 2351, 2388,\
     2430, 2531, 2483, 2570, 2503, 2450, 2327, 2397, 2358, 2339, 2167, 2114,\
     2088, 2096, 2006, 2001, 1954, 1933, 1896, 1938, 1966, 2024, 1949, 1988,\
     2081, 2159, 2076, 2089, 2087, 2169, 2173, 2084, 1792, 1610, 1511, 1472,\
     1403, 1341, 1283, 1233, 1209, 1153, 1180, 1165, 1094, 974, 923, 889,\
     890, 954, 920, 807, 621, 452, 315, 262, 242, 232, 168, 92)
#waterloo saturday
wls=(ring 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\
     30, 36, 41, 37, 70, 105, 136, 182, 243, 297, 304, 374,\
     445, 579, 634, 718, 817, 955, 1002, 1077, 1146, 1277, 1305, 1386,\
     1415, 1583, 1606, 1629, 1652, 1812, 1819, 1879, 1944, 2012, 1871, 1786,\
     1639, 1589, 1510, 1565, 1531, 1542, 1487, 1585, 1625, 1695, 1697, 1802,\
     1870, 1981, 2008, 2114, 2133, 2145, 1913, 1894, 1799, 1724, 1525, 1393,\
     1247, 1185, 1044, 964, 881, 829, 744, 803, 860, 910, 835, 786,\
     713, 727, 686, 627, 518, 423, 314, 239, 183, 169, 115, 69)
#kennington weekday
knw=(ring 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\
     0, 11, 16, 23, 34, 48, 58, 75, 99, 135, 176, 228,\
     286, 342, 344, 300, 235, 197, 154, 117, 91, 90, 82, 69,\
     63, 68, 67, 67, 67, 71, 67, 68, 67, 68, 65, 65,\
     64, 64, 64, 63, 64, 69, 70, 79, 91, 110, 108, 125,\
     132, 146, 131, 134, 127, 123, 102, 94, 84, 72, 61, 56,\
     50, 46, 41, 40, 38, 38, 34, 35, 36, 34, 29, 27,\
     28, 29, 27, 22, 16, 9, 4, 1, 0, 0, 0, 0)
#kingscross weekday
kxw=(ring 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18,\
     25, 30, 60, 81, 173, 279, 475, 642, 823, 1437, 2043, 2533,\
     2883, 3464, 3598, 3472, 3049, 2648, 2178, 1907, 1769, 1769, 1705, 1519,\
     1366, 1320, 1366, 1387, 1333, 1354, 1328, 1295, 1241, 1250, 1263, 1264,\
     1217, 1131, 1116, 1199, 1274, 1324, 1362, 1518, 1586, 1641, 1666, 2055,\
     2344, 2596, 2530, 2587, 2497, 2551, 2304, 2024, 1649, 1489, 1259, 1214,\
     1160, 1127, 1012, 875, 805, 830, 914, 897, 733, 631, 597, 639,\
     588, 482, 356, 303, 254, 175, 74, 12, 0, 0, 0, 0)
#waterloo weekday
wlw=(ring 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\
     3, 26, 41, 56, 194, 483, 898, 1363, 1984, 2716, 3949, 5226,\
     6294, 6887, 7242, 7031, 5904, 4453, 3002, 2291, 1892, 1841, 1635, 1449,\
     1314, 1286, 1249, 1252, 1265, 1284, 1225, 1196, 1148, 1161, 1120, 1089,\
     1044, 1043, 1022, 1025, 1037, 1086, 1140, 1240, 1324, 1437, 1505, 1730,\
     1928, 2243, 2415, 2611, 2546, 2492, 2253, 2013, 1651, 1398, 1130, 978,\
     840, 801, 723, 671, 614, 618, 652, 709, 667, 753, 767, 685,\
     538, 484, 449, 390, 288, 162, 63, 13, 0, 0, 0, 0)
#max data values for each station (saturdays)
knsm= kns.max
kxsm = kxs.max
wlsm = wls.max
l=knw.length #data lengths all the same form both w and s
#max data values for each station 9wqeekdays)
knwm=knw.max
kxwm=kxw.max
wlwm=wlw.max
#select data to use
if get(:day)=="Weekday"
  kn=knw;kx=kxw;wl=wlw
  knm=knwm;kxm=kxwm;wlm=wlwm
else
  kn=kns;kx=kxs;wl=wls
  knm=knsm;kxm=kxsm;wlm=wlsm
end
#cycle trhouhg data sets at varying speeds (bpm)
live_loop :speed do
  set :day,"Weekday" #first weekday data
  set :bpm ,(ring 20,40,90,180,400).reflect.take(8).tick
  use_bpm get(:bpm)
  sleep l*0.125
  set :day,"Saturday" #then saturday data
  sleep l*0.125
end

with_fx :gverb, room: 20, mix: 0.7 do #add some gverb
  live_loop :kennington do
    use_bpm get(:bpm)
    use_synth :mod_dsaw
    puts "Day: #{get(:day)} Time: #{t.tick} bpm #{current_bpm}"
    play note(:c2)+(30*(kn.look/knm.to_f)).to_i,amp: kn.look/knm.to_f,attack: 0.1,release: 0.5,pan: -1
    sleep 0.125
  end
  live_loop :kingscross do
    use_bpm get(:bpm)
    use_synth :tb303
    tick
    play note(:c2)+(30*(kx.look/kxm.to_f)).to_i,amp: kx.look/kxm.to_f,attack: 0.1,release: 0.5,pan: 1
    sleep 0.125
  end
  live_loop :waterloo do
    use_bpm get(:bpm)
    use_synth :zawa
    tick
    play note(:c2)+(30*(wl.look/wlm.to_f)).to_i,amp: wl.look/wlm.to_f,attack: 0.1,release: 0.5  ,pan: 0
    sleep 0.125
  end
end

EDITED error for Waterloo note. should now be correct

3 Likes