• Post Reply Bookmark Topic Watch Topic
  • New Topic

Playing songs in a sequencer one after another  RSS feed

 
Kyle Kerlew
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • 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)

 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thank you, assuming there are code tags, how do you use them?
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
stop is acessed statically outside the class

 
Mark Koontz
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch Mark Koontz
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!