Answers.Body: <p>I am hoping that someone else will post an answer better written than this one.</p>
  <p>One application of double-ended queues to real-life musical applications is to make sure that an internet-based music playlist or internet based radio station does not play a song that was one of the most recent 10, 20, or 30 songs you heard.</p>
  <pre class="lang-python prettyprint-override"><code>from collections import deque
  import random  
  
  class SongGetter:  
      # create a double-ended queue   
      forbidden_songs = deque()
      
      @classmethod
      def get_song_old_imp(cls):
          &quot;&quot;&quot;
             Faux implementation of how some internet radio service
             or playlist shuffler currently gets music
  
             This is a temporary place-holder of the code to be wrapped
          &quot;&quot;&quot;
          songs = [
              &quot;THE OFT REPEATED SONG&quot;,
              &quot;song1&quot;,
              &quot;song2&quot;,
              &quot;THE OFT REPEATED SONG&quot;,
              &quot;THE OFT REPEATED SONG&quot;,
              &quot;THE OFT REPEATED SONG&quot;,
              &quot;song3&quot;,
              &quot;song4&quot;,
              &quot;song5&quot;,
              &quot;THE OFT REPEATED SONG&quot;,
              &quot;THE OFT REPEATED SONG&quot;,
              &quot;THE OFT REPEATED SONG&quot;,
              &quot;song9&quot;,
              &quot;song10&quot;,
              &quot;THE OFT REPEATED SONG&quot;,
              &quot;THE OFT REPEATED SONG&quot;,
              &quot;song11&quot;,
              &quot;THE OFT REPEATED SONG&quot;,
              &quot;THE OFT REPEATED SONG&quot;,
              &quot;song12&quot;,
              &quot;THE OFT REPEATED SONG&quot;,
              &quot;THE OFT REPEATED SONG&quot;,
              &quot;song13&quot;,
              &quot;THE OFT REPEATED SONG&quot;,
              &quot;THE OFT REPEATED SONG&quot;,
              &quot;THE OFT REPEATED SONG&quot;,
              &quot;THE OFT REPEATED SONG&quot;,
              &quot;song14&quot;
          ]
          try:
              song = songs[cls.old_song_idx]
          except IndexError:
              cls.old_song_idx = 0 
              song = songs[cls.old_song_idx]
              
          cls.old_song_idx += 1
          return song
              
      old_song_idx = 0 
          
      @classmethod
      def get_song_new_imp(cls):  
          &quot;&quot;&quot;
          New Implementation of `Get a Song`
          ------------------------------------------
          If
              the new song is something we've listened to recently,
          then
              get a different song 
          &quot;&quot;&quot;   
          #      
          return cls.impimp()
          
      @classmethod
      def second_impimp(cls):
          &quot;&quot;&quot;
            
          &quot;&quot;&quot;
      
          next_song = cls.get_song_old_imp()
          
          while next_song in cls.forbidden_songs:
              next_song = cls.get_song_old_imp()
              
          cls.forbidden_songs.append(next_song)
          
          # unban the oldest song in the set of all banned songs 
          cls.forbidden_songs.popleft()
              
          return next_song
          
      
      @classmethod
      def first_impimp(cls):  
          &quot;&quot;&quot;
          What to do the first time Starbucks Coffee opens in the morning
          or the &quot;radio&quot;/internet playlist begins 
          &quot;&quot;&quot;   
          # get a song the old way you did last month        
          next_song = cls.get_song_old_imp()
          
          while next_song in cls.forbidden_songs:
              next_song = cls.get_song_old_imp()
              
          cls.forbidden_songs.append(next_song)
          
          if len(cls.forbidden_songs) &gt;= 10:
              # if we have banned (forbidden) 10 or more songs today
              # we need to start un-banning the oldest banned song 
              cls.impimp = cls.second_impimp
              
          return next_song
          
      # `imp imp` is the `implementation of the implementation`
      impimp = first_impimp
              
     
  #####################################################333
  
  for _ in range(50):    
      song = SongGetter.get_song_new_imp()
      play(song)
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-05-28T01:46:06.863Z
Answers.LastActivityDate: 2023-05-28T01:46:06.863Z
Answers.UserDisplayName: Samuel Muldoon
Answers.Body: <p>Repeat signs, Segno, Coda, are all examples of linking of sections. The &quot;London Manuscript&quot; (<a href="https://imslp.org/wiki/Manuscript,_GB-Lbl_Add._MS_29987_(Various)" rel="nofollow noreferrer">https://imslp.org/wiki/Manuscript,_GB-Lbl_Add._MS_29987_(Various)</a>) even contains many directions &quot;when you get here jump to there&quot;, giving in fact a DAG rather than a list.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-05-29T19:41:22.963Z
Answers.LastActivityDate: 2023-05-29T19:41:22.963Z
Answers.UserDisplayName: Victor Eijkhout
Answers.Body: <p>Music is not my field, and I may be the least musical person you'd ever come across, but I remember that it was once a &quot;thing&quot; to play records backwards and look for satanic messages. Since you can iterate a doubly linked list from either end, such a list containing sufficiently short passages might serve for this.</p>
  <p>Oddly enough, I am <em>today</em> building a circular linked list in Python out of double linked nodes to serve as either a stack or queue.</p>
  <p>A DJ might find such a thing useful if the direction of iteration could be reversed at any moment.</p>
  <hr />
  <p>Welcome to Heaven. Here is your harp.
  Welcome to Hell. Here is your accordion.</p>
  <p>(source: Far Side comics)</p>
  <p>As a kid, my instrument was accordion (badly played).</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-05-30T10:42:52.900Z
Answers.Text: I think _badly played_ was unnecessary here.
Answers.UserDisplayName: Binary Worrier
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-05-29T17:42:15.173Z
Answers.LastActivityDate: 2023-05-29T17:42:15.173Z
Answers.UserDisplayName: Buffy
Answers.Body: <blockquote>
  <p>occasionally students who are interested in music ask instructors for how a double ended queue could be useful in the music industry.</p>
  </blockquote>
  <p>This is a rather unusual situation and I'm surprised it arises for you often enough to ask about it here. You might want to elaborate more on <em>why</em> this particular question comes up so often (I'd expect it to come up, say, once in a teaching career). Do your culinary students ask where double-ended queues (&quot;deques&quot;) show up in that field?</p>
  <p>If there's no obvious application you can think of for deques in music, it's OK to say &quot;there are no obvious applications I can think of for deques in music&quot; rather than scraping around a mostly empty barrel and stretching the truth to come up with something.</p>
  <p>Linked lists in general are low-level data structures primarily used in systems-level applications. Double-ended queues are even more specialized. They're basically unnecessary for most day to day, business application-level development. Most of the time, a simple array is sufficient, and most languages don't have deques built-in to the standard library (Java, Python and I think C++ and C# are exceptions that come to mind).</p>
  <p>With that in mind, the operating system running your musical applications is very probably using them, as well as potentially the software running whatever audio system you're using, but that's low-level and perhaps unsatisfying, since the data structure is probably not doing anything obviously <em>musical</em> here.</p>
  <p>Scoping appears to be necessary. &quot;Music programming&quot; is a large expanse ranging from extremely low-level DSP engineering all w to extremely high-level music creation applications like Audacity, Lilypond, Ableton, Cubase, Reaktor, etc. Middle-level applications like Max/MSP, Tidalcycles and Supercollider exist as well. Zooming out to &quot;the music industry&quot; is even broader, and linked lists and deques surely appear in operating systems of people working in the music industry (again, unsatisfying and vague, probably not what the asker wanted to hear).</p>
  <p>If your students are asking about music-making techniques that could use linked lists or deques, you could probably treat a linear song structure as a sequence of linked nodes, but this isn't too helpful or interesting (and would probably involve duplicate nodes). Deques can be used for rotating purposes, which might imply a looping structure of some sort, but since this is so unusual and we're breaking a sweat to come up with something, we'd better just admit it. An array would be just as useful for storing, looping and forward/reversing a musical piece, with the bonus of constant-time random access. A deque is appropriate when you want to dequeue or prepend nodes to the front of a structure in constant time.</p>
  <p>I'd suffice to say that deques are a fundamental data structure in the low-level systems world, and then ask the student which level of abstraction and what domain they're interested in (it could be they don't even care about music production, and just want to know whether a deque could be used in a playlist app, or something like that).</p>
  <p>When a strange, overly-broad question arises, it's important to follow up and ask for clarification to understand what prompted the question and determine the motivation of the asker. Once the scope is appropriately refined and the intent is obvious, a satisfying answer will be much easier to provide.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-05-31T19:59:21.780Z
Answers.LastActivityDate: 2023-05-31T20:27:20.840Z
Answers.LastEditDate: 2023-05-31T20:27:20.840Z
Answers.UserDisplayName: ggorlen
Body: <p>When teaching computer programming, occasionally students who are interested in music ask instructors for how a double ended queue could be useful in the music industry.</p>
  <p>What is a &quot;<em>real-world</em>&quot; or &quot;<em>real-life</em>&quot; application of double-ended queues and computer programming for people interested in music?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-05-28T02:35:56.763Z
Comments.Text: This is a very strange question, and my degrees are in computer science and in music. The best I can think of is some sort of chord generator utilizing the circle (well, spiral in this case) of fifths.
Comments.UserDisplayName: Ben I.
Tags: <code-example>
Title: What is a musical application of linked lists?
ThreadText: # What is a musical application of linked lists?
  
  (Asked by: username_0 on 2023-05-28)
  
  When teaching computer programming, occasionally students who are interested in music ask instructors for how a double ended queue could be useful in the music industry.
  
  What is a "*real-world*" or "*real-life*" application of double-ended queues and computer programming for people interested in music?
  
  **Tags:** code-example
  
  > **Comments:**
  > **username_1**: This is a very strange question, and my degrees are in computer science and in music. The best I can think of is some sort of chord generator utilizing the circle (well, spiral in this case) of fifths.  
  
  ---
  
  ## 4 answers
  
  ### Answer by username_5 on 2023-05-31. Score: 2
  
  > occasionally students who are interested in music ask instructors for how a double ended queue could be useful in the music industry.
  
  This is a rather unusual situation and I'm surprised it arises for you often enough to ask about it here. You might want to elaborate more on *why* this particular question comes up so often (I'd expect it to come up, say, once in a teaching career). Do your culinary students ask where double-ended queues ("deques") show up in that field?
  
  If there's no obvious application you can think of for deques in music, it's OK to say "there are no obvious applications I can think of for deques in music" rather than scraping around a mostly empty barrel and stretching the truth to come up with something.
  
  Linked lists in general are low-level data structures primarily used in systems-level applications. Double-ended queues are even more specialized. They're basically unnecessary for most day to day, business application-level development. Most of the time, a simple array is sufficient, and most languages don't have deques built-in to the standard library (Java, Python and I think C++ and C# are exceptions that come to mind).
  
  With that in mind, the operating system running your musical applications is very probably using them, as well as potentially the software running whatever audio system you're using, but that's low-level and perhaps unsatisfying, since the data structure is probably not doing anything obviously *musical* here.
  
  Scoping appears to be necessary. "Music programming" is a large expanse ranging from extremely low-level DSP engineering all w to extremely high-level music creation applications like Audacity, Lilypond, Ableton, Cubase, Reaktor, etc. Middle-level applications like Max/MSP, Tidalcycles and Supercollider exist as well. Zooming out to "the music industry" is even broader, and linked lists and deques surely appear in operating systems of people working in the music industry (again, unsatisfying and vague, probably not what the asker wanted to hear).
  
  If your students are asking about music-making techniques that could use linked lists or deques, you could probably treat a linear song structure as a sequence of linked nodes, but this isn't too helpful or interesting (and would probably involve duplicate nodes). Deques can be used for rotating purposes, which might imply a looping structure of some sort, but since this is so unusual and we're breaking a sweat to come up with something, we'd better just admit it. An array would be just as useful for storing, looping and forward/reversing a musical piece, with the bonus of constant-time random access. A deque is appropriate when you want to dequeue or prepend nodes to the front of a structure in constant time.
  
  I'd suffice to say that deques are a fundamental data structure in the low-level systems world, and then ask the student which level of abstraction and what domain they're interested in (it could be they don't even care about music production, and just want to know whether a deque could be used in a playlist app, or something like that).
  
  When a strange, overly-broad question arises, it's important to follow up and ask for clarification to understand what prompted the question and determine the motivation of the asker. Once the scope is appropriately refined and the intent is obvious, a satisfying answer will be much easier to provide.
  
  
  ---
  
  ### Answer by username_0 on 2023-05-28. Score: 1
  
  I am hoping that someone else will post an answer better written than this one.
  
  One application of double-ended queues to real-life musical applications is to make sure that an internet-based music playlist or internet based radio station does not play a song that was one of the most recent 10, 20, or 30 songs you heard.
  
  ```python
  from collections import deque
  import random  
  
  class SongGetter:  
      # create a double-ended queue   
      forbidden_songs = deque()
      
      @classmethod
      def get_song_old_imp(cls):
          """
             Faux implementation of how some internet radio service
             or playlist shuffler currently gets music
  
             This is a temporary place-holder of the code to be wrapped
          """
          songs = [
              "THE OFT REPEATED SONG",
              "song1",
              "song2",
              "THE OFT REPEATED SONG",
              "THE OFT REPEATED SONG",
              "THE OFT REPEATED SONG",
              "song3",
              "song4",
              "song5",
              "THE OFT REPEATED SONG",
              "THE OFT REPEATED SONG",
              "THE OFT REPEATED SONG",
              "song9",
              "song10",
              "THE OFT REPEATED SONG",
              "THE OFT REPEATED SONG",
              "song11",
              "THE OFT REPEATED SONG",
              "THE OFT REPEATED SONG",
              "song12",
              "THE OFT REPEATED SONG",
              "THE OFT REPEATED SONG",
              "song13",
              "THE OFT REPEATED SONG",
              "THE OFT REPEATED SONG",
              "THE OFT REPEATED SONG",
              "THE OFT REPEATED SONG",
              "song14"
          ]
          try:
              song = songs[cls.old_song_idx]
          except IndexError:
              cls.old_song_idx = 0 
              song = songs[cls.old_song_idx]
              
          cls.old_song_idx += 1
          return song
              
      old_song_idx = 0 
          
      @classmethod
      def get_song_new_imp(cls):  
          """
          New Implementation of `Get a Song`
          ------------------------------------------
          If
              the new song is something we've listened to recently,
          then
              get a different song 
          """   
          #      
          return cls.impimp()
          
      @classmethod
      def second_impimp(cls):
          """
            
          """
      
          next_song = cls.get_song_old_imp()
          
          while next_song in cls.forbidden_songs:
              next_song = cls.get_song_old_imp()
              
          cls.forbidden_songs.append(next_song)
          
          # unban the oldest song in the set of all banned songs 
          cls.forbidden_songs.popleft()
              
          return next_song
          
      
      @classmethod
      def first_impimp(cls):  
          """
          What to do the first time Starbucks Coffee opens in the morning
          or the "radio"/internet playlist begins 
          """   
          # get a song the old way you did last month        
          next_song = cls.get_song_old_imp()
          
          while next_song in cls.forbidden_songs:
              next_song = cls.get_song_old_imp()
              
          cls.forbidden_songs.append(next_song)
          
          if len(cls.forbidden_songs) >= 10:
              # if we have banned (forbidden) 10 or more songs today
              # we need to start un-banning the oldest banned song 
              cls.impimp = cls.second_impimp
              
          return next_song
          
      # `imp imp` is the `implementation of the implementation`
      impimp = first_impimp
              
     
  #####################################################333
  
  for _ in range(50):    
      song = SongGetter.get_song_new_imp()
      play(song)
  
  ```
  
  
  ---
  
  ### Answer by username_2 on 2023-05-29. Score: 0
  
  Repeat signs, Segno, Coda, are all examples of linking of sections. The "London Manuscript" (<https://imslp.org/wiki/Manuscript,_GB-Lbl_Add._MS_29987_(Various)>) even contains many directions "when you get here jump to there", giving in fact a DAG rather than a list.
  
  
  ---
  
  ### Answer by username_3 on 2023-05-29. Score: 0
  
  Music is not my field, and I may be the least musical person you'd ever come across, but I remember that it was once a "thing" to play records backwards and look for satanic messages. Since you can iterate a doubly linked list from either end, such a list containing sufficiently short passages might serve for this.
  
  Oddly enough, I am *today* building a circular linked list in Python out of double linked nodes to serve as either a stack or queue.
  
  A DJ might find such a thing useful if the direction of iteration could be reversed at any moment.
  
  ---
  
  Welcome to Heaven. Here is your harp.
  Welcome to Hell. Here is your accordion.
  
  (source: Far Side comics)
  
  As a kid, my instrument was accordion (badly played).
  
  > **Comments:**
  > **username_4**: I think _badly played_ was unnecessary here.  
  
  ---
  
  