This week's giveaway is in the JDBC forum.
We're giving away four copies of Java Database Connections & Transactions (e-book only) and have Marco Behler on-line!
See this thread for details.
Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Playing songs in a sequencer one after another  RSS feed

 
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)

 
Marshal
Posts: 64496
225
  • 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?
 
Campbell Ritchie
Marshal
Posts: 64496
225
  • 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

 
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: 64496
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch Mark Koontz
 
Bring me the box labeled "thinking cap" ... and then read this tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!