• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Playing songs in a sequencer one after another

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Say I have an entire directory full of midi songs, and I want to add them to a sequencer and play them one after another in order, how would I go about doing that?

Here is the class if you need it to help me,
I'm new here and I don't know if there are code tags or not (I'm mobile if it makes a difference)

 
Marshal
Posts: 79969
396
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch
Please post the class here; many people are reluctant to download things from unfamiliar sites.
 
Kyle Kerlew
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you, assuming there are code tags, how do you use them?
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here you go https://coderanch.com/how-to/java/UseCodeTags
 
Campbell Ritchie
Marshal
Posts: 79969
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My, didn't that website mangle your code. That is what happens when you have the wrong line end combination. I have tried to sort it out, by copying to an IDE and using find‑and‑replace and ctrl‑I to sort out the indentation. I hope I have got it right.
Why are you using a static method for stop and instance methods for everything else?
 
Kyle Kerlew
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
stop is acessed statically outside the class

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just thinking out loud. I've never done this before, which is probably why the question made me curious enough to take a look.

Playing a list of files requires implementing the MetaEventListener interface so that you are notified of the end-of-track meta event (event.getType() == 47). This is probably the main question you have.

Rather than using a switch structure, you might consider employing a factory pattern, with a static method like public static MidiPlayer getMidiPlayer(File midi). If "midi" is a file, the factory returns an instance of a MidiFilePlayer. If "midi" is a directory, the factory returns an instance of a MidiDirectoryPlayer class that knows how to cycle through a list of files, randomly or in some order, using MidiFilePlayer. Otherwise, your play() method might smell.

Since the Sequencer start() method is asynchronous, you'd want to think about how to handle the end of file event. For example, you might implement or extend MidiFilePlayer to allow for a synchronous play() method, where the play() method itself waits for the end-of-file event before returning. Or you could provide a playAndWait() method. Otherwise, the caller will need to be able to add itself to the sequencer's MetaEventListener list. Or MidiFilePlayer could emit an end-of-file event. Options options options.
 
Campbell Ritchie
Marshal
Posts: 79969
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch Mark Koontz
 
I got this tall by not having enough crisco in my diet as a kid. This ad looks like it had plenty of shortening:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic