the goal
תנו רבנן אין עומדין להתפלל לא מתוך עצבות ולא מתוך עצלות ולא מתוך שחוק ולא מתוך שיחה ולא מתוך קלות ראש ולא מתוך דברים בטלים אלא מתוך שמחה של מצוה
On the topic of proper preparation for prayer, the Sages taught: One may neither stand to pray from an atmosphere of sorrow nor from an atmosphere of laziness, nor from an atmosphere of laughter, nor from an atmosphere of conversation, nor from an atmosphere of frivolity, nor from an atmosphere of purposeless matters. Rather, one should approach prayer from an atmosphere imbued with the joy of a mitzva.
ושבחתי אני את השמחה שמחה של מצוה ולשמחה מה זה עושה זו שמחה שאינה של מצוה ללמדך שאין שכינה שורה לא מתוך עצבות ולא מתוך עצלות ולא מתוך שחוק ולא מתוך קלות ראש ולא מתוך שיחה ולא מתוך דברים בטלים אלא מתוך דבר שמחה של מצוה שנאמר ועתה קחו לי מנגן והיה כנגן המנגן ותהי עליו יד ה׳ אמר רב יהודה וכן לדבר הלכה אמר רבא וכן לחלום טוב
Similarly, “So I commended mirth,” that is the joy of a mitzva. “And of mirth: What does it accomplish?” that is joy that is not the joy of a mitzva. The praise of joy mentioned here is to teach you that the Divine Presence rests upon an individual neither from an atmosphere of sadness, nor from an atmosphere of laziness, nor from an atmosphere of laughter, nor from an atmosphere of frivolity, nor from an atmosphere of idle conversation, nor from an atmosphere of idle chatter, but rather from an atmosphere imbued with the joy of a mitzva. As it was stated with regard to Elisha that after he became angry at the king of Israel, his prophetic spirit left him until he requested: “But now bring me a minstrel; and it came to pass, when the minstrel played, that the hand of the Lord came upon him” (II Kings 3:15). Rav Yehuda said: And, so too, one should be joyful before stating a matter of halakha. Rava said: And, so too, one should be joyful before going to sleep in order to have a good dream.

ללמדך שאין השכינה שורה לא מתוך עצלות ולא מתוך עצבות ולא מתוך שחוק ולא מתוך קלות ראש ולא מתוך דברים בטלים אלא מתוך דבר שמחה של מצוה שנאמר ועתה קחו לי מנגן והיה כנגן המנגן ותהי עליו יד ה׳

The Gemara adds: Incidentally, this serves to teach you that the Divine Presence rests upon an individual neither from an atmosphere of sadness, nor from an atmosphere of laziness, nor from an atmosphere of laughter, nor from an atmosphere of frivolity, nor from an atmosphere of idle conversation, nor from an atmosphere of idle chatter, but rather from an atmosphere imbued with the joy of a mitzva.As it is stated with regard to Elisha, after he became angry at the king of Israel, his prophetic spirit left him until he requested: “But now bring me a minstrel; and it came to pass when the minstrel played, that the hand of the Lord came upon him” (II Kings 3:15).

(א) מִיסוֹדֵי הַדָּת לֵידַע שֶׁהָאֵל מְנַבֵּא אֶת בְּנֵי הָאָדָם. וְאֵין הַנְּבוּאָה חָלָה אֶלָּא עַל חָכָם גָּדוֹל בַּחָכְמָה, גִּבּוֹר בְּמִדּוֹתָיו, וְלֹא יְהֵא יִצְרוֹ מִתְגַּבֵּר עָלָיו בְּדָבָר בָּעוֹלָם אֶלָּא הוּא מִתְגַּבֵּר בְּדַעְתּוֹ עַל יִצְרוֹ תָּמִיד. וְהוּא בַּעַל דֵּעָה רְחָבָה נְכוֹנָה עַד מְאֹד. אָדָם שֶׁהוּא מְמֻלָּא בְּכָל הַמִּדּוֹת הָאֵלּוּ שָׁלֵם בְּגוּפוֹ, כְּשֶׁיִּכָּנֵס לַפַּרְדֵּס וְיִמָּשֵׁךְ בְּאוֹתָן הָעִנְיָנִים הַגְּדוֹלִים הָרְחוֹקִים, וְתִהְיֶה לוֹ דֵּעָה נְכוֹנָה לְהָבִין וּלְהַשִּׂיג וְהוּא מִתְקַדֵּשׁ וְהוֹלֵךְ וּפוֹרֵשׁ מִדַּרְכֵי כְּלַל הָעָם הַהוֹלְכִים בְּמַחֲשַׁכֵּי הַזְּמַן, וְהוֹלֵךְ וּמְזָרֵז עַצְמוֹ וּמְלַמֵּד נַפְשׁוֹ שֶׁלֹּא תִּהְיֶה לוֹ מַחֲשָׁבָה כְּלָל בְּאֶחָד מִדְּבָרִים בְּטֵלִים וְלֹא מֵהַבְלֵי הַזְּמַן וְתַחְבּוּלוֹתָיו, אֶלָּא דַּעְתּוֹ פְּנוּיָה תָּמִיד לְמַעְלָה קְשׁוּרָה תַּחַת הַכִּסֵּא לְהָבִין בְּאוֹתָן הַצּוּרוֹת הַקְּדוֹשׁוֹת הַטְּהוֹרוֹת, וּמִסְתַּכֵּל בְּחָכְמָתוֹ שֶׁל הַקָּדוֹשׁ בָּרוּךְ הוּא כֻּלָּהּ מִצּוּרָה רִאשׁוֹנָה עַד טַבּוּר הָאָרֶץ וְיוֹדֵעַ מֵהֶן גָּדְלוֹ, מִיָּד רוּחַ הַקֹּדֶשׁ שׁוֹרָה עָלָיו. וּבְעֵת שֶׁתָּנוּחַ עָלָיו הָרוּחַ תִּתְעָרֵב נַפְשׁוֹ בְּמַעֲלַת הַמַּלְאָכִים הַנִּקְרָאִים אִישִׁים וְיֵהָפֵךְ לְאִישׁ אַחֵר וְיָבִין בְּדַעְתּוֹ שֶׁאֵינוֹ כְּמוֹת שֶׁהָיָה אֶלָּא שֶׁנִּתְעַלָּה עַל מַעֲלַת שְׁאָר בְּנֵי אָדָם הַחֲכָמִים, כְּמוֹ שֶׁנֶּאֱמַר בְּשָׁאוּל (שמואל א י ו) "וְהִתְנַבִּיתָ עִמָּם וְנֶהְפַּכְתָּ לְאִישׁ אַחֵר":

(1) It is a fundamental part of religion to acknowledge that God bestows prophecy upon the sons of men. But prophecy does not descend1Nedarim, 35; Pesahim, 66; Shabbat, 30. C. G. save upon a wise man, eminent in wisdom, of sterling character, never subdued by worldly passion, but conquering it by an ever-present will-power, broadminded and settled to the highest degree. A man, endowed with all these moral principles, of sound physique, when he enters the Vineyard and is carried away with the current of these great and remote subjects, and possessed of a mind ready to understand and attain, he continuing to gain in saintliness, separated from the general public which follows the dark paths of the times, continuing to take care of himself, training his soul to heed no thought in idle affairs nor in the vanities and phantasies of the time, but his mind be constantly ready and directed Upward, connected to the Throne Beneath, to understand the Holy and Pure Intelligences and to penetrate the scope of Wisdom of the Holy One, blessed is He! from the First Intelligence even unto the summit of the earth to know from them His greatness —immediately the Holy Spirit will rest upon him. And, when the Spirit will rest upon him his soul will be mingling with the Angels of the degree of the Sphere called Men, and will be transformed into another being, and will understand his own intelligence that he is not as he was, but that he was elevated above the degree of other wise sons of man, as it is said of Saul: "And thou shalt prophesy among them and thou shalt be turned into another man" (I Sam. 10.6).