No prophet is able to have prophecy at any time they want, rather they must concentrate their minds, be sitting happy, with a good heart and be isolated. For prophecy does not rest upon a person in a state of melancholy or in a state of laziness but rather [one must be] in a state of happiness. Therefore, the disciples of the prophets would have before them a harp, drum, flute, and a violin and then they would request prophecy. This is why it says (Samuel 1 10:5), "And they were attaining prophecy," meaning that they were going in the path of prophecy until they actually prophesied, like one would say so and so has risen [in stature.]
The Rambam is describing the state of mind that a person must be in to reach the level of prophecy. Most of these ideas come from the book of Samuel and Kings. For instance, it says in Samuel 1 10:5,
וּפָגַעְתָּ חֶבֶל נְבִאִים יֹרְדִים מֵהַבָּמָה וְלִפְנֵיהֶם נֵבֶל וְתֹף וְחָלִיל וְכִנּוֹר וְהֵמָּה מִתְנַבְּאִים:You will meet a band of prophets descending from the high place, and before them will be a psaltery and a drum, and a flute and a harp, and they will prophesies. (translation from Chabad.org)The Rambam concludes from this verse that these instruments are the ones used to help ease a person's state of mind. This, in turn, will allow a person who has reached a certain level of knowledge and closeness to G-D to attain prophecy.
Another verse, found in Kings 2 3:15, which teaches us this principle says,
וְעַתָּה קְחוּ לִי מְנַגֵּן וְהָיָה כְּנַגֵּן הַמְנַגֵּן וַתְּהִי עָלָיו יַד יְהֹוָה: "And now fetch me a musician." And it was that when the musician played, the hand of the Lord came upon him."(translation from Chabad.org)This verse is referring to Elisha the prophet being calmed by music after being agitated by the King of Israel. This verse clearly shows that a prophet must be in a clear state of mind, which is attained through music. Therefore, we can clearly see from Tanach (The Prophets) that the way a prophet can attain prophecy is by calming himself with music and clearing his mind so that he can focus on a connection with G-D.